2namespace Sale\Handlers\PaySystem;
5use Bitrix\Main\Request;
6use Bitrix\Main\Context;
7use Bitrix\Main\Type\DateTime;
8use Bitrix\Main\Localization\Loc;
10use Bitrix\Sale\PaySystem;
11use Bitrix\Sale\Payment;
12use Bitrix\Sale\PriceMaths;
13use Bitrix\Sale\Cashbox;
15Loc::loadMessages(__FILE__);
21class RoboxchangeHandler
25 use PaySystem\Cashbox\CheckTrait;
27 public const TEMPLATE_TYPE_CHECKOUT =
'checkout';
28 public const TEMPLATE_TYPE_IFRAME =
'iframe';
30 protected const DEFAULT_TEMPLATE_NAME =
'template';
32 private const ANALYTICS_LABEL_RU_VALUE =
'api_1c-bitrix';
33 private const ANALYTICS_LABEL_KZ_VALUE =
'api_1c-bitrix_kz';
45 $request = Context::getCurrent()->getRequest();
49 if ($this->service->canPrintCheckSelf(
$payment))
51 $receiptResult = $this->getReceipt(
$payment);
52 if (!$receiptResult->isSuccess())
54 $result =
new PaySystem\ServiceResult();
55 $result->addErrors($receiptResult->getErrors());
59 $receipt = self::encode($receiptResult->getData());
61 PaySystem\Logger::addDebugInfo(__CLASS__.
": receipt = {$receipt}");
68 'URL' => $this->getUrl(
$payment,
'pay'),
69 'PS_MODE' => self::getHandlerModeAlias($this->service->getField(
'PS_MODE')),
70 'SIGNATURE_VALUE' => $this->getSignatureValue(
$payment, $receipt, $additionalUserFields),
71 'ROBOXCHANGE_ORDERDESCR' => $this->getOrderDescription(
$payment),
73 'SUM' => PriceMaths::roundPrecision(
$payment->getSum()),
74 'CURRENCY' =>
$payment->getField(
'CURRENCY'),
75 'OUT_SUM_CURRENCY' => $this->getOutSumCurrency(
$payment),
76 'ADDITIONAL_USER_FIELDS' => $additionalUserFields,
77 'RECEIPT' => $receipt,
90 $countryCode = $this->getCountryCode(
$payment);
92 $additionalUserFields = [
93 'SHP_BX_PAYMENT_CODE' =>
$payment->getField(
'XML_ID'),
94 'SHP_BX_PAYSYSTEM_CODE' => $this->service->getField(
'ID'),
95 'SHP_HANDLER' =>
'ROBOXCHANGE',
96 'SHP_PARTNER' => $countryCode ===
'RU' ? self::ANALYTICS_LABEL_RU_VALUE : self::ANALYTICS_LABEL_KZ_VALUE,
97 'SHP_BX_REDIRECT_URL' =>
$request->get(
'SHP_BX_REDIRECT_URL') ?: $this->getReturnUrl(),
99 ksort($additionalUserFields);
101 return $additionalUserFields;
110 private function getSignatureValue(Payment
$payment,
string $receipt =
null,
array $additionalUserFields = []): string
112 $passwordCode =
'ROBOXCHANGE_SHOPPASSWORD';
115 $passwordCode .=
'_TEST';
120 $signaturePartList = [
126 if ($outSumCurrency = $this->getOutSumCurrency(
$payment))
128 $signaturePartList[] = $outSumCurrency;
133 $signaturePartList[] = $receipt;
136 $signaturePartList[] = $shopPassword1;
138 if ($additionalUserFields)
140 foreach ($additionalUserFields as $fieldName => $fieldValue)
142 $signaturePartList[] = implode(
'=', [$fieldName, $fieldValue]);
146 return md5(implode(
':', $signaturePartList));
153 private function getOrderDescription(Payment
$payment)
162 private function getTemplateName(Payment
$payment): string
165 if (empty($templateType) || $templateType === self::TEMPLATE_TYPE_CHECKOUT)
167 return static::DEFAULT_TEMPLATE_NAME;
170 return $templateType;
178 return [
'SHP_HANDLER' =>
'ROBOXCHANGE'];
186 protected static function isMyResponseExtended(Request
$request, $paySystemId)
188 $id = (int)
$request->get(
'SHP_BX_PAYSYSTEM_CODE');
189 return $id === (int)$paySystemId;
199 $passwordCode2 =
'ROBOXCHANGE_SHOPPASSWORD2';
202 $passwordCode2 .=
'_TEST';
207 $signaturePartList = [
213 foreach ($this->getAdditionalUserFields(
$payment,
$request) as $fieldName => $fieldValue)
215 $signaturePartList[] = implode(
'=', [$fieldName, $fieldValue]);
218 $hash = md5(implode(
':', $signaturePartList));
220 return mb_strtoupper(
$hash) === mb_strtoupper(
$request->get(
'SignatureValue'));
227 public function getPaymentIdFromRequest(Request
$request)
251 self::ACTIVE_URL =>
'https://auth.robokassa.#domain#/Merchant/Index.aspx',
256 private function getDomain(Payment
$payment): string
258 $countryCode = $this->getCountryCode(
$payment);
259 return mb_strtolower($countryCode);
273 $result =
new PaySystem\ServiceResult();
280 $result->addError(
new Error(Loc::getMessage(
'SALE_HPS_ROBOXCHANGE_INCORRECT_HASH')));
294 private function processNoticeAction(Payment
$payment, Request
$request): PaySystem\ServiceResult
296 $result =
new PaySystem\ServiceResult();
298 $psStatusDescription = Loc::getMessage(
'SALE_HPS_ROBOXCHANGE_RES_NUMBER').
": ".
$request->get(
'InvId');
299 $psStatusDescription .=
"; ".Loc::getMessage(
'SALE_HPS_ROBOXCHANGE_RES_DATEPAY').
": ".date(
"d.m.Y H:i:s");
301 if (
$request->get(
"IncCurrLabel") !==
null)
303 $psStatusDescription .=
"; ".Loc::getMessage(
'SALE_HPS_ROBOXCHANGE_RES_PAY_TYPE').
": ".
$request->get(
"IncCurrLabel");
308 "PS_STATUS_CODE" =>
"-",
309 "PS_STATUS_DESCRIPTION" => $psStatusDescription,
310 "PS_STATUS_MESSAGE" => Loc::getMessage(
'SALE_HPS_ROBOXCHANGE_RES_PAYED'),
312 "PS_CURRENCY" =>
$payment->getField(
'CURRENCY'),
313 "PS_RESPONSE_DATE" =>
new DateTime(),
316 PaySystem\Logger::addDebugInfo(
317 __CLASS__.
': PS_CHANGE_STATUS_PAY='.$this->getBusinessValue(
$payment,
'PS_CHANGE_STATUS_PAY')
322 $result->setOperationType(PaySystem\ServiceResult::MONEY_COMING);
332 protected function isTestMode(Payment
$payment =
null)
342 return [
'RUB',
'KZT',
'USD',
'EUR'];
349 private function getOutSumCurrency(Payment
$payment): string
351 $countryCode = $this->getCountryCode(
$payment);
357 ($countryCode ===
'RU' &&
$currency ===
'RUR')
358 || ($countryCode ===
'KZ' &&
$currency ===
'KZT')
371 private function getCountryCode(Payment
$payment): string
374 return $countryCode ?:
'RU';
382 public function sendResponse(PaySystem\ServiceResult
$result, Request
$request)
385 if (
$result->isResultApplied())
388 echo
'OK'.$request->get(
'InvId');
397 return PaySystem\Manager::getHandlerDescription(
'roboxchange')[
'HANDLER_MODE_LIST'];
400 private static function getHandlerModeAlias(
string $psMode): string
402 $defaultAlias =
'BankCard';
405 'bank_card' =>
'BankCard',
408 'apple_pay' =>
'ApplePay',
409 'google_pay' =>
'GooglePay',
410 'samsung_pay' =>
'SamsungPay',
413 return $aliases[$psMode] ?? $defaultAlias;
416 private function getReceipt(Payment
$payment): PaySystem\ServiceResult
418 $result =
new PaySystem\ServiceResult();
420 $checkQueryResult = $this->buildCheckQuery(
$payment);
421 if ($checkQueryResult->isSuccess())
423 $receiptData = $checkQueryResult->getData();
424 if (!empty($receiptData[
'items']) && !empty($receiptData[
'sno']))
427 'sno' => $receiptData[
'sno'],
428 'items' => $receiptData[
'items'],
433 $result->addError(PaySystem\Error::create(Loc::getMessage(
'SALE_HPS_ROBOXCHANGE_ERROR_EMPTY_RECEIPT')));
438 $result->addErrors($checkQueryResult->getErrors());
451 return Web\Json::encode(
$data, JSON_UNESCAPED_UNICODE);
456 return '\\'.Cashbox\CashboxRobokassa::class;
459 private function getReturnUrl(): string
461 return $this->service->getContext()->getUrl();
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
static getHandlerModeList()
showTemplate(Payment $payment=null, $template='')
setExtraParams(array $values)
getBusinessValue(Payment $payment=null, $code)
static getIndicativeFields()
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']