Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
provider.php
1<?php
3
6
13{
14 private const TYPE = 'paysystem';
15
16 private const PAY_SYSTEM_HANDLERS = [
17 \Sale\Handlers\PaySystem\YandexCheckoutHandler::class,
18 \Sale\Handlers\PaySystem\WooppayHandler::class,
19 \Sale\Handlers\PaySystem\RoboxchangeHandler::class,
20 \Sale\Handlers\PaySystem\PlatonHandler::class,
21 ];
22
24 private $payment;
25
27 private $paySystemService;
28
29 public function __construct(Sale\Payment $payment)
30 {
31 $this->payment = $payment;
32 $this->paySystemService = $this->payment->getPaySystem();
33 }
34
38 public static function getCode(): string
39 {
40 return self::TYPE;
41 }
42
46 protected function needProvideData(): bool
47 {
48 if (!$this->paySystemService)
49 {
50 return false;
51 }
52
53 $actionFile = $this->paySystemService->getField('ACTION_FILE');
54 $paySystemClassName = strtolower(Sale\PaySystem\Manager::getClassNameFromPath($actionFile));
55
56 $isPaySystemExists = (bool)array_filter(
57 self::PAY_SYSTEM_HANDLERS,
58 static function ($paySystemHandler) use ($paySystemClassName) {
59 return strtolower($paySystemHandler) === $paySystemClassName;
60 }
61 );
62
63 return $isPaySystemExists && $this->payment->isPaid();
64 }
65
69 protected function getProviderData(): array
70 {
71 $result = [];
72
73 $paymentData = $this->getPaymentData();
74 if ($paymentData)
75 {
76 $result = [
77 'pay_system' => $this->paySystemService->getField('ACTION_FILE'),
78 'transactions' => $paymentData,
79 ];
80 }
81
82 return $result;
83 }
84
88 private function getPaymentData(): array
89 {
90 $result = [];
91
92 $externalId = $this->payment->getField('PS_INVOICE_ID');
93 $date = $this->payment->getField('PS_RESPONSE_DATE') ?: $this->payment->getField('DATE_PAID');
94
95 if (!($date instanceof Main\Type\DateTime))
96 {
97 $date = new Main\Type\DateTime();
98 }
99
100 $date = $date->format('Y-m-d H:i:s');
101
102 $result[] = [
103 'id' => $externalId ?: $this->payment->getField('XML_ID'),
104 'date_time' => $date,
105 ];
106
107 return $result;
108 }
109}