Work with order payments (C#)
You can use the Entity Views and Actions API to integrate payment-related data or operations with other business systems.
This topic describes how to:
Add a payment to an order (C#)
You can add a payment to an order when the order status is on hold.
To add a payment to an order, for example a gift card payment, using C#:
-
Selecting the gift card option, for example, for gift card payment:
RequestResponseDataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", "OrderFulfillmentDetails", "SelectFulfillmentOption", string.Empty); EntityView view = Proxy.GetValue(query); var optionProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Option")); var availableOptionsPolicy = optionProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault(); optionProperty.Value = availableOptionsPolicy?.List.FirstOrDefault(o => o.Name.Equals("GiftCard")).Name; CommerceCommand command = Proxy.DoCommand(container.DoAction(view)); -
Provide the payment amount and the gift card information, for example:
RequestResponseview = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name)); view.Properties.FirstOrDefault(p => p.Name.Equals("GiftCardCode")).Value = "GC1000000"; view.Properties.FirstOrDefault(p => p.Name.Equals("Amount")).Value = "50"; command = Proxy.DoCommand(container.DoAction(view));
Void an order payment (C#)
You can void the payment of an order when the order status is on hold.
To void the payment of an order using C# :
-
Get the entity view for the action, for example:
RequestResponseDataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", string.Empty, "VoidPayment", paymentId); EntityView view = Proxy.GetValue(query); -
Execute the action:
RequestResponseCommerceCommand command = Proxy.DoCommand(container.DoAction(view));
Refund an order payment (C#)
You can refund an order payment when the status of the order is completed.
To refund an order payment using C#:
-
Get the entity view for the action, for example:
RequestResponseDataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", string.Empty, "RefundPayment", paymentId); EntityView view = Proxy.GetValue(query); -
Execute the action:
RequestResponseCommerceCommand command = Proxy.DoCommand(container.DoAction(view));