E
E
Evgeny Nikolaev2019-05-20 12:04:41
1C-Bitrix
Evgeny Nikolaev, 2019-05-20 12:04:41

Bitrix. Internet shop. API for working with a request. How to get PAY_SYSTEM_ID by Order ID?

Hello.
Now there is this code:
<?php
require $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php';
use Bitrix\Main\Context,
Bitrix\Currency\CurrencyManager,
Bitrix\Sale\Order,
Bitrix\Sale\Basket,
Bitrix\Sale\Delivery,
Bitrix\Sale\PaySystem,
YandexCheckout\Client;
global $USER;
Bitrix\Main\Loader::includeModule("sale");
Bitrix\Main\Loader::includeModule("catalog");
if(CModule::IncludeModule("sale")){
$order = Order::load(71);
$collection = $order->getPaymentCollection();
}
That is, I get an order object by order id = 71 with the line $order = Order::load(71);
Next, I presumably get a collection of payments with the line $collection = $order->getPaymentCollection();
If you call var_dump($collection); then PAY_SYSTEM_ID is defined equal to 2, while being in a private property. Of course, you can execute (array)($collection) to get an object in the form of an array, but I would like the correct solution using Bitrix, so please answer which method to get to PAY_SYSTEM_ID.
It doesn't matter - what is described above is a subtask of paying for an order via the API.
That is, further I plan to do something like the following
$service = \Bitrix\Sale\PaySystem\Manager::getObjectById(2);// Here Id is passed which is exactly what needs to be determined, that is, PAY_SYSTEM_ID
$payment = \Bitrix\Sale\Payment::create($collection, $service); $ payment-
>setField('SUM', 1000);// Create a payment for 1000 rubles, for example
$collection->addItem($payment);// Add a payment
to
the collection I didn’t create the order from the API correctly, namely, the payment amount had to be indicated at the stage of order formation, in this case there was no need for my question, namely, at the stage of order formation it was necessary to do the following: $paymentCollection = $ order->getPaymentCollection();
$payment = $paymentCollection->createItem();
$paySystemService = PaySystem\Manager::getObjectById(2);
$payment->setFields(array(
'PAY_SYSTEM_ID' => $paySystemService->getField("PAY_SYSTEM_ID"),
'PAY_SYSTEM_NAME' => $paySystemService->getField("NAME"),
'SUM' => ($cost + $ deliveryCost)// !!!!!!!!!!! I didn't have this line, so the payment amount was zero. That is, the payment amount is indicated here, I indicate it as the amount of the order with discounts plus the delivery amount
));
And already when checking the fact of payment, for example, from Yandex checkout, CSaleOrder::PayOrder($orderId, "Y"); Attention! According to the documentation, the method is obsolete, but I still don’t understand how to do it through Order
After using this method, a "Yes" mark appears in the payments against the payment information, and also if the amount indicated in SUM is enough to pay for the entire order, information appears that the order has been paid in the list of orders, and in any case a green indication appears in the order opposite the order method and the amount paid.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alams Stoyne, 2019-05-20
@nikolaevevge

There may be more than one payment in the order, therefore:

$paymentCollection = $order->getPaymentCollection();

foreach ($paymentCollection as $payment) {
    $sum = $payment->getSum(); // сумма к оплате
    $isPaid = $payment->isPaid(); // true, если оплачена
    $isReturned = $payment->isReturn(); // true, если возвращена

    $ps = $payment->getPaySystem(); // платежная система (объект Sale\PaySystem\Service)
    $psID = $payment->getPaymentSystemId(); // ID платежной системы
    $psName = $payment->getPaymentSystemName(); // название платежной системы
    $isInnerPs = $payment->isInner(); // true, если это оплата с внутреннего счета
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question