Exemplo n.º 1
0
                ?>
							<script language="JavaScript">
								window.open('<?php 
                echo $arParams["PATH_TO_PAYMENT"];
                ?>
?ORDER_ID=<?php 
                echo $arResult["ORDER_BASKET"]["ORDER_ID"];
                ?>
');
							</script>
							<?php 
                echo GetMessage("SOA_TEMPL_PAY_LINK", array("#LINK#" => $arParams["PATH_TO_PAYMENT"] . "?ORDER_ID=" . $arResult["ORDER_BASKET"]["ORDER_ID"]));
                ?>
							<?php 
            } else {
                $service = \Bitrix\Sale\PaySystem\Manager::getObjectById($arResult['PAY_SYSTEM_ID']);
                if ($service) {
                    $orderId = $arResult['ORDER_ID'];
                    /** @var \Bitrix\Sale\Order $order */
                    $order = \Bitrix\Sale\Order::load($orderId);
                    if ($order === null) {
                        $data = \Bitrix\Sale\Internals\OrderTable::getRow(array('select' => array('ID'), 'filter' => array('ACCOUNT_NUMBER' => $orderId)));
                        $order = \Bitrix\Sale\Order::load($data['ID']);
                    }
                    /** @var \Bitrix\Sale\PaymentCollection $paymentCollection */
                    $paymentCollection = $order->getPaymentCollection();
                    /** @var \Bitrix\Sale\Payment $payment */
                    foreach ($paymentCollection as $payment) {
                        if (!$payment->isInner()) {
                            $context = \Bitrix\Main\Application::getInstance()->getContext();
                            $service->initiatePay($payment, $context->getRequest());
Exemplo n.º 2
0
 /**
  * Modify payment collection.
  *
  * @param string $action			Action.
  * @param Payment $payment			Payment.
  * @param null|string $name				Field name.
  * @param null|string|int|float $oldValue		Old value.
  * @param null|string|int|float $value			New value.
  * @return Result
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\NotImplementedException
  * @throws Main\ObjectNotFoundException
  */
 public function onPaymentCollectionModify($action, Payment $payment, $name = null, $oldValue = null, $value = null)
 {
     $result = new Result();
     if ($action == EventActions::DELETE) {
         if ($this->getField('PAY_SYSTEM_ID') == $payment->getPaymentSystemId()) {
             /** @var PaymentCollection $paymentCollection */
             if (!($paymentCollection = $payment->getCollection())) {
                 throw new Main\ObjectNotFoundException('Entity "PaymentCollection" not found');
             }
             /** @var Payment $entityPayment */
             foreach ($paymentCollection as $entityPayment) {
                 if (intval($entityPayment->getField('PAY_SYSTEM_ID')) > 0 && intval($entityPayment->getField('PAY_SYSTEM_ID')) != $payment->getPaymentSystemId()) {
                     $this->setFieldNoDemand('PAY_SYSTEM_ID', $entityPayment->getField('PAY_SYSTEM_ID'));
                     break;
                 }
             }
         }
     }
     if ($action != EventActions::UPDATE) {
         return $result;
     }
     if ($name == "CURRENCY" && $value != $this->getField("CURRENCY")) {
         throw new Main\NotImplementedException();
     }
     if ($name == "SUM" || $name == "PAID") {
         if ($this->isCanceled()) {
             $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_PAID_ORDER_CANCELED'), 'SALE_ORDER_PAID_ORDER_CANCELED'));
             return $result;
         }
         if ($name == "SUM" && !$payment->isPaid()) {
             if ($value == 0 && $payment->isInner()) {
                 $payment->delete();
             }
             return $result;
         }
         $r = $this->syncOrderAndPayments($payment);
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
     } elseif ($name == "IS_RETURN") {
         if ($this->isCanceled()) {
             $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_RETURN_ORDER_CANCELED'), 'SALE_ORDER_RETURN_ORDER_CANCELED'));
             return $result;
         }
         if ($value != Payment::RETURN_NONE) {
             if (!$payment->isPaid()) {
                 $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_NOT_PAID'), 'SALE_ORDER_PAYMENT_RETURN_NOT_PAID'));
                 return $result;
             }
             $oldPaid = $this->isPaid() ? "Y" : "N";
             /** @var PaymentCollection $paymentCollection */
             if (!($paymentCollection = $this->getPaymentCollection())) {
                 throw new Main\ObjectNotFoundException('Entity "PaymentCollection" not found');
             }
             $creditSum = 0;
             $overPaid = $paymentCollection->getPaidSum() - $this->getPrice();
             if ($overPaid <= 0) {
                 $creditSum = $payment->getSum();
                 $overPaid = 0;
             } elseif ($payment->getSum() - $overPaid > 0) {
                 $creditSum = $payment->getSum() - $overPaid;
             }
             if ($value == Payment::RETURN_PS) {
                 $psId = $payment->getPaymentSystemId();
             } elseif ($value == Payment::RETURN_INNER) {
                 $psId = Manager::getInnerPaySystemId();
             } else {
                 $result->addError(new Entity\EntityError('unsupported operation'));
                 return $result;
             }
             $service = Manager::getObjectById($psId);
             if ($service && $service->isRefundable()) {
                 if ($creditSum) {
                     if ($value == Payment::RETURN_PS) {
                         if ($overPaid > 0) {
                             $userBudget = Internals\UserBudgetPool::getUserBudgetByOrder($this);
                             if (PriceMaths::roundByFormatCurrency($overPaid, $this->getCurrency()) > PriceMaths::roundByFormatCurrency($userBudget, $this->getCurrency())) {
                                 $result->addError(new Entity\EntityError(Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_PAID')));
                                 return $result;
                             }
                         }
                     }
                     $refResult = $service->refund($payment);
                     if ($refResult->isSuccess()) {
                         if ($overPaid > 0) {
                             Internals\UserBudgetPool::addPoolItem($this, -$overPaid, Internals\UserBudgetPool::BUDGET_TYPE_ORDER_PAY, $payment);
                         }
                     } else {
                         $result->addErrors($refResult->getErrors());
                         return $result;
                     }
                 }
             } else {
                 $result->addError(new Entity\EntityError(Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_NO_SUPPORTED')));
                 return $result;
             }
             $payment->setFieldNoDemand('PAID', 'N');
             $finalSumPaid = $this->getSumPaid() - $creditSum;
             if ($finalSumPaid != $this->getSumPaid()) {
                 $this->setFieldNoDemand('SUM_PAID', $finalSumPaid);
                 $this->setFieldNoDemand('PAYED', $this->getPrice() <= $finalSumPaid ? "Y" : "N");
             }
             /** @var Result $r */
             $r = $this->onAfterSyncPaid($oldPaid);
             if (!$r->isSuccess()) {
                 $result->addErrors($r->getErrors());
             }
         } else {
             if ($payment->isPaid()) {
                 $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_PAYMENT_RETURN_PAID'), 'SALE_ORDER_PAYMENT_RETURN_PAID'));
                 return $result;
             }
             $userBudget = Internals\UserBudgetPool::getUserBudgetByOrder($this);
             if (PriceMaths::roundByFormatCurrency($userBudget, $this->getCurrency()) < PriceMaths::roundByFormatCurrency($payment->getSum(), $this->getCurrency())) {
                 $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_PAYMENT_NOT_ENOUGH_USER_BUDGET'), "SALE_ORDER_PAYMENT_NOT_ENOUGH_USER_BUDGET"));
                 return $result;
             }
             Internals\UserBudgetPool::addPoolItem($this, $payment->getSum() * -1, Internals\UserBudgetPool::BUDGET_TYPE_ORDER_PAY, $payment);
             $r = $payment->setField('PAID', "Y");
             if (!$r->isSuccess()) {
                 $result->addErrors($r->getErrors());
                 return $result;
             }
         }
     } elseif ($name == "PAY_SYSTEM_ID") {
         if ($payment->getField('PAY_SYSTEM_ID') != $this->getField('PAY_SYSTEM_ID')) {
             $this->setFieldNoDemand('PAY_SYSTEM_ID', $payment->getField('PAY_SYSTEM_ID'));
         }
     } elseif ($name == "DATE_PAID") {
         if ($payment->getField('DATE_PAID') != $this->getField('DATE_PAID')) {
             $this->setFieldNoDemand('DATE_PAYED', $payment->getField('DATE_PAID'));
         }
     }
     if ($value != $oldValue) {
         $fields = $this->fields->getChangedValues();
         if (!array_key_exists("UPDATED_1C", $fields)) {
             parent::setField("UPDATED_1C", "N");
         }
     }
     return $result;
 }
Exemplo n.º 3
0
CCurrencyLang::disableUseHideZero();
$orderId = (int) $GLOBALS["SALE_INPUT_PARAMS"]["ORDER"]["ID"];
if ($orderId) {
    /** @var \Bitrix\Sale\Order $order */
    $order = \Bitrix\Sale\Order::load($orderId);
    if ($order) {
        /** @var \Bitrix\Sale\PaymentCollection $paymentCollection */
        $paymentCollection = $order->getPaymentCollection();
        if ($paymentCollection) {
            /** @var \Bitrix\Sale\Payment $payment */
            foreach ($paymentCollection as $payment) {
                if (!$payment->isInner()) {
                    break;
                }
            }
            if ($payment) {
                $context = \Bitrix\Main\Application::getInstance()->getContext();
                $service = \Bitrix\Sale\PaySystem\Manager::getObjectById($payment->getPaymentSystemId());
                if ($_REQUEST['pdf'] && $_REQUEST['GET_CONTENT'] == 'Y') {
                    $result = $service->initiatePay($payment, $context->getRequest(), \Bitrix\Sale\PaySystem\BaseServiceHandler::STRING);
                    if ($result->isSuccess()) {
                        return $result->getTemplate();
                    }
                }
                $result = $service->initiatePay($payment, $context->getRequest());
            }
            CCurrencyLang::enableUseHideZero();
        }
    }
}
Exemplo n.º 4
0
     if (!$result->isSuccess()) {
         $errorMessage .= join(',', $result->getErrorMessages()) . ".<br>";
     }
 } else {
     $result = PaySystemActionTable::add($fields);
     if (!$result->isSuccess()) {
         $errorMessage .= join(',', $result->getErrorMessages());
     } else {
         $id = $result->getId();
         if ($id > 0) {
             $fields = array('PARAMS' => serialize(array('BX_PAY_SYSTEM_ID' => $id)), 'PAY_SYSTEM_ID' => $id);
             $result = PaySystemActionTable::update($id, $fields);
             if (!$result->isSuccess()) {
                 $errorMessage .= join(',', $result->getErrorMessages());
             }
             $service = PaySystem\Manager::getObjectById($id);
             $currency = $service->getCurrency();
             if ($currency) {
                 $params = array('SERVICE_ID' => $id, 'SERVICE_TYPE' => Restrictions\Manager::SERVICE_TYPE_PAYMENT, 'PARAMS' => array('CURRENCY' => $currency));
                 Restrictions\Manager::getClassesList();
                 $saveResult = \Bitrix\Sale\Services\PaySystem\Restrictions\Currency::save($params);
                 if (!$saveResult->isSuccess()) {
                     $errorMessage .= Loc::getMessage('SALE_PSE_ERROR_RSRT_CURRENCY_SAVE');
                 }
             }
         }
     }
 }
 if ($errorMessage === '') {
     if ($isConsumerChange) {
         $priorActionFile = $request->get('PRIOR_ACTION_FILE');