1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
handler.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\PaySystem;
4
5use Bitrix\Main\Error;
6use Bitrix\Main\Request;
7use Bitrix\Main\Type\DateTime;
8use Bitrix\Sale\Payment;
9use Bitrix\Sale\PaySystem;
10use Bitrix\Main\Loader;
11use Bitrix\Main\Localization\Loc;
12
14Loc::loadMessages(__FILE__);
15
20class PayMasterHandler extends WebMoneyHandler
21{
27 public function initiatePay(Payment $payment, Request $request = null)
28 {
30 'PS_MODE' => $this->service->getField('PS_MODE'),
31 'URL' => $this->getUrl($payment, 'pay'),
32 'BX_PAYSYSTEM_CODE' => $this->service->getField('ID'),
33 'PAYMASTER_SUCCESS_URL' => $this->getSuccessUrl($payment),
34 'PAYMASTER_FAIL_URL' => $this->getFailUrl($payment),
35 );
37
38 return $this->showTemplate($payment, 'template');
39 }
40
44 static public function getIndicativeFields()
45 {
46 return array('BX_HANDLER' => 'PAYMASTER');
47 }
48
54 public function processRequest(Payment $payment, Request $request)
55 {
57 $serviceResult = new PaySystem\ServiceResult();
58
59 if ((int)$request->get('LMI_PREREQUEST') == 1 || (int)$request->get('LMI_PREREQUEST') == 2)
60 {
61 if (
62 !$this->checkSum($payment, $request) ||
63 $request->get('LMI_CURRENCY') != $this->getBusinessValue($payment, 'PAYMENT_CURRENCY') ||
64 $request->get('LMI_MERCHANT_ID') != $this->getBusinessValue($payment, 'PAYMASTER_SHOP_ACCT')
65 )
66 {
67 $serviceResult->addError(new Error(Loc::getMessage('SALE_HPS_PAYMASTER_ERROR_PARAMS_VALUE')));
68 }
69 else
70 {
71 $serviceResult->setData(array('CODE' => 'YES'));
72 }
73 }
74 else
75 {
76 if ($this->checkHash($payment, $request))
77 {
78 $psDescription = '';
79
80 if ($request->get("LMI_SIM_MODE") != 0)
81 $psDescription .= Loc::getMessage('SALE_HPS_PAYMASTER_SIM_MODE_TEST');
82
83 $psDescription .= str_replace('#MERCHANT_ID#', $request->get("LMI_MERCHANT_ID"), Loc::getMessage('SALE_HPS_PAYMASTER_DESC_MERCHANT_ID'));
84 $psDescription .= str_replace('#SYS_INVS_NO#', $request->get("LMI_SYS_INVS_NO"), Loc::getMessage('SALE_HPS_PAYMASTER_DESC_SYS_INVS_NO'));
85 $psDescription .= str_replace('#SYS_TRANS_NO#', $request->get("LMI_SYS_TRANS_NO"), Loc::getMessage('SALE_HPS_PAYMASTER_DESC_SYS_TRANS_NO'));
86 $psDescription .= str_replace('#SYS_TRANS_DATE#', $request->get("LMI_SYS_TRANS_DATE"), Loc::getMessage('SALE_HPS_PAYMASTER_DESC_SYS_TRANS_DATE'));
87 $psDescription .= str_replace('#PAY_SYSTEM#', $request->get("LMI_PAY_SYSTEM"), Loc::getMessage('SALE_HPS_PAYMASTER_DESC_PAY_SYSTEM'));
88
89 $psMessage = '';
90 if ($request->get("LMI_PAYER_PURSE") !== null)
91 $psMessage .= str_replace('#PAYER_PURSE#', $request->get("LMI_PAYER_PURSE"), Loc::getMessage('SALE_HPS_PAYMASTER_DESC_PAYER_PURSE'));
92
93 if ($request->get("LMI_PAYER_WM") !== null)
94 $psMessage .= str_replace('#PAYER_WM#', $request->get("LMI_PAYER_WM"), Loc::getMessage('SALE_HPS_PAYMASTER_DESC_PAYER_WM'));
95
96 if ($request->get("LMI_PAYMER_NUMBER") !== null)
97 $psMessage .= str_replace('#PAYMER_NUMBER#', $request->get("LMI_PAYER_NUMBER"), Loc::getMessage('SALE_HPS_PAYMASTER_DESC_PAYER_NUMBER'));
98
99 if ($request->get("LMI_PAYMER_EMAIL") !== null)
100 $psMessage .= str_replace('#PAYMER_EMAIL#', $request->get("LMI_PAYER_EMAIL"), Loc::getMessage('SALE_HPS_PAYMASTER_DESC_PAYER_EMAIL'));
101
102 if ($request->get("LMI_TELEPAT_PHONENUMBER") !== null)
103 $psMessage .= str_replace('#TELEPAT_PHONENUMBER#', $request->get("LMI_TELEPAT_PHONENUMBER"), Loc::getMessage('SALE_HPS_PAYMASTER_DESC_TELEPAT_PHONENUMBER'));
104
105 if ($request->get("LMI_TELEPAT_ORDERID") !== null)
106 $psMessage .= str_replace('#TELEPAT_ORDERID#', $request->get("LMI_TELEPAT_ORDERID"), Loc::getMessage('SALE_HPS_PAYMASTER_DESC_TELEPAT_ORDERID'));
107
108 $psFields = array(
109 "PS_STATUS" => "Y",
110 "PS_STATUS_CODE" => "-",
111 "PS_STATUS_DESCRIPTION" => $psDescription,
112 "PS_STATUS_MESSAGE" => $psMessage,
113 "PS_SUM" => $request->get("LMI_PAYMENT_AMOUNT"),
114 "PS_CURRENCY" => $this->getBusinessValue($payment, 'PAYMENT_CURRENCY'),
115 "PS_RESPONSE_DATE" => new DateTime()
116 );
117
118 if ($this->checkSum($payment, $request)
119 && $this->getBusinessValue($payment, 'PAYMENT_CURRENCY') == $request->get("LMI_CURRENCY")
120 && $this->getBusinessValue($payment, 'PAYMASTER_SHOP_ACCT') == $request->get("LMI_MERCHANT_ID")
121 && !$payment->isPaid()
122 )
123 {
124 $serviceResult->setOperationType(PaySystem\ServiceResult::MONEY_COMING);
125 $serviceResult->setPsData($psFields);
126 }
127 else
128 {
129 $serviceResult->addError(new Error('Incorrect payment sum or payment flag'));
130 }
131 }
132 else
133 {
134 $serviceResult->addError(new Error('Incorrect payment hash'));
135 }
136 }
137
138 if (!$serviceResult->isSuccess())
139 {
140 $error = 'Paymaster: processRequest: '.join('\n', $serviceResult->getErrorMessages());
141 PaySystem\Logger::addError($error);
142 }
143
144 return $serviceResult;
145 }
146
147
151 protected function getUrlList()
152 {
153 return array(
154 'pay' => array(
155 self::ACTIVE_URL => 'https://paymaster.ru/Payment/Init'
156 )
157 );
158 }
159
165 protected function checkHash(Payment $payment, Request $request)
166 {
167 $algorithm = $this->getBusinessValue($payment, 'PAYMASTER_HASH_ALGO');
168
169 $string = $request->get("LMI_MERCHANT_ID").";".$request->get("LMI_PAYMENT_NO").";".$request->get("LMI_SYS_PAYMENT_ID").";".$request->get("LMI_SYS_PAYMENT_DATE").";".$request->get("LMI_PAYMENT_AMOUNT").";".$request->get("LMI_CURRENCY").";".$request->get("LMI_PAID_AMOUNT").";".$request->get("LMI_PAID_CURRENCY").";".$request->get("LMI_PAYMENT_SYSTEM").";".$request->get("LMI_SIM_MODE").";".$this->getBusinessValue($payment, 'PAYMASTER_CNST_SECRET_KEY');
170
171 $hash = base64_encode(hash($algorithm, $string, true));
172
173 return mb_strtoupper($hash) == mb_strtoupper($request->get('LMI_HASH'));
174 }
175
181 public function sendResponse(PaySystem\ServiceResult $result, Request $request)
182 {
183 global $APPLICATION;
184 $APPLICATION->RestartBuffer();
185
186 $data = $result->getData();
187 if (array_key_exists('CODE', $data))
188 {
189 echo $data['CODE'];
190 die();
191 }
192 }
193
198 private function getSuccessUrl(Payment $payment)
199 {
200 return $this->getBusinessValue($payment, 'PAYMASTER_SUCCESS_URL') ?: $this->service->getContext()->getUrl();
201 }
202
207 private function getFailUrl(Payment $payment)
208 {
209 return $this->getBusinessValue($payment, 'PAYMASTER_FAIL_URL') ?: $this->service->getContext()->getUrl();
210 }
211}
$hash
Определения ajax_redirector.php:8
global $APPLICATION
Определения include.php:80
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
showTemplate(Payment $payment=null, $template='')
Определения baseservicehandler.php:59
getBusinessValue(Payment $payment=null, $code)
Определения baseservicehandler.php:184
static includeHandler($actionFile)
Определения manager.php:1045
processRequest(Payment $payment, Request $request)
$psDescription
Определения .description.php:7
$data['IS_AVAILABLE']
Определения .description.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
trait Error
Определения error.php:11
$payment
Определения payment.php:14
die
Определения quickway.php:367
$error
Определения subscription_card_product.php:20