1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
handler.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\PaySystem;
4
5use Bitrix\Main\Request;
6use Bitrix\Main\Type\DateTime;
7use Bitrix\Main\Type\Date;
8use Bitrix\Sale\Payment;
9use Bitrix\Sale\PaySystem;
10use Bitrix\Main\Application;
11use Bitrix\Main\Localization\Loc;
12use Bitrix\Main\Web\HttpClient;
13use Bitrix\Sale\PriceMaths;
14use Bitrix\Sale\Registry;
15
16Loc::loadMessages(__FILE__);
17
22class PayPalHandler
24 implements PaySystem\IPrePayable
25{
26 const DELIMITER_PAYMENT_ID = ':';
27
28 private $prePaymentSetting = array();
29
33 static public function getIndicativeFields()
34 {
35 return array('mc_gross', 'mc_currency');
36 }
37
43 protected static function isMyResponseExtended(Request $request, $paySystemId)
44 {
45 $data = PaySystem\Manager::getById($paySystemId);
46 if ($data)
47 {
48 return self::getRegistryType($request) === $data['ENTITY_REGISTRY_TYPE'];
49 }
50
51 return false;
52 }
53
58 private static function getRegistryType(Request $request)
59 {
60 $paymentId = null;
61 if ($request->get('custom') !== null)
62 {
63 $paymentId = $request->get('custom');
64 }
65
66 if ($paymentId === null)
67 {
68 $paymentId = $request->get('cm');
69 }
70
71 $pos = mb_strpos($paymentId, static::DELIMITER_PAYMENT_ID);
72 if ($pos !== false)
73 {
74 return mb_substr($paymentId, 0, $pos);
75 }
76
77 return Registry::REGISTRY_TYPE_ORDER;
78 }
79
85 public function processRequest(Payment $payment, Request $request)
86 {
88 $serviceResult = new PaySystem\ServiceResult();
89
90 $instance = Application::getInstance();
91 $context = $instance->getContext();
92 $server = $context->getServer();
93
94 $req = '';
95 if ($request->get('tx'))
96 {
97 $req = $this->getPdtRequest($payment, $request);
98 }
99 elseif ($request->get('txn_id') && $server->getRequestMethod() == "POST")
100 {
101 $req = $this->getIpnRequest($request);
102 }
103
104 if ($req !== '')
105 {
106 $domain = '';
107 if ($this->isTestMode($payment))
108 {
109 $domain = "sandbox.";
110 }
111 $host = "www.".$domain."paypal.com";
112
113 $header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
114 $header .= "Host: ".$host."\r\n";
115 $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
116 $header .= "Content-Length: ".mb_strlen($req)."\r\n";
117 $header .= "User-Agent: 1C-Bitrix\r\n";
118 $header .= "Connection: Close\r\n\r\n";
119
120 if ($this->getBusinessValue($payment, "PAYPAL_SSL_ENABLE") == "Y")
121 {
122 $fp = fsockopen("ssl://".$host, 443, $errNo, $errStr, 30);
123 }
124 else
125 {
126 $fp = fsockopen($host, 80, $errNo, $errStr, 30);
127 }
128
129 if ($fp)
130 {
131 PaySystem\Logger::addDebugInfo('PayPal: request: '.$header.$req);
132
133 fputs ($fp, $header.$req);
134 $response = '';
135 $headerDone = false;
136 while (!feof($fp))
137 {
138 $line = fgets ($fp, 1024);
139 if (strcmp($line, "\r\n") == 0)
140 {
141 $headerDone = true;
142 }
143 elseif ($headerDone)
144 {
145 $response .= $line;
146 }
147 }
148
149 PaySystem\Logger::addDebugInfo('PayPal: response: '.$response);
150
151 // parse the data
152 $lines = explode("\n", $response);
153
154 if (strcmp($lines[1], "SUCCESS") == 0)
155 {
156 return $this->processSuccessAction($payment, $request, $lines);
157 }
158 elseif (mb_strpos($response, "VERIFIED") !== false)
159 {
160 return $this->processVerifiedAction($payment, $request);
161 }
162 else
163 {
164 $serviceResult->setData(array('MESSAGE' => Loc::getMessage("SALE_HPS_PAYPAL_I1")));
165 }
166 }
167 else
168 {
169 $serviceResult->setData(
170 array('MESSAGE' => Loc::getMessage("SALE_HPS_PAYPAL_I3").'<br /><br />'.Loc::getMessage("SALE_HPS_PAYPAL_I4"))
171 );
172 }
173 }
174
175 return $serviceResult;
176 }
177
184 protected function processSuccessAction(Payment $payment, Request $request, $lines)
185 {
186 $serviceResult = new PaySystem\ServiceResult();
187
188 $keys = array();
189
190 for ($i=1, $cnt = count($lines); $i < $cnt; $i++)
191 {
192 list($key, $val) = explode('=', $lines[$i]);
193 $keys[urldecode($key)] = urldecode($val);
194 }
195
196 $psStatusMessage = 'Name: '.$keys['first_name'].' '.$keys['last_name'].'; ';
197 $psStatusMessage .= 'Email: '.$keys['payer_email'].'; ';
198 $psStatusMessage .= 'Item: '.$keys['item_name'].'; ';
199 $psStatusMessage .= 'Amount: '.$keys['mc_gross'].'; ';
200
201 $psStatusDescription = 'Payment status - '.$keys['payment_status'].'; ';
202 $psStatusDescription .= 'Payment sate - '.$keys['payment_date'].'; ';
203
204 $fields = array(
205 "PS_STATUS" => "Y",
206 "PS_STATUS_CODE" => "-",
207 "PS_STATUS_DESCRIPTION" => $psStatusDescription,
208 "PS_STATUS_MESSAGE" => $psStatusMessage,
209 "PS_SUM" => $keys["mc_gross"],
210 "PS_CURRENCY" => $keys["mc_currency"],
211 "PS_RESPONSE_DATE" => new DateTime(),
212 "PAY_VOUCHER_NUM" => $request->get('tx'),
213 "PAY_VOUCHER_DATE" => new Date()
214 );
215
216 $serviceResult->setPsData($fields);
217
218 $paymentSum = PriceMaths::roundPrecision($this->getBusinessValue($payment, 'PAYMENT_SHOULD_PAY'));
219
220 $payPalSum = (float)$keys["mc_gross"];
221 if ($keys["tax"])
222 {
223 $payPalSum -= (float)$keys["tax"];
224 }
225 $payPalSum = PriceMaths::roundPrecision($payPalSum);
226
227 PaySystem\Logger::addDebugInfo('PayPal: payPalSum='.$payPalSum."; paymentSum=".$paymentSum);
228
229 if ($paymentSum == $payPalSum
230 && mb_strtolower($keys["receiver_email"]) == mb_strtolower($this->getBusinessValue($payment, "PAYPAL_BUSINESS"))
231 && $keys["payment_status"] == "Completed"
232 )
233 {
234 $serviceResult->setOperationType(PaySystem\ServiceResult::MONEY_COMING);
235 }
236
237 $response = '<p><h3>'.Loc::getMessage('SALE_HPS_PAYPAL_T1').'</h3></p>';
238 $response .= '<b>'.Loc::getMessage('SALE_HPS_PAYPAL_T2').'</b><br>';
239 $response .= '<li>'.Loc::getMessage('SALE_HPS_PAYPAL_T3').': '.$keys['first_name'].' '.$keys['last_name'].'</li>';
240 $response .= '<li>'.Loc::getMessage('SALE_HPS_PAYPAL_T4').': '.$keys['item_name'].'</li>';
241 $response .= '<li>'.Loc::getMessage('SALE_HPS_PAYPAL_T5').': '.$keys['mc_gross'].'</li>';
242
243 $serviceResult->setData(array('MESSAGE' => $response));
244
245 return $serviceResult;
246 }
247
253 protected function processVerifiedAction(Payment $payment, Request $request)
254 {
255 $serviceResult = new PaySystem\ServiceResult();
256
257 $psStatusMessage = Loc::getMessage("SALE_HPS_PAYPAL_T3").": ".$request->get("first_name")." ".$request->get("last_name")."; ";
258 $psStatusMessage .= "Email: ".$request->get("payer_email")."; ";
259 $psStatusMessage .= Loc::getMessage("SALE_HPS_PAYPAL_T4").": ".$_POST["item_name"]."; ";
260 $psStatusMessage .= Loc::getMessage("SALE_HPS_PAYPAL_T5").": ".$_POST["mc_gross"]."; ";
261
262 $psStatusDescription = "Payment status - ".$request->get("payment_status")."; ";
263 $psStatusDescription .= "Payment sate - ".$request->get("payment_date")."; ";
264
265 $fields = array(
266 "PS_STATUS" => "Y",
267 "PS_STATUS_CODE" => "-",
268 "PS_STATUS_DESCRIPTION" => $psStatusDescription,
269 "PS_STATUS_MESSAGE" => $psStatusMessage,
270 "PS_SUM" => $request->get("mc_gross"),
271 "PS_CURRENCY" => $request->get("mc_currency"),
272 "PS_RESPONSE_DATE" => new DateTime(),
273 "PAY_VOUCHER_NUM" => $request->get('txn_id'),
274 "PAY_VOUCHER_DATE" => new Date()
275 );
276
277 $serviceResult->setPsData($fields);
278
279 $paymentSum = PriceMaths::roundPrecision($this->getBusinessValue($payment, 'PAYMENT_SHOULD_PAY'));
280
281 $payPalSum = (float)$request->get("mc_gross");
282 if ($request->get('tax'))
283 {
284 $payPalSum -= (float)$request->get('tax');
285 }
286 $payPalSum = PriceMaths::roundPrecision($payPalSum);
287
288 PaySystem\Logger::addDebugInfo('PayPal: payPalSum='.$payPalSum."; paymentSum=".$paymentSum);
289
290 if ($paymentSum == $payPalSum
291 && mb_strtolower($request->get("receiver_email")) == mb_strtolower($this->getBusinessValue($payment, "PAYPAL_BUSINESS"))
292 && $request->get("payment_status") == "Completed"
293 && $payment->getField("PAY_VOUCHER_NUM") != $request->get('txn_id')
294 )
295 {
296 $serviceResult->setOperationType(PaySystem\ServiceResult::MONEY_COMING);
297 }
298
299 return $serviceResult;
300 }
301
307 protected function getPdtRequest(Payment $payment, Request $request)
308 {
309 $req = '';
310 if ($request->get('tx'))
311 {
312 $req = 'cmd=_notify-synch';
313 $req .= "&tx=".$request->get('tx')."&at=".$this->getBusinessValue($payment, "PAYPAL_IDENTITY_TOKEN");
314 }
315
316 return $req;
317 }
318
323 protected function getIpnRequest(Request $request)
324 {
325 $req = 'cmd=_notify-validate';
326
327 foreach ($_POST as $key => $value)
328 {
329 $req .= '&'.$key.'='.urlencode(stripslashes($value));
330 }
331
332 return $req;
333 }
334
338 protected function getUrlList()
339 {
340 return array(
341 'pay' => array(
342 self::TEST_URL => 'https://www.sandbox.paypal.com/cgi-bin/webscr',
343 self::ACTIVE_URL => 'https://www.paypal.com/cgi-bin/webscr'
344 )
345 );
346 }
347
353 public function initiatePay(Payment $payment, Request $request = null)
354 {
355 $this->setExtraParams([
356 'URL' => $this->getUrl($payment, 'pay'),
357 'PAYPAL_RETURN' => $this->getReturnUrl($payment),
358 'PAYED' => $payment->isPaid() ? 'Y' : 'N',
359 ]);
360
361 return $this->showTemplate($payment, 'template');
362 }
363
368 public function getParamsBusValue(Payment $payment = null)
369 {
370 $params = parent::getParamsBusValue($payment);
371
372 if ($payment)
373 {
374 $registryType = $payment::getRegistryType();
375 $params['PAYMENT_ID'] = $registryType.static::DELIMITER_PAYMENT_ID.$params['PAYMENT_ID'];
376 }
377
378
379 return $params;
380 }
381
385 public function getCurrencyList()
386 {
387 return array('RUB', 'EUR', 'USD');
388 }
389
394 public function getPaymentIdFromRequest(Request $request)
395 {
396 $paymentId = null;
397 if ($request->get('custom') !== null)
398 {
399 $paymentId = $request->get('custom');
400 }
401
402 if ($paymentId === null)
403 {
404 $paymentId = $request->get('cm');
405 }
406
407 $pos = mb_strpos($paymentId, static::DELIMITER_PAYMENT_ID);
408 if ($pos !== false)
409 {
410 return mb_substr($paymentId, $pos + 1);
411 }
412
413 return $paymentId;
414 }
415
420 protected function isTestMode(Payment $payment = null)
421 {
422 return $this->getBusinessValue($payment, 'PS_IS_TEST') == 'Y';
423 }
424
430 public function sendResponse(PaySystem\ServiceResult $result, Request $request)
431 {
432 $data = $result->getData();
433
434 if (isset($data['MESSAGE']))
435 {
436 echo $data['MESSAGE'];
437 }
438
439 return '';
440 }
441
447 public function initPrePayment(Payment $payment = null, Request $request)
448 {
449 $this->prePaymentSetting = array(
450 'USER' => $this->getBusinessValue($payment, 'PAYPAL_USER'),
451 'PWD' => $this->getBusinessValue($payment, 'PAYPAL_PWD'),
452 'SIGNATURE' => $this->getBusinessValue($payment, 'PAYPAL_SIGNATURE'),
453 'CURRENCY' => $this->getBusinessValue($payment, 'PAYMENT_CURRENCY'),
454 'TEST' => $this->isTestMode($payment),
455 'NOTIFY_URL' => $this->getBusinessValue($payment, 'PAYPAL_NOTIFY_URL'),
456 'ENCODING' => $this->service->getField('ENCODING')
457 );
458
459 if (!$this->prePaymentSetting['CURRENCY'])
460 {
461 $this->prePaymentSetting['CURRENCY'] = \CSaleLang::GetLangCurrency(SITE_ID);
462 }
463
464 if ($this->prePaymentSetting['TEST'])
465 {
466 $this->prePaymentSetting['DOMAIN'] = "sandbox.";
467 }
468
469 if ($request->get("token"))
470 {
471 $this->prePaymentSetting['TOKEN'] = $request->get("token");
472 }
473
474 if ($request->get("PayerID"))
475 {
476 $this->prePaymentSetting['PayerID'] = $request->get("PayerID");
477 }
478
479 $this->prePaymentSetting['VERSION'] = "98.0";
480
481 $dbSite = \CSite::GetByID(SITE_ID);
482 $arSite = $dbSite->Fetch();
483
484 $this->prePaymentSetting['SERVER_NAME'] = $arSite["SERVER_NAME"];
485 if ($this->prePaymentSetting['SERVER_NAME'])
486 {
487 if (defined("SITE_SERVER_NAME") && SITE_SERVER_NAME <> '')
488 {
489 $this->prePaymentSetting['SERVER_NAME'] = SITE_SERVER_NAME;
490 }
491 else
492 {
493 $this->prePaymentSetting['SERVER_NAME'] = \COption::GetOptionString("main", "server_name");
494 }
495 }
496
497 $this->prePaymentSetting['SERVER_NAME'] = (\CMain::IsHTTPS() ? "https" : "http")."://".$this->prePaymentSetting['SERVER_NAME'];
498
499 if(!$this->prePaymentSetting['USER'])
500 {
501 $GLOBALS["APPLICATION"]->ThrowException("CSalePaySystempaypal: init error", "CSalePaySystempaypal_init_error");
502 return false;
503 }
504
505 return true;
506 }
507
512 protected function parsePrePaymentResult($data)
513 {
514 global $APPLICATION;
515
516 $keyArray = array();
517 $res1 = explode("&", $data);
518 foreach ($res1 as $res2)
519 {
520 list($key, $val) = explode("=", $res2);
521 $keyArray[urldecode($key)] = urldecode($val);
522 if ($this->prePaymentSetting['ENCODING'])
523 {
524 $keyArray[urldecode($key)] = \Bitrix\Main\Text\Encoding::convertEncoding($keyArray[urldecode($key)], $this->prePaymentSetting['ENCODING'], SITE_CHARSET);
525 }
526 }
527
528 return $keyArray;
529 }
530
534 public function getProps()
535 {
536 $data = array();
537
538 if ($this->prePaymentSetting['TOKEN'])
539 {
540 $url = "https://api-3t.".$this->prePaymentSetting['DOMAIN']."paypal.com/nvp";
542 "METHOD" => "GetExpressCheckoutDetails",
543 "VERSION" => $this->prePaymentSetting['VERSION'],
544 "USER" => $this->prePaymentSetting['USER'],
545 "PWD" => $this->prePaymentSetting['PWD'],
546 "SIGNATURE" => $this->prePaymentSetting['SIGNATURE'],
547 "TOKEN" => $this->prePaymentSetting['TOKEN'],
548 "buttonsource" => "Bitrix_Cart"
549 );
550
551 $ht = new HttpClient(array("version" => "1.1"));
552 if ($res = $ht->post($url, $arFields))
553 {
554 $result = $this->parsePrePaymentResult($res);
555 if ($result["ACK"] == "Success")
556 {
557 $data = array(
558 "FIO" => $result["FIRSTNAME"]." ".$result["LASTNAME"],
559 "EMAIL" => $result["EMAIL"],
560 "ZIP" => $result["SHIPTOZIP"],
561 "ADDRESS" => $result["SHIPTOSTREET"]." ".$result["SHIPTOSTREET2"],
562 "COUNTRY" => $result["SHIPTOCOUNTRYNAME"],
563 "STATE" => $result["SHIPTOSTATE"],
564 "CITY" => $result["SHIPTOCITY"],
565 "LOCATION" => $result["SHIPTOCITY"],
566 "PP_SOURCE" => $result,
567 );
568
569 return $data;
570 }
571 }
572 }
573
574 return $data;
575 }
576
580 public function payOrder($orderData = array())
581 {
582 $serviceResult = new PaySystem\ServiceResult();
583
584 if($this->prePaymentSetting['TOKEN'])
585 {
586 $url = "https://api-3t.".$this->prePaymentSetting['DOMAIN']."paypal.com/nvp";
588 "METHOD" => "GetExpressCheckoutDetails",
589 "VERSION" => $this->prePaymentSetting['VERSION'],
590 "USER" => $this->prePaymentSetting['USER'],
591 "PWD" => $this->prePaymentSetting['PWD'],
592 "SIGNATURE" => $this->prePaymentSetting['SIGNATURE'],
593 "TOKEN" => $this->prePaymentSetting['TOKEN'],
594 "buttonsource" => "Bitrix_Cart",
595 );
596
597 $ht = new \Bitrix\Main\Web\HttpClient(array("version" => "1.1"));
598 if($res = $ht->post($url, $arFields))
599 {
600 $result = $this->parsePrePaymentResult($res);
601 if($result["ACK"] == "Success" && in_array($result["CHECKOUTSTATUS"], array("PaymentActionNotInitiated")))
602 {
603 $arFields["METHOD"] = "DoExpressCheckoutPayment";
604 $arFields["PAYERID"] = $this->prePaymentSetting['payerId'];
605 $arFields["PAYMENTACTION"] = "Sale";
606 $arFields["PAYMENTREQUEST_0_AMT"] = number_format($this->prePaymentSetting['ORDER_PRICE'], 2, ".", "");
607 $arFields["PAYMENTREQUEST_0_CURRENCYCODE"] = $this->prePaymentSetting['CURRENCY'];
608 $arFields["PAYMENTREQUEST_0_DESC"] = "Order #".$this->prePaymentSetting['ORDER_ID'];
609 $arFields["PAYMENTREQUEST_0_NOTETEX"] = "Order #".$this->prePaymentSetting['ORDER_ID'];
610 $arFields["PAYMENTREQUEST_0_INVNUM"] = $this->prePaymentSetting['ORDER_ID'];
611
612 if(DoubleVal($this->prePaymentSetting['DELIVERY_PRICE']) > 0)
613 {
614 $arFields["PAYMENTREQUEST_0_SHIPPINGAMT"] = number_format($this->prePaymentSetting['DELIVERY_PRICE'], 2, ".", "");
615 }
616 $orderProps = $this->getProps();
617
618 if(!empty($orderProps))
619 {
620 $arFields["PAYMENTREQUEST_0_SHIPTONAME"] = $orderProps["PP_SOURCE"]["PAYMENTREQUEST_0_SHIPTONAME"];
621 $arFields["PAYMENTREQUEST_0_SHIPTOSTREET"] = $orderProps["PP_SOURCE"]["PAYMENTREQUEST_0_SHIPTOSTREET"];
622 $arFields["PAYMENTREQUEST_0_SHIPTOSTREET2"] = $orderProps["PP_SOURCE"]["PAYMENTREQUEST_0_SHIPTOSTREET2"];
623 $arFields["PAYMENTREQUEST_0_SHIPTOCITY"] = $orderProps["PP_SOURCE"]["PAYMENTREQUEST_0_SHIPTOCITY"];
624 $arFields["PAYMENTREQUEST_0_SHIPTOSTATE"] = $orderProps["PP_SOURCE"]["PAYMENTREQUEST_0_SHIPTOSTATE"];
625 $arFields["PAYMENTREQUEST_0_SHIPTOZIP"] = $orderProps["PP_SOURCE"]["PAYMENTREQUEST_0_SHIPTOZIP"];
626 $arFields["PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE"] = $orderProps["PP_SOURCE"]["PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE"];
627 }
628
629 if(!empty($orderData["BASKET_ITEMS"]))
630 {
631 $arFields["PAYMENTREQUEST_0_ITEMAMT"] = number_format($this->prePaymentSetting['ORDER_PRICE']-$this->prePaymentSetting['DELIVERY_PRICE'], 2, ".", "");
632 foreach($orderData["BASKET_ITEMS"] as $i => $val)
633 {
634 $arFields["L_PAYMENTREQUEST_0_NAME".$i] = $val["NAME"];
635 $arFields["L_PAYMENTREQUEST_0_AMT".$i] = number_format($val["PRICE"], 2, ".", "");
636 $arFields["L_PAYMENTREQUEST_0_QTY".$i] = $val["QUANTITY"];
637 $arFields["L_PAYMENTREQUEST_0_NUMBER".$i] = $val["PRODUCT_ID"];
638 }
639 }
640
641 if($this->prePaymentSetting['DELIVERY_PRICE'] <> '')
642 {
643 $arFields["PAYMENTREQUEST_0_NOTIFYURL"] = $this->prePaymentSetting['NOTIFY_URL'];
644 }
645
646 if($postResult = $ht->Post($url, $arFields))
647 {
648 $parseResult = $this->parsePrePaymentResult($postResult);
649
650 if($parseResult["ACK"] == "Success" && in_array($parseResult["PAYMENTINFO_0_PAYMENTSTATUS"], array("Completed")))
651 {
652 $psStatusMessage = "Name: ".$result["FIRSTNAME"]." ".$result["LASTNAME"]."; ";
653 $psStatusMessage .= "Email: ".$result["EMAIL"]."; ";
654
655 $psStatusDescription = "Payment status: ".$parseResult["PAYMENTINFO_0_PAYMENTSTATUS"]."; ";
656 $psStatusDescription .= "Payment sate: ".$parseResult["PAYMENTINFO_0_ORDERTIME"]."; ";
657
658 $fields = array(
659 "PS_STATUS" => "Y",
660 "PS_STATUS_CODE" => "-",
661 "PS_STATUS_DESCRIPTION" => $psStatusDescription,
662 "PS_STATUS_MESSAGE" => $psStatusMessage,
663 "PS_SUM" => $parseResult["PAYMENTINFO_0_AMT"],
664 "PS_CURRENCY" => $parseResult["PAYMENTINFO_0_CURRENCYCODE"],
665 "PS_RESPONSE_DATE" => ConvertTimeStamp(false, "FULL"),
666 "PAY_VOUCHER_NUM" => $parseResult["PAYMENTINFO_0_TRANSACTIONID"],
667 "PAY_VOUCHER_DATE" => ConvertTimeStamp(false, "FULL"),
668 );
669 }
670 else
671 {
672 $psStatusMessage = "Name: ".$result["FIRSTNAME"]." ".$result["LASTNAME"]."; ";
673 $psStatusMessage .= "Email: ".$result["EMAIL"]."; ";
674
675 $psStatusDescription = "Payment status: ".$parseResult["PAYMENTINFO_0_PAYMENTSTATUS"]."; ";
676 $psStatusDescription .= "Pending reason: ".$parseResult["PAYMENTINFO_0_PENDINGREASON"]."; ";
677 $psStatusDescription .= "Payment sate: ".$parseResult["PAYMENTINFO_0_ORDERTIME"]."; ";
678
679 $fields = array(
680 "PS_STATUS" => "N",
681 "PS_STATUS_CODE" => $parseResult["PAYMENTINFO_0_PAYMENTSTATUS"],
682 "PS_STATUS_DESCRIPTION" => $psStatusDescription,
683 "PS_STATUS_MESSAGE" => $psStatusMessage,
684 "PS_SUM" => $parseResult["PAYMENTINFO_0_AMT"],
685 "PS_CURRENCY" => $parseResult["PAYMENTINFO_0_CURRENCYCODE"],
686 "PS_RESPONSE_DATE" => ConvertTimeStamp(false, "FULL"),
687 "PAY_VOUCHER_NUM" => $parseResult["PAYMENTINFO_0_TRANSACTIONID"],
688 "PAY_VOUCHER_DATE" => ConvertTimeStamp(false, "FULL"),
689 );
690 }
691
692 $serviceResult->setPsData($fields);
693 }
694 }
695 }
696 }
697 }
698
703 public function BasketButtonAction($orderData = array())
704 {
705 global $APPLICATION;
706 if (array_key_exists('paypalbutton_x', $_POST) && array_key_exists('paypalbutton_y', $_POST))
707 {
708 $url = "https://api-3t.".$this->prePaymentSetting['DOMAIN']."paypal.com/nvp";
709
711 "METHOD" => "SetExpressCheckout",
712 "VERSION" => "98.0",
713 "USER" => $this->prePaymentSetting['USER'],
714 "PWD" => $this->prePaymentSetting['PWD'],
715 "SIGNATURE" => $this->prePaymentSetting['SIGNATURE'],
716 "PAYMENTREQUEST_0_AMT" => number_format($orderData["AMOUNT"], 2, ".", ""),
717 "PAYMENTREQUEST_0_CURRENCYCODE" => $this->prePaymentSetting['CURRENCY'],
718 "RETURNURL" => $this->prePaymentSetting['SERVER_NAME'].$orderData["PATH_TO_ORDER"],
719 "CANCELURL" => $this->prePaymentSetting['SERVER_NAME'].$APPLICATION->GetCurPageParam("paypal=Y&paypal_error=Y", array("paypal", "paypal_error")),
720 "PAYMENTREQUEST_0_PAYMENTACTION" => "Authorization",
721 "PAYMENTREQUEST_0_DESC" => "Order payment for ".$this->prePaymentSetting['SERVER_NAME'],
722 "LOCALECODE" => mb_strtoupper(LANGUAGE_ID),
723 "buttonsource" => "Bitrix_Cart",
724 );
725
726 if(!empty($orderData["BASKET_ITEMS"]))
727 {
728 $arFields["PAYMENTREQUEST_0_ITEMAMT"] = number_format($orderData["AMOUNT"], 2, ".", "");
729 foreach($orderData["BASKET_ITEMS"] as $k => $val)
730 {
731 $arFields["L_PAYMENTREQUEST_0_NAME".$k] = $val["NAME"];
732 $arFields["L_PAYMENTREQUEST_0_AMT".$k] = number_format($val["PRICE"], 2, ".", "");
733 $arFields["L_PAYMENTREQUEST_0_QTY".$k] = $val["QUANTITY"];
734 }
735 }
736
737 $arFields["RETURNURL"] .= ((mb_strpos($arFields["RETURNURL"], "?") === false) ? "?" : "&")."paypal=Y";
738
739 $ht = new \Bitrix\Main\Web\HttpClient(array("version" => "1.1"));
740 if($res = $ht->post($url, $arFields))
741 {
742 $result = $this->parsePrePaymentResult($res);
743
744 if($result["TOKEN"] != '')
745 {
746 $url = "https://www.".$this->prePaymentSetting['DOMAIN']."paypal.com/webscr?cmd=_express-checkout&token=".$result["TOKEN"];
747 if($orderData["ORDER_REQUEST"] == "Y")
748 {
749 return $url;
750 }
752 }
753 else
754 {
755 $GLOBALS["APPLICATION"]->ThrowException($result['L_SHORTMESSAGE0'].' : '.$result['L_LONGMESSAGE0'], "CSalePaySystemPrePayment_action_error");
756 return false;
757 }
758 }
759 else
760 {
761 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SALE_HPS_PAYPAL_ERROR"), "CSalePaySystemPrePayment_action_error");
762 return false;
763 }
764 }
765
766 return true;
767 }
768
772 public function setOrderConfig($orderData = array())
773 {
774 if ($orderData)
775 {
776 $this->prePaymentSetting = array_merge($this->prePaymentSetting, $orderData);
777 }
778 }
779
784 private function getReturnUrl(Payment $payment)
785 {
786 return $this->getBusinessValue($payment, 'PAYPAL_RETURN') ?: $this->service->getContext()->getUrl();
787 }
788}
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)
$arFields
Определения dblapprove.php:5
$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
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$context
Определения csv_new_setup.php:223
const SITE_CHARSET
Определения include.php:62
ConvertTimeStamp($timestamp=false, $type="SHORT", $site=false, $bSearchInSitesOnly=false)
Определения tools.php:733
GetMessage($name, $aReplace=null)
Определения tools.php:3397
LocalRedirect($url, $skip_security_check=false, $status="302 Found")
Определения tools.php:4005
$host
Определения mysql_to_pgsql.php:32
$GLOBALS['____1690880296']
Определения license.php:1
$payment
Определения payment.php:14
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$instance
Определения ps_b24_final.php:14
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$val
Определения options.php:1793
$response
Определения result.php:21
const SITE_ID
Определения sonet_set_content_view.php:12
$k
Определения template_pdf.php:567
$url
Определения iframe.php:7
$fields
Определения yandex_run.php:501