Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
pullmanager.php
1<?php
2
4
8
10{
11 public const MODULE_ID = 'sale';
12 public const PAYMENT_COMMAND = 'PAYMENT';
13
14 public const SUCCESSFUL_PAYMENT = 'SUCCESSFUL_PAYMENT';
15 public const FAILURE_PAYMENT = 'FAILURE_PAYMENT';
16
17 public static function subscribeOnPayment(int $userId): void
18 {
19 if ($userId <= 0)
20 {
21 return;
22 }
23
24 if (self::includePullModule())
25 {
26 \CPullWatch::Add($userId, self::PAYMENT_COMMAND);
27 }
28 }
29
30 public static function onSuccessfulPayment(Sale\Payment $payment): void
31 {
32 if (!self::includePullModule())
33 {
34 return;
35 }
36
37 self::sendEvent(
38 self::SUCCESSFUL_PAYMENT,
39 $payment->getId()
40 );
41 }
42
43 public static function onFailurePayment(Sale\Payment $payment): void
44 {
45 if (!self::includePullModule())
46 {
47 return;
48 }
49
50 self::sendEvent(
51 self::FAILURE_PAYMENT,
52 $payment->getId()
53 );
54 }
55
56 private static function sendEvent(string $eventName, int $id): void
57 {
58 $userIds = self::getSubscribedUserIds();
59 if (empty($userIds))
60 {
61 return;
62 }
63
64 Pull\Event::add(
65 $userIds,
66 [
67 'module_id' => self::MODULE_ID,
68 'command' => self::PAYMENT_COMMAND,
69 'params' => [
70 'eventName' => $eventName,
71 'paymentId' => $id,
72 ],
73 ]
74 );
75 }
76
77 private static function getSubscribedUserIds(): array
78 {
79 return Pull\Model\WatchTable::getUserIdsByTag(
80 self::PAYMENT_COMMAND
81 );
82 }
83
84 private static function includePullModule(): bool
85 {
86 return Main\Loader::includeModule('pull');
87 }
88}
static subscribeOnPayment(int $userId)
static onSuccessfulPayment(Sale\Payment $payment)
static onFailurePayment(Sale\Payment $payment)