示例#1
0
 /**
  * Function gets pay system info from database, no cache is used here
  * @return void
  */
 protected function obtainDataPaySystem()
 {
     if (empty($this->dbResult["ID"])) {
         return;
     }
     foreach ($this->dbResult['PAYMENT'] as &$payment) {
         if (intval($payment["PAY_SYSTEM_ID"])) {
             $payment["PAY_SYSTEM"] = \Bitrix\Sale\PaySystem\Manager::getById($payment["PAY_SYSTEM_ID"]);
             $payment["PAY_SYSTEM"]['NAME'] = htmlspecialcharsbx($payment["PAY_SYSTEM"]['NAME']);
         }
         if ($payment["PAID"] != "Y" && $this->dbResult["CANCELED"] != "Y") {
             $payment['BUFFERED_OUTPUT'] = '';
             $payment['ERROR'] = '';
             $service = new \Bitrix\Sale\PaySystem\Service($payment["PAY_SYSTEM"]);
             if ($service) {
                 $payment["CAN_REPAY"] = "Y";
                 if ($service->getField("NEW_WINDOW") == "Y") {
                     $payment["PAY_SYSTEM"]["PSA_ACTION_FILE"] = htmlspecialcharsbx($this->arParams["PATH_TO_PAYMENT"]) . '?ORDER_ID=' . urlencode(urlencode($this->dbResult["ACCOUNT_NUMBER"])) . '&PAYMENT_ID=' . $payment['ID'];
                 } else {
                     CSalePaySystemAction::InitParamArrays($this->dbResult, $this->requestData["ID"], '', array(), $payment);
                     // for compatibility
                     $actionFile = $service->getField('ACTION_FILE');
                     $map = CSalePaySystemAction::getOldToNewHandlersMap();
                     $oldHandler = array_search($actionFile, $map);
                     if ($oldHandler !== false && !$service->isCustom()) {
                         $actionFile = $oldHandler;
                     }
                     $pathToAction = Main\Application::getDocumentRoot() . $actionFile;
                     $pathToAction = str_replace("\\", "/", $pathToAction);
                     while (substr($pathToAction, strlen($pathToAction) - 1, 1) == "/") {
                         $pathToAction = substr($pathToAction, 0, strlen($pathToAction) - 1);
                     }
                     if (file_exists($pathToAction)) {
                         if (is_dir($pathToAction) && file_exists($pathToAction . "/payment.php")) {
                             $pathToAction .= "/payment.php";
                         }
                         $payment["PAY_SYSTEM"]["PSA_ACTION_FILE"] = $pathToAction;
                     }
                     $encoding = $service->getField("ENCODING");
                     if (strlen($encoding) > 0) {
                         define("BX_SALE_ENCODING", $encoding);
                         AddEventHandler("main", "OnEndBufferContent", array($this, "changeBodyEncoding"));
                     }
                     /** @var \Bitrix\Sale\Order $order */
                     $order = \Bitrix\Sale\Order::load($this->dbResult["ID"]);
                     if ($order) {
                         /** @var \Bitrix\Sale\PaymentCollection $paymentCollection */
                         $paymentCollection = $order->getPaymentCollection();
                         if ($paymentCollection) {
                             /** @var \Bitrix\Sale\Payment $paymentItem */
                             $paymentItem = $paymentCollection->getItemById($payment['ID']);
                             if ($paymentItem) {
                                 $initResult = $service->initiatePay($paymentItem, null, \Bitrix\Sale\PaySystem\BaseServiceHandler::STRING);
                                 if ($initResult->isSuccess()) {
                                     $payment['BUFFERED_OUTPUT'] = $initResult->getTemplate();
                                 } else {
                                     $payment['ERROR'] = implode('\\n', $initResult->getErrorMessages());
                                 }
                             }
                         }
                     }
                 }
                 $payment["PAY_SYSTEM"]["PSA_NEW_WINDOW"] = $payment["PAY_SYSTEM"]["NEW_WINDOW"];
             }
         }
     }
     unset($payment);
     // for compatibility
     $this->dbResult['PAY_SYSTEM'] = $this->dbResult['PAYMENT'][0]['PAY_SYSTEM'];
     $this->dbResult['CAN_REPAY'] = $this->dbResult['PAYMENT'][0]['CAN_REPAY'];
 }
示例#2
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
$entityId = CSalePaySystemAction::GetParamValue("ORDER_PAYMENT_ID");
list($orderId, $paymentId) = \Bitrix\Sale\PaySystem\Manager::getIdsByPayment($entityId);
/** @var \Bitrix\Sale\Order $order */
$order = \Bitrix\Sale\Order::load($orderId);
/** @var \Bitrix\Sale\PaymentCollection $paymentCollection */
$paymentCollection = $order->getPaymentCollection();
/** @var \Bitrix\Sale\Payment $payment */
$payment = $paymentCollection->getItemById($paymentId);
$data = \Bitrix\Sale\PaySystem\Manager::getById($payment->getPaymentSystemId());
$service = new \Bitrix\Sale\PaySystem\Service($data);
$service->initiatePay($payment);