Файловый менеджер - Редактировать - /var/www/axolotl/data/www/axolotls.ru/www/bitrix/components/bitrix/salescenter.paysystem.panel/class.php
Назад
<?php if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die(); use Bitrix\Main, Bitrix\Main\Loader, Bitrix\Main\Localization\Loc, Bitrix\Sale, Bitrix\Rest, Bitrix\SalesCenter\Integration\SaleManager, Bitrix\SalesCenter\Integration\RestManager, Bitrix\SalesCenter\Integration\Bitrix24Manager, Bitrix\Main\Engine\Contract\Controllerable; Loc::loadMessages(__FILE__); /** * Class SalesCenterPaySystemPanel */ class SalesCenterPaySystemPanel extends CBitrixComponent implements Controllerable { private const INTEGRATIONS_URL = 'https://integrations.bitrix24.site/'; private const PAYSYSTEM_TITLE_LENGTH_LIMIT = 50; private const MARKETPLACE_CATEGORY_PAYMENT = 'payment'; private $paySystemPanelId = 'salescenter-paysystem'; private $paySystemAppPanelId = 'salescenter-paysystem-app'; private $mode; private $paySystemList; private $paySystemColor; /** * @param $arParams * @return array */ public function onPrepareComponentParams($arParams) { $arParams['MODE'] = $arParams['MODE'] ?? 'main'; $this->mode = $arParams['MODE']; return parent::onPrepareComponentParams($arParams); } protected function listKeysSignedParameters() { return [ 'PAYSYSTEM_COLOR', ]; } /** * @return bool */ private function isMainMode(): bool { return $this->mode === 'main'; } /** * @return mixed|void * @throws Main\ArgumentException * @throws Main\LoaderException * @throws Main\SystemException */ public function executeComponent() { if (!Loader::includeModule('salescenter')) { $this->showError(Loc::getMessage('SPP_SALESCENTER_MODULE_ERROR')); return; } if (!Loader::includeModule('sale')) { $this->showError(Loc::getMessage('SPP_SALE_MODULE_ERROR')); return; } if(!SaleManager::getInstance()->isManagerAccess()) { $this->showError(Loc::getMessage('SPP_ACCESS_DENIED')); return; } $this->prepareResult(); $this->includeComponentTemplate(); } /** * @return array * @throws Main\ArgumentException * @throws Main\ArgumentNullException * @throws Main\ArgumentOutOfRangeException * @throws Main\IO\FileNotFoundException * @throws Main\LoaderException * @throws Main\ObjectPropertyException * @throws Main\SystemException */ public function prepareResult(): array { $this->paySystemList = SaleManager::getSaleshubPaySystemItems(); $this->paySystemColor = $this->getPaySystemColor(); $this->arResult['mode'] = $this->mode; $this->arResult['isMainMode'] = $this->isMainMode(); $marketplaceRecommendedItems = []; if (RestManager::getInstance()->isEnabled()) { $recommendedItemCodeList = $this->getMarketPlaceRecommendedItemCodeList(); $marketplaceRecommendedItems = $this->getMarketplaceItems($recommendedItemCodeList); } $paySystemItems = array_merge( $this->getPaySystemItems(), $marketplaceRecommendedItems ); // paysystem $this->arResult['paySystemPanelParams'] = [ 'id' => $this->paySystemPanelId, 'items' => $paySystemItems, ]; $paySystemExtraItems = []; if ($this->isMainMode()) { // marketplace $paySystemExtraItems[] = $this->getPaySystemExtraItem(); if (Bitrix24Manager::getInstance()->isEnabled()) { $paySystemExtraItems[] = $this->getRecommendItem(); } foreach ($this->getUserPaySystemItems() as $userPaySystemItem) { $paySystemExtraItems[] = $userPaySystemItem; } if (RestManager::getInstance()->isEnabled()) { $partnerItemCodeList = $this->getMarketPlacePartnerItemCodeList(); foreach ($this->getMarketplaceItems($partnerItemCodeList) as $marketplaceItem) { $paySystemExtraItems[] = $marketplaceItem; } } foreach ($this->getActionboxItems() as $actionboxItem) { $paySystemExtraItems[] = $actionboxItem; } foreach ($this->getIntegrationItems() as $integrationItem) { $paySystemExtraItems[] = $integrationItem; } } $this->arResult['paySystemAppPanelParams'] = [ 'id' => $this->paySystemAppPanelId, 'items' => $paySystemExtraItems, ]; return $this->arResult; } /** * @param $error */ private function showError($error) { ShowError($error); } /** * @param $paySystemList * @return array */ private function getFilterForPaySystem($paySystemList): array { $filter = [ 'ENTITY_REGISTRY_TYPE' => 'ORDER', ]; $subFilter = []; foreach ($paySystemList as $handler => $handlerItem) { $psMode = empty($handlerItem['psMode']) ? [] : array_keys($handlerItem['psMode']); if ($psMode) { $subFilter[] = [ '=ACTION_FILE' => $handler, '=PS_MODE' => $psMode, ]; } else { $subFilter[] = [ '=ACTION_FILE' => $handler, ]; } } if ($subFilter) { $filter[] = array_merge(['LOGIC' => 'OR'], $subFilter); } return $filter; } /** * @return Main\Web\Uri */ private function getPaySystemComponentPath(): Main\Web\Uri { $paySystemPath = \CComponentEngine::makeComponentPath('bitrix:salescenter.paysystem'); $paySystemPath = getLocalPath('components'.$paySystemPath.'/slider.php'); $paySystemPath = new Main\Web\Uri($paySystemPath); return $paySystemPath; } /** * @return array * @throws Main\ArgumentException * @throws Main\ArgumentNullException * @throws Main\ArgumentOutOfRangeException */ private function getPaySystemItems(): array { $paySystemPanel = $this->getPaySystemPanel(); $paySystemPath = $this->getPaySystemComponentPath(); $filter = $this->getFilterForPaySystem($this->paySystemList); $paySystemIterator = Sale\PaySystem\Manager::getList([ 'select' => ['ID', 'ACTIVE', 'NAME', 'ACTION_FILE', 'PS_MODE'], 'filter' => $filter, ]); $paySystemActions = []; foreach ($paySystemIterator as $paySystem) { $paySystemHandler = $paySystem['ACTION_FILE']; $inPanel = array_key_exists($paySystem['ACTION_FILE'], $paySystemPanel); $psMode = $paySystem['PS_MODE']; if ($psMode) { $inPanel = in_array($psMode, $paySystemPanel[$paySystem['ACTION_FILE']] ?? [], true); } if ((!$inPanel && !$this->isMainMode()) || !$this->isPaySystemAvailable($paySystem['ACTION_FILE']) ) { continue; } $isActive = $paySystem['ACTIVE'] === 'Y'; $queryParams = [ 'lang' => LANGUAGE_ID, 'publicSidePanel' => 'Y', 'ID' => $paySystem['ID'], 'ACTION_FILE' => $paySystem['ACTION_FILE'], ]; if ($psMode) { $queryParams['PS_MODE'] = $psMode; if (!isset($paySystemActions[$paySystemHandler]['ACTIVE'][$psMode]) || $paySystemActions[$paySystemHandler]['ACTIVE'][$psMode] === false ) { $paySystemActions[$paySystemHandler]['ACTIVE'][$psMode] = $isActive; } $paySystemActions[$paySystemHandler]['PS_MODE'] = true; $paySystemActions[$paySystemHandler]['ITEMS'][$psMode][] = [ 'NAME' => Loc::getMessage('SPP_PAYSYSTEM_SETTINGS', [ '#PAYSYSTEM_NAME#' => htmlspecialcharsbx($paySystem['NAME']) ]), 'LINK' => $paySystemPath->addParams($queryParams)->getLocator(), ]; } else { $paySystemPath->addParams($queryParams)->getLocator(); if (!isset($paySystemActions[$paySystemHandler]['ACTIVE']) || $paySystemActions[$paySystemHandler]['ACTIVE'] === false ) { $paySystemActions[$paySystemHandler]['ACTIVE'] = $isActive; } $paySystemActions[$paySystemHandler]['PS_MODE'] = false; $paySystemActions[$paySystemHandler]['ITEMS'][] = [ 'NAME' => Loc::getMessage('SPP_PAYSYSTEM_SETTINGS', [ '#PAYSYSTEM_NAME#' => htmlspecialcharsbx($paySystem['NAME']) ]), 'LINK' => $paySystemPath->addParams($queryParams)->getLocator(), ]; } } foreach ($paySystemPanel as $handler => $psModeList) { if (!$this->isPaySystemAvailable($handler)) { continue; } if ($psModeList) { foreach ($psModeList as $psMode) { if (!$this->isPaySystemAvailable($handler, $psMode)) { continue; } if (empty($paySystemActions[$handler]['ITEMS'][$psMode])) { $paySystemActions[$handler]['PS_MODE'] = true; $paySystemActions[$handler]['ACTIVE'][$psMode] = false; $paySystemActions[$handler]['ITEMS'][$psMode] = []; } } } elseif (empty($paySystemActions[$handler])) { $paySystemActions[$handler] = [ 'ACTIVE' => false, 'PS_MODE' => false, ]; } } if ($paySystemActions) { $paySystemActions = $this->getPaySystemMenu($paySystemActions); } $paySystemItems = []; foreach ($paySystemActions as $handler => $paySystem) { $queryParams = [ 'lang' => LANGUAGE_ID, 'publicSidePanel' => 'Y', 'CREATE' => 'Y', ]; $isActive = false; $title = Loc::getMessage('SPP_PAYSYSTEM_'.strtoupper($handler).'_TITLE'); if (isset($paySystem['ITEMS'])) { $isPsMode = $paySystem['PS_MODE']; if ($isPsMode) { foreach ($paySystem['ITEMS'] as $psMode => $paySystemItem) { $type = $psMode; $isActive = $paySystemActions[$handler]['ACTIVE'][$psMode]; if (!$isActive && (!in_array($psMode, $paySystemPanel[$handler]))) { continue; } if (empty($paySystemItem) && (!in_array($psMode, $paySystemPanel[$handler]))) { continue; } $title = Loc::getMessage('SPP_PAYSYSTEM_'.strtoupper($handler).'_'.strtoupper($psMode).'_TITLE'); $queryParams['ACTION_FILE'] = $handler; $queryParams['PS_MODE'] = $psMode; $paySystemPath = $this->getPaySystemComponentPath(); $paySystemPath->addParams($queryParams); $image = $this->getImagePath().$handler.'_'.$psMode.'.svg'; $itemSelectedImage = $this->getImagePath().$handler.'_'.$psMode.'_s.svg'; if (!Main\IO\File::isFileExists(Main\Application::getDocumentRoot().$image)) { $image = $this->getImagePath().$handler.'.svg'; $itemSelectedImage = $this->getImagePath().$handler.'_s.svg'; } $paySystemItems[] = [ 'id' => $handler.'_'.$psMode, 'sort' => $this->getPaySystemSort($handler, $psMode), 'title' => $title, 'image' => $image, 'itemSelectedColor' => $this->paySystemColor[$handler][$psMode], 'itemSelected' => $isActive, 'itemSelectedImage' => $itemSelectedImage, 'data' => [ 'type' => 'paysystem', 'connectPath' => $paySystemPath->getLocator(), 'menuItems' => $paySystemItem, 'showMenu' => !empty($paySystemItem), 'paySystemType' => $type, 'recommendation' => $this->isPaySystemRecommendation($handler, $psMode), ], ]; } } else { $isActive = $paySystemActions[$handler]['ACTIVE']; if (!$isActive && (!array_key_exists($handler, $paySystemPanel))) { continue; } $type = $handler; $queryParams['ACTION_FILE'] = $handler; $paySystemPath = $this->getPaySystemComponentPath(); $paySystemPath->addParams($queryParams); $paySystemItems[] = [ 'id' => $handler, 'sort' => $this->getPaySystemSort($handler), 'title' => $title, 'image' => $this->getImagePath().$handler.'.svg', 'itemSelectedColor' => $this->paySystemColor[$handler], 'itemSelected' => $isActive, 'itemSelectedImage' => $this->getImagePath().$handler.'_s.svg', 'data' => [ 'type' => 'paysystem', 'connectPath' => $paySystemPath->getLocator(), 'menuItems' => $paySystem['ITEMS'], 'showMenu' => !empty($paySystem['ITEMS']), 'paySystemType' => $type, 'recommendation' => $this->isPaySystemRecommendation($handler), ], ]; } } else { $type = $handler; $queryParams['ACTION_FILE'] = $handler; $paySystemPath = $this->getPaySystemComponentPath(); $paySystemPath->addParams($queryParams); $paySystemItems[] = [ 'id' => $handler, 'sort' => $this->getPaySystemSort($handler), 'title' => $title, 'image' => $this->getImagePath().$handler.'.svg', 'itemSelectedColor' => $this->paySystemColor[$handler], 'itemSelected' => $isActive, 'itemSelectedImage' => $this->getImagePath().$handler.'_s.svg', 'data' => [ 'type' => 'paysystem', 'connectPath' => $paySystemPath->getLocator(), 'menuItems' => [], 'showMenu' => false, 'paySystemType' => $type, 'recommendation' => $this->isPaySystemRecommendation($handler), ], ]; } } Main\Type\Collection::sortByColumn($paySystemItems, ['sort' => SORT_ASC]); return $paySystemItems; } /** * @param $handler * @param null $psMode * @return bool * @throws Main\ArgumentNullException * @throws Main\ArgumentOutOfRangeException */ private function isPaySystemAvailable($handler, $psMode = null): bool { $description = Sale\PaySystem\Manager::getHandlerDescription($handler); $isAvailable = !(isset($description['IS_AVAILABLE']) && !$description['IS_AVAILABLE']); if (!$psMode) { return $isAvailable; } $psModeList = []; /** @var Sale\PaySystem\BaseServiceHandler $handlerClass */ [$handlerClass] = Sale\PaySystem\Manager::includeHandler($handler); if (class_exists($handlerClass)) { $psModeList = $handlerClass::getHandlerModeList(); } return isset($psModeList[$psMode]); } /** * @return array */ private function getPaySystemColor(): array { return [ 'yandexcheckout' => [ 'bank_card' => '#19D0C8', 'sberbank' => '#2C9B47', 'sberbank_sms' => '#289D37', 'alfabank' => '#EE2A23', 'yandex_money' => '#FFA900', 'qiwi' => '#E9832C', 'webmoney' => '#006FA8', 'embedded' => '#0697F2', ], 'skb' => [ 'skb' => '#F65E64', ], 'bepaid' => [ 'widget' => '#E36F10', ], 'uapay' => '#E41F18', 'cash' => '#8EB927', 'sberbankonline' => '#2C9B47', 'webmoney' => '#006FA8', 'qiwi' => '#E9832C', 'paypal' => '#243B80', 'liqpay' => '#7AB72B', ]; } /** * @return array */ private function getPaySystemPanel(): array { $zone = $this->getZone(); $paySystemPanel = []; if ($this->isMainMode()) { foreach ($this->paySystemList as $handler => $handlerItem) { if (!empty($handlerItem['psMode'])) { foreach ($handlerItem['psMode'] as $psMode => $psModeItem) { if ($psModeItem['main']) { $paySystemPanel[$handler][] = $psMode; } } } elseif ($handlerItem['main'] || ($zone !== 'ru' && $handler === 'paypal') ) { $paySystemPanel[$handler] = []; } } } else { foreach ($this->paySystemList as $handler => $handlerItem) { if (!empty($handlerItem['psMode'])) { foreach ($handlerItem['psMode'] as $psMode => $psModeItem) { $paySystemPanel[$handler][] = $psMode; } } else { $paySystemPanel[$handler] = []; } } } return $paySystemPanel; } /** * @param $handler * @param bool $psMode * @return int|mixed */ private function getPaySystemSort($handler, $psMode = false) { $defaultSort = 100; if ($psMode) { return $this->paySystemList[$handler]['psMode'][$psMode]['sort'] ?? $defaultSort; } return $this->paySystemList[$handler]['sort'] ?? $defaultSort; } private function isPaySystemRecommendation($handler, $psMode = false) { $isRecommendation = false; if ($psMode) { return $this->paySystemList[$handler]['psMode'][$psMode]['recommendation'] ?? $isRecommendation; } return $this->paySystemList[$handler]['recommendation'] ?? $isRecommendation; } /** * @param array $paySystemActions * @return array */ private function getPaySystemMenu(array $paySystemActions): array { $name = Loc::getMessage('SPP_PAYSYSTEM_ADD'); foreach ($paySystemActions as $handler => $paySystems) { if (!$paySystems || empty($paySystems['ITEMS'])) { continue; } $queryParams = [ 'lang' => LANGUAGE_ID, 'publicSidePanel' => 'Y', 'CREATE' => 'Y', 'ACTION_FILE' => strtolower($handler) ]; if ($paySystems['PS_MODE']) { foreach ($paySystems['ITEMS'] as $psMode => $paySystem) { if (!$paySystem) { continue; } $queryParams['PS_MODE'] = $psMode; $paySystemPath = $this->getPaySystemComponentPath(); $paySystemPath->addParams($queryParams); array_unshift($paySystemActions[$handler]['ITEMS'][$psMode], [ 'NAME' => $name, 'LINK' => $paySystemPath->getLocator(), ], [ 'DELIMITER' => true ] ); } } else { $paySystemPath = $this->getPaySystemComponentPath(); $paySystemPath->addParams($queryParams); array_unshift($paySystemActions[$handler]['ITEMS'], [ 'NAME' => $name, 'LINK' => $paySystemPath->getLocator(), ], [ 'DELIMITER' => true ] ); } } return $paySystemActions; } /** * @return string */ private function getImagePath(): string { static $imagePath = ''; if ($imagePath) { return $imagePath; } $componentPath = \CComponentEngine::makeComponentPath('bitrix:salescenter.paysystem.panel'); $componentPath = getLocalPath('components'.$componentPath); $imagePath = $componentPath.'/templates/.default/images/'; return $imagePath; } /** * @return array */ private function getPaySystemExtraItem(): array { $paySystemPath = \CComponentEngine::makeComponentPath('bitrix:salescenter.paysystem.panel'); $paySystemPath = getLocalPath('components'.$paySystemPath.'/slider.php'); $paySystemPath = new Main\Web\Uri($paySystemPath); $paySystemPath->addParams([ 'analyticsLabel' => 'salescenterClickPaymentTile', 'type' => 'extra', 'mode' => 'extra' ]); return [ 'id' => 'paysystem', 'title' => Loc::getMessage('SPP_PAYSYSTEM_ITEM_EXTRA'), 'image' => $this->getImagePath().'paysystem.svg', 'selectedColor' => '#E8A312', 'selected' => false, 'selectedImage' => $this->getImagePath().'paysystem_s.svg', 'data' => [ 'type' => 'paysystem_extra', 'connectPath' => $paySystemPath->getLocator(), ] ]; } /** * @return array * @throws Main\ArgumentException * @throws Main\ArgumentNullException * @throws Main\ArgumentOutOfRangeException * @throws Main\IO\FileNotFoundException */ private function getUserPaySystemItems(): array { $userHandlerList = $this->getUserPaySystemHandlersList(); if (empty($userHandlerList)) { return []; } $paySystemPath = $this->getPaySystemComponentPath(); $filter = $this->getFilterForPaySystem($userHandlerList); $paySystemIterator = Sale\PaySystem\Manager::getList([ 'select' => ['ID', 'ACTIVE', 'NAME', 'ACTION_FILE', 'PS_MODE'], 'filter' => $filter, ]); $paySystemActions = []; foreach ($paySystemIterator as $paySystem) { $paySystemHandler = $paySystem['ACTION_FILE']; $psMode = $paySystem['PS_MODE']; $isActive = $paySystem['ACTIVE'] === 'Y'; $queryParams = [ 'lang' => LANGUAGE_ID, 'publicSidePanel' => 'Y', 'ID' => $paySystem['ID'], 'ACTION_FILE' => $paySystem['ACTION_FILE'], ]; if ($psMode) { $queryParams['PS_MODE'] = $psMode; if (!isset($paySystemActions[$paySystemHandler]['ACTIVE'][$psMode]) || $paySystemActions[$paySystemHandler]['ACTIVE'][$psMode] === false ) { $paySystemActions[$paySystemHandler]['ACTIVE'][$psMode] = $isActive; } $paySystemActions[$paySystemHandler]['PS_MODE'] = true; $paySystemActions[$paySystemHandler]['ITEMS'][$psMode][] = [ 'NAME' => Loc::getMessage('SPP_PAYSYSTEM_SETTINGS', [ '#PAYSYSTEM_NAME#' => htmlspecialcharsbx($paySystem['NAME']) ]), 'LINK' => $paySystemPath->addParams($queryParams)->getLocator(), ]; } else { $paySystemPath->addParams($queryParams)->getLocator(); if (!isset($paySystemActions[$paySystemHandler]['ACTIVE']) || $paySystemActions[$paySystemHandler]['ACTIVE'] === false ) { $paySystemActions[$paySystemHandler]['ACTIVE'] = $isActive; } $paySystemActions[$paySystemHandler]['PS_MODE'] = false; $paySystemActions[$paySystemHandler]['ITEMS'][] = [ 'NAME' => Loc::getMessage('SPP_PAYSYSTEM_SETTINGS', [ '#PAYSYSTEM_NAME#' => htmlspecialcharsbx($paySystem['NAME']) ]), 'LINK' => $paySystemPath->addParams($queryParams)->getLocator(), ]; } } foreach ($userHandlerList as $handler => $psModeList) { $psModeList = $psModeList['psMode'] ?? []; if ($psModeList) { foreach (array_keys($psModeList) as $psMode) { if (empty($paySystemActions[$handler]['ITEMS'][$psMode])) { $paySystemActions[$handler]['PS_MODE'] = true; $paySystemActions[$handler]['ACTIVE'][$psMode] = false; $paySystemActions[$handler]['ITEMS'][$psMode] = []; } } } elseif (empty($paySystemActions[$handler])) { $paySystemActions[$handler] = [ 'ACTIVE' => false, 'PS_MODE' => false, ]; } } if ($paySystemActions) { $paySystemActions = $this->getPaySystemMenu($paySystemActions); } $paySystemItems = []; foreach ($paySystemActions as $handler => $paySystem) { $queryParams = [ 'lang' => LANGUAGE_ID, 'publicSidePanel' => 'Y', 'CREATE' => 'Y', ]; $isActive = false; $title = $userHandlerList[$handler]['name']; $title = $this->getFormattedTitle($title); $image = $this->getImagePath().'marketplace_default.svg'; $selectedImage = $this->getImagePath().'marketplace_default_s.svg'; if (isset($paySystem['ITEMS'])) { $isPsMode = $paySystem['PS_MODE']; if ($isPsMode) { foreach ($paySystem['ITEMS'] as $psMode => $paySystemItem) { $type = $psMode; $isActive = $paySystemActions[$handler]['ACTIVE'][$psMode]; $title = "{$userHandlerList[$handler]['name']}({$userHandlerList[$handler]['psMode'][$psMode]})"; $title = $this->getFormattedTitle($title); $queryParams['ACTION_FILE'] = $handler; $queryParams['PS_MODE'] = $psMode; $paySystemPath = $this->getPaySystemComponentPath(); $paySystemPath->addParams($queryParams); $paySystemItems[] = [ 'id' => $handler.'_'.$psMode, 'title' => $title, 'image' => $image, 'itemSelectedColor' => '#56C472', 'itemSelected' => $isActive, 'itemSelectedImage' => $selectedImage, 'data' => [ 'type' => 'paysystem', 'connectPath' => $paySystemPath->getLocator(), 'menuItems' => $paySystemItem, 'showMenu' => !empty($paySystemItem), 'paySystemType' => $type, ], ]; } } else { $isActive = $paySystemActions[$handler]['ACTIVE']; $type = $handler; $queryParams['ACTION_FILE'] = $handler; $paySystemPath = $this->getPaySystemComponentPath(); $paySystemPath->addParams($queryParams); $paySystemItems[] = [ 'id' => $handler, 'title' => $title, 'image' => $image, 'itemSelectedColor' => '#56C472', 'itemSelected' => $isActive, 'itemSelectedImage' => $selectedImage, 'data' => [ 'type' => 'paysystem', 'connectPath' => $paySystemPath->getLocator(), 'menuItems' => $paySystem['ITEMS'], 'showMenu' => !empty($paySystem['ITEMS']), 'paySystemType' => $type, ], ]; } } else { $type = $handler; $queryParams['ACTION_FILE'] = $handler; $paySystemPath = $this->getPaySystemComponentPath(); $paySystemPath->addParams($queryParams); $paySystemItems[] = [ 'id' => $handler, 'title' => $title, 'image' => $image, 'itemSelectedColor' => '#56C472', 'itemSelected' => $isActive, 'itemSelectedImage' => $selectedImage, 'data' => [ 'type' => 'paysystem', 'connectPath' => $paySystemPath->getLocator(), 'menuItems' => [], 'showMenu' => false, 'paySystemType' => $type, ], ]; } } return $paySystemItems; } /** * @return array * @throws Main\ArgumentNullException * @throws Main\ArgumentOutOfRangeException * @throws Main\IO\FileNotFoundException */ private function getUserPaySystemHandlersList(): array { $userHandlerList = []; $handlerList = Sale\PaySystem\Manager::getHandlerList(); if (isset($handlerList['USER'])) { $userHandlers = array_keys($handlerList['USER']); foreach ($userHandlers as $key => $userHandler) { if (strpos($userHandler, '/') !== false) { unset($userHandlers[$key]); continue; } $handlerDescription = Sale\PaySystem\Manager::getHandlerDescription($userHandler); if (empty($handlerDescription)) { continue; } $userHandlerList[$userHandler] = [ 'name' => $handlerDescription['NAME'] ?? $handlerList['USER'][$userHandler], ]; /** @var Sale\PaySystem\BaseServiceHandler $handlerClass */ $handlerClass = Sale\PaySystem\Manager::getClassNameFromPath($userHandler); if (!class_exists($handlerClass)) { $documentRoot = Main\Application::getDocumentRoot(); $path = Sale\PaySystem\Manager::getPathToHandlerFolder($userHandler); $fullPath = $documentRoot.$path.'/handler.php'; if ($path && Main\IO\File::isFileExists($fullPath)) { require_once $fullPath; } } if (class_exists($handlerClass) && ($psMode = $handlerClass::getHandlerModeList())) { $userHandlerList[$userHandler]['psMode'] = $psMode; } } } return $userHandlerList; } /** * @return array * @throws Main\SystemException */ private function getIntegrationItems(): array { $integrationItems = []; if (RestManager::getInstance()->isEnabled()) { $showAllItem = $this->getShowAllItem(); if ($showAllItem) { $integrationItems[] = $showAllItem; } } $integrationItems[] = $this->getNeedIntegrationItem(); return $integrationItems; } /** * @param array $marketplaceItemCodeList * @return array * @throws Main\ArgumentException * @throws Main\LoaderException * @throws Main\ObjectPropertyException * @throws Main\SystemException */ private function getMarketplaceItems(array $marketplaceItemCodeList): array { $installedApps = $this->getMarketplaceInstalledApps(); $marketplaceItemCodeList = array_unique(array_merge(array_keys($installedApps), $marketplaceItemCodeList)); $zone = $this->getZone(); $partnerItemList = []; foreach($marketplaceItemCodeList as $marketplaceItemCode) { if ($marketplaceApp = RestManager::getInstance()->getMarketplaceAppByCode($marketplaceItemCode)) { $title = $marketplaceApp['NAME'] ?? $marketplaceApp['LANG'][$zone]['NAME'] ?? current($marketplaceApp['LANG'])['NAME'] ?? ''; if (!empty($marketplaceApp['ICON_PRIORITY']) || !empty($marketplaceApp['ICON'])) { $hasOwnIcon = true; $img = $marketplaceApp['ICON_PRIORITY'] ?: $marketplaceApp['ICON']; } else { $hasOwnIcon = false; $img = $this->getImagePath().'marketplace_default.svg'; } $partnerItemList[] = [ 'id' => (array_key_exists($marketplaceItemCode, $installedApps) ? $installedApps[$marketplaceItemCode]['ID'] : $marketplaceApp['ID'] ), 'title' => $this->getFormattedTitle($title), 'image' => $img, 'itemSelected' => array_key_exists($marketplaceItemCode, $installedApps), 'data' => [ 'type' => 'marketplaceApp', 'code' => $marketplaceApp['CODE'], 'hasOwnIcon' => $hasOwnIcon, ], ]; } } return $partnerItemList; } /** * @return array|string[] * @throws Main\SystemException */ private function getMarketPlaceRecommendedItemCodeList(): array { $result = []; $zone = $this->getZone(); $partnerItems = RestManager::getInstance()->getByTag([ RestManager::TAG_PAYSYSTEM_PAYMENT, RestManager::TAG_PAYSYSTEM_RECOMMENDED, $zone ]); if (!empty($partnerItems['ITEMS'])) { foreach ($partnerItems['ITEMS'] as $partnerItem) { $result[] = $partnerItem['CODE']; } } return $result; } /** * @return array|string[] * @throws Main\SystemException */ private function getMarketPlacePartnerItemCodeList(): array { $result = []; $zone = $this->getZone(); if (in_array($zone, ['en', 'br', 'la'])) { $result = [ 'integrations24.mercadopago', ]; } $partnerItems = RestManager::getInstance()->getByTag([ RestManager::TAG_PAYSYSTEM_PAYMENT, RestManager::TAG_PAYSYSTEM_PARTNERS, $zone ]); if (!empty($partnerItems['ITEMS'])) { foreach ($partnerItems['ITEMS'] as $partnerItem) { $result[] = $partnerItem['CODE']; } } return $result; } /** * @return array * @throws Main\ArgumentException * @throws Main\LoaderException * @throws Main\ObjectPropertyException * @throws Main\SystemException */ private function getMarketplaceInstalledApps(): array { if(!Main\Loader::includeModule('rest')) { return []; } static $marketplaceInstalledApps = []; if(!empty($marketplaceInstalledApps)) { return $marketplaceInstalledApps; } $marketplaceAppCodeList = RestManager::getInstance()->getMarketplaceAppCodeList(self::MARKETPLACE_CATEGORY_PAYMENT); $appIterator = Rest\AppTable::getList([ 'select' => [ 'ID', 'CODE', ], 'filter' => [ '=CODE' => $marketplaceAppCodeList, 'SCOPE' => '%pay_system%', '=ACTIVE' => 'Y', ] ]); while ($row = $appIterator->fetch()) { $marketplaceInstalledApps[$row['CODE']] = $row; } return $marketplaceInstalledApps; } /** * @return array * @throws Main\SystemException */ private function getShowAllItem(): array { $paySystemAppsCount = RestManager::getInstance()->getMarketplaceAppsCount(self::MARKETPLACE_CATEGORY_PAYMENT); return [ 'id' => 'counter', 'title' => Loc::getMessage('SPP_PAYSYSTEM_APP_TOTAL_APPLICATIONS'), 'data' => [ 'type' => 'counter', 'connectPath' => '/marketplace/?category='.self::MARKETPLACE_CATEGORY_PAYMENT, 'count' => $paySystemAppsCount, 'description' => Loc::getMessage('SPP_PAYSYSTEM_APP_SEE_ALL'), ], ]; } /** * @return array */ private function getNeedIntegrationItem(): array { $integrationsUrl = static::INTEGRATIONS_URL; if (Main\Context::getCurrent()->getLanguage() !== 'en') { $integrationsUrl .= Main\Context::getCurrent()->getLanguage() . '/'; } return [ 'id' => 'integration', 'data' => [ 'type' => 'integration', 'url' => $integrationsUrl, 'description' => Loc::getMessage('SPP_PAYSYSTEM_APP_INTEGRATION_REQUIRED'), ], ]; } /** * @return array */ private function getActionboxItems(): array { $dynamicItems = []; $userLang = LANGUAGE_ID ?? 'en'; $cacheTTL = 86400; $cacheId = 'scActionsRest' . $userLang; $cachePath = 'restItems'; $cache = Main\Data\Cache::createInstance(); if ($cache->InitCache($cacheTTL, $cacheId, $cachePath)) { $res = $cache->GetVars(); if (is_array($res) && (count($res) > 0)) { $dynamicItems = $res; } } if (count($dynamicItems) <= 0) { $marketplace = new Rest\Marketplace\MarketplaceActions(); $restItems = $marketplace->getItems('salecenter', $userLang); if (!empty($restItems) && count($restItems) > 0) { $dynamicItems = $this->prepareRestItems($restItems); if ($dynamicItems !== null) { $cache->startDataCache($cacheTTL, $cacheId, $cachePath); $cache->endDataCache($dynamicItems); } } } return $dynamicItems; } /** * @param $items * @return array */ private function prepareRestItems($items): array { $result = []; if (is_array($items)) { foreach ($items as $item) { if ($item['SLIDER'] === 'Y') { preg_match("/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)/i", $item['HANDLER']) ? $handler = 'landing' : $handler = 'marketplace'; } else { $handler = 'anchor'; } $result[] = [ 'title' => $item['NAME'], 'image' => $item['IMAGE'], 'outerImage' => true, 'itemSelected' => false, 'data' => [ 'type' => 'actionbox', 'showMenu' => false, 'move' => $item['HANDLER'], 'handler' => $handler, ], ]; } } return $result; } private function getRecommendItem(): array { $feedbackPath = \CComponentEngine::makeComponentPath('bitrix:salescenter.feedback'); $feedbackPath = getLocalPath('components'.$feedbackPath.'/slider.php'); $feedbackPath = new Main\Web\Uri($feedbackPath); $queryParams = [ 'lang' => LANGUAGE_ID, 'feedback_type' => 'paysystem_offer', ]; $feedbackPath->addParams($queryParams); return [ 'id' => 'recommend', 'title' => Loc::getMessage('SPP_PAYSYSTEM_APP_RECOMMEND'), 'image' => $this->getImagePath().'recommend.svg', 'data' => [ 'type' => 'recommend', 'connectPath' => $feedbackPath->getLocator(), ] ]; } /** * @param string $title * @return string */ private function getFormattedTitle(string $title): string { if (strlen($title) > self::PAYSYSTEM_TITLE_LENGTH_LIMIT) { $title = substr($title, 0, self::PAYSYSTEM_TITLE_LENGTH_LIMIT - 3).'...'; } return $title; } private function getZone() { if (Main\ModuleManager::isModuleInstalled('bitrix24')) { $zone = \CBitrix24::getPortalZone(); } else { $iterator = Main\Localization\LanguageTable::getList([ 'select' => ['ID'], 'filter' => ['=DEF' => 'Y', '=ACTIVE' => 'Y'] ]); $row = $iterator->fetch(); $zone = $row['ID']; } return $zone; } /** * @inheritDoc */ public function configureActions() { return []; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.8 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка