10 private const SIGN_PART =
'bitrix';
11 private const CREATE_ACTION =
'rk_reg_created';
17 $action = $request->get(
'act');
18 if ($action === self::CREATE_ACTION)
20 $checkRequiredFieldsResult = $this->checkRequiredFields($request);
21 if (!$checkRequiredFieldsResult->isSuccess())
23 $result->addErrors($checkRequiredFieldsResult->getErrors());
27 $signedDomain = $request->get(
'signed_domain') ??
'';
30 $result->addError(
new Main\
Error(
'Signed domain not valid'));
34 $shopId = $request->get(
'shopId');
35 $sign = $request->get(
'sign');
36 $key1 = $request->get(
'key_1');
37 $key2 = $request->get(
'key_2');
39 if (!$this->isSignValid($shopId, $sign))
41 $result->addError(
new Main\
Error(
'Bad sign'));
47 $saveResult = self::save($shopId, $key1, $key2);
52 $saveResult->addError(
new Main\
Error($exception->getMessage()));
55 if (!$saveResult->isSuccess())
57 $result->addErrors($saveResult->getErrors());
72 private static function save(
string $shopId,
string $key1,
string $key2): Main\
Result
74 $settingsFields = self::prepareSettings($shopId, $key1, $key2);
78 $currentSettings = $shopSettings->get();
81 return $shopSettings->update($settingsFields);
84 return $shopSettings->add($settingsFields);
87 private static function prepareSettings(
string $shopId,
string $key1,
string $key2): array
90 'ROBOXCHANGE_SHOPLOGIN' => $shopId,
91 'ROBOXCHANGE_SHOPPASSWORD' => $key1,
92 'ROBOXCHANGE_SHOPPASSWORD2' => $key2,
96 private function isSignValid(
string $shopId,
string $sign): bool
98 $calculatedSign = md5(sprintf(
'%s.%s', self::SIGN_PART, $shopId));
99 return strcasecmp($calculatedSign, $sign) === 0;
102 private function checkRequiredFields(Main\Request $request): Main\Result
104 $result =
new Main\Result();
114 foreach ($requireFields as $field)
116 if (!$request->get($field))
118 $result->addError(
new Main\Error(
"{$field} not found"));
127 $request = Main\Application::getInstance()->getContext()->getRequest();
128 $protocol = $request->isHttps() ?
'https' :
'http';
129 $domain =
"{$protocol}://{$request->getHttpHost()}";
131 return (
new Sale\PaySystem\Robokassa\
DomainSigner($domain))->isValidDomain($signedDomain);