48 private static $handlerDirectories = array(
50 'LOCAL' =>
'/local/php_interface/include/sale_payment/',
51 'SYSTEM' =>
'/bitrix/modules/sale/handlers/paysystem/',
58 'SYSTEM_OLD' =>
'/bitrix/modules/sale/payment/'
68 $handlerDirectories = self::$handlerDirectories;
69 $handlerDirectories[
'CUSTOM'] = Option::get(
"sale",
"path2user_ps_files", BX_PERSONAL_ROOT.
"/php_interface/include/sale_payment/");
71 if (IsModuleInstalled(
'intranet'))
73 unset($handlerDirectories[
'SYSTEM_OLD']);
76 return $handlerDirectories;
84 public static function getList(array $params = array())
86 return PaySystemActionTable::getList($params);
99 'select' => array(
'*'),
100 'filter' => array(
'ID' => $id)
104 return $dbRes->fetch();
114 'select' => array(
'*'),
115 'filter' => array(
'CODE' => $code)
119 return $dbRes->fetch();
130 $oldFields = PaySystemActionTable::getByPrimary($primary)->fetch();
133 $newFields = array_merge($oldFields, $data);
134 $data[
'PS_CLIENT_TYPE'] = (
new Service($newFields))->getClientTypeFromHandler();
137 $updateResult = PaySystemActionTable::update($primary, $data);
138 if ($oldFields && $updateResult->isSuccess())
140 $oldFields = array_intersect_key($oldFields, $data);
142 'PAY_SYSTEM_ID' => $primary,
143 'OLD_FIELDS' => $oldFields,
144 'NEW_FIELDS' => $data,
146 $event =
new Event(
'sale', self::EVENT_ON_PAYSYSTEM_UPDATE, $eventParams);
150 return $updateResult;
160 $data[
'PS_CLIENT_TYPE'] = (
new Service($data))->getClientTypeFromHandler();
162 return PaySystemActionTable::add($data);
170 return uniqid(
'bx_');
193 while ($item = $items->fetch())
195 $name = $item[
'ACTION_FILE'];
197 foreach (self::getHandlerDirectories() as $type => $path)
200 if (File::isFileExists($documentRoot.$path.$name.
'/handler.php'))
202 [$className] = self::includeHandler($item[
'ACTION_FILE']);
205 if (class_exists($className) && is_callable(array($className,
'isMyResponse')))
207 if ($className::isMyResponse($request, $item[
'ID']))
224 $pos = mb_strrpos($className,
'\\');
226 $className = mb_substr($className, $pos + 1);
228 $folder = str_replace(
'Handler',
'', $className);
229 $folder = self::sanitize($folder);
230 $folder = ToLower($folder);
241 return preg_replace(
"/[^a-z0-9._]/i",
"", $name);
251 if (empty($paymentId))
257 'select' => [
'ID',
'ORDER_ID'],
260 if (intval($paymentId).
'|' == $paymentId.
'|')
262 $params[
'filter'][
'=ID'] = $paymentId;
266 $params[
'filter'][
'=ACCOUNT_NUMBER'] = $paymentId;
272 $paymentClassName = $registry->getPaymentClassName();
273 $result = $paymentClassName::getList($params);
274 $data = $result->fetch() ?: [];
276 return [(int)$data[
'ORDER_ID'], (
int)$data[
'ID']];
289 while ($item = $items->fetch())
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'
301 $result[
'PAYSYSTEM_'.$item[
'ID']] = $data;
314 'select' => array(
'IS_CASH'),
315 'filter' => array(
'ID' => $paySystemId)
319 $data = $dbRes->fetch();
321 return $data[
'IS_CASH'];
335 public static function getListWithRestrictionsByOrder(
Order $order,
float $sum =
null,
int $mode = Restrictions\Manager::MODE_CLIENT): array
338 $orderClone = $order->createClone();
340 $orderPrice = $orderClone->getPrice();
341 $paymentSum = $orderPrice;
342 if ($sum && $sum >= 0 && $sum <= $orderPrice)
347 $paymentCollection = $orderClone->getPaymentCollection();
348 $payment = $paymentCollection->createItem();
349 $payment->setFields([
350 'SUM' => $paymentSum,
369 '=ENTITY_REGISTRY_TYPE' => $payment::getRegistryType(),
372 $bindingPaySystemIds = [];
373 if ($mode == Restrictions\Manager::MODE_CLIENT)
376 if ($bindingPaySystemIds)
378 $filter[
'=ID'] = $bindingPaySystemIds;
390 while ($paySystem = $dbRes->fetch())
392 if ($bindingPaySystemIds)
394 $result[$paySystem[
'ID']] = $paySystem;
396 elseif ($mode == Restrictions\Manager::MODE_MANAGER)
398 $checkServiceResult = Restrictions\Manager::checkService($paySystem[
'ID'], $payment, $mode);
399 if ($checkServiceResult != Restrictions\Manager::SEVERITY_STRICT)
401 if ($checkServiceResult == Restrictions\Manager::SEVERITY_SOFT)
403 $paySystem[
'RESTRICTED'] = $checkServiceResult;
405 $result[$paySystem[
'ID']] = $paySystem;
408 elseif ($mode == Restrictions\Manager::MODE_CLIENT)
410 if (Restrictions\Manager::checkService($paySystem[
'ID'], $payment, $mode) === Restrictions\Manager::SEVERITY_NONE)
412 $result[$paySystem[
'ID']] = $paySystem;
426 public static function getHandlerList()
434 foreach (self::getHandlerDirectories() as $type => $dir)
441 $directory =
new Directory($documentRoot.$dir);
442 foreach ($directory->getChildren() as $handler)
444 if (!$handler->isDirectory())
449 $isDescriptionExist =
false;
451 foreach ($handler->getChildren() as $item)
459 if (mb_strpos($item->getName(),
'.description') !==
false)
461 $handlerName = $handler->getName();
463 include $item->getPath();
465 if (array_key_exists(
'NAME', $data))
467 $psTitle = $data[
'NAME'].
' ('.$handlerName.
')';
468 if (isset($data[
'IS_AVAILABLE']))
470 $isAvailable = $data[
'IS_AVAILABLE'];
477 $psTitle = $handlerName;
481 $psTitle .=
' ('.$handlerName.
')';
484 $handlerName = str_replace(Path::normalize($documentRoot),
'', $handler->getPath());
486 $group = (mb_strpos($type,
'SYSTEM') !==
false) ?
'SYSTEM' :
'USER';
488 if (!isset($result[$group][$handlerName]))
490 if ($isAvailable !==
null
491 && $isAvailable === static::HANDLER_AVAILABLE_FALSE
497 $result[$group][$handlerName] = $psTitle;
499 $isDescriptionExist =
true;
505 if (!$isDescriptionExist)
507 $group = (mb_strpos($type,
'SYSTEM') !==
false) ?
'SYSTEM' :
'USER';
508 $handlerName = str_replace($documentRoot,
'', $handler->getPath());
509 $result[$group][$handlerName] = $handler->getName();
514 $result[
'USER'] = array_merge(static::getRestHandlers(), $result[
'USER']);
525 $pos = mb_strrpos($path,
'/');
527 if ($pos == mb_strlen($path))
529 $path = mb_substr($path, 0, $pos - 1);
530 $pos = mb_strrpos($path,
'/');
534 $path = mb_substr($path, $pos + 1);
536 return "Sale\\Handlers\\PaySystem\\".$path.
'Handler';
548 $service =
new Service(array(
'ACTION_FILE' => $handler,
'PS_MODE' => $psMode));
549 $data = $service->getHandlerDescription();
551 $eventParams = array(
'handler' => $handler);
552 $event =
new Event(
'sale', self::EVENT_ON_GET_HANDLER_DESC, $eventParams);
554 foreach ($event->getResults() as $eventResult)
556 if ($eventResult->getType() !== EventResult::ERROR)
558 $codes = $eventResult->getParameters();
559 if ($codes && is_array($codes))
561 if (!isset($data[
'CODES']) || !is_array($data[
'CODES']))
566 $data[
'CODES'] = array_merge($data[
'CODES'], $codes);
571 if (isset($data[
'CODES']) && is_array($data[
'CODES']))
577 $sortA = $a[
'SORT'] ?? 0;
578 $sortB = $b[
'SORT'] ?? 0;
580 return ($sortA < $sortB) ? -1 : 1;
602 $dirs = self::getHandlerDirectories();
604 if (mb_strpos($folder, DIRECTORY_SEPARATOR) !==
false)
606 $folderWithoutHandlerName = array_slice(explode(DIRECTORY_SEPARATOR, $folder), 1, -1);
607 $folderWithoutHandlerName = implode(DIRECTORY_SEPARATOR, $folderWithoutHandlerName);
609 $handlersDirectory =
new Directory($folderWithoutHandlerName);
610 $handlersDirectoryPhysicalPath = DIRECTORY_SEPARATOR.$handlersDirectory->getPhysicalPath().DIRECTORY_SEPARATOR;
612 foreach ($dirs as $dir)
614 if ($documentRoot.$dir !== $documentRoot.$handlersDirectoryPhysicalPath)
624 foreach ($dirs as $dir)
626 $path = $dir.$folder;
647 if ($cacheManager->read(self::TTL, self::CACHE_ID))
649 $id = $cacheManager->get(self::CACHE_ID);
654 $data = PaySystemActionTable::getRow(
657 'filter' => [
'ACTION_FILE' =>
'inner']
662 $id = self::createInnerPaySystem();
669 $cacheManager->set(self::CACHE_ID, $id);
679 private static function createInnerPaySystem()
681 $paySystemSettings = array(
684 'ACTION_FILE' =>
'inner',
691 if (File::isFileExists($imagePath))
693 $paySystemSettings[
'LOGOTIP'] = \CFile::MakeFileArray($imagePath);
694 $paySystemSettings[
'LOGOTIP'][
'MODULE_ID'] =
"sale";
695 \CFile::SaveForDB($paySystemSettings,
'LOGOTIP',
'sale/paysystem/logotip');
698 $result = PaySystemActionTable::add($paySystemSettings);
700 if ($result->isSuccess())
701 return $result->getId();
712 return (
bool)self::getById($id);
724 $data = Manager::getById($id);
726 if (is_array($data) && $data)
739 public static function getTariff($folder, $paySystemId = 0)
744 $path = self::getPathToHandlerFolder($folder);
747 if (File::isFileExists($documentRoot.$path.
'/handler.php'))
749 $actionFile = self::getFolderFromClassName(self::getClassNameFromPath($path));
750 [$className] = self::includeHandler($actionFile);
751 if (class_exists($className) && is_subclass_of($className, IPayable::class))
753 $result = $className::getStructure($paySystemId);
759 $result = \CSalePaySystemsHelper::getPaySystemTarif($folder, $paySystemId);
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],
811 public static function delete($primary)
818 $paySystemInfo = PaySystemActionTable::getRowById($primary);
819 if ($paySystemInfo[
'LOGOTIP'])
821 \CFile::Delete($paySystemInfo[
'LOGOTIP']);
824 self::deleteRestrictions($primary);
829 self::deleteBusinessValues($service);
833 if ($deleteResult->isSuccess())
835 if ($service && $service->isSupportPrintCheck())
837 $onDeletePaySystemResult = Cashbox\EventHandler::onDeletePaySystem($service);
838 if (!$onDeletePaySystemResult->isSuccess())
840 $deleteResult->addErrors($onDeletePaySystemResult->getErrors());
845 return $deleteResult;
854 private static function deleteRestrictions(
int $paySystemId): void
856 $restrictionList = Restrictions\Manager::getRestrictionsList($paySystemId);
857 if ($restrictionList)
859 Restrictions\Manager::getClassesList();
861 foreach ($restrictionList as $restriction)
864 $className = $restriction[
'CLASS_NAME'];
865 if (is_subclass_of($className, Restriction::class))
867 $className::delete($restriction[
'ID'], $paySystemId);
880 private static function deleteBusinessValues(Service $service): void
884 $paySystemCount = PaySystemActionTable::getList([
887 'ACTION_FILE' => $service->getField(
'ACTION_FILE'),
889 'count_total' =>
true,
891 if ($paySystemCount === 1)
893 $handlerDescription = $service->getHandlerDescription();
894 $handlerDescriptionCodes = array_keys($handlerDescription[
'CODES'] ?? []);
895 foreach ($handlerDescriptionCodes as $code)
897 BusinessValueTable::deleteByCodeKey($code);
911 $dbRestriction = ServiceRestrictionTable::getList(array(
913 'SERVICE_ID' => $paySystemId,
914 'SERVICE_TYPE' => Restrictions\Manager::SERVICE_TYPE_PAYMENT,
915 '=CLASS_NAME' =>
'\\'.Restrictions\PersonType::class
919 while ($restriction = $dbRestriction->fetch())
920 $data = array_merge($data, $restriction[
'PARAMS'][
'PERSON_TYPE_ID']);
937 public static function getPaymentObjectByData(array $data)
944 $orderClass = $registry->getOrderClassName();
947 $order = $orderClass::create($context->getSite());
948 $order->setPersonTypeId($data[
'PERSON_TYPE_ID']);
951 $basketClass = $registry->getBasketClassName();
953 $basket = $basketClass::create($context->getSite());
954 $order->setBasket($basket);
956 $collection = $order->getPaymentCollection();
959 return $collection->createItem();
970 $paySystemList = array();
971 $dbRes = static::getList();
972 while ($data = $dbRes->fetch())
975 if ($service->isRefundable())
976 $paySystemList[$data[
'ACTION_FILE']][] = $data;
980 foreach ($paySystemList as $handler => $data)
983 $classHandler = static::getClassNameFromPath($handler);
985 if (is_subclass_of($classHandler,
'\Bitrix\Sale\PaySystem\ServiceHandler'))
987 $settings = $classHandler::findMyDataRefundablePage($data);
989 $result = array_merge($settings, $result);
999 private static function getRestHandlers()
1003 $dbRes = PaySystemRestHandlersTable::getList();
1004 while ($item = $dbRes->fetch())
1006 $result[$item[
'CODE']] = $item[
'NAME'].
' ('.$item[
'CODE'].
')';
1018 static $result = [];
1020 if (isset($result[$handler]))
1022 return $result[$handler];
1025 $handlerData = PaySystemRestHandlersTable::getList([
1026 'filter' => [
'=CODE' => $handler],
1029 $result[$handler] = (bool)$handlerData;
1031 return $result[$handler] ??
false;
1046 if ($name = self::getFolderFromClassName($actionFile))
1049 foreach (self::getHandlerDirectories() as $type => $path)
1051 if (File::isFileExists($documentRoot.$path.$name.
'/handler.php'))
1053 $className = self::getClassNameFromPath($actionFile);
1054 if (!class_exists($className))
1055 require_once($documentRoot.$path.$name.
'/handler.php');
1057 if (class_exists($className))
1059 $handlerType = $type;
1068 if ($className ===
'')
1070 if (self::isRestHandler($actionFile))
1072 $className =
'\Bitrix\Sale\PaySystem\RestHandler';
1073 if (!class_exists($actionFile))
1075 class_alias($className, $actionFile);
1080 $className =
'\Bitrix\Sale\PaySystem\CompatibilityHandler';
1092 $handlerDescription = Manager::getHandlerDescription($handler, $psMode);
1094 if (!$handlerDescription)
1099 if (isset($handlerDescription[
'HANDLER_MODE_LIST'][$psMode]))
1101 return $handlerDescription[
'HANDLER_MODE_LIST'][$psMode];
1103 elseif (isset($handlerDescription[
'NAME']))
1105 return $handlerDescription[
'NAME'];
static getMessage($code, $replace=null, $language=null)