Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
paymentavailablespaysystems.php
1<?php
2
4
11
12Loc::loadMessages(__FILE__);
13
20{
27 public static function clearBindings(int $paymentId)
28 {
29 return self::setBindings($paymentId, []);
30 }
31
41 public static function setBindings(int $paymentId, array $paySystemIds)
42 {
43 $result = new Result();
44
45 // check existing payment
46 $existPayment = PaymentTable::getCount([
47 '=ID' => $paymentId,
48 ]) > 0;
49 if (!$existPayment)
50 {
51 $result->addError(
52 new Error(Loc::getMessage('SALE_PS_PAYMENT_AVAILABLES_PAYSYSTEMS_NOT_FOUND_PAYMENT'))
53 );
54 return $result;
55 }
56
57 // grouping existing items by added & deleted
58 $existPaySystemIds = [];
60 'select' => [
61 'ID',
62 'PAY_SYSTEM_ID',
63 ],
64 'filter' => [
65 '=PAYMENT_ID' => $paymentId,
66 ],
67 ]);
68
69 $deletedIds = [];
70 $paySystemIds = array_map('intval', $paySystemIds);
71 foreach ($existRows as $row)
72 {
73 $rowPaySystemId = (int)$row['PAY_SYSTEM_ID'];
74 if (in_array($rowPaySystemId, $paySystemIds, true))
75 {
76 $existPaySystemIds[] = $rowPaySystemId;
77 }
78 else
79 {
80 $deletedIds[] = (int)$row['ID'];
81 }
82 }
83 $addedPaySystemIds = array_diff($paySystemIds, $existPaySystemIds);
84
85 // delete old pay systems
86 foreach ($deletedIds as $deleteId)
87 {
88 $deleteResult = PaymentPaySystemAvailableTable::delete($deleteId);
89 foreach ($deleteResult->getErrors() as $err)
90 {
91 $result->addError($err);
92 }
93 }
94
95 // add new exist pay systems
96 $paySystems = PaySystemActionTable::getList([
97 'select' => [
98 'ID',
99 ],
100 'filter' => [
101 '=ID' => $addedPaySystemIds,
102 ],
103 ]);
104 foreach ($paySystems as $item)
105 {
107 'PAYMENT_ID' => $paymentId,
108 'PAY_SYSTEM_ID' => (int)$item['ID'],
109 ]);
110 foreach ($addResult->getErrors() as $err)
111 {
112 $result->addError($err);
113 }
114 }
115
116 return $result;
117 }
118
125 public static function getAvailablePaySystemIdsByPaymentId(int $paymentId)
126 {
127 $ret = [];
128
130 'select' => [
131 'PAY_SYSTEM_ID',
132 ],
133 'filter' => [
134 '=PAYMENT_ID' => $paymentId,
135 ],
136 ]);
137 foreach ($rows as $row)
138 {
139 $ret[] = (int)$row['PAY_SYSTEM_ID'];
140 }
141
142 return $ret;
143 }
144}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getList(array $parameters=array())
static setBindings(int $paymentId, array $paySystemIds)