Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
manager.php
1<?php
2
4
28
29Loc::loadMessages(__FILE__);
30
35final class Manager
36{
39
40 const EVENT_ON_GET_HANDLER_DESC = 'OnSaleGetHandlerDescription';
41 const EVENT_ON_PAYSYSTEM_UPDATE = 'OnSalePaySystemUpdate';
42
43 const CACHE_ID = "BITRIX_SALE_INNER_PS_ID";
44 const TTL = 31536000;
48 private static $handlerDirectories = array(
49 'CUSTOM' => '',
50 'LOCAL' => '/local/php_interface/include/sale_payment/',
51 'SYSTEM' => '/bitrix/modules/sale/handlers/paysystem/',
52
58 'SYSTEM_OLD' => '/bitrix/modules/sale/payment/'
59 );
60
66 public static function getHandlerDirectories()
67 {
68 $handlerDirectories = self::$handlerDirectories;
69 $handlerDirectories['CUSTOM'] = Option::get("sale", "path2user_ps_files", BX_PERSONAL_ROOT."/php_interface/include/sale_payment/");
70
71 if (IsModuleInstalled('intranet'))
72 {
73 unset($handlerDirectories['SYSTEM_OLD']);
74 }
75
76 return $handlerDirectories;
77 }
78
84 public static function getList(array $params = array())
85 {
86 return PaySystemActionTable::getList($params);
87 }
88
93 public static function getById($id)
94 {
95 if ((int)$id <= 0)
96 return false;
97
98 $params = array(
99 'select' => array('*'),
100 'filter' => array('ID' => $id)
101 );
102
103 $dbRes = self::getList($params);
104 return $dbRes->fetch();
105 }
106
111 public static function getByCode($code)
112 {
113 $params = array(
114 'select' => array('*'),
115 'filter' => array('CODE' => $code)
116 );
117
118 $dbRes = self::getList($params);
119 return $dbRes->fetch();
120 }
121
128 public static function update($primary, array $data): \Bitrix\Main\ORM\Data\UpdateResult
129 {
130 $oldFields = PaySystemActionTable::getByPrimary($primary)->fetch();
131 if ($oldFields)
132 {
133 $newFields = array_merge($oldFields, $data);
134 $data['PS_CLIENT_TYPE'] = (new Service($newFields))->getClientTypeFromHandler();
135 }
136
137 $updateResult = PaySystemActionTable::update($primary, $data);
138 if ($oldFields && $updateResult->isSuccess())
139 {
140 $oldFields = array_intersect_key($oldFields, $data);
141 $eventParams = [
142 'PAY_SYSTEM_ID' => $primary,
143 'OLD_FIELDS' => $oldFields,
144 'NEW_FIELDS' => $data,
145 ];
146 $event = new Event('sale', self::EVENT_ON_PAYSYSTEM_UPDATE, $eventParams);
147 $event->send();
148 }
149
150 return $updateResult;
151 }
152
158 public static function add(array $data): \Bitrix\Main\ORM\Data\AddResult
159 {
160 $data['PS_CLIENT_TYPE'] = (new Service($data))->getClientTypeFromHandler();
161
162 return PaySystemActionTable::add($data);
163 }
164
168 public static function generateXmlId()
169 {
170 return uniqid('bx_');
171 }
172
182 public static function searchByRequest(Request $request)
183 {
184 $documentRoot = Application::getDocumentRoot();
185
186 $items = self::getList([
187 'select' => ['*'],
188 'filter' => [
189 'ACTIVE' => 'Y',
190 ],
191 ]);
192
193 while ($item = $items->fetch())
194 {
195 $name = $item['ACTION_FILE'];
196
197 foreach (self::getHandlerDirectories() as $type => $path)
198 {
199 $className = '';
200 if (File::isFileExists($documentRoot.$path.$name.'/handler.php'))
201 {
202 [$className] = self::includeHandler($item['ACTION_FILE']);
203 }
204
205 if (class_exists($className) && is_callable(array($className, 'isMyResponse')))
206 {
207 if ($className::isMyResponse($request, $item['ID']))
208 {
209 return $item;
210 }
211 }
212 }
213 }
214
215 return false;
216 }
217
222 public static function getFolderFromClassName($className)
223 {
224 $pos = mb_strrpos($className, '\\');
225 if ($pos !== false)
226 $className = mb_substr($className, $pos + 1);
227
228 $folder = str_replace('Handler', '', $className);
229 $folder = self::sanitize($folder);
230 $folder = ToLower($folder);
231
232 return $folder;
233 }
234
239 public static function sanitize($name)
240 {
241 return preg_replace("/[^a-z0-9._]/i", "", $name);
242 }
243
249 public static function getIdsByPayment($paymentId, $registryType = Registry::REGISTRY_TYPE_ORDER): array
250 {
251 if (empty($paymentId))
252 {
253 return [0, 0];
254 }
255
256 $params = [
257 'select' => ['ID', 'ORDER_ID'],
258 ];
259
260 if (intval($paymentId).'|' == $paymentId.'|')
261 {
262 $params['filter']['=ID'] = $paymentId;
263 }
264 else
265 {
266 $params['filter']['=ACCOUNT_NUMBER'] = $paymentId;
267 }
268
269 $registry = Registry::getInstance($registryType);
270
272 $paymentClassName = $registry->getPaymentClassName();
273 $result = $paymentClassName::getList($params);
274 $data = $result->fetch() ?: [];
275
276 return [(int)$data['ORDER_ID'], (int)$data['ID']];
277 }
278
283 public static function getConsumersList()
284 {
285 $result = array();
286
287 $items = self::getList();
288
289 while ($item = $items->fetch())
290 {
291 $data = self::getHandlerDescription($item['ACTION_FILE'], $item['PS_MODE']);
292 $data['NAME'] = $item['NAME'];
293 $data['GROUP'] = 'PAYSYSTEM';
294 $data['PROVIDERS'] = [
295 'VALUE', 'COMPANY', 'ORDER', 'USER', 'PROPERTY',
296 'PAYMENT', 'BANK_DETAIL', 'MC_BANK_DETAIL',
297 'REQUISITE', 'MC_REQUISITE', 'CRM_COMPANY',
298 'CRM_MYCOMPANY', 'CRM_CONTACT'
299 ];
300
301 $result['PAYSYSTEM_'.$item['ID']] = $data;
302 }
303
304 return $result;
305 }
306
311 public static function getPsType($paySystemId)
312 {
313 $params = array(
314 'select' => array('IS_CASH'),
315 'filter' => array('ID' => $paySystemId)
316 );
317
318 $dbRes = self::getList($params);
319 $data = $dbRes->fetch();
320
321 return $data['IS_CASH'];
322 }
323
335 public static function getListWithRestrictionsByOrder(Order $order, float $sum = null, int $mode = Restrictions\Manager::MODE_CLIENT): array
336 {
338 $orderClone = $order->createClone();
339
340 $orderPrice = $orderClone->getPrice();
341 $paymentSum = $orderPrice;
342 if ($sum && $sum >= 0 && $sum <= $orderPrice)
343 {
344 $paymentSum = $sum;
345 }
346
347 $paymentCollection = $orderClone->getPaymentCollection();
348 $payment = $paymentCollection->createItem();
349 $payment->setFields([
350 'SUM' => $paymentSum,
351 ]);
352
353 return self::getListWithRestrictions($payment, $mode);
354 }
355
363 public static function getListWithRestrictions(Payment $payment, $mode = Restrictions\Manager::MODE_CLIENT)
364 {
365 $result = array();
366
367 $filter = [
368 '=ACTIVE' => 'Y',
369 '=ENTITY_REGISTRY_TYPE' => $payment::getRegistryType(),
370 ];
371
372 $bindingPaySystemIds = [];
373 if ($mode == Restrictions\Manager::MODE_CLIENT)
374 {
375 $bindingPaySystemIds = PaymentAvailablesPaySystems::getAvailablePaySystemIdsByPaymentId($payment->getId());
376 if ($bindingPaySystemIds)
377 {
378 $filter['=ID'] = $bindingPaySystemIds;
379 }
380 }
381
382 $dbRes = self::getList([
383 'filter' => $filter,
384 'order' => [
385 'SORT' => 'ASC',
386 'NAME' => 'ASC',
387 ],
388 ]);
389
390 while ($paySystem = $dbRes->fetch())
391 {
392 if ($bindingPaySystemIds)
393 {
394 $result[$paySystem['ID']] = $paySystem;
395 }
396 elseif ($mode == Restrictions\Manager::MODE_MANAGER)
397 {
398 $checkServiceResult = Restrictions\Manager::checkService($paySystem['ID'], $payment, $mode);
399 if ($checkServiceResult != Restrictions\Manager::SEVERITY_STRICT)
400 {
401 if ($checkServiceResult == Restrictions\Manager::SEVERITY_SOFT)
402 {
403 $paySystem['RESTRICTED'] = $checkServiceResult;
404 }
405 $result[$paySystem['ID']] = $paySystem;
406 }
407 }
408 elseif ($mode == Restrictions\Manager::MODE_CLIENT)
409 {
410 if (Restrictions\Manager::checkService($paySystem['ID'], $payment, $mode) === Restrictions\Manager::SEVERITY_NONE)
411 {
412 $result[$paySystem['ID']] = $paySystem;
413 }
414 }
415 }
416
417 return $result;
418 }
419
426 public static function getHandlerList()
427 {
428 $documentRoot = Application::getDocumentRoot();
429 $result = array(
430 'SYSTEM' => array(),
431 'USER' => array()
432 );
433
434 foreach (self::getHandlerDirectories() as $type => $dir)
435 {
436 if (!Directory::isDirectoryExists($documentRoot.$dir))
437 {
438 continue;
439 }
440
441 $directory = new Directory($documentRoot.$dir);
442 foreach ($directory->getChildren() as $handler)
443 {
444 if (!$handler->isDirectory())
445 {
446 continue;
447 }
448
449 $isDescriptionExist = false;
451 foreach ($handler->getChildren() as $item)
452 {
453 if ($item->isFile())
454 {
455 $data = array();
456 $psTitle = '';
457 $isAvailable = null;
458
459 if (mb_strpos($item->getName(), '.description') !== false)
460 {
461 $handlerName = $handler->getName();
462
463 include $item->getPath();
464
465 if (array_key_exists('NAME', $data))
466 {
467 $psTitle = $data['NAME'].' ('.$handlerName.')';
468 if (isset($data['IS_AVAILABLE']))
469 {
470 $isAvailable = $data['IS_AVAILABLE'];
471 }
472 }
473 else
474 {
475 if ($psTitle == '')
476 {
477 $psTitle = $handlerName;
478 }
479 else
480 {
481 $psTitle .= ' ('.$handlerName.')';
482 }
483
484 $handlerName = str_replace(Path::normalize($documentRoot), '', $handler->getPath());
485 }
486 $group = (mb_strpos($type, 'SYSTEM') !== false) ? 'SYSTEM' : 'USER';
487
488 if (!isset($result[$group][$handlerName]))
489 {
490 if ($isAvailable !== null
491 && $isAvailable === static::HANDLER_AVAILABLE_FALSE
492 )
493 {
494 continue(2);
495 }
496
497 $result[$group][$handlerName] = $psTitle;
498 }
499 $isDescriptionExist = true;
500 continue;
501 }
502 }
503 }
504
505 if (!$isDescriptionExist)
506 {
507 $group = (mb_strpos($type, 'SYSTEM') !== false) ? 'SYSTEM' : 'USER';
508 $handlerName = str_replace($documentRoot, '', $handler->getPath());
509 $result[$group][$handlerName] = $handler->getName();
510 }
511 }
512 }
513
514 $result['USER'] = array_merge(static::getRestHandlers(), $result['USER']);
515
516 return $result;
517 }
518
523 public static function getClassNameFromPath($path)
524 {
525 $pos = mb_strrpos($path, '/');
526
527 if ($pos == mb_strlen($path))
528 {
529 $path = mb_substr($path, 0, $pos - 1);
530 $pos = mb_strrpos($path, '/');
531 }
532
533 if ($pos !== false)
534 $path = mb_substr($path, $pos + 1);
535
536 return "Sale\\Handlers\\PaySystem\\".$path.'Handler';
537 }
538
546 public static function getHandlerDescription($handler, $psMode = null)
547 {
548 $service = new Service(array('ACTION_FILE' => $handler, 'PS_MODE' => $psMode));
549 $data = $service->getHandlerDescription();
550
551 $eventParams = array('handler' => $handler);
552 $event = new Event('sale', self::EVENT_ON_GET_HANDLER_DESC, $eventParams);
553 $event->send();
554 foreach ($event->getResults() as $eventResult)
555 {
556 if ($eventResult->getType() !== EventResult::ERROR)
557 {
558 $codes = $eventResult->getParameters();
559 if ($codes && is_array($codes))
560 {
561 if (!isset($data['CODES']) || !is_array($data['CODES']))
562 {
563 $data['CODES'] = [];
564 }
565
566 $data['CODES'] = array_merge($data['CODES'], $codes);
567 }
568 }
569 }
570
571 if (isset($data['CODES']) && is_array($data['CODES']))
572 {
573 uasort(
574 $data['CODES'],
575 function ($a, $b)
576 {
577 $sortA = $a['SORT'] ?? 0;
578 $sortB = $b['SORT'] ?? 0;
579
580 return ($sortA < $sortB) ? -1 : 1;
581 }
582 );
583 }
584
585 return $data;
586 }
587
594 public static function getPathToHandlerFolder($folder): ?string
595 {
596 if (!$folder)
597 {
598 return null;
599 }
600
601 $documentRoot = Application::getDocumentRoot();
602 $dirs = self::getHandlerDirectories();
603
604 if (mb_strpos($folder, DIRECTORY_SEPARATOR) !== false)
605 {
606 $folderWithoutHandlerName = array_slice(explode(DIRECTORY_SEPARATOR, $folder), 1, -1);
607 $folderWithoutHandlerName = implode(DIRECTORY_SEPARATOR, $folderWithoutHandlerName);
608
609 $handlersDirectory = new Directory($folderWithoutHandlerName);
610 $handlersDirectoryPhysicalPath = DIRECTORY_SEPARATOR.$handlersDirectory->getPhysicalPath().DIRECTORY_SEPARATOR;
611
612 foreach ($dirs as $dir)
613 {
614 if ($documentRoot.$dir !== $documentRoot.$handlersDirectoryPhysicalPath)
615 {
616 continue;
617 }
618
619 return Directory::isDirectoryExists($documentRoot.$folder) ? $folder : null;
620 }
621 }
622 else
623 {
624 foreach ($dirs as $dir)
625 {
626 $path = $dir.$folder;
627 if (!Directory::isDirectoryExists($documentRoot.$path))
628 {
629 continue;
630 }
631
632 return $path;
633 }
634 }
635
636 return null;
637 }
638
642 public static function getInnerPaySystemId() : int
643 {
644 $id = 0;
645 $cacheManager = Application::getInstance()->getManagedCache();
646
647 if ($cacheManager->read(self::TTL, self::CACHE_ID))
648 {
649 $id = $cacheManager->get(self::CACHE_ID);
650 }
651
652 if ($id <= 0)
653 {
654 $data = PaySystemActionTable::getRow(
655 [
656 'select' => ['ID'],
657 'filter' => ['ACTION_FILE' => 'inner']
658 ]
659 );
660 if ($data === null)
661 {
662 $id = self::createInnerPaySystem();
663 }
664 else
665 {
666 $id = $data['ID'];
667 }
668
669 $cacheManager->set(self::CACHE_ID, $id);
670 }
671
672 return (int)$id;
673 }
674
679 private static function createInnerPaySystem()
680 {
681 $paySystemSettings = array(
682 'NAME' => Loc::getMessage('SALE_PS_MANAGER_INNER_NAME'),
683 'PSA_NAME' => Loc::getMessage('SALE_PS_MANAGER_INNER_NAME'),
684 'ACTION_FILE' => 'inner',
685 'ACTIVE' => 'Y',
686 'ENTITY_REGISTRY_TYPE' => Registry::REGISTRY_TYPE_ORDER,
687 'NEW_WINDOW' => 'N'
688 );
689
690 $imagePath = Application::getDocumentRoot().'/bitrix/images/sale/sale_payments/inner.png';
691 if (File::isFileExists($imagePath))
692 {
693 $paySystemSettings['LOGOTIP'] = \CFile::MakeFileArray($imagePath);
694 $paySystemSettings['LOGOTIP']['MODULE_ID'] = "sale";
695 \CFile::SaveForDB($paySystemSettings, 'LOGOTIP', 'sale/paysystem/logotip');
696 }
697
698 $result = PaySystemActionTable::add($paySystemSettings);
699
700 if ($result->isSuccess())
701 return $result->getId();
702
703 return 0;
704 }
705
710 public static function isExist($id)
711 {
712 return (bool)self::getById($id);
713 }
714
719 public static function getObjectById($id)
720 {
721 if ((int)$id <= 0)
722 return null;
723
724 $data = Manager::getById($id);
725
726 if (is_array($data) && $data)
727 return new Service($data);
728
729 return null;
730 }
731
739 public static function getTariff($folder, $paySystemId = 0)
740 {
741 $documentRoot = Application::getDocumentRoot();
742 $result = array();
743
744 $path = self::getPathToHandlerFolder($folder);
745 if ($path !== null)
746 {
747 if (File::isFileExists($documentRoot.$path.'/handler.php'))
748 {
749 $actionFile = self::getFolderFromClassName(self::getClassNameFromPath($path));
750 [$className] = self::includeHandler($actionFile);
751 if (class_exists($className) && is_subclass_of($className, IPayable::class))
752 {
753 $result = $className::getStructure($paySystemId);
754 }
755 }
756 }
757 else
758 {
759 $result = \CSalePaySystemsHelper::getPaySystemTarif($folder, $paySystemId);
760 }
761
762 return $result;
763 }
764
768 public static function getBusValueGroups()
769 {
770 return [
771 'CONNECT_SETTINGS_ALFABANK' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_ALFABANK'), 'SORT' => 100],
772 'CONNECT_SETTINGS_AUTHORIZE' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_AUTHORIZE'), 'SORT' => 100],
773 'CONNECT_SETTINGS_YANDEX' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_YANDEX'), 'SORT' => 100],
774 'CONNECT_SETTINGS_YANDEX_INVOICE' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_YANDEX_INVOICE'), 'SORT' => 100],
775 'CONNECT_SETTINGS_WEBMONEY' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_WEBMONEY'), 'SORT' => 100],
776 'CONNECT_SETTINGS_ASSIST' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_ASSIST'), 'SORT' => 100],
777 'CONNECT_SETTINGS_ROBOXCHANGE' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_ROBOXCHANGE'), 'SORT' => 100],
778 'CONNECT_SETTINGS_QIWI' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_QIWI'), 'SORT' => 100],
779 'CONNECT_SETTINGS_PAYPAL' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_PAYPAL'), 'SORT' => 100],
780 'CONNECT_SETTINGS_PAYMASTER' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_PAYMASTER'), 'SORT' => 100],
781 'CONNECT_SETTINGS_LIQPAY' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_LIQPAY'), 'SORT' => 100],
782 'CONNECT_SETTINGS_BILL' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_BILL'), 'SORT' => 100],
783 'CONNECT_SETTINGS_BILLDE' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_BILLDE'), 'SORT' => 100],
784 'CONNECT_SETTINGS_BILLEN' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_BILLEN'), 'SORT' => 100],
785 'CONNECT_SETTINGS_BILLUA' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_BILLUA'), 'SORT' => 100],
786 'CONNECT_SETTINGS_BILLLA' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_BILLLA'), 'SORT' => 100],
787 'CONNECT_SETTINGS_SBERBANK' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_SBERBANK'), 'SORT' => 100],
788 'GENERAL_SETTINGS' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_GENERAL_SETTINGS'), 'SORT' => 100],
789 'COLUMN_SETTINGS' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_COLUMN'), 'SORT' => 100],
790 'VISUAL_SETTINGS' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_VISUAL'), 'SORT' => 100],
791 'PAYMENT' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_PAYMENT'), 'SORT' => 200],
792 'PAYSYSTEM' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_PAYSYSTEM'), 'SORT' => 500],
793 'PS_OTHER' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_PS_OTHER'), 'SORT' => 10000],
794 'CONNECT_SETTINGS_UAPAY' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_UAPAY'), 'SORT' => 100],
795 'CONNECT_SETTINGS_ADYEN' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_ADYEN'), 'SORT' => 100],
796 'CONNECT_SETTINGS_APPLE_PAY' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_APPLE_PAY'), 'SORT' => 200],
797 'CONNECT_SETTINGS_SKB' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_SINARA'), 'SORT' => 100],
798 'CONNECT_SETTINGS_BEPAID' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_BEPAID'), 'SORT' => 100],
799 'CONNECT_SETTINGS_WOOPPAY' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_WOOPPAY'), 'SORT' => 100],
800 'CONNECT_SETTINGS_PLATON' => ['NAME' => Loc::getMessage('SALE_PS_MANAGER_GROUP_CONNECT_SETTINGS_PLATON'), 'SORT' => 100],
801 ];
802 }
803
811 public static function delete($primary)
812 {
813 if (empty($primary))
814 {
815 throw new ArgumentException('Parameter $primary can\'t be empty');
816 }
817
818 $paySystemInfo = PaySystemActionTable::getRowById($primary);
819 if ($paySystemInfo['LOGOTIP'])
820 {
821 \CFile::Delete($paySystemInfo['LOGOTIP']);
822 }
823
824 self::deleteRestrictions($primary);
825
826 $service = Manager::getObjectById($primary);
827 if ($service)
828 {
829 self::deleteBusinessValues($service);
830 }
831
832 $deleteResult = PaySystemActionTable::delete($primary);
833 if ($deleteResult->isSuccess())
834 {
835 if ($service && $service->isSupportPrintCheck())
836 {
837 $onDeletePaySystemResult = Cashbox\EventHandler::onDeletePaySystem($service);
838 if (!$onDeletePaySystemResult->isSuccess())
839 {
840 $deleteResult->addErrors($onDeletePaySystemResult->getErrors());
841 }
842 }
843 }
844
845 return $deleteResult;
846 }
847
854 private static function deleteRestrictions(int $paySystemId): void
855 {
856 $restrictionList = Restrictions\Manager::getRestrictionsList($paySystemId);
857 if ($restrictionList)
858 {
859 Restrictions\Manager::getClassesList();
860
861 foreach ($restrictionList as $restriction)
862 {
864 $className = $restriction['CLASS_NAME'];
865 if (is_subclass_of($className, Restriction::class))
866 {
867 $className::delete($restriction['ID'], $paySystemId);
868 }
869 }
870 }
871 }
872
880 private static function deleteBusinessValues(Service $service): void
881 {
882 BusinessValue::delete(Service::PAY_SYSTEM_PREFIX . $service->getField('ID'));
883
884 $paySystemCount = PaySystemActionTable::getList([
885 'select' => ['ID'],
886 'filter' => [
887 'ACTION_FILE' => $service->getField('ACTION_FILE'),
888 ],
889 'count_total' => true,
890 ])->getCount();
891 if ($paySystemCount === 1)
892 {
893 $handlerDescription = $service->getHandlerDescription();
894 $handlerDescriptionCodes = array_keys($handlerDescription['CODES'] ?? []);
895 foreach ($handlerDescriptionCodes as $code)
896 {
897 BusinessValueTable::deleteByCodeKey($code);
898 }
899 }
900 }
901
907 public static function getPersonTypeIdList($paySystemId)
908 {
909 $data = array();
910
911 $dbRestriction = ServiceRestrictionTable::getList(array(
912 'filter' => array(
913 'SERVICE_ID' => $paySystemId,
914 'SERVICE_TYPE' => Restrictions\Manager::SERVICE_TYPE_PAYMENT,
915 '=CLASS_NAME' => '\\'.Restrictions\PersonType::class
916 )
917 ));
918
919 while ($restriction = $dbRestriction->fetch())
920 $data = array_merge($data, $restriction['PARAMS']['PERSON_TYPE_ID']);
921
922 return $data;
923 }
924
937 public static function getPaymentObjectByData(array $data)
938 {
939 $context = Application::getInstance()->getContext();
940
942
944 $orderClass = $registry->getOrderClassName();
945
947 $order = $orderClass::create($context->getSite());
948 $order->setPersonTypeId($data['PERSON_TYPE_ID']);
949
951 $basketClass = $registry->getBasketClassName();
952
953 $basket = $basketClass::create($context->getSite());
954 $order->setBasket($basket);
955
956 $collection = $order->getPaymentCollection();
957 if ($collection)
958 {
959 return $collection->createItem();
960 }
961
962 return null;
963 }
964
968 public static function getDataRefundablePage()
969 {
970 $paySystemList = array();
971 $dbRes = static::getList();
972 while ($data = $dbRes->fetch())
973 {
974 $service = new Service($data);
975 if ($service->isRefundable())
976 $paySystemList[$data['ACTION_FILE']][] = $data;
977 }
978
979 $result = array();
980 foreach ($paySystemList as $handler => $data)
981 {
982 /* @var ServiceHandler $classHandler */
983 $classHandler = static::getClassNameFromPath($handler);
984
985 if (is_subclass_of($classHandler, '\Bitrix\Sale\PaySystem\ServiceHandler'))
986 {
987 $settings = $classHandler::findMyDataRefundablePage($data);
988 if ($settings)
989 $result = array_merge($settings, $result);
990 }
991 }
992
993 return $result;
994 }
995
999 private static function getRestHandlers()
1000 {
1001 $result = array();
1002
1003 $dbRes = PaySystemRestHandlersTable::getList();
1004 while ($item = $dbRes->fetch())
1005 {
1006 $result[$item['CODE']] = $item['NAME'].' ('.$item['CODE'].')';
1007 }
1008
1009 return $result;
1010 }
1011
1016 public static function isRestHandler($handler)
1017 {
1018 static $result = [];
1019
1020 if (isset($result[$handler]))
1021 {
1022 return $result[$handler];
1023 }
1024
1025 $handlerData = PaySystemRestHandlersTable::getList([
1026 'filter' => ['=CODE' => $handler],
1027 'limit' => 1,
1028 ])->fetch();
1029 $result[$handler] = (bool)$handlerData;
1030
1031 return $result[$handler] ?? false;
1032 }
1033
1041 public static function includeHandler($actionFile): array
1042 {
1043 $className = '';
1044 $handlerType = '';
1045
1046 if ($name = self::getFolderFromClassName($actionFile))
1047 {
1048 $documentRoot = Application::getDocumentRoot();
1049 foreach (self::getHandlerDirectories() as $type => $path)
1050 {
1051 if (File::isFileExists($documentRoot.$path.$name.'/handler.php'))
1052 {
1053 $className = self::getClassNameFromPath($actionFile);
1054 if (!class_exists($className))
1055 require_once($documentRoot.$path.$name.'/handler.php');
1056
1057 if (class_exists($className))
1058 {
1059 $handlerType = $type;
1060 break;
1061 }
1062
1063 $className = '';
1064 }
1065 }
1066 }
1067
1068 if ($className === '')
1069 {
1070 if (self::isRestHandler($actionFile))
1071 {
1072 $className = '\Bitrix\Sale\PaySystem\RestHandler';
1073 if (!class_exists($actionFile))
1074 {
1075 class_alias($className, $actionFile);
1076 }
1077 }
1078 else
1079 {
1080 $className = '\Bitrix\Sale\PaySystem\CompatibilityHandler';
1081 }
1082 }
1083
1084 return [
1085 $className,
1086 $handlerType,
1087 ];
1088 }
1089
1090 public static function getHandlerName(string $handler, string $psMode = ''): string
1091 {
1092 $handlerDescription = Manager::getHandlerDescription($handler, $psMode);
1093
1094 if (!$handlerDescription)
1095 {
1096 return '';
1097 }
1098
1099 if (isset($handlerDescription['HANDLER_MODE_LIST'][$psMode]))
1100 {
1101 return $handlerDescription['HANDLER_MODE_LIST'][$psMode];
1102 }
1103 elseif (isset($handlerDescription['NAME']))
1104 {
1105 return $handlerDescription['NAME'];
1106 }
1107
1108 return '';
1109 }
1110}
static isDirectoryExists($path)
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static delete($consumerKey, $personTypeId=null)
static getListWithRestrictions(CollectableEntity $entity)
Definition manager.php:41
static getList(array $parameters=[])
Definition manager.php:135
static getClassNameFromPath($path)
Definition manager.php:523
static getList(array $params=array())
Definition manager.php:84
static getTariff($folder, $paySystemId=0)
Definition manager.php:739
static getPsType($paySystemId)
Definition manager.php:311
static searchByRequest(Request $request)
Definition manager.php:182
static getHandlerName(string $handler, string $psMode='')
Definition manager.php:1090
static getPersonTypeIdList($paySystemId)
Definition manager.php:907
static getFolderFromClassName($className)
Definition manager.php:222
static add(array $data)
Definition manager.php:158
static isRestHandler($handler)
Definition manager.php:1016
static getListWithRestrictions(Payment $payment, $mode=Restrictions\Manager::MODE_CLIENT)
Definition manager.php:363
static includeHandler($actionFile)
Definition manager.php:1041
static getHandlerDescription($handler, $psMode=null)
Definition manager.php:546
static getPathToHandlerFolder($folder)
Definition manager.php:594
static update($primary, array $data)
Definition manager.php:128
static getInstance($type)
Definition registry.php:183