3namespace Sale\Handlers\PaySystem;
5use Bitrix\Main\Localization;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Main\Request;
9use Bitrix\Main\Web\HttpClient;
10use Bitrix\Sale\Cashbox;
11use Bitrix\Sale\Payment;
12use Bitrix\Sale\PaymentCollection;
13use Bitrix\Sale\PaySystem;
14use Bitrix\Sale\PriceMaths;
15use Bitrix\Sale\Services\Base\RestrictionInfo;
16use Bitrix\Sale\Services\Base\RestrictionInfoCollection;
25class YandexCheckoutHandler
34 const CMS_NAME =
'api_1c-bitrix';
39 public const PAYMENT_STATUS_WAITING_FOR_CAPTURE =
'waiting_for_capture';
43 public const PAYMENT_STATUS_PENDING =
'pending';
47 public const AUTH_TYPE =
'yandex';
49 public const PAYMENT_STATUS_SUCCEEDED =
'succeeded';
50 public const PAYMENT_STATUS_CANCELED =
'canceled';
52 public const PAYMENT_METHOD_SMART =
'';
53 public const PAYMENT_METHOD_ALFABANK =
'alfabank';
54 public const PAYMENT_METHOD_BANK_CARD =
'bank_card';
55 public const PAYMENT_METHOD_YANDEX_MONEY =
'yoo_money';
56 public const PAYMENT_METHOD_SBERBANK =
'sberbank';
57 public const PAYMENT_METHOD_CASH =
'cash';
58 public const PAYMENT_METHOD_EMBEDDED =
'embedded';
59 public const PAYMENT_METHOD_TINKOFF_BANK =
'tinkoff_bank';
60 public const PAYMENT_METHOD_SBP =
'sbp';
61 public const PAYMENT_METHOD_SBER_LOAN =
'sber_loan';
63 public const MODE_SMART =
'';
64 public const MODE_ALFABANK =
'alfabank';
65 public const MODE_BANK_CARD =
'bank_card';
66 public const MODE_YANDEX_MONEY =
'yoo_money';
67 public const MODE_SBERBANK =
'sberbank';
68 public const MODE_SBERBANK_SMS =
'sberbank_sms';
69 public const MODE_SBERBANK_QR =
'sberbank_qr';
70 public const MODE_CASH =
'cash';
71 public const MODE_MOBILE_BALANCE =
'mobile_balance';
72 public const MODE_EMBEDDED =
'embedded';
73 public const MODE_TINKOFF_BANK =
'tinkoff_bank';
74 public const MODE_SBP =
'sbp';
75 public const MODE_SBER_LOAN =
'sber_loan';
77 public const URL =
'https://api.yookassa.ru/v3';
79 private const CALLBACK_IP_LIST = [
88 private const CONFIRMATION_TYPE_REDIRECT =
"redirect";
89 private const CONFIRMATION_TYPE_EXTERNAL =
"external";
90 private const CONFIRMATION_TYPE_EMBEDDED =
"embedded";
91 private const CONFIRMATION_TYPE_QR =
'qr';
93 private const SEND_METHOD_HTTP_POST =
"POST";
94 private const SEND_METHOD_HTTP_GET =
"GET";
96 use PaySystem\Cashbox\CheckTrait;
115 $request = Main\Context::getCurrent()->getRequest();
118 $result =
new PaySystem\ServiceResult();
120 $yandexPaymentData = [];
122 if (
$payment->getField(
"PS_INVOICE_ID"))
124 $yandexPaymentResult = $this->getYandexPayment(
$payment);
125 if ($yandexPaymentResult->isSuccess())
127 $yandexPaymentData = $yandexPaymentResult->getData();
131 $isNeedCreate = $this->needCreateYandexPayment(
$payment,
$request, $yandexPaymentData);
134 $createYandexPaymentResult = $this->createYandexPayment(
$payment,
$request);
135 if (!$createYandexPaymentResult->isSuccess())
137 return $createYandexPaymentResult;
140 $yandexPaymentData = $createYandexPaymentResult->getData();
142 if (isset($yandexPaymentData[
'id']))
144 $result->setPsData([
'PS_INVOICE_ID' => $yandexPaymentData[
'id']]);
155 if ($showTemplateResult->isSuccess())
157 $result->setTemplate($showTemplateResult->getTemplate());
161 $result->addErrors($showTemplateResult->getErrors());
164 if ($isNeedCreate && !empty($yandexPaymentData[
'confirmation'][
'confirmation_url']))
166 $result->setPaymentUrl($yandexPaymentData[
'confirmation'][
'confirmation_url']);
169 if (!empty($yandexPaymentData[
'confirmation'][
'confirmation_data']) && $this->isQrPaymentType())
171 $qrCode = self::generateQrCode($yandexPaymentData[
'confirmation'][
'confirmation_data']);
174 $result->setQr(base64_encode($qrCode));
187 protected function needCreateYandexPayment(Payment
$payment, Request
$request, $additionalParams = []): bool
189 if (($additionalParams[
'status'] ??
'') === self::PAYMENT_STATUS_SUCCEEDED)
215 'SUM' => PriceMaths::roundPrecision(
$payment->getSum()),
216 'CURRENCY' =>
$payment->getField(
'CURRENCY'),
221 $params[
'URL'] = $additionalParams[
'confirmation'][
'confirmation_url'] ??
'';
225 $phoneFields = $this->getPhoneFields();
226 $phoneFields = $phoneFields[$this->service->getField(
'PS_MODE')] ?? [];
228 $params[
'FIELDS'] = $this->getPaymentMethodFields();
229 $params[
'PHONE_FIELDS'] = $phoneFields;
231 $params[
'PAYMENT_METHOD'] = $this->service->getField(
'PS_MODE');
233 $params[
'PAYSYSTEM_ID'] = $this->service->getField(
'ID');
238 $params[
'CONFIRMATION_TOKEN'] = $additionalParams[
'confirmation'][
'confirmation_token'] ??
'';
243 $params[
'URL'] = $additionalParams[
'confirmation'][
'confirmation_data'] ??
'';
246 $qrCode = self::generateQrCode(
$params[
'URL']);
249 $params[
'QR_CODE_IMAGE'] = base64_encode($qrCode);
261 protected function getTemplateName(Request
$request, $additionalParams = []): string
265 if (isset($additionalParams[
"status"])
266 && $additionalParams[
"status"] === self::PAYMENT_STATUS_SUCCEEDED
269 return "template_success";
272 if ($this->hasPaymentMethodFields() &&
273 !$this->isFillPaymentMethodFields(
$request)
278 elseif ($this->isSetExternalPaymentType())
282 elseif ($this->isSetEmbeddedPaymentType())
286 elseif ($this->isQrPaymentType())
297 private function isSetExternalPaymentType(): bool
300 static::MODE_ALFABANK,
301 static::MODE_SBERBANK_SMS
304 return in_array($this->service->getField(
'PS_MODE'), $externalPayment,
true);
310 private function isSetEmbeddedPaymentType(): bool
312 return $this->service->getField(
'PS_MODE') === static::MODE_EMBEDDED;
315 private function isQrPaymentType(): bool
319 static::MODE_SBERBANK_QR,
322 return in_array($this->service->getField(
'PS_MODE'), $qrPayment,
true);
338 private function createYandexPayment(Payment
$payment, Request
$request,
bool $isRepeated =
false): PaySystem\ServiceResult
340 $result =
new PaySystem\ServiceResult();
343 $headers = $this->getHeaders(
$payment);
354 if ($this->service->canPrintCheckSelf(
$payment))
356 $receiptResult = $this->getReceipt(
$payment);
357 if (!$receiptResult->isSuccess())
359 $result->addErrors($receiptResult->getErrors());
363 $receiptData = $receiptResult->getData();
364 $params[
'receipt'] = $receiptData[
'receipt'];
366 PaySystem\Logger::addDebugInfo(__CLASS__ .
": receipt = " . self::encode($receiptData[
'receipt']));
369 $sendResult = $this->send(self::SEND_METHOD_HTTP_POST,
$url, $headers,
$params);
370 if (!$sendResult->isSuccess())
372 $result->addErrors($sendResult->getErrors());
378 $verificationResult = $this->verifyYandexPayment(
$response);
379 if ($verificationResult->isSuccess())
385 $result->addErrors($verificationResult->getErrors());
395 private function verifyYandexPayment(
$response): PaySystem\ServiceResult
397 $result =
new PaySystem\ServiceResult();
399 if (
$response[
'status'] === static::PAYMENT_STATUS_CANCELED)
401 $error = Localization\Loc::getMessage(
402 'SALE_HPS_YANDEX_CHECKOUT_RESPONSE_ERROR_' . mb_strtoupper(
$response[
'cancellation_details'][
'reason'])
407 PaySystem\Error::createForBuyer(
$error,
$response[
'cancellation_details'][
'party'])
413 PaySystem\Error::create(Localization\Loc::getMessage(
'SALE_HPS_YANDEX_CHECKOUT_ERROR_PAYMENT_CANCELED'))
424 private function getIdempotenceKey(): string
426 return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
427 mt_rand(0, 0xffff), mt_rand(0, 0xffff),
429 mt_rand(0, 0x0fff) | 0x4000,
430 mt_rand(0, 0x3fff) | 0x8000,
431 mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
449 $result =
new PaySystem\ServiceResult();
451 $httpClient =
new HttpClient();
452 foreach ($headers as
$name => $value)
454 $httpClient->setHeader(
$name, $value);
457 if (
$method === self::SEND_METHOD_HTTP_GET)
469 PaySystem\Logger::addDebugInfo(__CLASS__.
': request data: '.
$postData);
476 $errors = $httpClient->getError();
482 $errorMessages[] =
"{$code}={$message}";
485 PaySystem\Logger::addDebugInfo(
486 __CLASS__ .
': response error: ' . implode(
', ', $errorMessages)
490 $result->addError(
new Main\
Error(Localization\Loc::getMessage(
'SALE_HPS_YANDEX_CHECKOUT_ERROR_QUERY')));
494 PaySystem\Logger::addDebugInfo(__CLASS__.
': response data: '.
$response);
498 $httpStatus = $httpClient->getStatus();
499 if ($httpStatus === 200)
503 elseif ($httpStatus !== 201)
505 if ($httpStatus === 401 && self::isOAuth())
507 $error = Localization\Loc::getMessage(
'SALE_HPS_YANDEX_CHECKOUT_HTTP_STATUS_OAUTH_'.$httpStatus.
'');
511 $error = Localization\Loc::getMessage(
'SALE_HPS_YANDEX_CHECKOUT_HTTP_STATUS_'.$httpStatus);
536 private function getYandexBasePaymentQueryParams(Payment
$payment):
array
539 'description' => $this->getPaymentDescription(
$payment),
541 'value' => (string)PriceMaths::roundPrecision(
$payment->getSum()),
542 'currency' =>
$payment->getField(
'CURRENCY'),
546 'BX_PAYMENT_NUMBER' =>
$payment->getId(),
547 'BX_PAYSYSTEM_CODE' => $this->service->getField(
'ID'),
548 'BX_HANDLER' =>
'YANDEX_CHECKOUT',
549 'cms_name' => static::CMS_NAME,
564 protected function getYandexPaymentQueryParams(Payment
$payment, Request
$request)
568 $query[
'confirmation'] = [
569 'type' => self::CONFIRMATION_TYPE_REDIRECT,
570 'return_url' => $this->getReturnUrl(
$payment),
576 $query[
'recipient'] = [
'gateway_id' => $articleId];
579 if ($this->isSetEmbeddedPaymentType())
581 $query[
'confirmation'] = [
582 'type' => self::CONFIRMATION_TYPE_EMBEDDED,
585 elseif ($this->isQrPaymentType())
587 $query[
'confirmation'] = [
588 'type' => self::CONFIRMATION_TYPE_QR,
590 $query[
'payment_method_data'] = [
591 'type' => $this->getYandexHandlerType($this->service->getField(
'PS_MODE')),
594 elseif ($this->service->getField(
'PS_MODE') !== static::MODE_SMART)
597 $query[
'payment_method_data'] = [
598 'type' => $this->getYandexHandlerType($this->service->getField(
'PS_MODE'))
601 if ($this->isSetExternalPaymentType())
603 $query[
'confirmation'] = [
604 'type' => self::CONFIRMATION_TYPE_EXTERNAL,
608 if ($this->hasPaymentMethodFields())
610 $fields = $this->getPaymentMethodFields();
615 $fieldValue =
$request->get($field);
616 if ($this->isPhone($field))
618 $fieldValue = $this->normalizePhone(
$request->get($field));
620 $query[
'payment_method_data'][$field] = $fieldValue;
626 if ($this->isRecurring(
$payment) && !self::isOAuth())
628 $query[
'save_payment_method'] =
true;
634 private function getReceipt(Payment
$payment): PaySystem\ServiceResult
636 $result =
new PaySystem\ServiceResult();
638 $checkQueryResult = $this->buildCheckQuery(
$payment);
639 if ($checkQueryResult->isSuccess())
641 $receiptData = $checkQueryResult->getData();
642 if (!empty($receiptData[
'items']) && !empty($receiptData[
'customer']))
645 'receipt' => $receiptData,
650 $result->addError(PaySystem\Error::create(Loc::getMessage(
'SALE_HPS_YANDEX_CHECKOUT_ERROR_EMPTY_RECEIPT')));
655 $result->addErrors($checkQueryResult->getErrors());
674 $query[
'payment_method_id'] =
$payment->getField(
'PS_RECURRING_TOKEN');
683 private function getReturnUrl(Payment
$payment)
697 protected function getPaymentDescription(Payment
$payment)
700 $collection =
$payment->getCollection();
701 $order = $collection->getOrder();
702 $userEmail =
$order->getPropertyCollection()->getUserEmail();
713 $payment->getField(
'ACCOUNT_NUMBER'),
714 $order->getField(
'ACCOUNT_NUMBER'),
717 ($userEmail) ? $userEmail->getValue() :
''
719 $this->getBusinessValue(
$payment,
'YANDEX_CHECKOUT_DESCRIPTION')
735 private function getPhoneNumber(Payment
$payment): ?string
740 $collection =
$payment->getCollection();
741 $order = $collection->getOrder();
744 && $clientCollection =
$order->getContactCompanyCollection()
747 $primaryClient = $clientCollection->getPrimaryContact();
750 if ($primaryClient ===
null)
752 $primaryClient = $clientCollection->getPrimaryCompany();
758 $clientId = $primaryClient->getField(
'ENTITY_ID');
759 $crmFieldMultiResult = \CCrmFieldMulti::GetList(
764 'TYPE_ID' =>
'PHONE',
767 while ($crmFieldMultiData = $crmFieldMultiResult->Fetch())
769 $phoneNumber = $crmFieldMultiData[
'VALUE'];
780 $phoneNumberProp =
$order->getPropertyCollection()->getPhone();
781 if ($phoneNumberProp)
783 $phoneNumber = $phoneNumberProp->getValue();
787 return $phoneNumber ? $this->normalizePhone($phoneNumber) : null;
794 private function getBasicAuthString(Payment
$payment): string
796 return base64_encode(
810 return Main\Web\Json::encode(
$data, JSON_UNESCAPED_UNICODE);
817 private static function decode(
$data)
821 return Main\Web\Json::decode(
$data);
823 catch (Main\ArgumentException $exception)
844 $result =
new PaySystem\ServiceResult();
846 $checkIpResult = $this->checkIpAddress();
847 if (!$checkIpResult->isSuccess())
849 $result->addErrors($checkIpResult->getErrors());
853 $inputStream = static::readFromStream();
855 $data = static::decode($inputStream);
859 if (
$response[
'status'] === static::PAYMENT_STATUS_SUCCEEDED)
864 $response[
'status'] === static::PAYMENT_STATUS_CANCELED
873 $result->addError(PaySystem\Error::create(Localization\Loc::getMessage(
'SALE_HPS_YANDEX_CHECKOUT_ERROR_QUERY')));
881 $description = Localization\Loc::getMessage(
'SALE_HPS_YANDEX_CHECKOUT_TRANSACTION') .
$response[
'id'];
886 'PS_SUM' =>
$response[
'amount'][
'value'],
888 'PS_CURRENCY' =>
$response[
'amount'][
'currency'],
889 'PS_RESPONSE_DATE' =>
new Main\Type\DateTime()
892 if (
$response[
'payment_method'][
'saved'])
901 PaySystem\Logger::addDebugInfo(
907 $result->setOperationType(PaySystem\ServiceResult::MONEY_COMING);
912 $error = Localization\Loc::getMessage(
'SALE_HPS_YANDEX_CHECKOUT_ERROR_SUM');
922 $cancellationParty =
$response[
'cancellation_details'][
'party'];
923 $cancellationReason =
$response[
'cancellation_details'][
'reason'];
925 $party = Localization\Loc::getMessage(
926 'SALE_HPS_YANDEX_CHECKOUT_REQUEST_CANCEL_PARTY_' . mb_strtoupper($cancellationParty)
930 $party = $cancellationParty;
933 $reason = Localization\Loc::getMessage(
934 'SALE_HPS_YANDEX_CHECKOUT_REQUEST_CANCEL_REASON_' . mb_strtoupper($cancellationReason)
938 $reason = $cancellationReason;
944 Localization\Loc::getMessage(
945 'SALE_HPS_YANDEX_CHECKOUT_REQUEST_CANCEL_PARTY',
950 Localization\Loc::getMessage(
951 'SALE_HPS_YANDEX_CHECKOUT_REQUEST_CANCEL_REASON',
953 '#REASON#' => $reason,
962 'PS_RESPONSE_DATE' =>
new Main\Type\DateTime(),
968 PaySystem\Error::create(Localization\Loc::getMessage(
'SALE_HPS_YANDEX_CHECKOUT_ERROR_PAYMENT_CANCELED'))
981 private function isSumCorrect(Payment
$payment,
array $paymentData)
983 PaySystem\Logger::addDebugInfo(
984 __CLASS__.
': yandexSum='.PriceMaths::roundPrecision($paymentData[
'amount'][
'value']).
"; paymentSum=".PriceMaths::roundPrecision(
$payment->getSum())
987 return PriceMaths::roundPrecision($paymentData[
'amount'][
'value']) === PriceMaths::roundPrecision(
$payment->getSum());
999 private function getYandexPayment(Payment
$payment): PaySystem\ServiceResult
1001 $result =
new PaySystem\ServiceResult();
1004 $headers = $this->getHeaders(
$payment);
1006 $sendResult = $this->send(self::SEND_METHOD_HTTP_GET,
$url, $headers);
1007 if ($sendResult->isSuccess())
1009 $result->setData($sendResult->getData());
1013 $result->addErrors($sendResult->getErrors());
1026 public function refund(Payment
$payment, $refundableSum)
1028 $result =
new PaySystem\ServiceResult();
1032 $headers = $this->getHeaders(
$payment);
1034 $sendResult = $this->send(self::SEND_METHOD_HTTP_POST,
$url, $headers,
$params);
1035 if (!$sendResult->isSuccess())
1037 $result->addErrors($sendResult->getErrors());
1043 if (
$response[
'status'] === static::PAYMENT_STATUS_SUCCEEDED
1044 && PriceMaths::roundPrecision(
$response[
'amount'][
'value']) === PriceMaths::roundPrecision($refundableSum)
1047 $result->setOperationType(PaySystem\ServiceResult::MONEY_LEAVING);
1058 public function cancel(Payment
$payment)
1061 $headers = $this->getHeaders(
$payment);
1063 $sendResult = $this->send(self::SEND_METHOD_HTTP_POST,
$url, $headers);
1064 if (!$sendResult->isSuccess())
1066 $error = __CLASS__.
': cancel: '.implode(
"\n", $sendResult->getErrorMessages());
1067 PaySystem\Logger::addError(
$error);
1085 $result =
new PaySystem\ServiceResult();
1088 $headers = $this->getHeaders(
$payment);
1097 'value' => (
string)PriceMaths::roundPrecision(
$sum),
1098 'currency' =>
$payment->getField(
'CURRENCY')
1102 $sendResult = $this->send(self::SEND_METHOD_HTTP_POST,
$url, $headers,
$params);
1103 if ($sendResult->isSuccess())
1106 $description = Localization\Loc::getMessage(
'SALE_HPS_YANDEX_CHECKOUT_TRANSACTION').$response[
'id'];
1109 "PS_STATUS_CODE" => mb_substr(
$response[
'status'], 0, 5),
1111 "PS_SUM" =>
$response[
'amount'][
'value'],
1112 "PS_CURRENCY" =>
$response[
'amount'][
'currency'],
1113 "PS_RESPONSE_DATE" =>
new Main\Type\DateTime()
1116 if (
$response[
'status'] === static::PAYMENT_STATUS_SUCCEEDED)
1119 $result->setOperationType(PaySystem\ServiceResult::MONEY_COMING);
1130 $error = __CLASS__.
': confirm: '.join(
"\n", $sendResult->getErrorMessages());
1131 PaySystem\Logger::addError(
$error);
1144 'Content-Type' =>
'application/json',
1145 'Idempotence-Key' => $this->getIdempotenceKey(),
1150 $headers[
'Authorization'] = $this->getAuthorizationHeader(
$payment);
1152 catch (\Exception $ex)
1154 $headers[
'Authorization'] =
'Basic '.$this->getBasicAuthString(
$payment);
1166 private function getAuthorizationHeader(Payment
$payment): string
1168 if (self::isOAuth())
1170 $token = $this->getYandexToken();
1171 return 'Bearer '.$token;
1174 return 'Basic '.$this->getBasicAuthString(
$payment);
1182 private function getYandexToken()
1184 if (!Main\Loader::includeModule(
'seo'))
1189 $authAdapter = Seo\Checkout\Service::getAuthAdapter(Seo\Checkout\Service::TYPE_YOOKASSA);
1190 $token = $authAdapter->getToken();
1193 $authAdapter = Seo\Checkout\Service::getAuthAdapter(Seo\Checkout\Service::TYPE_YANDEX);
1194 $token = $authAdapter->getToken();
1206 private function getRefundQueryParams(Payment
$payment, $refundableSum)
1209 'payment_id' =>
$payment->getField(
'PS_INVOICE_ID'),
1211 'value' => (
string)PriceMaths::roundPrecision($refundableSum),
1212 'currency' =>
$payment->getField(
'CURRENCY'),
1221 public function getPaymentIdFromRequest(Request
$request)
1223 $inputStream = static::readFromStream();
1227 $data = static::decode($inputStream);
1228 if (
$data ===
false)
1233 return $data[
'object'][
'metadata'][
'BX_PAYMENT_NUMBER'];
1245 return PaySystem\Manager::getHandlerDescription(
'YandexCheckout')[
'HANDLER_MODE_LIST'];
1252 protected function getYandexHandlerType($psMode)
1255 static::MODE_SMART => static::PAYMENT_METHOD_SMART,
1256 static::MODE_ALFABANK => static::PAYMENT_METHOD_ALFABANK,
1257 static::MODE_BANK_CARD => static::PAYMENT_METHOD_BANK_CARD,
1258 static::MODE_YANDEX_MONEY => static::PAYMENT_METHOD_YANDEX_MONEY,
1259 static::MODE_SBERBANK => static::PAYMENT_METHOD_SBERBANK,
1260 static::MODE_SBERBANK_SMS => static::PAYMENT_METHOD_SBERBANK,
1261 static::MODE_SBERBANK_QR => static::PAYMENT_METHOD_SBERBANK,
1262 static::MODE_CASH => static::PAYMENT_METHOD_CASH,
1263 static::MODE_EMBEDDED => static::PAYMENT_METHOD_EMBEDDED,
1264 static::MODE_TINKOFF_BANK => static::PAYMENT_METHOD_TINKOFF_BANK,
1265 static::MODE_SBER_LOAN => static::PAYMENT_METHOD_SBER_LOAN,
1266 static::MODE_SBP => static::PAYMENT_METHOD_SBP,
1269 if (array_key_exists($psMode, $handlersMap))
1271 return $handlersMap[$psMode];
1283 'pay' => static::URL.
'/payments',
1284 'refund' => static::URL.
'/refunds',
1285 'confirm' => static::URL.
'/payments/#payment_id#/capture',
1286 'cancel' => static::URL.
'/payments/#payment_id#/cancel',
1287 'payment' => static::URL.
'/payments/#payment_id#',
1288 'settings' => static::URL.
'/me',
1297 public static function isMyResponse(Request
$request, $paySystemId)
1299 $inputStream = static::readFromStream();
1303 $data = static::decode($inputStream);
1304 if (
$data ===
false)
1309 if (isset(
$data[
'object'][
'metadata'][
'BX_HANDLER'])
1310 &&
$data[
'object'][
'metadata'][
'BX_HANDLER'] ===
'YANDEX_CHECKOUT'
1311 && isset(
$data[
'object'][
'metadata'][
'BX_PAYSYSTEM_CODE'])
1312 && (
int)
$data[
'object'][
'metadata'][
'BX_PAYSYSTEM_CODE'] === (
int)$paySystemId
1325 private static function readFromStream()
1327 return file_get_contents(
'php://input');
1346 $url = str_replace(
'#payment_id#',
$payment->getField(
'PS_INVOICE_ID'),
$url);
1355 private function getPaymentMethodFields():
array
1357 $paymentMethodFields =
array(
1358 static::MODE_ALFABANK =>
array(
'login'),
1359 static::MODE_MOBILE_BALANCE =>
array(
'phone'),
1360 static::MODE_SBERBANK_SMS =>
array(
'phone'),
1363 if (isset($paymentMethodFields[$this->service->getField(
'PS_MODE')]))
1365 return $paymentMethodFields[$this->service->getField(
'PS_MODE')];
1375 private function isFillPaymentMethodFields(Request
$request): bool
1377 $fields = $this->getPaymentMethodFields();
1396 private function isPhone($field): bool
1398 $paymentMethodPhoneFields = $this->getPhoneFields();
1401 if (isset($paymentMethodPhoneFields[$this->service->getField(
'PS_MODE')]))
1403 $phoneFields = $paymentMethodPhoneFields[$this->service->getField(
'PS_MODE')];
1406 return in_array($field, $phoneFields);
1412 private function getPhoneFields():
array
1415 static::MODE_MOBILE_BALANCE => [
'phone'],
1416 static::MODE_SBERBANK_SMS => [
'phone'],
1424 private function normalizePhone($number)
1426 $normalizedNumber = \NormalizePhone($number);
1428 if ($normalizedNumber)
1430 return $normalizedNumber;
1439 private function hasPaymentMethodFields(): bool
1441 $fields = $this->getPaymentMethodFields();
1457 public function repeatRecurrent(Payment
$payment, Request
$request =
null): PaySystem\ServiceResult
1461 $request = Main\Context::getCurrent()->getRequest();
1472 public function cancelRecurrent(Payment
$payment, Request
$request =
null): PaySystem\ServiceResult
1474 return (
new PaySystem\ServiceResult());
1481 public function isRecurring(Payment
$payment): bool
1484 self::MODE_BANK_CARD,
1485 self::MODE_YANDEX_MONEY,
1486 self::MODE_EMBEDDED,
1489 $isPsModeSupport = in_array($this->service->getField(
"PS_MODE"),
$modeList,
true);
1492 && $isPsModeSupport;
1498 private function checkIpAddress(): PaySystem\ServiceResult
1500 $result =
new PaySystem\ServiceResult();
1503 $yandexIp = Main\Context::getCurrent()->getRequest()->getRemoteAddress();
1504 foreach (self::CALLBACK_IP_LIST as $callbackIp)
1506 $ipAddress =
new Main\Web\IpAddress($yandexIp);
1507 if ($ipAddress->matchRange($callbackIp))
1517 PaySystem\Error::create(
1518 Localization\Loc::getMessage(
'SALE_HPS_YANDEX_CHECKOUT_ERROR_CHECK_IP', [
1519 '#IP_ADDRESS#' => $yandexIp,
1534 private static function isOAuth(): bool
1537 return Main\Config\Option::get(
'sale',
'YANDEX_CHECKOUT_OAUTH',
false) ==
true;
1542 $psMode = $this->service->getField(
'PS_MODE');
1544 $baseRestrictions = parent::getRestrictionList();
1545 if ($psMode === self::PAYMENT_METHOD_SBER_LOAN)
1547 $restrictionInfo =
new RestrictionInfo(
'Price', [
1548 'MIN_VALUE' => 3000,
1549 'MAX_VALUE' => 600000,
1552 $baseRestrictions->add($restrictionInfo);
1555 $psMode === self::PAYMENT_METHOD_SBP
1556 || $this->getYandexHandlerType($psMode) === self::PAYMENT_METHOD_SBERBANK
1559 $restrictionInfo =
new RestrictionInfo(
'Price', [
1561 'MAX_VALUE' => 1000000,
1564 $baseRestrictions->add($restrictionInfo);
1567 return $baseRestrictions;
1570 private static function generateQrCode(
string $data): ?string
1572 return (
new PaySystem\BarcodeGenerator())->generate(
$data);
1577 return '\\'.Cashbox\CashboxYooKassa::class;
1580 public function isFiscalizationEnabled(Payment
$payment): bool
1583 $headers = $this->getHeaders(
$payment);
1585 $sendResult = $this->send(self::SEND_METHOD_HTTP_GET,
$url, $headers);
1586 if ($sendResult->isSuccess())
1588 $data = $sendResult->getData();
1590 return $data[
'fiscalization'][
'enabled'] ??
false;
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
static loadMessages($file)
static getHandlerModeList()
showTemplate(Payment $payment=null, $template='')
setExtraParams(array $values)
getBusinessValue(Payment $payment=null, $code)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']