1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
restservice.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\PaySystem;
4
5use Bitrix\Main;
6use Bitrix\Rest;
7use Bitrix\Rest\AccessException;
8use Bitrix\Rest\RestException;
9use Bitrix\Sale\BusinessValue;
10use Bitrix\Sale\Internals;
11use Bitrix\Sale\Order;
12use Bitrix\Sale\Payment;
13use Bitrix\Sale\Registry;
14use Bitrix\Sale\Services\PaySystem\Restrictions;
15use Bitrix\Crm\Invoice;
16use Bitrix\Crm\Service\Container;
17
18if (!Main\Loader::includeModule('rest'))
19{
20 return;
21}
22
28{
29 const SCOPE = 'pay_system';
30
31 const ERROR_CHECK_FAILURE = 'ERROR_CHECK_FAILURE';
32 const ERROR_HANDLER_ALREADY_EXIST = 'ERROR_HANDLER_ALREADY_EXIST';
33 const ERROR_HANDLER_NOT_FOUND = 'ERROR_HANDLER_NOT_FOUND';
34 const ERROR_PERSON_TYPE_NOT_FOUND = 'ERROR_PERSON_TYPE_NOT_FOUND';
35 const ERROR_PAY_SYSTEM_NOT_FOUND = 'ERROR_PAY_SYSTEM_NOT_FOUND';
36
37 private const ERROR_HANDLER_ADD = 'ERROR_HANDLER_ADD';
38 private const ERROR_HANDLER_UPDATE = 'ERROR_HANDLER_UPDATE';
39 private const ERROR_HANDLER_DELETE = 'ERROR_HANDLER_DELETE';
40
41 const ERROR_PAY_SYSTEM_ADD = 'ERROR_PAY_SYSTEM_ADD';
42 const ERROR_PAY_SYSTEM_UPDATE = 'ERROR_PAY_SYSTEM_UPDATE';
43 const ERROR_PAY_SYSTEM_DELETE = 'ERROR_PAY_SYSTEM_DELETE';
44
45 const ERROR_INTERNAL_INVOICE_NOT_FOUND = 'ERROR_INTERNAL_INVOICE_NOT_FOUND';
46 const ERROR_INTERNAL_ORDER_NOT_FOUND = 'ERROR_INTERNAL_ORDER_NOT_FOUND';
47 const ERROR_PROCESS_REQUEST_RESULT = 'ERROR_PROCESS_REQUEST_RESULT';
48 const ERROR_PAY_INVOICE_NOT_SUPPORTED = 'ERROR_INVOICE_NO_SUPPORTED';
49
50 private const ALLOWED_PAYSYSTEM_FIELDS = [
51 'ID' => [
52 'TYPE' => 'integer',
53 ],
54 'PERSON_TYPE_ID' => [
55 'TYPE' => 'integer',
56 ],
57 'NAME' => [
58 'TYPE' => 'string',
59 ],
60 'PSA_NAME' => [
61 'TYPE' => 'string',
62 ],
63 'SORT' => [
64 'TYPE' => 'integer',
65 ],
66 'DESCRIPTION' => [
67 'TYPE' => 'string',
68 ],
69 'ACTION_FILE' => [
70 'TYPE' => 'string',
71 ],
72 'RESULT_FILE' => [
73 'TYPE' => 'string',
74 ],
75 'NEW_WINDOW' => [
76 'TYPE' => 'string',
77 ],
78 'TARIF' => [
79 'TYPE' => 'string',
80 ],
81 'PS_MODE' => [
82 'TYPE' => 'string',
83 ],
84 'HAVE_PAYMENT' => [
85 'TYPE' => 'string',
86 ],
87 'HAVE_ACTION' => [
88 'TYPE' => 'string',
89 ],
90 'HAVE_RESULT' => [
91 'TYPE' => 'string',
92 ],
93 'HAVE_PREPAY' => [
94 'TYPE' => 'string',
95 ],
96 'HAVE_PRICE' => [
97 'TYPE' => 'string',
98 ],
99 'HAVE_RESULT_RECEIVE' => [
100 'TYPE' => 'string',
101 ],
102 'ENCODING' => [
103 'TYPE' => 'string',
104 ],
105 'ACTIVE' => [
106 'TYPE' => 'string',
107 ],
108 'ALLOW_EDIT_PAYMENT' => [
109 'TYPE' => 'string',
110 ],
111 'IS_CASH' => [
112 'TYPE' => 'string',
113 ],
114 'AUTO_CHANGE_1C' => [
115 'TYPE' => 'string',
116 ],
117 'CAN_PRINT_CHECK' => [
118 'TYPE' => 'string',
119 ],
120 'ENTITY_REGISTRY_TYPE' => [
121 'TYPE' => 'string',
122 ],
123 'XML_ID' => [
124 'TYPE' => 'string',
125 ],
126 ];
127
128 public static function onRestAppDelete(array $fields): void
129 {
130 if (!Main\Loader::includeModule('rest'))
131 {
132 return;
133 }
134
135 if (empty($fields['APP_ID']) || empty($fields['CLEAN']) || $fields['CLEAN'] !== true)
136 {
137 return;
138 }
139
141 if (!$app)
142 {
143 return;
144 }
145
146 $restHandlerResult = Internals\PaySystemRestHandlersTable::getList([
147 'select' => ['ID', 'CODE'],
148 'filter' => [
149 '=APP_ID' => $app['CLIENT_ID'],
150 ],
151 ]);
152 while ($restHandler = $restHandlerResult->fetch())
153 {
154 $paySystemResult = Manager::getList([
155 'select' => ['ID'],
156 'filter' => [
157 '=ACTION_FILE' => $restHandler['CODE'],
158 ],
159 ]);
160 while ($paySystem = $paySystemResult->fetch())
161 {
162 Manager::delete($paySystem['ID']);
163 }
164
165 Internals\PaySystemRestHandlersTable::delete($restHandler['ID']);
166 }
167 }
168
172 public static function onRestServiceBuildDescription()
173 {
174 return [
175 static::SCOPE => [
176 'sale.paysystem.handler.add' => [__CLASS__, 'addHandler'],
177 'sale.paysystem.handler.update' => [__CLASS__, 'updateHandler'],
178 'sale.paysystem.handler.delete' => [__CLASS__, 'deleteHandler'],
179 'sale.paysystem.handler.list' => [__CLASS__, 'getHandlerList'],
180
181 'sale.paysystem.add' => [__CLASS__, 'addPaySystem'],
182 'sale.paysystem.update' => [__CLASS__, 'updatePaySystem'],
183 'sale.paysystem.delete' => [__CLASS__, 'deletePaySystem'],
184 'sale.paysystem.list' => [__CLASS__, 'getPaySystemList'],
185
186 'sale.paysystem.settings.get' => [__CLASS__, 'getSettings'],
187 'sale.paysystem.settings.update' => [__CLASS__, 'updateSettings'],
188
189 'sale.paysystem.settings.invoice.get' => [__CLASS__, 'getSettingsByInvoice'],
190 'sale.paysystem.settings.payment.get' => [__CLASS__, 'getSettingsByPayment'],
191
192 'sale.paysystem.pay.invoice' => [__CLASS__, 'payInvoice'],
193 'sale.paysystem.pay.payment' => [__CLASS__, 'payPayment'],
194 ]
195 ];
196 }
197
205 public static function addPaySystem(array $params, $n, \CRestServer $server)
206 {
207 static::checkPaySystemPermission();
208
209 $params = self::preparePaySystemParams($params, $server);
210
211 if (!isset($params['ENTITY_REGISTRY_TYPE']))
212 {
213 if (IsModuleInstalled('crm'))
214 {
215 $params['ENTITY_REGISTRY_TYPE'] = REGISTRY_TYPE_CRM_INVOICE;
216 }
217 else
218 {
219 $params['ENTITY_REGISTRY_TYPE'] = Registry::REGISTRY_TYPE_ORDER;
220 }
221 }
222
223 static::checkParamsBeforePaySystemAdd($params);
224
225 $fields = [
226 'NAME' => $params['NAME'],
227 'PSA_NAME' => $params['NAME'],
228 'NEW_WINDOW' => isset($params['NEW_WINDOW']) && $params['NEW_WINDOW'] === 'Y' ? 'Y' : 'N',
229 'ACTIVE' => isset($params['ACTIVE']) && $params['ACTIVE'] === 'Y' ? 'Y' : 'N',
230 'PERSON_TYPE_ID' => $params['PERSON_TYPE_ID'],
231 'ACTION_FILE' => $params['BX_REST_HANDLER'],
232 'HAVE_PREPAY' => 'N',
233 'HAVE_RESULT' => 'N',
234 'HAVE_ACTION' => 'N',
235 'HAVE_PAYMENT' => 'N',
236 'HAVE_RESULT_RECEIVE' => 'Y',
237 'ENTITY_REGISTRY_TYPE' => $params['ENTITY_REGISTRY_TYPE'],
238 'DESCRIPTION' => $params['DESCRIPTION'],
239 'XML_ID' => $params['XML_ID'],
240 ];
241
242 if (isset($params['LOGOTIP']))
243 {
244 $fields['LOGOTIP'] = self::saveFile($params['LOGOTIP']);
245 }
246
248 if ($result->isSuccess())
249 {
250 $id = $result->getId();
251 Manager::update($id, array('PAY_SYSTEM_ID' => $id));
252
253 foreach ($params['SETTINGS'] as $key => $value)
254 {
256 $key,
258 $params['PERSON_TYPE_ID'],
259 [
260 'PROVIDER_KEY' => $value['TYPE'],
261 'PROVIDER_VALUE' => $value['VALUE']
262 ]
263 );
264 }
265
266 if ($fields['PERSON_TYPE_ID'] > 0)
267 {
268 static::savePersonTypeId($id, $params['PERSON_TYPE_ID']);
269 }
270
271 static::logAnalytics(
272 'addPaySystem' . $params['ENTITY_REGISTRY_TYPE'],
273 $params['BX_REST_HANDLER'],
274 $params['PERSON_TYPE_ID'],
275 $server
276 );
277
278 return $id;
279 }
280
281 $error = implode("\n", $result->getErrorMessages());
282 throw new RestException($error, self::ERROR_PAY_SYSTEM_ADD);
283 }
284
290 protected static function checkParamsBeforePaySystemAdd($params)
291 {
292 if (empty($params['BX_REST_HANDLER']))
293 {
294 throw new RestException('Parameter BX_REST_HANDLER is not defined', self::ERROR_CHECK_FAILURE);
295 }
296
297 $handlerData = self::getHandlerData($params['BX_REST_HANDLER']);
298 if (!$handlerData)
299 {
300 throw new RestException('Handler not found', self::ERROR_HANDLER_NOT_FOUND);
301 }
302
303 if ($params['APP_ID'] && !empty($handlerData['APP_ID']) && $handlerData['APP_ID'] !== $params['APP_ID'])
304 {
305 throw new AccessException();
306 }
307
308 if (!isset($params['NAME']) || $params['NAME'] === '')
309 {
310 throw new RestException('Parameter NAME is not defined', self::ERROR_CHECK_FAILURE);
311 }
312
313 $dbRes = Internals\PersonTypeTable::getList([
314 'filter' => [
315 '=ID' => $params['PERSON_TYPE_ID'],
316 '=ENTITY_REGISTRY_TYPE' => $params['ENTITY_REGISTRY_TYPE'],
317 ]
318 ]);
319 if (!$dbRes->fetch())
320 {
321 throw new RestException('Incorrect person type id!', self::ERROR_PERSON_TYPE_NOT_FOUND);
322 }
323 }
324
329 private static function savePersonTypeId($serviceId, $personTypeId)
330 {
331 $params = [
332 'filter' => [
333 "SERVICE_ID" => $serviceId,
335 "=CLASS_NAME" => '\\'.Restrictions\PersonType::class
336 ]
337 ];
338
339 $dbRes = Internals\ServiceRestrictionTable::getList($params);
340 if ($data = $dbRes->fetch())
341 {
342 $restrictionId = $data['ID'];
343 }
344 else
345 {
346 $restrictionId = 0;
347 }
348
349 $fields = array(
350 "SERVICE_ID" => $serviceId,
351 "SERVICE_TYPE" => Restrictions\Manager::SERVICE_TYPE_PAYMENT,
352 "SORT" => 100,
353 "PARAMS" => array('PERSON_TYPE_ID' => array($personTypeId))
354 );
355
356 Restrictions\PersonType::save($fields, $restrictionId);
357 }
358
365 public static function updatePaySystem(array $params, $n, \CRestServer $server)
366 {
367 static::checkPaySystemPermission();
368
369 $params = self::preparePaySystemParams($params, $server);
370
371 static::checkParamsBeforePaySystemUpdate($params);
372
373 $fields = array();
374 if (isset($params['FIELDS']['NAME']))
375 {
376 $fields['NAME'] = $params['FIELDS']['NAME'];
377 }
378
379 if (isset($params['FIELDS']['DESCRIPTION']))
380 {
381 $fields['DESCRIPTION'] = $params['FIELDS']['DESCRIPTION'];
382 }
383
384 if (isset($params['FIELDS']['NEW_WINDOW']))
385 {
386 $fields['NEW_WINDOW'] = $params['FIELDS']['NEW_WINDOW'];
387 }
388
389 if (isset($params['FIELDS']['ACTIVE']))
390 {
391 $fields['ACTIVE'] = $params['FIELDS']['ACTIVE'];
392 }
393
394 if (isset($params['FIELDS']['PERSON_TYPE_ID']))
395 {
396 $fields['PERSON_TYPE_ID'] = $params['FIELDS']['PERSON_TYPE_ID'];
397 }
398
399 if (isset($params['FIELDS']['BX_REST_HANDLER']))
400 {
401 $fields['ACTION_FILE'] = $params['FIELDS']['BX_REST_HANDLER'];
402 }
403
404 if (isset($params['FIELDS']['XML_ID']))
405 {
406 $fields['XML_ID'] = $params['FIELDS']['XML_ID'];
407 }
408
409 if (isset($params['FIELDS']['LOGOTIP']))
410 {
411 $fields['LOGOTIP'] = self::saveFile($params['FIELDS']['LOGOTIP']);
412 }
413
415
416 if ($fields['PERSON_TYPE_ID'] > 0)
417 {
418 static::savePersonTypeId($params['ID'], $fields['PERSON_TYPE_ID']);
419 }
420
421 return $result->isSuccess();
422 }
423
429 protected static function checkParamsBeforePaySystemUpdate($params)
430 {
431 $handlerList = Manager::getHandlerList();
432
433 $handler = $params['FIELDS']['BX_REST_HANDLER'] ?? null;
434 if ($handler && !isset($handlerList['USER'][$handler]) && !isset($handlerList['SYSTEM'][$handler]))
435 {
436 throw new RestException('Handler not found', self::ERROR_HANDLER_NOT_FOUND);
437 }
438
439 if ((int)($params['ID'] ?? 0) === 0)
440 {
441 throw new RestException('Parameter ID is not defined', self::ERROR_CHECK_FAILURE);
442 }
443
445 'filter' => [
446 'ID' => $params['ID'],
447 ]
448 ]);
449
450 $data = $dbRes->fetch();
451 if (!$data)
452 {
453 throw new RestException('Pay system not found', self::ERROR_PAY_SYSTEM_NOT_FOUND);
454 }
455
456 if (!self::hasAccessToPaySystem($data, $params['APP_ID']))
457 {
458 throw new AccessException();
459 }
460
461 if (isset($params['FIELDS']['PERSON_TYPE_ID']))
462 {
463 $dbRes = Internals\PersonTypeTable::getList([
464 'filter' => [
465 '=ID' => $params['FIELDS']['PERSON_TYPE_ID'],
466 '=ENTITY_REGISTRY_TYPE' => $data['ENTITY_REGISTRY_TYPE'],
467 ]
468 ]);
469 if (!$dbRes->fetch())
470 {
471 throw new RestException('Incorrect person type id!', self::ERROR_PERSON_TYPE_NOT_FOUND);
472 }
473 }
474 }
475
483 public static function updateSettings(array $params, $n, \CRestServer $server)
484 {
485 static::checkPaySystemPermission();
486
487 $params = self::preparePaySystemParams($params, $server);
488
489 static::checkParamsBeforeSettingsUpdate($params);
490
491 foreach ($params['SETTINGS'] as $field => $value)
492 {
493 if (!is_array($value))
494 {
495 throw new RestException('The value of SETTINGS[' . $field . '] is not valid', self::ERROR_CHECK_FAILURE);
496 }
497
499 $field,
501 $params['PERSON_TYPE_ID'],
502 [
503 'PROVIDER_KEY' => $value['TYPE'],
504 'PROVIDER_VALUE' => $value['VALUE']
505 ]
506 );
507
508 if (!$result->isSuccess())
509 {
510 return false;
511 }
512 }
513
514 return true;
515 }
516
521 protected static function checkParamsBeforeSettingsUpdate($params)
522 {
523 if (!isset($params['ID']))
524 {
525 throw new RestException('Parameter ID is not defined', self::ERROR_CHECK_FAILURE);
526 }
527
528 $item = Manager::getById($params['ID']);
529 if (!$item)
530 {
531 throw new RestException('Pay system not found', static::ERROR_CHECK_FAILURE);
532 }
533
534 if (!isset($params['SETTINGS']) || empty($params['SETTINGS']))
535 {
536 throw new RestException('Parameter SETTINGS is not defined or empty', self::ERROR_HANDLER_NOT_FOUND);
537 }
538
539 if (!self::hasAccessToPaySystem($item, $params['APP_ID']))
540 {
541 throw new AccessException();
542 }
543 }
544
551 public static function getSettings(array $params, $n, \CRestServer $server)
552 {
553 static::checkPaySystemPermission();
554
555 $params = self::preparePaySystemParams($params, $server);
556
557 static::checkParamsBeforeSettingsGet($params);
558
559 $result = [];
560
561 $consumers = BusinessValue::getConsumers();
562 $codes = $consumers[Service::PAY_SYSTEM_PREFIX.$params['ID']]['CODES'];
563
564 foreach ($codes as $field => $value)
565 {
566 $mapping = BusinessValue::getMapping(
567 $field,
569 $params['PERSON_TYPE_ID']
570 );
571
572 $result[$field] = [
573 'TYPE' => $mapping['PROVIDER_KEY'],
574 'VALUE' => $mapping['PROVIDER_VALUE']
575 ];
576 }
577
578 return $result;
579 }
580
586 protected static function checkParamsBeforeSettingsGet($params)
587 {
588 if (!isset($params['PERSON_TYPE_ID']))
589 {
590 throw new RestException('Parameter PERSON_TYPE_ID is not defined', self::ERROR_CHECK_FAILURE);
591 }
592
593 if (!isset($params['ID']))
594 {
595 throw new RestException('Parameter ID is not defined', self::ERROR_CHECK_FAILURE);
596 }
597
598 $item = Manager::getById($params['ID']);
599 if (!$item)
600 {
601 throw new RestException('Pay system not found', static::ERROR_CHECK_FAILURE);
602 }
603
604 if (!self::hasAccessToPaySystem($item, $params['APP_ID']))
605 {
606 throw new AccessException();
607 }
608 }
609
614 public static function deletePaySystem(array $params, $n, \CRestServer $server)
615 {
616 static::checkPaySystemPermission();
617
618 $params = self::preparePaySystemParams($params, $server);
619
620 static::checkParamsBeforePaySystemDelete($params);
621
623
624 return $result->isSuccess();
625 }
626
632 protected static function checkParamsBeforePaySystemDelete($params)
633 {
634 if ((int)($params['ID'] ?? 0) === 0)
635 {
636 throw new RestException('Parameter ID is not defined', self::ERROR_CHECK_FAILURE);
637 }
638
640 if (!$data)
641 {
642 throw new RestException('Pay system not found', self::ERROR_PAY_SYSTEM_NOT_FOUND);
643 }
644
645 if (!self::hasAccessToPaySystem($data, $params['APP_ID']))
646 {
647 throw new AccessException();
648 }
649 }
650
658 public static function addHandler(array $params, $n, \CRestServer $server)
659 {
660 static::checkPaySystemPermission();
661
662 $params = self::prepareHandlerParams($params, $server);
663
664 self::checkParamsOnAddHandler($params);
665
666 $data = [
667 'NAME' => $params['NAME'],
668 'CODE' => $params['CODE'],
669 'SORT' => $params['SORT'] ?? 100,
670 'SETTINGS' => $params['SETTINGS'],
671 'APP_ID' => $params['APP_ID'],
672 ];
673
674 $result = Internals\PaySystemRestHandlersTable::add($data);
675 if ($result->isSuccess())
676 {
677 return $result->getId();
678 }
679
680 $error = implode("\n", $result->getErrorMessages());
681 throw new RestException($error, self::ERROR_HANDLER_ADD);
682 }
683
688 private static function checkParamsOnAddHandler(array $params)
689 {
690 if (!isset($params['NAME']))
691 {
692 throw new RestException('Parameter NAME is not defined', self::ERROR_CHECK_FAILURE);
693 }
694
695 if (!isset($params['CODE']))
696 {
697 throw new RestException('Parameter CODE is not defined', self::ERROR_CHECK_FAILURE);
698 }
699
700 if (!isset($params['SETTINGS']))
701 {
702 throw new RestException('Parameter SETTINGS is not defined', self::ERROR_CHECK_FAILURE);
703 }
704
705 if (!isset($params['SETTINGS']['CODES']))
706 {
707 throw new RestException('Parameter SETTINGS[CODES] is not defined', self::ERROR_CHECK_FAILURE);
708 }
709
710 if (
711 empty($params['SETTINGS']['FORM_DATA'])
712 && empty($params['SETTINGS']['CHECKOUT_DATA'])
713 && empty($params['SETTINGS']['IFRAME_DATA'])
714 )
715 {
716 throw new RestException(
717 'Parameter SETTINGS[FORM_DATA] or SETTINGS[CHECKOUT_DATA] or SETTINGS[IFRAME_DATA] is not defined',
718 self::ERROR_CHECK_FAILURE
719 );
720 }
721
722 if (
723 !empty($params['SETTINGS']['FORM_DATA'])
724 && empty($params['SETTINGS']['FORM_DATA']['ACTION_URI'])
725 )
726 {
727 throw new RestException('Parameter SETTINGS[FORM_DATA][ACTION_URI] is not defined', self::ERROR_CHECK_FAILURE);
728 }
729
730 if (
731 !empty($params['SETTINGS']['CHECKOUT_DATA'])
732 && empty($params['SETTINGS']['CHECKOUT_DATA']['ACTION_URI'])
733 )
734 {
735 throw new RestException('Parameter SETTINGS[IFRAME_DATA][ACTION_URI] is not defined', self::ERROR_CHECK_FAILURE);
736 }
737
738 if (
739 !empty($params['SETTINGS']['IFRAME_DATA'])
740 && empty($params['SETTINGS']['IFRAME_DATA']['ACTION_URI'])
741 )
742 {
743 throw new RestException('Parameter SETTINGS[IFRAME_DATA][ACTION_URI] is not defined', self::ERROR_CHECK_FAILURE);
744 }
745
746 if (
747 isset($params['SETTINGS']['CLIENT_TYPE'])
748 && !ClientType::isValid((string)$params['SETTINGS']['CLIENT_TYPE'])
749 )
750 {
751 throw new RestException('Parameter value SETTINGS[CLIENT_TYPE] is invalid', self::ERROR_CHECK_FAILURE);
752 }
753
754 $dbRes = Internals\PaySystemRestHandlersTable::getList([
755 'filter' => [
756 '=CODE' => $params['CODE']
757 ]
758 ]);
759 if ($dbRes->fetch())
760 {
761 throw new RestException('Handler already exists!', self::ERROR_HANDLER_ALREADY_EXIST);
762 }
763 }
764
772 public static function updateHandler(array $params, $n, \CRestServer $server)
773 {
774 static::checkPaySystemPermission();
775
776 $params = self::prepareHandlerParams($params, $server);
777
778 self::checkParamsOnUpdateHandler($params);
779
780 $result = Internals\PaySystemRestHandlersTable::update($params['ID'], $params['FIELDS']);
781 if ($result->isSuccess())
782 {
783 return true;
784 }
785
786 $error = implode("\n", $result->getErrorMessages());
787 throw new RestException($error, self::ERROR_HANDLER_UPDATE);
788 }
789
795 private static function checkParamsOnUpdateHandler(array $params)
796 {
797 if (!isset($params['FIELDS']) || !is_array($params['FIELDS']))
798 {
799 throw new RestException('Parameter FIELDS is not defined', self::ERROR_CHECK_FAILURE);
800 }
801
802 if (
803 isset($params['SETTINGS']['CLIENT_TYPE'])
804 && !ClientType::isValid((string)$params['SETTINGS']['CLIENT_TYPE'])
805 )
806 {
807 throw new RestException('Parameter value SETTINGS[CLIENT_TYPE] is invalid', self::ERROR_CHECK_FAILURE);
808 }
809
810 $paySystemRestHandlers = Internals\PaySystemRestHandlersTable::getList(array(
811 'filter' => array(
812 'ID' => $params['ID']
813 )
814 ))->fetch();
815 if (!$paySystemRestHandlers)
816 {
817 throw new RestException('Handler not found', self::ERROR_HANDLER_NOT_FOUND);
818 }
819
820 if ($params['APP_ID'] && !empty($paySystemRestHandlers['APP_ID']) && $paySystemRestHandlers['APP_ID'] !== $params['APP_ID'])
821 {
822 throw new AccessException();
823 }
824 }
825
833 public static function deleteHandler(array $params, $n, \CRestServer $server)
834 {
835 static::checkPaySystemPermission();
836
837 $params = self::prepareHandlerParams($params, $server);
838
839 self::checkParamsOnDeleteHandler($params);
840
841 $result = Internals\PaySystemRestHandlersTable::delete($params['ID']);
842 if ($result->isSuccess())
843 {
844 return true;
845 }
846
847 $error = implode("\n", $result->getErrorMessages());
848 throw new RestException($error, self::ERROR_HANDLER_DELETE);
849 }
850
855 private static function checkParamsOnDeleteHandler($params): void
856 {
857 $dbRes = Internals\PaySystemRestHandlersTable::getList(array(
858 'filter' => array(
859 'ID' => $params['ID']
860 )
861 ));
862 $data = $dbRes->fetch();
863 if (!$data)
864 {
865 throw new RestException('Handler not found', self::ERROR_HANDLER_NOT_FOUND);
866 }
867
868 if ($params['APP_ID'] && !empty($data['APP_ID']) && $data['APP_ID'] !== $params['APP_ID'])
869 {
870 throw new AccessException();
871 }
872
873 $dbRes = Manager::getList(array('filter' => array('ACTION_FILE' => $data['CODE'])));
874 if ($dbRes->fetch())
875 {
876 throw new RestException('Pay system with handler '.mb_strtoupper($data['CODE']).' exists!', self::ERROR_PAY_SYSTEM_DELETE);
877 }
878 }
879
886 public static function getHandlerList(array $params, $n, \CRestServer $server)
887 {
888 static::checkPaySystemPermission();
889
890 $result = array();
891 $dbRes = Internals\PaySystemRestHandlersTable::getList([
892 'select' => ['ID', 'NAME', 'CODE', 'SORT', 'SETTINGS'],
893 ]);
894 while ($item = $dbRes->fetch())
895 {
896 $result[] = $item;
897 }
898
899 return $result;
900 }
901
908 public static function getPaySystemList(array $params, $n, \CRestServer $server)
909 {
910 static::checkPaySystemPermission();
911 $params = self::prepareIncomingParams($params);
912 self::checkParamsBeforePaySystemListGet($params);
913
914 $select =
915 isset($params['SELECT']) && is_array($params['SELECT'])
916 ? array_flip(self::prepareIncomingParams(array_flip($params['SELECT'])))
917 : array_keys(self::ALLOWED_PAYSYSTEM_FIELDS)
918 ;
919
920 $filter = [];
921 $filterFromParams = isset($params['FILTER']) && is_array($params['FILTER']) ? $params['FILTER'] : [];
922 if ($filterFromParams)
923 {
924 $incomingFieldsMap = self::getIncomingFieldsMap();
925 foreach ($filterFromParams as $rawName => $value)
926 {
927 $filterField = \CSqlUtil::GetFilterOperation($rawName);
928 $fieldName = $incomingFieldsMap[$filterField['FIELD']] ?? $filterField['FIELD'];
929 $filter[$fieldName] = $value;
930 }
931 }
932
933 $order =
934 isset($params['ORDER']) && is_array($params['ORDER'])
935 ? self::prepareIncomingParams($params['ORDER'])
936 : []
937 ;
938
939 $result = array();
941 'select' => $select,
942 'filter' => $filter,
943 'order' => $order,
944 ]);
945 while ($item = $dbRes->fetch())
946 {
947 $result[] = self::prepareOutcomingFields($item);
948 }
949
950 return $result;
951 }
952
957 private static function checkParamsBeforePaySystemListGet(array $params)
958 {
959 $select = isset($params['SELECT']) && is_array($params['SELECT']) ? $params['SELECT'] : [];
960 if ($select)
961 {
962 $select = array_flip(self::prepareIncomingParams(array_flip($select)));
963 $diffSelect = array_diff(
964 $select,
965 array_keys(self::ALLOWED_PAYSYSTEM_FIELDS)
966 );
967
968 if ($diffSelect)
969 {
970 throw new RestException(
971 implode(', ', $diffSelect) . ' not allowed for select',
972 self::ERROR_CHECK_FAILURE
973 );
974 }
975 }
976
977 $filter = isset($params['FILTER']) && is_array($params['FILTER']) ? $params['FILTER'] : [];
978 if ($filter)
979 {
980 $filterFields = [];
981 foreach ($filter as $rawName => $value)
982 {
983 $filterField = \CSqlUtil::GetFilterOperation($rawName);
984 if (isset($filterField['FIELD']))
985 {
986 $filterFields[] = $filterField['FIELD'];
987 }
988 }
989
990 $filterFields = array_flip(self::prepareIncomingParams(array_flip($filterFields)));
991 $diffFilter = array_diff(
993 array_keys(self::ALLOWED_PAYSYSTEM_FIELDS)
994 );
995 if ($diffFilter)
996 {
997 throw new RestException(
998 implode(', ', $diffFilter) . ' not allowed for filter',
999 self::ERROR_CHECK_FAILURE
1000 );
1001 }
1002 }
1003
1004 $order =
1005 isset($params['ORDER']) && is_array($params['ORDER'])
1006 ? self::prepareIncomingParams($params['ORDER'])
1007 : []
1008 ;
1009 if ($order)
1010 {
1011 $diffOrder = array_diff(
1012 array_keys($order),
1013 array_keys(self::ALLOWED_PAYSYSTEM_FIELDS)
1014 );
1015 if ($diffOrder)
1016 {
1017 throw new RestException(
1018 implode(', ', $diffOrder) . ' not allowed for order',
1019 self::ERROR_CHECK_FAILURE
1020 );
1021 }
1022 }
1023 }
1024
1032 public static function getSettingsByInvoice(array $params, $n, \CRestServer $server)
1033 {
1034 static::checkInvoicePermission();
1035
1036 $params = self::preparePaySystemParams($params, $server);
1037
1038 self::checkParamsBeforeSettingsByInvoiceGet($params);
1039
1040 if (isset($params['PAY_SYSTEM_ID']))
1041 {
1042 $service = Manager::getObjectById($params['PAY_SYSTEM_ID']);
1043 }
1044 else
1045 {
1046 $dbRes = Manager::getList(array('filter' => array('=ACTION_FILE' => $params['BX_REST_HANDLER'])));
1047 $item = $dbRes->fetch();
1048 if (!$item)
1049 {
1050 throw new RestException('Pay system with handler '.$params['BX_REST_HANDLER'].' not found', self::ERROR_PAY_SYSTEM_NOT_FOUND);
1051 }
1052
1053 $service = new Service($item);
1054 }
1055
1056 $invoice = Invoice\Invoice::load($params['INVOICE_ID']);
1057 if ($invoice)
1058 {
1059 $paymentCollection = $invoice->getPaymentCollection();
1061 {
1063 foreach ($paymentCollection as $payment)
1064 {
1065 if (!$payment->isInner())
1066 {
1067 return $service->getParamsBusValue($payment);
1068 }
1069 }
1070 }
1071 }
1072
1073 throw new RestException('Invoice #'.$params['INVOICE_ID'].' not found', self::ERROR_INTERNAL_INVOICE_NOT_FOUND);
1074 }
1075
1083 public static function getSettingsByPayment(array $params, $n, \CRestServer $server)
1084 {
1085 static::checkOrderPermission();
1086
1087 $params = self::preparePaySystemParams($params, $server);
1088
1089 self::checkParamsBeforeSettingsByPaymentGet($params);
1090
1091 [$orderId, $paymentId] = Manager::getIdsByPayment($params['PAYMENT_ID']);
1092
1094
1096 $orderClassName = $registry->getOrderClassName();
1097 $order = $orderClassName::load($orderId);
1098 if ($order)
1099 {
1100 $paymentCollection = $order->getPaymentCollection();
1101
1103 $payment = $paymentCollection->getItemById($paymentId);
1104
1105 $service = Manager::getObjectById($params['PAY_SYSTEM_ID']);
1106
1107 return $service->getParamsBusValue($payment);
1108 }
1109
1110 throw new RestException('Order #'.$orderId.' not found', self::ERROR_INTERNAL_ORDER_NOT_FOUND);
1111 }
1112
1120 public static function payInvoice(array $params, $n, \CRestServer $server)
1121 {
1122 if (!Main\Loader::includeModule('crm'))
1123 {
1124 throw new RestException('Pay invoice is not supported!', self::ERROR_PAY_INVOICE_NOT_SUPPORTED);
1125 }
1126
1127 static::checkInvoicePermission();
1128
1129 $params = self::prepareIncomingParams($params);
1130
1131 self::checkParamsForInvoice($params);
1132
1133 $dbRes = Invoice\Payment::getList(array(
1134 'select' => array('ID'),
1135 'filter' => array(
1136 'ORDER_ID' => $params['INVOICE_ID'],
1137 '!PAY_SYSTEM_ID' => Manager::getInnerPaySystemId(),
1138 )
1139 ));
1140
1141 $payment = $dbRes->fetch();
1142 if (!$payment)
1143 {
1144 throw new RestException('Invoice #'.$params['INVOICE_ID'].' not found', self::ERROR_INTERNAL_INVOICE_NOT_FOUND);
1145 }
1146
1147 $params['PAYMENT_ID'] = $payment['ID'];
1148
1149 $filter = [
1150 '=ENTITY_REGISTRY_TYPE' => REGISTRY_TYPE_CRM_INVOICE
1151 ];
1152
1153 if (isset($params['PAY_SYSTEM_ID']))
1154 {
1155 $filter['=ID'] = $params['PAY_SYSTEM_ID'];
1156 }
1157 else
1158 {
1159 $filter['=ACTION_FILE'] = $params['BX_REST_HANDLER'];
1160 }
1161
1163 'select' => ['ID'],
1164 'filter' => $filter
1165 ]);
1166 $item = $dbRes->fetch();
1167 if (!$item)
1168 {
1169 throw new RestException('Pay system not found', static::ERROR_PROCESS_REQUEST_RESULT);
1170 }
1171
1172 $params['PAY_SYSTEM_ID'] = $item['ID'];
1173
1174 return self::payPaymentInternal($params, $server);
1175 }
1176
1183 public static function payPayment(array $params, $n, \CRestServer $server)
1184 {
1185 static::checkOrderPermission();
1186
1187 $params = self::prepareIncomingParams($params);
1188
1189 self::checkParamsForPayment($params);
1190
1191 return self::payPaymentInternal($params, $server);
1192 }
1193
1200 private static function payPaymentInternal(array $params, \CRestServer $restServer)
1201 {
1202 $context = Main\Context::getCurrent();
1203 $server = $context->getServer();
1204
1205 $request = new Main\HttpRequest($server, array(), $params, array(), array());
1206
1207 $service = Manager::getObjectById($params['PAY_SYSTEM_ID']);
1208
1209 $result = $service->processRequest($request);
1210 if (!$result->isSuccess())
1211 {
1212 $error = join("\n", $result->getErrorMessages());
1213 throw new RestException($error, static::ERROR_PROCESS_REQUEST_RESULT);
1214 }
1215
1216 static::logAnalytics(
1217 'payPayment' . $service->getField('ENTITY_REGISTRY_TYPE'),
1218 $service->getField('ACTION_FILE'),
1219 $service->getField('PERSON_TYPE_ID'),
1220 $restServer
1221 );
1222
1223 return true;
1224 }
1225
1231 private static function arrayChangeKeyCaseRecursive(array $data, $case = CASE_UPPER)
1232 {
1233 return array_map(static function ($item) use ($case) {
1234 if (is_array($item))
1235 {
1236 $item = self::arrayChangeKeyCaseRecursive($item, $case);
1237 }
1238 return $item;
1239 }, array_change_key_case($data, $case));
1240 }
1241
1246 private static function prepareIncomingParams(array $data): array
1247 {
1248 return self::replaceIncomingKeys(self::arrayChangeKeyCaseRecursive($data));
1249 }
1250
1256 private static function prepareHandlerParams(array $data, \CRestServer $server): array
1257 {
1258 $data = self::replaceIncomingKeys(array_change_key_case($data, CASE_UPPER));
1259 $data['APP_ID'] = $server->getClientId();
1260
1261 return $data;
1262 }
1263
1264 private static function preparePaySystemParams(array $data, \CRestServer $server): array
1265 {
1266 $data = self::prepareIncomingParams($data);
1267 $data['APP_ID'] = $server->getClientId();
1268
1269 return $data;
1270 }
1271
1276 private static function checkParamsForInvoice(array $params)
1277 {
1278 if (!isset($params['BX_REST_HANDLER']) && !isset($params['PAY_SYSTEM_ID']))
1279 {
1280 throw new RestException('Empty field BX_REST_HANDLER and PAY_SYSTEM_ID', self::ERROR_CHECK_FAILURE);
1281 }
1282
1283 if (isset($params['PAY_SYSTEM_ID']))
1284 {
1285 $data = Manager::getById($params['PAY_SYSTEM_ID']);
1286 if (!$data)
1287 {
1288 throw new RestException('Pay system with ID='.$params['PAY_SYSTEM_ID'].' not found', static::ERROR_CHECK_FAILURE);
1289 }
1290 }
1291
1292 if (isset($params['BX_REST_HANDLER']))
1293 {
1294 $dbRes = Internals\PaySystemRestHandlersTable::getList(array(
1295 'filter' => array(
1296 '=CODE' => $params['BX_REST_HANDLER']
1297 )
1298 ));
1299 if (!$dbRes->fetch())
1300 {
1301 throw new RestException('Incorrect rest handler code', static::ERROR_CHECK_FAILURE);
1302 }
1303 }
1304
1305 if (empty($params['INVOICE_ID']))
1306 {
1307 throw new RestException('Empty field INVOICE_ID!', self::ERROR_CHECK_FAILURE);
1308 }
1309 }
1310
1316 private static function checkParamsBeforeSettingsByInvoiceGet(array $params)
1317 {
1318 if (!isset($params['BX_REST_HANDLER']) && !isset($params['PAY_SYSTEM_ID']))
1319 {
1320 throw new RestException('Empty field BX_REST_HANDLER and PAY_SYSTEM_ID', self::ERROR_CHECK_FAILURE);
1321 }
1322
1323 if (empty($params['INVOICE_ID']))
1324 {
1325 throw new RestException('Empty field INVOICE_ID', self::ERROR_CHECK_FAILURE);
1326 }
1327
1328 if (isset($params['PAY_SYSTEM_ID']))
1329 {
1330 $data = Manager::getById($params['PAY_SYSTEM_ID']);
1331 if (!$data)
1332 {
1333 throw new RestException('Pay system with ID='.$params['PAY_SYSTEM_ID'].' not found', static::ERROR_CHECK_FAILURE);
1334 }
1335
1336 if (!self::hasAccessToPaySystem($data, $params['APP_ID']))
1337 {
1338 throw new AccessException();
1339 }
1340 }
1341
1342 if (isset($params['BX_REST_HANDLER']))
1343 {
1344 $dbRes = Internals\PaySystemRestHandlersTable::getList(array(
1345 'filter' => array(
1346 '=CODE' => $params['BX_REST_HANDLER']
1347 )
1348 ));
1349
1350 $handlerData = $dbRes->fetch();
1351 if (!$handlerData)
1352 {
1353 throw new RestException('Incorrect rest handler code', static::ERROR_CHECK_FAILURE);
1354 }
1355
1356 if ($params['APP_ID'] && !empty($handlerData['APP_ID']) && $handlerData['APP_ID'] !== $params['APP_ID'])
1357 {
1358 throw new AccessException();
1359 }
1360 }
1361 }
1362
1368 private static function checkParamsForPayment(array $params)
1369 {
1370 if (empty($params['PAY_SYSTEM_ID']))
1371 {
1372 throw new RestException('Empty field PAY_SYSTEM_ID!', self::ERROR_CHECK_FAILURE);
1373 }
1374
1375 $item = Manager::getById($params['PAY_SYSTEM_ID']);
1376 if (!$item)
1377 {
1378 throw new RestException('Pay system not found', static::ERROR_CHECK_FAILURE);
1379 }
1380
1381 if (empty($params['PAYMENT_ID']))
1382 {
1383 throw new RestException('Empty field PAYMENT_ID', self::ERROR_CHECK_FAILURE);
1384 }
1385
1387
1389 $paymentClassName = $registry->getPaymentClassName();
1390 $dbRes = $paymentClassName::getList([
1391 'select' => ['ID', 'PAY_SYSTEM_ID'],
1392 'filter' => [
1393 '=ID' => $params['PAYMENT_ID'],
1394 '=PAY_SYSTEM_ID' => $params['PAY_SYSTEM_ID']
1395 ]
1396 ]);
1397
1398 if (!$dbRes->fetch())
1399 {
1400 throw new RestException(
1401 'Payment with ID='
1402 . $params['PAYMENT_ID']
1403 . ' and PAY_SYSTEM_ID='.$params['PAY_SYSTEM_ID']
1404 . ' not found', self::ERROR_CHECK_FAILURE
1405 );
1406 }
1407 }
1408
1414 private static function checkParamsBeforeSettingsByPaymentGet(array $params)
1415 {
1416 if (empty($params['PAY_SYSTEM_ID']))
1417 {
1418 throw new RestException('Empty field PAY_SYSTEM_ID!', self::ERROR_CHECK_FAILURE);
1419 }
1420
1421 if (empty($params['PAYMENT_ID']))
1422 {
1423 throw new RestException('Empty field PAYMENT_ID', self::ERROR_CHECK_FAILURE);
1424 }
1425
1426 $item = Manager::getById($params['PAY_SYSTEM_ID']);
1427 if (!$item)
1428 {
1429 throw new RestException('Pay system not found', static::ERROR_CHECK_FAILURE);
1430 }
1431
1432 if (!self::hasAccessToPaySystem($item, $params['APP_ID']))
1433 {
1434 throw new AccessException();
1435 }
1436
1438
1440 $paymentClassName = $registry->getPaymentClassName();
1441 $dbRes = $paymentClassName::getList([
1442 'select' => ['ID', 'PAY_SYSTEM_ID'],
1443 'filter' => [
1444 '=ID' => $params['PAYMENT_ID'],
1445 '=PAY_SYSTEM_ID' => $params['PAY_SYSTEM_ID']
1446 ]
1447 ]);
1448
1449 if (!$dbRes->fetch())
1450 {
1451 throw new RestException(
1452 'Payment with ID='
1453 . $params['PAYMENT_ID']
1454 . ' and PAY_SYSTEM_ID='.$params['PAY_SYSTEM_ID']
1455 . ' not found', self::ERROR_CHECK_FAILURE
1456 );
1457 }
1458 }
1459
1464 protected static function checkOrderPermission()
1465 {
1466 global $APPLICATION;
1467
1468 if (IsModuleInstalled('intranet') && Main\Loader::includeModule('crm'))
1469 {
1470 $crmUserPermissions = Container::getInstance()->getUserPermissions()->entityType();
1471 if (
1472 !$crmUserPermissions->canAddItems(\CCrmOwnerType::Order)
1473 && !$crmUserPermissions->canUpdateItems(\CCrmOwnerType::Order)
1474 )
1475 {
1476 throw new AccessException();
1477 }
1478 }
1479 else
1480 {
1481 $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
1482
1483 if ($saleModulePermissions == "D")
1484 {
1485 throw new AccessException();
1486 }
1487 }
1488 }
1489
1493 protected static function checkInvoicePermission(): void
1494 {
1495 global $APPLICATION;
1496
1497 if (IsModuleInstalled('intranet') && Main\Loader::includeModule('crm'))
1498 {
1499 $crmUserPermissions = Container::getInstance()->getUserPermissions()->entityType();
1500 if (
1501 !$crmUserPermissions->canUpdateItems(\CCrmOwnerType::Invoice)
1502 && !$crmUserPermissions->canAddItems(\CCrmOwnerType::Invoice)
1503 )
1504 {
1505 throw new AccessException();
1506 }
1507 }
1508 else
1509 {
1510 $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
1511
1512 if($saleModulePermissions == "D")
1513 {
1514 throw new AccessException();
1515 }
1516 }
1517 }
1518
1527
1532 private static function saveFile($fileContent)
1533 {
1534 $file = \CRestUtil::saveFile($fileContent);
1535 if ($file)
1536 {
1537 $file['MODULE_ID'] = 'sale';
1538 return \CFile::SaveFile($file, 'sale');
1539 }
1540
1541 return null;
1542 }
1543
1547 private static function getIncomingFieldsMap(): array
1548 {
1549 return [
1550 'LOGOTYPE' => 'LOGOTIP',
1551 'TARIFF' => 'TARIF',
1552 ];
1553 }
1554
1558 private static function getOutcomingFieldsMap(): array
1559 {
1560 return [
1561 'LOGOTIP' => 'LOGOTYPE',
1562 'TARIF' => 'TARIFF',
1563 ];
1564 }
1565
1566 private static function prepareOutcomingFields(array $data): array
1567 {
1568 return self::replaceOutcomingKeys(
1569 static::castOutcomingFieldsData($data)
1570 );
1571 }
1572
1573 private static function getFieldNamesOfType(string $type): array
1574 {
1575 return array_keys(
1576 array_filter(
1577 self::ALLOWED_PAYSYSTEM_FIELDS,
1578 static function ($field) use ($type)
1579 {
1580 return isset($field['TYPE']) && $field['TYPE'] === $type;
1581 }
1582 )
1583 );
1584 }
1585
1586 protected static function castOutcomingFieldsData(array $data): array
1587 {
1588 $result = [];
1589
1590 $stringFields = self::getFieldNamesOfType('string');
1591 foreach ($stringFields as $stringField)
1592 {
1593 if (!array_key_exists($stringField, $data))
1594 {
1595 continue;
1596 }
1597
1598 $result[$stringField] = isset($data[$stringField])
1599 ? (string)$data[$stringField]
1600 : null
1601 ;
1602 }
1603
1604 $intFields = self::getFieldNamesOfType('integer');
1605 foreach ($intFields as $intField)
1606 {
1607 if (!array_key_exists($intField, $data))
1608 {
1609 continue;
1610 }
1611
1612 $result[$intField] = isset($data[$intField])
1613 ? (int)$data[$intField]
1614 : null
1615 ;
1616 }
1617
1618 return $result;
1619 }
1620
1625 private static function replaceIncomingKeys(array $data): array
1626 {
1627 return self::replaceKeys($data, self::getIncomingFieldsMap());
1628 }
1629
1634 private static function replaceOutcomingKeys(array $data): array
1635 {
1636 return self::replaceKeys($data, self::getOutcomingFieldsMap());
1637 }
1638
1644 private static function replaceKeys(array $data, array $map): array
1645 {
1646 foreach ($map as $key => $newKey)
1647 {
1648 if (array_key_exists($key, $data))
1649 {
1650 $data[$newKey] = $data[$key];
1651 unset($data[$key]);
1652 }
1653
1654 if (
1655 isset($data['FIELDS'])
1656 && is_array($data['FIELDS'])
1657 && array_key_exists($key, $data['FIELDS'])
1658 )
1659 {
1660 $data['FIELDS'][$newKey] = $data['FIELDS'][$key];
1661 unset($data['FIELDS'][$key]);
1662 }
1663 }
1664
1665 return $data;
1666 }
1667
1668 private static function logAnalytics($action, $handler, $personType, \CRestServer $restServer) : bool
1669 {
1670 $code = '';
1671 $type = '';
1672 if ($restServer->getAuthType() === \Bitrix\Rest\OAuth\Auth::AUTH_TYPE)
1673 {
1674 $app = \Bitrix\Rest\AppTable::getByClientId($restServer->getClientId());
1675 if ($app['CODE'])
1676 {
1677 $code = $app['CODE'];
1678 $type = 'appCode';
1679 }
1680 }
1681 else
1682 {
1683 $code = $restServer->getPasswordId();
1684 $type = 'webHook';
1685 }
1686
1687 if ($code !== '')
1688 {
1689 $tag = uniqid($code, true);
1691 'sale',
1692 $action,
1693 $tag,
1694 $code,
1695 $type
1696 );
1698 'sale',
1699 $action,
1700 $tag,
1701 $handler,
1702 'handler'
1703 );
1705 'sale',
1706 $action,
1707 $tag,
1708 $personType,
1709 'personType'
1710 );
1711 }
1712
1713 return true;
1714 }
1715
1716 private static function hasAccessToPaySystem(array $paySystemData, string $appId = null): bool
1717 {
1718 $handlerCode = $paySystemData['ACTION_FILE'];
1719 if (Manager::isRestHandler($handlerCode))
1720 {
1721 $handlerData = self::getHandlerData($handlerCode);
1722 if ($appId && !empty($handlerData['APP_ID']) && $handlerData['APP_ID'] !== $appId)
1723 {
1724 return false;
1725 }
1726 }
1727 else
1728 {
1729 return false;
1730 }
1731
1732 return true;
1733 }
1734
1735 private static function getHandlerData(string $code): ?array
1736 {
1737 static $result = [];
1738
1739 if (!empty($result[$code]))
1740 {
1741 return $result[$code];
1742 }
1743
1744 $handlerData = Internals\PaySystemRestHandlersTable::getList([
1745 'filter' => ['=CODE' => $code],
1746 'limit' => 1,
1747 ])->fetch();
1748 if (is_array($handlerData))
1749 {
1750 $result[$code] = $handlerData;
1751 }
1752
1753 return $result[$code] ?? null;
1754 }
1755}
$type
Определения options.php:106
global $APPLICATION
Определения include.php:80
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static getByClientId($clientId)
Определения app.php:967
static setMapping($codeKey, $consumerKey, $personTypeId, array $mapping, $withCommon=false)
Определения businessvalue.php:206
static getMapping($codeKey, $consumerKey=null, $personTypeId=null, array $options=array())
Определения businessvalue.php:131
static getConsumers()
Определения businessvalue.php:412
static isValid(string $value)
Определения clienttype.php:46
static getList(array $params=array())
Определения manager.php:84
static getInnerPaySystemId()
Определения manager.php:642
static getById($id)
Определения manager.php:93
static delete($primary)
Определения manager.php:815
static add(array $data)
Определения manager.php:158
static isRestHandler($handler)
Определения manager.php:1020
static getObjectById($id)
Определения manager.php:719
static update($primary, array $data)
Определения manager.php:128
static getPaySystemList(array $params, $n, \CRestServer $server)
Определения restservice.php:908
const ERROR_PAY_SYSTEM_NOT_FOUND
Определения restservice.php:35
static updateSettings(array $params, $n, \CRestServer $server)
Определения restservice.php:483
const ERROR_CHECK_FAILURE
Определения restservice.php:31
static onRestServiceBuildDescription()
Определения restservice.php:172
static onRestAppDelete(array $fields)
Определения restservice.php:128
static getSettings(array $params, $n, \CRestServer $server)
Определения restservice.php:551
static checkParamsBeforeSettingsUpdate($params)
Определения restservice.php:521
static updateHandler(array $params, $n, \CRestServer $server)
Определения restservice.php:772
const ERROR_PERSON_TYPE_NOT_FOUND
Определения restservice.php:34
static addPaySystem(array $params, $n, \CRestServer $server)
Определения restservice.php:205
static payInvoice(array $params, $n, \CRestServer $server)
Определения restservice.php:1120
const ERROR_HANDLER_ALREADY_EXIST
Определения restservice.php:32
static castOutcomingFieldsData(array $data)
Определения restservice.php:1586
static checkParamsBeforeSettingsGet($params)
Определения restservice.php:586
static checkParamsBeforePaySystemDelete($params)
Определения restservice.php:632
static getHandlerList(array $params, $n, \CRestServer $server)
Определения restservice.php:886
const ERROR_INTERNAL_ORDER_NOT_FOUND
Определения restservice.php:46
const ERROR_INTERNAL_INVOICE_NOT_FOUND
Определения restservice.php:45
static deleteHandler(array $params, $n, \CRestServer $server)
Определения restservice.php:833
static payPayment(array $params, $n, \CRestServer $server)
Определения restservice.php:1183
static checkOrderPermission()
Определения restservice.php:1464
const ERROR_PAY_SYSTEM_UPDATE
Определения restservice.php:42
const ERROR_PAY_INVOICE_NOT_SUPPORTED
Определения restservice.php:48
static checkPaySystemPermission()
Определения restservice.php:1523
static updatePaySystem(array $params, $n, \CRestServer $server)
Определения restservice.php:365
const ERROR_HANDLER_NOT_FOUND
Определения restservice.php:33
const ERROR_PAY_SYSTEM_ADD
Определения restservice.php:41
static addHandler(array $params, $n, \CRestServer $server)
Определения restservice.php:658
static checkParamsBeforePaySystemUpdate($params)
Определения restservice.php:429
static deletePaySystem(array $params, $n, \CRestServer $server)
Определения restservice.php:614
static checkInvoicePermission()
Определения restservice.php:1493
static checkParamsBeforePaySystemAdd($params)
Определения restservice.php:290
const ERROR_PROCESS_REQUEST_RESULT
Определения restservice.php:47
const ERROR_PAY_SYSTEM_DELETE
Определения restservice.php:43
const PAY_SYSTEM_PREFIX
Определения service.php:39
static getInstance($type)
Определения registry.php:183
const REGISTRY_TYPE_ORDER
Определения registry.php:16
Определения rest.php:24
getPasswordId()
Определения rest.php:367
getAuthType()
Определения rest.php:347
getClientId()
Определения rest.php:362
static GetFilterOperation($key)
Определения sql_util.php:45
Определения rest.php:896
$data['IS_AVAILABLE']
Определения .description.php:13
$orderId
Определения payment.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$fileContent
Определения file_property.php:47
$result
Определения get_property_values.php:14
$select
Определения iblock_catalog_list.php:194
$filter
Определения iblock_catalog_list.php:54
$filterFields
Определения iblock_catalog_list.php:55
$app
Определения proxy.php:8
$context
Определения csv_new_setup.php:223
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
IsModuleInstalled($module_id)
Определения tools.php:5301
AddEventToStatFile($module, $action, $tag, $label, $action_type='', $user_id=null)
Определения tools.php:3976
$map
Определения config.php:5
$payment
Определения payment.php:14
$order
Определения payment.php:8
$paymentCollection
Определения payment.php:11
$service
Определения payment.php:18
if(empty($signedUserToken)) $key
Определения quickway.php:257
$saleModulePermissions
Определения tools.php:21
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$error
Определения subscription_card_product.php:20
$action
Определения file_dialog.php:21
$n
Определения update_log.php:107
$dbRes
Определения yandex_detail.php:168
$fields
Определения yandex_run.php:501