CCrmInvoiceRecurringRestProxy::processEvent

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmInvoiceRecurringRestProxy
  4. processEvent
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmInvoiceRecurringRestProxy
  • Вызов: CCrmInvoiceRecurringRestProxy::processEvent
static function processEvent(array $arParams, array $arHandler)
{
	$eventName = mb_strtolower($arHandler['EVENT_NAME']);
	$event = $arParams[0];
	$eventFields = [];
	if ($event instanceof Main\Event)
	{
		$eventFields = $event->getParameters();
	}
	if ($eventName === 'oncrminvoicerecurringexpose')
	{
		$id = isset($eventFields['ID']) ? (int)$eventFields['ID'] : 0;
		if($id <= 0)
		{
			throw new RestException("Could not find entity ID in fields of event \"{$eventName}\"");
		}

		$newInvoiceId = isset($eventFields['INVOICE_ID']) ? (int)$eventFields['INVOICE_ID'] : 0;
		if($newInvoiceId <= 0)
		{
			throw new RestException("Could not find new invoice ID in fields of event \"{$eventName}\"");
		}

		$recurringId = isset($eventFields['RECURRING_ID']) ? (int)$eventFields['RECURRING_ID'] : 0;

		return [
			'FIELDS' => [
				'ID' => $id,
				'RECURRING_INVOICE_ID' => $recurringId,
				'INVOICE_ID' => $newInvoiceId,
			]
		];
	}
	else
	{
		switch ($eventName)
		{
			case 'oncrminvoicerecurringadd':
			case 'oncrminvoicerecurringupdate':
				{
					$ID = isset($eventFields['ID']) ? (int)$eventFields['ID'] : 0;
					$invoiceId = isset($eventFields['INVOICE_ID']) ? (int)$eventFields['INVOICE_ID'] : 0;
					$resultFields = [
						'ID' => $ID,
						'RECURRING_INVOICE_ID' => $invoiceId
					];
				}
				break;
			case 'oncrminvoicerecurringdelete':
				{
					$ID = isset($eventFields['ID']) ? (int)$eventFields['ID'] : 0;
					$resultFields['ID'] = $ID;
				}
				break;
			default:
				throw new RestException("The Event \"{$eventName}\" is not supported in current context");
		}

		if($ID <= 0)
		{
			throw new RestException("Could not find entity ID in fields of event \"{$eventName}\"");
		}

		return ['FIELDS' => $resultFields];
	}
}

Добавить комментарий