Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
resthandler.php
1<?php
2
4
15
21{
22 private $handlerFields = array();
23
24 private const FORM_MODE = 'form';
25 private const CHECKOUT_MODE = 'checkout';
26 private const IFRAME_MODE = 'iframe';
27
34 public function initiatePay(Payment $payment, Request $request = null)
35 {
36 if ($request === null)
37 {
38 $request = Context::getCurrent()->getRequest();
39 }
40
41 $mode = $this->getMode();
42
43 if ($mode === self::CHECKOUT_MODE)
44 {
45 return $this->initiateCheckoutPay($payment, $request);
46 }
47
48 if ($mode === self::IFRAME_MODE)
49 {
50 return $this->initiateIframePay($payment);
51 }
52
53 return $this->initiateFormPay($payment, $request);
54 }
55
56 private function initiateCheckoutPay(Payment $payment, Request $request): ServiceResult
57 {
58 $result = new ServiceResult();
59
60 $settings = $this->getHandlerSettings();
61
62 $actionUri = $settings['CHECKOUT_DATA']['ACTION_URI'] ?? null;
63 if (!isset($actionUri))
64 {
65 $result->addError(new Error(Loc::getMessage('SALE_HANDLERS_REST_HANDLER_ERROR_URI_MISSING')));
66 return $result;
67 }
68
69 if (!$this->canCheckout($payment, $request))
70 {
71 $template = $this->getCheckoutFormTemplate($payment);
72 }
73 else
74 {
75 $params = $this->getCheckoutPayParams($payment, $request);
76 $requestResult = Rest\Http::sendRequest($actionUri, $params);
77 if (!$requestResult->isSuccess())
78 {
79 $result->addErrors($requestResult->getErrors());
80 return $result;
81 }
82
83 $requestData = $requestResult->getData();
84 if (empty($requestData['PAYMENT_URL']) || empty($requestData['PAYMENT_ID']))
85 {
86 if (!empty($requestData['PAYMENT_ERRORS']) && is_array($requestData['PAYMENT_ERRORS']))
87 {
88 foreach ($requestData['PAYMENT_ERRORS'] as $error)
89 {
90 $result->addError(new Error($error));
91 }
92
93 return $result;
94 }
95
96 $result->addError(new Error(Loc::getMessage('SALE_HANDLERS_REST_HANDLER_ERROR_DATA_MISSING')));
97 return $result;
98 }
99
100 $result->setPsData(['PS_INVOICE_ID' => $requestData['PAYMENT_ID']]);
101 $url = $requestData['PAYMENT_URL'];
102
103 $result->setPaymentUrl($url);
104
105 $qrCode = ((new PaySystem\BarcodeGenerator())->generate($url));
106 if ($qrCode)
107 {
108 $result->setQr(base64_encode($qrCode));
109 }
110
111 $template = $this->getCheckoutPayTemplate($url);
112 }
113
114 if ($this->initiateMode === static::STREAM)
115 {
116 echo $template;
117 }
118 else
119 {
120 $result->setTemplate($template);
121 }
122
123 return $result;
124 }
125
126 private function needMoreCheckoutParams(array $settings, array $params): bool
127 {
128 $checkoutSettings = $settings['CHECKOUT_DATA'];
129 if (isset($checkoutSettings['FIELDS']))
130 {
131 return !empty(array_diff_key($checkoutSettings['FIELDS'], $params));
132 }
133
134 return false;
135 }
136
137 private function getCheckoutPayParams(Payment $payment, Request $request): array
138 {
139 $params = [];
140
141 $checkoutSettings = $this->getHandlerSettings()['CHECKOUT_DATA'];
142 if (isset($checkoutSettings['FIELDS']))
143 {
144 $params = $this->getQueryDataFromFields($payment, $checkoutSettings['FIELDS']);
145 }
146
147 $requestData = $request->toArray();
148 foreach ($requestData as $field => $value)
149 {
150 if (isset($checkoutSettings['FIELDS'][$field]))
151 {
152 $params[$field] = $value;
153 }
154 }
155
156 return array_merge($params, $this->getSystemParams($payment));
157 }
158
159 private function getCheckoutFormTemplate(Payment $payment): string
160 {
161 $settings = $this->getHandlerSettings();
162 $formSettings = $settings['CHECKOUT_DATA'];
163
164 $template = '<div class="mb-4" id="rest-checkout">';
165 $template .= '<form name="rest-checkout-form" id="rest-checkout-form">';
166
167 if (isset($formSettings['FIELDS']))
168 {
169 $template .= $this->getTemplateFromFields($payment, $formSettings['FIELDS']);
170 }
171
172 $template .= '<input type="hidden" name="BX_PAYSYSTEM_ID" value="'.$this->service->getField('ID').'">';
173 $template .= '<input name="button" value="'.Loc::getMessage('SALE_HANDLERS_REST_HANDLER_BUTTON_PAID').'" type="submit" class="btn btn-lg btn-success pl-4 pr-4" style="border-radius: 32px;">';
174 $template .= '</form>';
175 $template .= '</div>';
176
177 $messages = Loc::loadLanguageFile(__FILE__);
178 $template .= '
179 <script>
180 BX.message(' . \CUtil::PhpToJSObject($messages) . ');
181
182 (function() {
183 "use strict";
184
185 if (!BX.Sale)
186 {
187 BX.Sale = {};
188 }
189
190 if (BX.Sale.RestHandler)
191 {
192 return;
193 }
194
195 BX.Sale.RestHandler = {
196 init: function(params)
197 {
198 this.formNode = BX(params.formId);
199 this.paysystemBlockNode = BX(params.paysystemBlockId);
200 this.ajaxUrl = params.ajaxUrl;
201 this.paymentId = params.paymentId;
202 this.paySystemId = params.paySystemId;
203 this.isAllowedSubmitting = true;
204 this.returnUrl = params.returnUrl;
205
206 this.bindEvents();
207 },
208
209 bindEvents: function()
210 {
211 BX.bind(this.formNode, "submit", BX.proxy(this.sendRequest, this));
212 },
213
214 sendRequest: function(e)
215 {
216 e.preventDefault();
217
218 if (!this.isAllowedSubmitting)
219 {
220 return;
221 }
222
223 var data,
224 formData = this.getAllFormData(),
225 submitButton = this.formNode.querySelector("input[type=\"submit\"]"),
226 i;
227
228 if (submitButton)
229 {
230 submitButton.disabled = true;
231 }
232 this.isAllowedSubmitting = false;
233
234 data = {
235 sessid: BX.bitrix_sessid(),
236 PAYMENT_ID: this.paymentId,
237 PAYSYSTEM_ID: this.paySystemId,
238 RETURN_URL: this.returnUrl,
239 };
240
241 for (i in formData)
242 {
243 if (formData.hasOwnProperty(i))
244 {
245 data[i] = formData[i];
246 }
247 }
248
249 BX.ajax({
250 method: "POST",
251 dataType: "json",
252 url: this.ajaxUrl,
253 data: data,
254 onsuccess: BX.proxy(function (result) {
255 if (result.status === "success")
256 {
257 this.isAllowedSubmitting = true;
258 this.updateTemplateHtml(result.template);
259 }
260 else if (result.status === "error")
261 {
262 this.isAllowedSubmitting = true;
263 this.showErrorTemplate(result.buyerErrors);
264 BX.onCustomEvent("onPaySystemAjaxError", [result.buyerErrors]);
265 }
266 }, this)
267 });
268 },
269
270 getAllFormData: function()
271 {
272 var prepared = BX.ajax.prepareForm(this.formNode),
273 i;
274
275 for (i in prepared.data)
276 {
277 if (prepared.data.hasOwnProperty(i) && i === "")
278 {
279 delete prepared.data[i];
280 }
281 }
282
283 return !!prepared && prepared.data ? prepared.data : {};
284 },
285
286 updateTemplateHtml: function (html)
287 {
288 BX.html(this.paysystemBlockNode, html)
289 },
290
291 showErrorTemplate: function(errors)
292 {
293 var errorsList = [
294 BX.message("SALE_HANDLERS_REST_HANDLER_TEMPLATE_ERROR_MESSAGE_HEADER"),
295 ];
296 if (errors)
297 {
298 for (var error in errors)
299 {
300 if (errors.hasOwnProperty(error))
301 {
302 errorsList.push(errors[error]);
303 }
304 }
305 }
306
307 errorsList.push(BX.message("SALE_HANDLERS_REST_HANDLER_TEMPLATE_ERROR_MESSAGE_FOOTER"));
308
309 var resultDiv = BX.create("div", {
310 props: {className: "alert alert-danger"},
311 html: errorsList.join("<br />"),
312 });
313
314 this.paysystemBlockNode.innerHTML = "";
315 this.paysystemBlockNode.appendChild(resultDiv);
316 },
317 }
318 })();
319
320 BX.ready(function() {
321 BX.Sale.RestHandler.init({
322 formId: "rest-checkout-form",
323 paysystemBlockId: "rest-checkout",
324 ajaxUrl: "/bitrix/tools/sale_ps_ajax.php",
325 paymentId: "' . \CUtil::JSEscape($payment->getId()) . '",
326 paySystemId: "' . \CUtil::JSEscape($payment->getPaymentSystemId()) . '",
327 returnUrl: "' . $this->service->getContext()->getUrl() . '",
328 });
329 });
330 </script>
331 ';
332
333 return $template;
334 }
335
336 private function getCheckoutPayTemplate($paymentUrl): string
337 {
338 $template = '<a class="btn btn-lg btn-success" style="border-radius: 32px;" href="' . $paymentUrl . '">';
339 $template .= Loc::getMessage('SALE_HANDLERS_REST_HANDLER_BUTTON_PAID');
340 $template .= '</a>';
341
342 return $template;
343 }
344
345 private function initiateIframePay(Payment $payment): ServiceResult
346 {
347 $result = new ServiceResult();
348
349 $template = $this->getIframeTemplate($payment);
350 if ($this->initiateMode === static::STREAM)
351 {
352 echo $template;
353 }
354 else
355 {
356 $result->setTemplate($template);
357 }
358
359 return $result;
360 }
361
362 private function initiateFormPay(Payment $payment, ?Request $request): ServiceResult
363 {
364 $result = $this->showTemplate($payment, "template");
365 if (!$result->isSuccess())
366 {
367 $result = new ServiceResult();
368 $template = $this->getDefaultTemplate($payment);
369 if ($this->initiateMode === static::STREAM)
370 {
371 echo $template;
372 }
373 else
374 {
375 $result->setTemplate($template);
376 }
377 }
378
379 $result->setPaymentUrl($this->getPaymentUrl($payment));
380
381 return $result;
382 }
383
388 private function getPaymentUrl(Payment $payment): string
389 {
390 if ($this->isAllowAutoRedirect())
391 {
392 $settings = $this->getHandlerSettings();
393
394 if (isset($settings['FORM_DATA']['FIELDS']))
395 {
396 $queryParams = $this->getQueryDataFromFields($payment, $settings['FORM_DATA']['FIELDS']);
397 }
398 elseif (isset($settings['FORM_DATA']['PARAMS']))
399 {
400 $queryParams = $this->getQueryDataFromParams($payment, $settings['FORM_DATA']['PARAMS']);
401 }
402
403 $queryParams['BX_PAYSYSTEM_ID'] = $this->service->getField('ID');
404 return (new Uri($settings['FORM_DATA']['ACTION_URI']))->addParams($queryParams)->getLocator();
405 }
406
407 return '';
408 }
409
413 private function isAllowAutoRedirect(): bool
414 {
415 $result = false;
416
417 $settings = $this->getHandlerSettings();
418 $formSettings = $settings['FORM_DATA'];
419 if (!empty($formSettings['ACTION_URI']) && mb_strtoupper($formSettings['METHOD']) === 'GET')
420 {
421 $result = true;
422 if (isset($formSettings['FIELDS']))
423 {
424 foreach ($formSettings['FIELDS'] as $value)
425 {
426 if ((isset($value['VISIBLE']) && $value['VISIBLE'] === 'Y') || is_array($value['CODE']))
427 {
428 $result = false;
429 break;
430 }
431 }
432 }
433 }
434
435 return $result;
436 }
437
443 private function getQueryDataFromFields(Payment $payment, array $fields): array
444 {
445 $result = [];
446 $businessValueParams = $this->getParamsBusValue($payment);
447
448 foreach ($fields as $key => $value)
449 {
450 if (!is_array($value['CODE']) && !empty($value['CODE']))
451 {
452 $result[$key] = $businessValueParams[$value['CODE']];
453 }
454 }
455
456 return $result;
457 }
458
459 private function getIframeTemplate(Payment $payment): string
460 {
461 \CJSCore::Init("loader");
462
463 $settings = $this->getHandlerSettings();
464 $formSettings = $settings['IFRAME_DATA'];
465
466 $iframeData = $this->getIframePayParams($payment);
467
468 $actionUriHost = (new Uri($formSettings['ACTION_URI']))->getHost();
469
470 $template = "
471 <div class='rest-paysystem-wrapper' id='rest-paysystem-wrapper'>
472 <iframe
473 src='{$formSettings['ACTION_URI']}'
474 class='rest-payment-frame'
475 name='restPaymentFrame'
476 id='rest-payment-frame'
477 style='border: none; height: 350px; width: 100%'
478 sandbox='allow-forms allow-scripts allow-modals allow-top-navigation allow-same-origin'
479 >
480 <div class='alert alert-danger'>" . Loc::getMessage('SALE_HANDLERS_REST_HANDLER_ERROR_IFRAME') . "</div>
481 </iframe>
482 <div class='alert alert-info'>" . Loc::getMessage('SALE_HANDLERS_REST_HANDLER_TEMPLATE_WARNING_RETURN') . "</div>
483 </div>
484 ";
485 $template .= '
486 <script>
487 BX.ready(function() {
488 var iframe = document.getElementById("rest-payment-frame");
489 var loader = null;
490
491 if (BX.Loader)
492 {
493 loader = new BX.Loader({
494 target: iframe.parentElement,
495 size: iframe.offsetHeight / 2,
496 });
497 loader.show();
498 }
499
500 var parent = iframe.parentElement;
501 iframe.style.width = parent.clientWidth;
502
503 iframe.onload = function () {
504 if (loader)
505 {
506 loader.hide();
507 }
508
509 var paymentFrame = iframe.contentWindow;
510 if (paymentFrame)
511 {
512 var iframeData = ' . \CUtil::PhpToJSObject($iframeData) . ';
513 iframeData.BX_COMPUTED_STYLE = JSON.parse(JSON.stringify(window.getComputedStyle(parent)));
514
515 paymentFrame.postMessage(iframeData, "' . $formSettings['ACTION_URI'] . '");
516 }
517 }
518 iframe.onerror = function () {
519 if (loader)
520 {
521 loader.hide();
522 }
523
524 var restPaysystemWrapper = document.getElementById("rest-paysystem-wrapper");
525 restPaysystemWrapper.innerHTML = "";
526 restPaysystemWrapper.appendChild(
527 BX.create("div", {
528 props: {className: "alert alert-danger"},
529 text: "' . Loc::getMessage('SALE_HANDLERS_REST_HANDLER_ERROR_IFRAME_LOAD') . '",
530 })
531 );
532 }
533
534 window.addEventListener("message", function (event) {
535 try
536 {
537 var originHost = new URL(event.origin).hostname;
538 }
539 catch(error)
540 {
541 return;
542 }
543
544 if (originHost !== "' . $actionUriHost . '")
545 {
546 return;
547 }
548
549 if (event.data.width && parseInt(event.data.width) > 0)
550 {
551 iframe.style.width = event.data.width + "px";
552 }
553 if (event.data.height && parseInt(event.data.height) > 0)
554 {
555 iframe.style.height = event.data.height + "px";
556 }
557 }, false);
558 });
559 </script>
560 ';
561
562 return $template;
563 }
564
565 private function getIframePayParams(Payment $payment): array
566 {
567 $params = [];
568
569 $formSettings = $this->getHandlerSettings()['IFRAME_DATA'];
570 if (isset($formSettings['FIELDS']))
571 {
572 $params = $this->getQueryDataFromFields($payment, $formSettings['FIELDS']);
573 }
574
575 return array_merge($params, $this->getSystemParams($payment));
576 }
577
583 private function getDefaultTemplate(Payment $payment): string
584 {
585 $settings = $this->getHandlerSettings();
586 $formSettings = $settings['FORM_DATA'];
587
588 $template = '<form action="'.htmlspecialcharsbx($formSettings['ACTION_URI']).'" method="'.htmlspecialcharsbx($formSettings['METHOD']).'" name="rest-handler-form">';
589
590 if (isset($formSettings['FIELDS']))
591 {
592 $template .= $this->getTemplateFromFields($payment, $formSettings['FIELDS']);
593 }
594 elseif (isset($formSettings['PARAMS']))
595 {
596 $template .= $this->getTemplateFromParams($payment, $formSettings['PARAMS']);
597 }
598
599 $template .= '<input type="hidden" name="BX_PAYSYSTEM_ID" value="' . $this->service->getField('ID') . '">';
600 $template .= '<input type="hidden" name="BX_RETURN_URL" value="' . $this->service->getContext()->getUrl() . '">';
601 $template .= '<input name="button" value="' . Loc::getMessage('SALE_HANDLERS_REST_HANDLER_BUTTON_PAID') . '" type="submit" class="btn btn-lg btn-success pl-4 pr-4" style="border-radius: 32px;">';
602 $template .= '</form>';
603
604 return $template;
605 }
606
613 private function getTemplateFromFields(Payment $payment, array $fields): string
614 {
615 $template = '';
616
617 foreach ($fields as $key => $value)
618 {
619 $input = $this->getInputParams($payment, $value);
620 $template .= $this->createInput($key, $input);
621 }
622
623 return $template;
624 }
625
631 private function getInputParams(Payment $payment, $value): array
632 {
633 $result = [
634 'TYPE' => 'STRING',
635 'VALUE' => '',
636 'NAME' => '',
637 'HIDDEN' => 'Y',
638 ];
639
640 $settings = $this->getHandlerSettings();
641 $params = $this->getParamsBusValue($payment);
642
643 if (is_array($value['CODE']))
644 {
646 $input = $value['CODE'];
647 $result['NAME'] = $input['NAME'] ?? '';
648 }
649 else
650 {
652 $code = $value['CODE'];
653 $input = $settings['CODES'][$code];
654 $result['VALUE'] = $params[$code];
655 $result['NAME'] = $input['NAME'] ?? '';
656 }
657
658 if (isset($input['INPUT']['TYPE']))
659 {
660 $result['TYPE'] = mb_strtoupper($input['INPUT']['TYPE']);
661 }
662
663 if (isset($value['VISIBLE']) && $value['VISIBLE'] === 'Y')
664 {
665 $result['HIDDEN'] = 'N';
666 }
667
668 return $result;
669 }
670
677 private function createInput(string $name, array $input): string
678 {
679 if (!in_array($input['TYPE'], ['Y/N', 'STRING', 'ENUM'], true))
680 {
681 return '';
682 }
683
684 if ($input['HIDDEN'] === 'Y')
685 {
686 return Input\Manager::getEditHtml($name, $input);
687 }
688
689 $inputHtml = '';
690 $input['STYLE'] = "max-width: 300px;";
691
692 if ($input['TYPE'] === 'Y/N')
693 {
694 $input['CLASS'] = "form-check-input";
695
696 $inputHtml .= '<div class="form-check">';
697 $inputHtml .= Input\Manager::getEditHtml($name, $input);
698 $inputHtml .= '<label class="form-check-label">'.$input['NAME'].'</label>';
699 $inputHtml .= '</div>';
700 }
701 elseif ($input['TYPE'] === 'STRING' || $input['TYPE'] === 'ENUM')
702 {
703 $input['CLASS'] = "form-control";
704
705 $inputHtml .= '<div class="form-group">';
706 $inputHtml .= '<label>'.$input['NAME'].'</label>';
707 $inputHtml .= Input\Manager::getEditHtml($name, $input);
708 $inputHtml .= '</div>';
709 }
710
711 return $inputHtml;
712 }
713
717 public function getCurrencyList()
718 {
719 $settings = $this->getHandlerSettings();
720 return $settings['CURRENCY'];
721 }
722
726 public function getClientType($psMode)
727 {
728 $settings = $this->getHandlerSettings();
729
730 $clientType = (string)($settings['CLIENT_TYPE'] ?? '');
731 if ($clientType && ClientType::isValid($clientType))
732 {
733 return $clientType;
734 }
735
736 return parent::getClientType($psMode);
737 }
738
739 protected function includeDescription(): array
740 {
741 $fields = $this->getHandlerFields();
742 $settings = $this->getHandlerSettings();
743
744 return [
745 'NAME' => $fields['NAME'] ?? '',
746 'SORT' => $fields['SORT'] ?? 100,
747 'CODES' => $settings['CODES'] ?: []
748 ];
749 }
750
751 private function getHandlerFields(): array
752 {
753 if (!$this->handlerFields)
754 {
755 $handler = $this->service->getField('ACTION_FILE');
756 $dbRes = PaySystemRestHandlersTable::getList([
757 'filter' => ['CODE' => $handler]
758 ]);
759 $data = $dbRes->fetch();
760
761 if ($data)
762 {
763 $this->handlerFields = $data;
764 }
765 }
766
767 return $this->handlerFields;
768 }
769
773 private function getHandlerSettings(): array
774 {
775 $handlerFields = $this->getHandlerFields();
776 return $handlerFields['SETTINGS'] ?? [];
777 }
778
779 private function getMode(): string
780 {
781 $settings = $this->getHandlerSettings();
782
783 if (!empty($settings['IFRAME_DATA']))
784 {
785 return self::IFRAME_MODE;
786 }
787
788 if (!empty($settings['CHECKOUT_DATA']))
789 {
790 return self::CHECKOUT_MODE;
791 }
792
793 return self::FORM_MODE;
794 }
795
796 private function getSystemParams(Payment $payment): array
797 {
798 $params['BX_SYSTEM_PARAMS'] = [
799 'RETURN_URL' => $this->service->getContext()->getUrl(),
800 'PAYSYSTEM_ID' => $this->service->getField('ID'),
801 'PAYMENT_ID' => $payment->getId(),
802 'SUM' => $payment->getSum(),
803 'CURRENCY' => $payment->getField('CURRENCY'),
804 ];
805
806 $invoiceId = $payment->getField('PS_INVOICE_ID');
807 if (isset($invoiceId))
808 {
809 $params['BX_SYSTEM_PARAMS']['EXTERNAL_PAYMENT_ID'] = $invoiceId;
810 }
811
812 return $params;
813 }
814
820 public function processRequest(Payment $payment, Request $request)
821 {
822 $result = new ServiceResult();
823
824 $result->setPsData($this->getPsData($request));
825 $result->setOperationType(ServiceResult::MONEY_COMING);
826
827 return $result;
828 }
829
834 private function getPsData(Request $request): array
835 {
836 $psData = [
837 'PS_STATUS' => 'Y',
838 'PS_STATUS_CODE' => 'Y',
839 'PS_RESPONSE_DATE' => new Type\DateTime(),
840 'PAY_VOUCHER_DATE' => new Type\Date(),
841 ];
842
843 if ($psInvoiceId = $request->get('PS_INVOICE_ID'))
844 {
845 $psData['PS_INVOICE_ID'] = $psInvoiceId;
846 }
847
848 if ($psStatusCode = $request->get('PS_STATUS_CODE'))
849 {
850 $psData['PS_STATUS_CODE'] = $psStatusCode;
851 }
852
853 if ($psStatusDescription = $request->get('PS_STATUS_DESCRIPTION'))
854 {
855 $psData['PS_STATUS_DESCRIPTION'] = $psStatusDescription;
856 }
857
858 if ($psStatusMessage = $request->get('PS_STATUS_MESSAGE'))
859 {
860 $psData['PS_STATUS_MESSAGE'] = $psStatusMessage;
861 }
862
863 if ($psSum = $request->get('PS_SUM'))
864 {
865 $psData['PS_SUM'] = $psSum;
866 }
867
868 if ($psCurrency = $request->get('PS_CURRENCY'))
869 {
870 $psData['PS_CURRENCY'] = $psCurrency;
871 }
872
873 if ($psRecurringToken = $request->get('PS_RECURRING_TOKEN'))
874 {
875 $psData['PS_RECURRING_TOKEN'] = $psRecurringToken;
876 }
877
878 if ($psCardNumber = $request->get('PS_CARD_NUMBER'))
879 {
880 $psData['PS_CARD_NUMBER'] = $psCardNumber;
881 }
882
883 return $psData;
884 }
885
890 public function getPaymentIdFromRequest(Request $request)
891 {
892 return $request->get('PAYMENT_ID');
893 }
894
902 private function getQueryDataFromParams(Payment $payment, array $params): array
903 {
904 $result = [];
905 $businessValueParams = $this->getParamsBusValue($payment);
906
907 foreach ($params as $key => $value)
908 {
909 $result[$key] = $businessValueParams[$value];
910 }
911
912 return $result;
913 }
914
922 private function getTemplateFromParams(Payment $payment, array $params): string
923 {
924 $template = '';
925 $businessValueParams = $this->getParamsBusValue($payment);
926
927 foreach ($params as $key => $value)
928 {
929 $template .= '<input type="hidden" name="'.htmlspecialcharsbx($key).'" value="'.htmlspecialcharsbx($businessValueParams[$value]).'">';
930 }
931
932 return $template;
933 }
934
935 public function canCheckout(Payment $payment, Request $request = null): bool
936 {
937 if ($request === null)
938 {
939 $request = Context::getCurrent()->getRequest();
940 }
941
942 $mode = $this->getMode();
943 if ($mode !== self::CHECKOUT_MODE)
944 {
945 return false;
946 }
947
948 $settings = $this->getHandlerSettings();
949 $actionUri = $settings['CHECKOUT_DATA']['ACTION_URI'] ?? null;
950 if (!isset($actionUri))
951 {
952 return false;
953 }
954
955 $params = $this->getCheckoutPayParams($payment, $request);
956
957 return !$this->needMoreCheckoutParams($settings, $params);
958 }
959}
static getCurrent()
Definition context.php:241
static loadLanguageFile($file, $language=null, $normalize=true)
Definition loc.php:224
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
showTemplate(Payment $payment=null, $template='')
static isValid(string $value)
initiatePay(Payment $payment, Request $request=null)
processRequest(Payment $payment, Request $request)
getPaymentIdFromRequest(Request $request)
canCheckout(Payment $payment, Request $request=null)