Payment Actions

Tags: v6

Adding Payments

To add a payment to an order, there are methods available:

You can also use the similarly named methods of the operations service extensions, which implicitly create an editing session (the difference is the need to perform multiple actions on the order. If, in addition to adding a payment, you need to add a guest to the order, you must use methods within the editing session). For configuring and registering external payment types, see the article Integration with External Payment Types.

Payment Addition Limitations:

A payment can only be added to an order if the order is in the new (New) or bill (Bill) status; otherwise, the method throws a ConstraintViolationException. Additionally, you cannot add multiple unprocessed payment items of the same type to an order (NOTE: it is planned to allow adding multiple unprocessed payment items to an order).

Examples

card

Comments:

Paying for an Order

To pay for an order, there are methods available:

there is also a method to convert a payment item into a prepayment in SyrveFront

If the payment is made using a fiscal cash type, a fiscal withdrawal will be issued to the user on whose behalf the payment operation is performed using the IOperationService.PayOrderAndPayOutOnUser method.

Examples

Paying for an order with sufficient funds already deposited

Let there be an order IOrder order that needs to be closed in SyrveFront and sufficient processed payments have already been made to the order (processed payment items are either prepayments made on the SyrveFront cash register screen or payments added at the initiative of the plugin using the AddExternalPaymentItem method with the isProcessed flag set to true). For such an order, the method can be called:

operationService.PayOrder(credentials, order);

payOrder

Paying for an order in cash with settlement to the waiter

Let there be an order IOrder order that needs to be paid in cash for the full amount and closed in SyrveFront. To do this, the appropriate paymentType must be selected. Then the method IOperationService.PayOrderAndPayOutOnUser is called. In the example below, the order is paid in cash for the full amount:

var order = PluginContext.Operations.GetOrders().Last(o => o.Status == OrderStatus.New || o.Status == OrderStatus.Bill);
var credentials = PluginContext.Operations.AuthenticateByPin("777");
var paymentType = operationService.GetPaymentTypesToPayOutOnUser().First(x => x.IsCash);
PluginContext.Operations.PayOrderAndPayOutOnUser(credentials, order, paymentType, order.ResultSum);
Paying with a plugin payment type

Let there be an IOrder order that needs to be paid with a plugin payment type.

var order = PluginContext.Operations.GetOrders().Last(o => o.Status == OrderStatus.New);
var paymentType = PluginContext.Operations.GetPaymentTypes().Single(i => i.Kind== PaymentTypeKind.External && i.Name == "SamplePaymentType");
var credentials = PluginContext.Operations.GetCredentials();
PluginContext.Operations.PayOrderAndPayOutOnUser(credentials, order, paymentType, order.ResultSum);
Comments:

Refund of Payment

Refunding payments and returning orders at the initiative of the plugin is not yet implemented, so it must be performed from stationary SyrveFront terminals by a system user.

Processing Payments

Adding a payment processed externally to an order

In some cases, it is necessary to add a payment item to an order that has already been processed outside of SyrveFront. To do this, the AddExternalPaymentItem method is used, with the isProcessed parameter set to true. In this case, SyrveFront considers that the necessary transactions related to the payment item have been completed externally. Therefore, it does not take any action on its part for processing and marks this payment item as processed.

Example
var order = PluginContext.Operations.GetOrders().Last(o => o.Status == OrderStatus.New);
var paymentType = PluginContext.Operations.GetPaymentTypes().Last(x => x.Kind == PaymentTypeKind.Cash);
PluginContext.Operations.AddExternalPaymentItem(150, true, null, paymentType, order, PluginContext.Operations.GetCredentials());

cash

Adding a processed payment to an order and converting it to a prepayment in SyrveFront

Sometimes it is necessary to add a payment item to an order so that it appears in Syrve Office reports before the order is closed. In this case, the payment should be added to the order using the AddExternalPaymentItem method with the isProcessed parameter set to true, and then the IOperationService.ProcessPrepay method should be called.

Example
var order = PluginContext.Operations.GetOrders().Last(o => o.Status == OrderStatus.New);
var paymentType = PluginContext.Operations.GetPaymentTypes().Last(x => x.Kind == PaymentTypeKind.Card && x.Name.ToUpper() == "DINERS");
var additionalData = new CardPaymentItemAdditionalData { CardNumber = "123456" };
var credentials = PluginContext.Operations.GetCredentials();
var paymentItem = PluginContext.Operations.AddExternalPaymentItem(150, true, additionalData, paymentType, order, credentials);
order = PluginContext.Operations.GetOrderById(order.Id);
PluginContext.Operations.ProcessPrepay(credentials, order, paymentItem);

card

Adding a preliminary payment to an order and subsequently converting it to a prepayment in SyrveFront

To pay for a delivery order, you should first add a preliminary payment using the IEditSession.AddPreliminaryPaymentItem method, and then call the IOperationService.ProcessPrepay method.

Example
var order = PluginContext.Operations.GetDeliveryOrders().Last(o => o.Status == OrderStatus.New || o.Status == OrderStatus.Bill);
var paymentType = PluginContext.Operations.GetPaymentTypes().Last(i => i.Kind == PaymentTypeKind.Cash);
var credentials = PluginContext.Operations.GetCredentials();
var paymentItem = PluginContext.Operations.AddPreliminaryPaymentItem(order.ResultSum, null, paymentType, order, credentials);
PluginContext.Operations.ProcessPrepay(credentials, PluginContext.Operations.GetDeliveryOrderById(order.Id), paymentItem);

Payment Types That Support Silent Processing

Sometimes clients need the ability to make a prepayment or tip initiated by the plugin (without entering the prepayment or tip popup in SyrveFront) using an unprocessed payment type (for subsequent processing on the SyrveFront side). An unprocessed payment type means it was created with the isProcessed flag set to false. Processing any payment initiated by the plugin requires that the payment supports so-called silent payment, where no interaction with the SyrveFront user interface is required for processing (e.g., for data collection), it is assumed that all necessary data has already been collected. Among the payment types that support silent payment, there are those that support it by default:

Additionally, silent payment support can be implemented for external plugin types. For more details, see the section External Payment Types.

Additionally:

Deleting Payments

Example

More examples can be found in the SDK SamplePaymentPlugin project.