1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
handler.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\PaySystem;
4
5use Bitrix\Main\Error;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\Request;
8use Bitrix\Main\Type\DateTime;
9use Bitrix\Sale\Payment;
10use Bitrix\Sale\PaySystem;
11use Bitrix\Sale\PaySystem\ServiceResult;
12use Bitrix\Sale\PriceMaths;
13
14Loc::loadMessages(__FILE__);
15
16class WebMoneyHandler extends PaySystem\ServiceHandler
17{
21 static public function getIndicativeFields()
22 {
23 return array('BX_HANDLER' => 'WEBMONEY');
24 }
25
31 static protected function isMyResponseExtended(Request $request, $paySystemId)
32 {
33 $id = $request->get('BX_PAYSYSTEM_CODE');
34 return $id == $paySystemId;
35 }
36
42 public function initiatePay(Payment $payment, Request $request = null)
43 {
45 'URL' => $this->getUrl($payment, 'pay'),
46 'ENCODING' => $this->service->getField('ENCODING'),
47 'BX_PAYSYSTEM_CODE' => $this->service->getField('ID'),
48 'WEBMONEY_SUCCESS_URL' => $this->getSuccessUrl($payment),
49 'WEBMONEY_FAIL_URL' => $this->getFailUrl($payment),
50 );
51
53
54 return $this->showTemplate($payment, 'template');
55 }
56
62 public function processRequest(Payment $payment, Request $request)
63 {
65 $serviceResult = new PaySystem\ServiceResult();
66
67 if ((int)$request->get('LMI_PREREQUEST') == 1)
68 {
69 if (
70 !$this->checkSum($payment, $request) ||
71 $request->get('LMI_PAYEE_PURSE') != $this->getBusinessValue($payment, 'WEBMONEY_SHOP_ACCT')
72 )
73 {
74 $serviceResult->addError(new Error('Incorrect sum or WEBMONEY_SHOP_ACCT'));
75 }
76 }
77 else
78 {
79 if ($this->checkHash($payment, $request))
80 {
81 $psDescription = '';
82
83 if ($request->get("LMI_MODE") != 0)
84 $psDescription .= Loc::getMessage('SALE_HPS_WEBMONEY_TEST');
85
86 $psDescription .= Loc::getMessage('SALE_HPS_WEBMONEY_PAYEE_PURSE', array('#PAYEE_PURSE#' => $request->get("LMI_PAYEE_PURSE")))."; ";
87 $psDescription .= Loc::getMessage('SALE_HPS_WEBMONEY_INVS_NO', array('#INVS_NO#' => $request->get("LMI_SYS_INVS_NO")))."; ";
88 $psDescription .= Loc::getMessage('SALE_HPS_WEBMONEY_TRANS_NO', array('#TRANS_NO#' => $request->get("LMI_SYS_TRANS_NO")))."; ";
89 $psDescription .= Loc::getMessage('SALE_HPS_WEBMONEY_TRANS_DATE', array('#TRANS_DATE#' => $request->get("LMI_SYS_TRANS_DATE")))."; ";
90
91 $psMessage = "";
92 if ($request->get("LMI_PAYER_PURSE") !== null)
93 $psMessage .= Loc::getMessage('SALE_HPS_WEBMONEY_PAYER_PURSE', array('#PAYER_PURSE#' => $request->get("LMI_PAYER_PURSE")))."; ";
94
95 if ($request->get("LMI_PAYER_WM") !== null)
96 $psMessage .= Loc::getMessage('SALE_HPS_WEBMONEY_PAYER_WM', array('#PAYER_WM#' => $request->get("LMI_PAYER_WM")))."; ";
97
98 if ($request->get("LMI_PAYMER_NUMBER") !== null)
99 $psMessage .= Loc::getMessage('SALE_HPS_WEBMONEY_PAYMER_NUMBER', array('#PAYMER_NUMBER#' => $request->get("LMI_PAYMER_NUMBER")))."; ";
100
101 if ($request->get("LMI_PAYMER_EMAIL") !== null)
102 $psMessage .= Loc::getMessage('SALE_HPS_WEBMONEY_PAYMER_EMAIL', array('#PAYMER_EMAIL#' => $request->get("LMI_PAYMER_EMAIL")))."; ";
103
104 if ($request->get("LMI_TELEPAT_PHONENUMBER") !== null)
105 $psMessage .= Loc::getMessage('SALE_HPS_WEBMONEY_TELEPAT_PHONENUMBER', array('#TELEPAT_PHONENUMBER#' => $request->get("LMI_TELEPAT_PHONENUMBER")))."; ";
106
107 if ($request->get("LMI_TELEPAT_ORDERID") !== null)
108 $psMessage .= Loc::getMessage('SALE_HPS_WEBMONEY_TELEPAT_ORDERID', array('#TELEPAT_ORDERID#' => $request->get("LMI_TELEPAT_ORDERID")));
109
110 $psFields = array(
111 "PS_STATUS" => "Y",
112 "PS_STATUS_CODE" => "-",
113 "PS_STATUS_DESCRIPTION" => $psDescription,
114 "PS_STATUS_MESSAGE" => $psMessage,
115 "PS_SUM" => $request->get('LMI_PAYMENT_AMOUNT'),
116 "PS_CURRENCY" => $payment->getField('CURRENCY'),
117 "PS_RESPONSE_DATE" => new DateTime()
118 );
119
120 if ($this->checkSum($payment, $request)
121 && $this->getBusinessValue($payment, 'WEBMONEY_SHOP_ACCT') == $request->get("LMI_PAYEE_PURSE")
122 && !$payment->isPaid()
123 && $this->getBusinessValue($payment, 'PS_CHANGE_STATUS_PAY') == "Y"
124 )
125 {
126 $serviceResult->setOperationType(PaySystem\ServiceResult::MONEY_COMING);
127 $serviceResult->setPsData($psFields);
128 }
129 else
130 {
131 $serviceResult->addError(new Error('Incorrect payment sum or payment flag'));
132 }
133 }
134 else
135 {
136 $serviceResult->addError(new Error('Incorrect payment hash'));
137 }
138 }
139
140 return $serviceResult;
141 }
142
147 public function getPaymentIdFromRequest(Request $request)
148 {
149 return $request->get('LMI_PAYMENT_NO');
150 }
151
156 protected function isTestMode(Payment $payment = null)
157 {
158 return $this->getBusinessValue($payment, 'PS_IS_TEST');
159 }
160
164 protected function getUrlList()
165 {
166 return array(
167 'pay' => array(
168 self::ACTIVE_URL => 'https://merchant.webmoney.ru/lmi/payment.asp'
169 )
170 );
171 }
172
178 protected function checkSum(Payment $payment, Request $request)
179 {
180 $paymentShouldPay = round($this->getBusinessValue($payment, 'PAYMENT_SHOULD_PAY'), 2);
181 $lmiPaymentAmount = round($request->get('LMI_PAYMENT_AMOUNT'), 2);
182
183 return $paymentShouldPay == $lmiPaymentAmount;
184 }
185
191 protected function checkHash(Payment $payment, Request $request)
192 {
193 $algorithm = $this->getBusinessValue($payment, 'WEBMONEY_HASH_ALGO');
194
195 $string = $request->get("LMI_PAYEE_PURSE").$request->get("LMI_PAYMENT_AMOUNT").$request->get("LMI_PAYMENT_NO").$request->get("LMI_MODE").$request->get("LMI_SYS_INVS_NO").$request->get("LMI_SYS_TRANS_NO").$request->get("LMI_SYS_TRANS_DATE").$this->getBusinessValue($payment, 'WEBMONEY_CNST_SECRET_KEY').$request->get("LMI_PAYER_PURSE").$request->get("LMI_PAYER_WM");
196
197 $hash = hash($algorithm, $string);
198
199 return mb_strtoupper($hash) == mb_strtoupper($request->get('LMI_HASH'));
200 }
201
205 public function getCurrencyList()
206 {
207 return array('RUB', 'USD', 'EUR', 'UAH');
208 }
209
215 public function sendResponse(ServiceResult $result, Request $request)
216 {
217 global $APPLICATION;
218
219 if ($result->isSuccess() && (int)$request->get('LMI_PREREQUEST') == 1)
220 {
221 $APPLICATION->RestartBuffer();
222
223 echo 'YES';
224 die();
225 }
226 }
227
232 private function getSuccessUrl(Payment $payment)
233 {
234 return $this->getBusinessValue($payment, 'WEBMONEY_SUCCESS_URL') ?: $this->service->getContext()->getUrl();
235 }
236
241 private function getFailUrl(Payment $payment)
242 {
243 return $this->getBusinessValue($payment, 'WEBMONEY_FAIL_URL') ?: $this->service->getContext()->getUrl();
244 }
245}
$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
getUrl(Payment $payment=null, $action)
Определения baseservicehandler.php:343
showTemplate(Payment $payment=null, $template='')
Определения baseservicehandler.php:59
getBusinessValue(Payment $payment=null, $code)
Определения baseservicehandler.php:184
processRequest(Payment $payment, Request $request)
$psDescription
Определения .description.php:7
</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