---
title: "Work with order payments (C#)"
slug: "work-with-order-payments--c--"
abstract: "How to add a payment, void a payment, or refund a payment."
---
# 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#)](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/work-with-order-payments--c--.html#UUID-ec63b5e5-7504-199a-4e95-9ad523f4f86b_section-idm45837281904832 "Add a payment to an order (C#)")
- [Void an order payment (C#)](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/work-with-order-payments--c--.html#UUID-ec63b5e5-7504-199a-4e95-9ad523f4f86b_section-idm45837281682464 "Void an order payment (C#)")
- [Refund an order payment (C#)](https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-commerce/work-with-order-payments--c--.html#UUID-ec63b5e5-7504-199a-4e95-9ad523f4f86b_section-idm45837281138864 "Refund an order payment (C#)")

<details>
<summary><h2>Add a payment to an order (C#)</h2></summary>

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:

    ```csharp
    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:

    ```

    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));
    ```

</details>

<details>
<summary><h2>Void an order payment (C#)</h2></summary>

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:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", string.Empty, "VoidPayment",
    paymentId);
    EntityView view = Proxy.GetValue(query);
    ```

2. Execute the action:

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

</details>

<details>
<summary><h2>Refund an order payment (C#)</h2></summary>

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:

    ```csharp
    DataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", string.Empty, "RefundPayment",
    paymentId);
    EntityView view = Proxy.GetValue(query);
    ```

2. Execute the action:

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

</details>