1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
registerservice.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\PaySystem\Robokassa;
4
5use Bitrix\Main;
6use Bitrix\Sale;
7
8final class RegisterService
9{
10 private const SIGN_PART = 'bitrix';
11 private const CREATE_ACTION = 'rk_reg_created';
12
14 {
16
17 $action = $request->get('act');
18 if ($action === self::CREATE_ACTION)
19 {
20 $checkRequiredFieldsResult = $this->checkRequiredFields($request);
21 if (!$checkRequiredFieldsResult->isSuccess())
22 {
23 $result->addErrors($checkRequiredFieldsResult->getErrors());
24 return $result;
25 }
26
27 $signedDomain = $request->get('signed_domain') ?? '';
28 if (!$this->isValidDomain($signedDomain))
29 {
30 $result->addError(new Main\Error('Signed domain not valid'));
31 return $result;
32 }
33
34 $shopId = $request->get('shopId');
35 $sign = $request->get('sign');
36 $key1 = $request->get('key_1');
37 $key2 = $request->get('key_2');
38
39 if (!$this->isSignValid($shopId, $sign))
40 {
41 $result->addError(new Main\Error('Bad sign'));
42 return $result;
43 }
44
45 try
46 {
47 $saveResult = self::save($shopId, $key1, $key2);
48 }
49 catch (\Exception $exception)
50 {
51 $saveResult = new Main\Result();
52 $saveResult->addError(new Main\Error($exception->getMessage()));
53 }
54
55 if (!$saveResult->isSuccess())
56 {
57 $result->addErrors($saveResult->getErrors());
58 }
59 }
60
61 return $result;
62 }
63
72 private static function save(string $shopId, string $key1, string $key2): Main\Result
73 {
74 $settingsFields = self::prepareSettings($shopId, $key1, $key2);
75
77
80 {
81 return $shopSettings->update($settingsFields);
82 }
83
84 return $shopSettings->add($settingsFields);
85 }
86
87 private static function prepareSettings(string $shopId, string $key1, string $key2): array
88 {
89 return [
90 'ROBOXCHANGE_SHOPLOGIN' => $shopId,
91 'ROBOXCHANGE_SHOPPASSWORD' => $key1,
92 'ROBOXCHANGE_SHOPPASSWORD2' => $key2,
93 ];
94 }
95
96 private function isSignValid(string $shopId, string $sign): bool
97 {
98 $calculatedSign = md5(sprintf('%s.%s', self::SIGN_PART, $shopId));
99 return strcasecmp($calculatedSign, $sign) === 0;
100 }
101
102 private function checkRequiredFields(Main\Request $request): Main\Result
103 {
104 $result = new Main\Result();
105
106 $requireFields = [
107 'shopId',
108 'sign',
109 'key_1',
110 'key_2',
111 'signed_domain',
112 ];
113
114 foreach ($requireFields as $field)
115 {
116 if (!$request->get($field))
117 {
118 $result->addError(new Main\Error("{$field} not found"));
119 }
120 }
121
122 return $result;
123 }
124
125 public function isValidDomain(string $signedDomain): bool
126 {
127 $request = Main\Application::getInstance()->getContext()->getRequest();
128 $protocol = $request->isHttps() ? 'https' : 'http';
129 $domain = "{$protocol}://{$request->getHttpHost()}";
130
131 return (new Sale\PaySystem\Robokassa\DomainSigner($domain))->isValidDomain($signedDomain);
132 }
133}
$currentSettings
Определения options.php:1301
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static getInstance()
Определения application.php:98
Определения error.php:15
Определения request.php:10
isValidDomain(string $signedDomain)
Определения registerservice.php:125
processRequest(Main\Request $request)
Определения registerservice.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$protocol
Определения .description.php:9
$shopSettings
Определения .description.php:149
$sign
Определения payment.php:69
$shopId
Определения refund.php:14
$action
Определения file_dialog.php:21