Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
paymentrepository.php
1<?php
2
4
6
13{
15 private static $instance;
16
20 private function __construct()
21 {}
22
26 public static function getInstance(): PaymentRepository
27 {
28 if (is_null(self::$instance))
29 {
30 self::$instance = new self();
31 }
32
33 return self::$instance;
34 }
35
40 public function getById(int $id): ?Sale\Payment
41 {
42 $paymentList = $this->getList([
43 'select' => ['ID', 'ORDER_ID'],
44 'filter' => [
45 '=ID' => $id
46 ],
47 ]);
48
49 return $paymentList[0] ?? null;
50 }
51
56 public function getByIds(array $ids): array
57 {
58 return $this->getList([
59 'select' => ['ID', 'ORDER_ID'],
60 'filter' => [
61 '@ID' => $ids
62 ],
63 ]);
64 }
65
70 public function getList(array $parameters): array
71 {
72 $result = [];
73
75 $paymentClass = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER)->getPaymentClassName();
76
77 $paymentList = $paymentClass::getList($parameters);
78 while ($paymentRow = $paymentList->fetch())
79 {
80 $payment = $this->getByRow($paymentRow);
81 if (is_null($payment))
82 {
83 continue;
84 }
85
86 $result[] = $payment;
87 }
88
89 return $result;
90 }
91
96 private function getByRow(array $paymentRow): ?Sale\Payment
97 {
98 $orderClassName = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER)->getOrderClassName();
99
101 $order = $orderClassName::load($paymentRow['ORDER_ID']);
102 if ($order === null)
103 {
104 return null;
105 }
106
107 $paymentId = (int)$paymentRow['ID'];
108 if ($paymentId > 0)
109 {
111 $payment = $order->getPaymentCollection()->getItemById($paymentRow['ID']);
112
113 return $payment;
114 }
115
116 return null;
117 }
118}