Work with order payments (C#)

Version: 10.3

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#:

  1. Selecting the gift card option, for example, for gift card payment:

    RequestResponse
    DataServiceQuerySingle<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));
    
  2. Provide the payment amount and the gift card information, for example:

    RequestResponse
    view = 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# :

  1. Get the entity view for the action, for example:

    RequestResponse
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", string.Empty, "VoidPayment",
    paymentId);
    EntityView view = Proxy.GetValue(query);
  2. Execute the action:

    RequestResponse
    CommerceCommand 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#:

  1. Get the entity view for the action, for example:

    RequestResponse
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", string.Empty, "RefundPayment",
    paymentId);
    EntityView view = Proxy.GetValue(query);
  2. Execute the action:

    RequestResponse
     CommerceCommand command = Proxy.DoCommand(container.DoAction(view));

Do you have some feedback for us?

If you have suggestions for improving this article,