Close Orders with Silent Payments Directly from the API
Tags:
In the recent release of SyrveFront 7.4.6, it became possible to close orders with payments that support silent processing directly from the API, without accessing the cash register screen. This functionality is supported in the specified version of SyrveFront across all available API versions: V5, V6, V7Preview3, V7Preview4, V7.
Previously, silent processing for plugin payments in an order was only supported by the method ProcessPrepay. However, converting a payment into a prepayment involves unnecessary steps in accounting and has its own peculiarities. Now, such an order can be paid and closed by calling the method PayOrder. A necessary condition is that all unprocessed payments contained in the order must support silent payment.
Example
const bool isProcessed = false;
var credentials = PluginContext.Operations.GetCredentials();
var order = PluginContext.Operations.GetOrders().Last(o => o.Status == OrderStatus.New);
var paymentType = PluginContext.Operations.GetPaymentTypes().First(x => x.Kind == PaymentTypeKind.External && x.Name == "SampleApiPayment");
var additionalData = new ExternalPaymentItemAdditionalData { CustomData = Serializer.Serialize(new PaymentAdditionalData { SilentPay = true }) };
// Adding plugin payment for the full amount
PluginContext.Operations.AddExternalPaymentItem(order.ResultSum, isProcessed, additionalData, null, paymentType, order, credentials);
order = PluginContext.Operations.GetOrderById(order.Id);
// Closing the order with existing payments
PluginContext.Operations.PayOrder(credentials, order);