• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/ads/pixel/conversioneventtriggers/paymenttrigger.php
  • Класс: Bitrix\Crm\Ads\Pixel\ConversionEventTriggers\PaymentTrigger
  • Вызов: PaymentTrigger::getConversionEventBuilder
protected function getConversionEventBuilder(): CrmConversionEventBuilderInterface
{
	return new class($this->payment) extends AbstractFacebookBuilder implements CrmConversionEventBuilderInterface {

		/**@var Payment|null $deal */
		protected $payment;

		public function __construct(Payment $payment)
		{
			$this->payment = $payment;
		}

		public function getUserData(): array
		{
			$userData = [];

			if (($order = $this->payment->getOrder()) && $order instanceof Order)
			{
				$binding = $order->getEntityBinding();
				if (
					$binding
					&& $binding->getOwnerTypeId() === \CCrmOwnerType::Deal
				)
				{
					$userData = $this->getDealUserData($this->getDeal($binding->getOwnerId()));
				}
				elseif ($collection = $order->getContactCompanyCollection())
				{
					if (
						($company = $collection->getPrimaryCompany()) &&
						!empty($data = $this->getCompanyUserData($company->getId()))
					)
					{
						$userData[] = $data;
					}
					if (
						($contact = $collection->getPrimaryContact()) &&
						!empty($data = $this->getContactUserData($contact->getId()))
					)
					{
						$userData[] = $data;
					}
				}
			}

			return $userData;
		}

		public function getEventParams($entity): ?array
		{
			return [
				'event_name' => Facebook\Event::EVENT_PURCHASE,
				'action_source' => Facebook\Event::ACTION_SOURCE_SYSTEM_GENERATED,
				'user_data' => $entity,
				'custom_data' => [
					'value' => $this->payment->getSumPaid() ?? $this->payment->getSum(),
					'currency' => $this->payment->getOrder()->getCurrency(),
				],
			];
		}
	};
}