3namespace Sale\Handlers\PaySystem;
5use Bitrix\Main\Entity\EntityError;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\Request;
9use Bitrix\Main\Type\DateTime;
10use Bitrix\Main\Web\HttpClient;
11use Bitrix\Sale\PaySystem;
12use Bitrix\Sale\Payment;
13use Bitrix\Sale\PriceMaths;
15Loc::loadMessages(__FILE__);
27 'URL' => $this->getUrl(
$payment,
'pay'),
28 'ASSIST_SUCCESS_URL' => $this->getSuccessUrl(
$payment),
29 'ASSIST_FAIL_URL' => $this->getFailUrl(
$payment),
41 return array(
'ordernumber',
'billnumber',
'orderamount',
'amount',
'meantypename',
'meantype_id',
'approvalcode',
'operationtype');
49 public function refund(Payment
$payment, $refundableSum)
51 $result =
new PaySystem\ServiceResult();
54 $refundUrl = $this->getUrl(
$payment,
'return');
57 'Billnumber' =>
$payment->getField(
'PS_INVOICE_ID'),
58 'Merchant_ID' =>
$params[
'ASSIST_SHOP_IDP'],
59 'Login' =>
$params[
'ASSIST_SHOP_LOGIN'],
60 'Password' =>
$params[
'ASSIST_SHOP_PASSWORD'],
61 'Amount' => $refundableSum,
62 'Currency' =>
$params[
'PAYMENT_CURRENCY'],
66 $clientHttp =
new HttpClient();
71 $xml = new \CDataXML();
73 $data = $xml->GetArray();
74 if (
$data &&
$data[
'result'][
'@'][
'firstcode'] ==
'0' &&
$data[
'result'][
'@'][
'secondcode'] ==
'0')
76 $result->setOperationType(PaySystem\ServiceResult::MONEY_LEAVING);
80 $error =
'assist error refund: firstcode='.$data[
'result'][
'@'][
'firstcode'].
' secondcode='.
$data[
'result'][
'@'][
'secondcode'];
81 PaySystem\Logger::addError(
'Assist: return: '.
$error);
82 $result->addError(
new EntityError(Loc::getMessage(
'SALE_PS_MESSAGE_ERROR_CONNECT_PAY_SYS')));
87 $message =
'Incorrect server response';
90 PaySystem\Logger::addError(
'Assist: return: '.
$message);
109 return (mb_strtoupper(
$hash) == mb_strtoupper(
$request->get(
'checkvalue')));
122 return PriceMaths::roundPrecision($paymentSum) === PriceMaths::roundPrecision(
$sum);
130 public function sendResponse(PaySystem\ServiceResult
$result, Request
$request)
135 header(
'Content-Type: text/xml');
136 header(
'Pragma: no-cache');
137 $text =
'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n';
139 if (
$result->isResultApplied())
141 $text .=
'<pushpaymentresult firstcode=\'0\' secondcode=\'0\'>';
143 $text .=
'<billnumber>'.$request->get(
'billnumber').
'</billnumber>';
144 $text .=
'<packetdate>'.$request->get(
'packetdate').
'</packetdate>';
149 $text .=
'<pushpaymentresult firstcode=\'9\' secondcode=\'7\'>';
152 $text .=
'</pushpaymentresult>';
162 public function getPaymentIdFromRequest(Request
$request)
164 return $request->get(
'ordernumber');
174 $result =
new PaySystem\ServiceResult();
179 $psStatus = (
$status ==
"Approved") ?
"Y" :
"N";
183 "PS_STATUS" => $psStatus,
184 "PS_STATUS_CODE" => mb_substr(
$status, 0, 5),
185 "PS_STATUS_DESCRIPTION" => Loc::getMessage(
'SALE_PS_DESCRIPTION_'.mb_strtoupper(
$status)),
186 "PS_STATUS_MESSAGE" => Loc::getMessage(
'SALE_PS_MESSAGE_'.mb_strtoupper(
$status)),
187 "PS_SUM" =>
$request->get(
'orderamount'),
188 "PS_CURRENCY" =>
$request->get(
'ordercurrency'),
189 "PS_INVOICE_ID" =>
$request->get(
'billnumber'),
190 "PS_RESPONSE_DATE" =>
new DateTime()
200 $result->setOperationType(PaySystem\ServiceResult::MONEY_COMING);
204 $result->addError(
new Error(
'Incorrect sum or payment flag'));
214 PaySystem\Logger::addError(
'Assist: '.
$request->get(
'orderstate').
': '.join(
'\n',
$result->getErrorMessages()));
224 protected function isTestMode(Payment
$payment =
null)
235 'confirm' =>
'https://#SERVER_NAME#/charge/charge.cfm',
236 'return' =>
'https://#SERVER_NAME#/cancel/wscancel.cfm',
237 'pay' =>
'https://#SERVER_NAME#/pay/order.cfm',
238 'check' =>
'https://#SERVER_NAME#/orderstate/orderstate.cfm',
251 $domain =
'payments.demo.paysecure.ru';
255 return str_replace(
'#SERVER_NAME#', $domain,
$url);
263 return array(
'RUB',
'USD',
'EUR');
270 public function check(Payment
$payment)
272 $serviceResult =
new PaySystem\ServiceResult();
282 'StartYear' => date(
'Y',
$dtm),
283 'StartMonth' => date(
'n',
$dtm),
284 'StartYDay' => date(
'j',
$dtm)
287 $httpClient =
new HttpClient();
288 $queryRes = $httpClient->query(
'POST', $this->getUrl(
$payment,
'check'),
$postData);
292 $httpResult = $httpClient->getResult();
294 $objXML = new \CDataXML();
295 $objXML->LoadString($httpResult);
296 $data = $objXML->GetArray();
298 if (
$data &&
$data[
'result'][
'@'][
'firstcode'] ==
'0')
300 $orderData =
$data[
'result'][
'#'][
'order'][0][
'#'];
303 $check = mb_strtoupper(md5(
ToUpper(md5($this->
getBusinessValue(
$payment,
'ASSIST_SHOP_SECRET_WORLD')).md5($this->
getBusinessValue(
$payment,
'ASSIST_SHOP_IDP').$orderData[
'ordernumber'][0][
'#'].$orderData[
'orderamount'][0][
'#'].$orderData[
'ordercurrency'][0][
'#'].$orderData[
'orderstate'][0][
'#']))));
305 if (mb_strtoupper($orderData[
'checkvalue'][0][
'#']) == $check)
307 $status = str_replace(
' ',
'', $orderData[
'orderstate'][0][
'#']);
310 'PS_STATUS' => ($orderData[
'orderstate'][0][
'#'] ==
'Approved' ?
'Y' :
'N'),
311 'PS_STATUS_CODE' => mb_substr($orderData[
'orderstate'][0][
'#'], 0, 5),
312 'PS_STATUS_DESCRIPTION' => Loc::getMessage(
'SALE_PS_DESCRIPTION_'.mb_strtoupper(
$status)),
313 'PS_STATUS_MESSAGE' => Loc::getMessage(
'SALE_PS_MESSAGE_'.mb_strtoupper(
$status)),
314 'PS_SUM' => DoubleVal($orderData[
'orderamount'][0][
'#']),
315 'PS_CURRENCY' => $orderData[
'ordercurrency'][0][
'#'],
316 'PS_RESPONSE_DATE' =>
new DateTime(),
318 $serviceResult->setPsData($psData);
322 $this->getBusinessValue(
$payment,
'PS_CHANGE_STATUS_PAY') ==
'Y' &&
323 $psData[
"PS_STATUS"] ==
"Y" &&
324 $payment->getSum() == floatval($psData[
"PS_SUM"])
327 $serviceResult->setOperationType(PaySystem\ServiceResult::MONEY_COMING);
334 $serviceResult->addError(
new EntityError(Loc::getMessage(
'SALE_PS_MESSAGE_ERROR_CONNECT_PAY_SYS')));
338 return $serviceResult;
345 private function getSuccessUrl(Payment
$payment)
354 private function getFailUrl(Payment
$payment)
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
showTemplate(Payment $payment=null, $template='')
getParamsBusValue(Payment $payment=null)
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)
AddToTimeStamp($arrAdd, $stmp=false)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']