3namespace Sale\Handlers\PaySystem;
6use Bitrix\Main\Request;
7use Bitrix\Main\Type\DateTime;
8use Bitrix\Main\Localization\Loc;
9use Bitrix\Main\Web\HttpClient;
10use Bitrix\Sale\PaySystem;
11use Bitrix\Sale\Payment;
12use Bitrix\Main\Application;
13use Bitrix\Sale\PriceMaths;
26 $request = Main\Context::getCurrent()->getRequest();
30 if (!preg_match(
'/^\+7\d{10}$/', $phone))
34 'PAYSYSTEM_ID' => $this->service->getField(
'ID'),
35 'BUYER_PERSON_PHONE' => $phone,
36 'RETURN_URL' => $this->getSuccessUrl(
$payment),
44 'BUYER_PERSON_PHONE' => $phone,
45 'QIWI_SUCCESS_URL' => $this->getSuccessUrl(
$payment),
46 'QIWI_FAIL_URL' => $this->getFailUrl(
$payment),
59 $newPhone = trim((
string)
$request->getPost(
'NEW_PHONE'));
72 private function normalizePhone($number)
74 $normalizedNumber = \NormalizePhone($number);
75 if ($normalizedNumber)
77 return '+'.$normalizedNumber;
88 return array(
'txn_id',
'to',
'from',
'summ');
95 public function getPaymentIdFromRequest(Request
$request)
107 self::ACTIVE_URL =>
'https://w.qiwi.com/order/external/create.action'
110 self::ACTIVE_URL =>
'https://w.qiwi.com/api/v2/prv/{prv_id}/bills/{bill_id}'
132 $result =
new PaySystem\ServiceResult();
134 $instance = \Bitrix\Main\Application::getInstance();
145 $result->setData(
array(
'CODE' =>
'QIWI_WALLET_ERROR_CODE_AUTH'));
151 if ($server->get(
'HTTP_X_API_SIGNATURE') !==
null && $this->getBusinessValue(
$payment,
'QIWI_API_PASSWORD'))
156 $check = base64_encode(sha1(
$key, implode(
"|", array_values(
$postParams))));
158 if ($check != $server->get(
'HTTP_X_API_SIGNATURE'))
160 $result->setData(
array(
'CODE' =>
'QIWI_WALLET_ERROR_CODE_AUTH'));
166 $result->setData(
array(
'CODE' =>
'QIWI_WALLET_ERROR_CODE_AUTH'));
173 "PS_STATUS" =>
$request->get(
'status') ==
"paid" ?
"Y" :
"N",
174 "PS_STATUS_CODE" => mb_substr(
$request->get(
'status'), 0, 5),
175 "PS_STATUS_MESSAGE" => Loc::getMessage(
"SALE_QWH_STATUS_MESSAGE_".mb_strtoupper($_POST[
'status'])),
176 "PS_RESPONSE_DATE" =>
new DateTime(),
177 "PS_SUM" => (
double)
$request->get(
'amount'),
178 "PS_CURRENCY" =>
$request->get(
'ccy'),
179 "PS_STATUS_DESCRIPTION" =>
""
182 if ((
int)
$request->get(
'error') > 0)
184 $paidInfo[
'PS_STATUS_DESCRIPTION'] =
"Error: ".Loc::getMessage(
"SALE_HPS_QIWI_ERROR_CODE_".
$request->get(
'error'));
186 $result->setData(
array(
'CODE' =>
'QIWI_WALLET_ERROR_CODE_OTHER'));
191 foreach($_POST as
$key => $value)
198 if (
$request->get(
'status') ==
"paid" && $changeStatusPay)
200 $result->setOperationType(PaySystem\ServiceResult::MONEY_COMING);
201 $result->setData(
array(
'CODE' =>
'QIWI_WALLET_ERROR_CODE_NONE'));
211 protected function isTestMode(Payment
$payment =
null)
221 return array(
'RUB',
'USD');
229 public function sendResponse(PaySystem\ServiceResult
$result, Request
$request)
237 header(
"Content-Type: text/xml");
238 header(
"Pragma: no-cache");
239 $xml =
'<?xml version="1.0" encoding="UTF-8"?><result><result_code>'.$this->getErrorCodeValue(
$data[
'CODE']).
'</result_code></result>';
248 protected function getAuthHeader()
250 $instance = \Bitrix\Main\Application::getInstance();
254 $incomingToken =
false;
255 if ($server->get(
"REMOTE_USER") !==
null)
257 $incomingToken = $server->get(
"REMOTE_USER");
259 elseif ($server->get(
"REDIRECT_REMOTE_USER") !==
null)
261 $incomingToken = $server->get(
"REDIRECT_REMOTE_USER");
263 elseif ($server->get(
"HTTP_AUTHORIZATION") !==
null)
265 $incomingToken = $server->get(
"HTTP_AUTHORIZATION");
267 elseif (function_exists(
"apache_request_headers"))
269 $headers = \apache_request_headers();
271 if(array_key_exists(
"Authorization", $headers))
272 $incomingToken = $headers[
"Authorization"];
274 return $incomingToken;
287 $header = $this->getAuthHeader();
293 return $header == $check;
300 protected function getErrorCodeValue(
$code)
303 'QIWI_WALLET_ERROR_CODE_NONE' => 0,
304 'QIWI_WALLET_ERROR_CODE_BAD_REQUEST' => 5,
305 'QIWI_WALLET_ERROR_CODE_BUSY' => 13,
306 'QIWI_WALLET_ERROR_CODE_AUTH' => 150,
307 'QIWI_WALLET_ERROR_CODE_NOT_FOUND' => 210,
308 'QIWI_WALLET_ERROR_CODE_EXISTS' => 215,
309 'QIWI_WALLET_ERROR_CODE_TOO_LOW' => 241,
310 'QIWI_WALLET_ERROR_CODE_TOO_HIGH' => 242,
311 'QIWI_WALLET_ERROR_CODE_NO_PURSE' => 298,
312 'QIWI_WALLET_ERROR_CODE_OTHER' => 300
315 return $codes[
$code];
322 public function check(Payment
$payment)
324 $result =
new PaySystem\ServiceResult();
330 $request->setHeader(
"Accept",
"text/json");
334 array(
"{prv_id}",
"{bill_id}"),
357 "PS_STATUS_CODE" =>
$response[
'result_code'],
358 "PS_STATUS_MESSAGE" => Loc::getMessage(
"SALE_QWH_ERROR_CODE_" .
$response[
'result_code']),
359 "PS_STATUS_DESCRIPTION" => isset(
$response[
'description']) ?
$response[
'description'] :
"",
360 "PS_RESPONSE_DATE" =>
new DateTime()
370 "PS_STATUS" => $bill[
'status'] ==
"paid" ?
"Y" :
"N",
371 "PS_STATUS_CODE" => mb_substr($bill[
'status'], 0, 10),
372 "PS_STATUS_MESSAGE" => Loc::getMessage(
"SALE_QWH_STATUS_MESSAGE_".mb_strtoupper($bill[
'status'])),
373 "PS_RESPONSE_DATE" =>
new DateTime(),
374 "PS_SUM" => (
double)$bill[
'amount'],
375 "PS_CURRENCY" => $bill[
'ccy'],
376 'PS_STATUS_DESCRIPTION' =>
''
379 foreach($bill as
$key => $value)
380 $psData[
'PS_STATUS_DESCRIPTION'] .=
"{$key}:{$value}, ";
382 $billAmount = PriceMaths::roundPrecision($bill[
'amount']);
383 $paymentSum = PriceMaths::roundPrecision(
$payment->getSum());
385 if($bill[
'status'] ==
"paid" && $billAmount == $paymentSum && $this->
getBusinessValue(
$payment,
'PS_CHANGE_STATUS_PAY'))
386 $result->setOperationType(PaySystem\ServiceResult::MONEY_COMING);
398 private function getSuccessUrl(Payment
$payment)
407 private function getFailUrl(Payment
$payment)
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
getUrl(Payment $payment=null, $action)
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(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']