1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
cashboxpaysystem.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\Cashbox;
4
5use Bitrix\Main;
6use Bitrix\Sale;
7use Bitrix\Sale\BusinessValue;
8
10
15abstract class CashboxPaySystem extends Cashbox implements IPrintImmediately, ICheckable
16{
17 public const CACHE_ID = '';
18 private const TTL = 31536000;
19 protected const SEND_METHOD_HTTP_POST = 'POST';
20 protected const SEND_METHOD_HTTP_GET = 'GET';
21
22 abstract protected function getPrintUrl(): string;
23
24 abstract protected function getCheckUrl(): string;
25
26 abstract protected function send(string $url, Sale\Payment $payment, array $fields, string $method = self::SEND_METHOD_HTTP_POST): Sale\Result;
27
28 abstract protected function processPrintResult(Sale\Result $result): Sale\Result;
29
30 abstract protected function getDataForCheck(Sale\Payment $payment): array;
31
32 abstract protected function processCheckResult(Sale\Result $result): Sale\Result;
33
35
36 abstract public static function getPaySystemCodeForKkm(): string;
37
41 public static function getSupportedKkmModels()
42 {
43 $supportedKkmModels = [];
44
45 $paySystemIterator = Sale\PaySystem\Manager::getList([
46 'filter' => [
47 '=ACTIVE' => 'Y',
48 ]
49 ]);
50 while ($paySystemItem = $paySystemIterator->fetch())
51 {
52 $paySystemService = new Sale\PaySystem\Service($paySystemItem);
53 if (
54 $paySystemService->isSupportPrintCheck()
55 && $paySystemService->getCashboxClass() === '\\'.static::class
56 )
57 {
58 $supportedKkmModels[] = static::getKkmValue($paySystemService);
59 }
60 }
61
62 $supportedKkmModels = array_unique(array_merge(...$supportedKkmModels));
63
64 $result = [];
65 foreach ($supportedKkmModels as $supportedKkm)
66 {
67 $result[$supportedKkm] = [
68 'NAME' => $supportedKkm
69 ];
70 }
71
72 return $result;
73 }
74
80 protected function getPaySystemSetting(Sale\Payment $payment, string $code)
81 {
82 $params = $payment->getPaySystem()->getParamsBusValue($payment);
83 return $params[$code] ?? null;
84 }
85
91 protected function checkParams(Check $check): Sale\Result
92 {
93 $result = new Sale\Result();
94
96 if ($payment && $service = $payment->getPaySystem())
97 {
98 if (!$service->isSupportPrintCheck())
99 {
100 $result->addError(
101 new Main\Error(
102 Main\Localization\Loc::getMessage(
103 'SALE_CASHBOX_PAYSYSTEM_PAYSYSTEM_NOT_SUPPORT_PRINT_CHECK',
104 [
105 '#PAY_SYSTEM_NAME#' => $service->getField('NAME')
106 ]
107 )
108 )
109 );
110 }
111
112 if (!$service->canPrintCheckSelf($payment))
113 {
114 $result->addError(
115 new Main\Error(
116 Main\Localization\Loc::getMessage(
117 'SALE_CASHBOX_PAYSYSTEM_PAYSYSTEM_CANT_PRINT_CHECK_SELF',
118 [
119 '#PAY_SYSTEM_NAME#' => $service->getField('NAME')
120 ]
121 )
122 )
123 );
124 }
125 }
126 else
127 {
128 $result->addError(
129 new Main\Error(
130 Main\Localization\Loc::getMessage('SALE_CASHBOX_PAYSYSTEM_PAYMENT_NOT_FOUND')
131 )
132 );
133 }
134
135 return $result;
136 }
137
143 public function printImmediately(Check $check): Sale\Result
144 {
145 $result = new Sale\Result();
146
147 $checkParamsResult = $this->checkParams($check);
148 if (!$checkParamsResult->isSuccess())
149 {
150 $result->addErrors($checkParamsResult->getErrors());
151 return $result;
152 }
153
154 if ($this->needPrintCheck($check))
155 {
157 if (!$payment)
158 {
159 $result->addError(
160 new Main\Error(
161 Main\Localization\Loc::getMessage('SALE_CASHBOX_PAYSYSTEM_PAYMENT_NOT_FOUND')
162 )
163 );
164 return $result;
165 }
166
167 $url = $this->getPrintUrl();
168 $fields = $this->buildCheckQuery($check);
169
170 $sendResult = $this->send($url, $payment, $fields);
171 if ($sendResult->isSuccess())
172 {
173 $processPrintResult = $this->processPrintResult($sendResult);
174 if ($processPrintResult->isSuccess())
175 {
176 $result->setData($processPrintResult->getData());
177 }
178 else
179 {
180 $result->addErrors($processPrintResult->getErrors());
181 }
182 }
183 else
184 {
185 $result->addErrors($sendResult->getErrors());
186 }
187 }
188
189 return $result;
190 }
191
198 protected function needPrintCheck(Check $check): bool
199 {
200 $isShipmentEntity = (bool)array_filter(
201 $check->getEntities(),
202 static function ($entity)
203 {
204 return $entity instanceof Sale\Shipment;
205 }
206 );
207
208 return $check::getType() === SellCheck::getType() && $isShipmentEntity;
209 }
210
211 public function buildZReportQuery($id)
212 {
213 return [];
214 }
215
226 public function check(Check $check): Sale\Result
227 {
228 $result = new Sale\Result();
229
230 $checkParamsResult = $this->checkParams($check);
231 if (!$checkParamsResult->isSuccess())
232 {
233 $result->addErrors($checkParamsResult->getErrors());
234 return $result;
235 }
236
238 if (!$payment)
239 {
240 $result->addError(
241 new Main\Error(
242 Main\Localization\Loc::getMessage('SALE_CASHBOX_PAYSYSTEM_PAYMENT_NOT_FOUND')
243 )
244 );
245 return $result;
246 }
247
248 $url = $this->getCheckUrl();
249 $fields = $this->getDataForCheck($payment);
250 $sendMethod = $this->getCheckHttpMethod();
251
252 $sendResult = $this->send($url, $payment, $fields, $sendMethod);
253 if (!$sendResult->isSuccess())
254 {
255 $result->addErrors($sendResult->getErrors());
256 return $result;
257 }
258
259 $processCheckResult = $this->processCheckResult($sendResult);
260 if ($processCheckResult->isSuccess())
261 {
262 $onAfterProcessCheckResult = $this->onAfterProcessCheck($processCheckResult, $payment);
263 if (!$onAfterProcessCheckResult->isSuccess())
264 {
265 $result->addErrors($onAfterProcessCheckResult->getErrors());
266 }
267 }
268 else
269 {
270 $result->addErrors($processCheckResult->getErrors());
271 }
272
273 return $result;
274 }
275
279 protected function getCheckHttpMethod(): string
280 {
281 return self::SEND_METHOD_HTTP_POST;
282 }
283
287 public static function getFfdVersion(): ?float
288 {
289 return 1.05;
290 }
291
297 {
298 $paySystemCodeForKkm = static::getPaySystemCodeForKkm();
299 $supportedKkmModels = BusinessValue::getValuesByCode(
300 $service->getConsumerName(),
301 $paySystemCodeForKkm
302 );
303
304 return $supportedKkmModels;
305 }
306
307 public static function isOfdSettingsNeeded(): bool
308 {
309 return false;
310 }
311}
Определения error.php:15
static loadMessages($file)
Определения loc.php:65
static getValuesByCode(string $consumerName, string $code)
Определения businessvalue.php:747
buildCheckQuery(Check $check)
send(string $url, Sale\Payment $payment, array $fields, string $method=self::SEND_METHOD_HTTP_POST)
onAfterProcessCheck(Sale\Result $result, Sale\Payment $payment)
getPaySystemSetting(Sale\Payment $payment, string $code)
Определения cashboxpaysystem.php:80
needPrintCheck(Check $check)
Определения cashboxpaysystem.php:198
checkParams(Check $check)
Определения cashboxpaysystem.php:91
getDataForCheck(Sale\Payment $payment)
static getKkmValue(Sale\PaySystem\Service $service)
Определения cashboxpaysystem.php:296
printImmediately(Check $check)
Определения cashboxpaysystem.php:143
processCheckResult(Sale\Result $result)
processPrintResult(Sale\Result $result)
static getPaymentByCheck(Check $check)
Определения checkmanager.php:1910
static getType()
Определения sellcheck.php:19
static getList(array $params=array())
Определения manager.php:84
Определения payment.php:19
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$entity
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$payment
Определения payment.php:14
$service
Определения payment.php:18
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$method
Определения index.php:27
$url
Определения iframe.php:7