# Applying store credit

Providing and highlighting a loyalty reward builds customer loyalty and increases profitability. This topic explains how to use the Commerce API to leverage the power of the store credit program to reward and retain loyal shoppers.

To support store credit, Commerce API requires [more than one source](/commerce-api/payments/sources/using-the-source-identifier.md#primary-versus-secondary-sources) in a cart. You need to [create a source for the shopper's payment](/commerce-api/payments/sources/using-the-source-identifier.md#creating-primary-sources) and[ another for store credit](/commerce-api/payments/sources/using-the-source-identifier.md#creating-secondary-sources). Once you create both sources, you can [attach them to the cart](/commerce-api/payments/sources/using-the-source-identifier.md#attaching-multiple-payment-sources-to-the-cart) for the charge.

## Store credit flow

A secondary payment source is leveraged to reward loyal customers in the store credit flow. This process involves creating and managing store credit and integrating it with primary payment methods to complete purchases. By effectively using store credit, businesses can enhance customer retention and provide a flexible payment option that improves overall shopping experiences. Below are the steps to implement and use store credit within the Commerce API.

1. [Create a cart](/commerce-api/shopper-apis/cart/creating-or-updating-a-cart.md#creating-a-cart).
2. Create a [store credit source](/commerce-api/payments/sources/using-the-source-identifier.md#creating-secondary-sources).
3. [Attach the secondary source to the cart](/commerce-api/payments/sources/using-the-source-identifier.md#attaching-multiple-payment-sources-to-the-cart) (for example, the store credit source).
4. Attach the primary source to the cart (for example, the credit card source).\
   **Note**: If the secondary source can cover the entire order amount, you can skip this step. &#x20;
5. [Submit the cart](/commerce-api/shopper-apis/cart/submitting-a-cart.md).
6. If you [configured notifications](/commerce-api/events/events.md#creating-email-notifications), the shopper receives an order confirmation notification. See [Post-order notifications](#post-order-notification) for more information.

## Store credit sequence diagram

Below is a sequence diagram outlining the process of implementing store credit in a Commerce API environment:

<figure><img src="/files/ClXXUvSAZ22r2n7hhacm" alt=""><figcaption><p>Store credit sequence diagram</p></figcaption></figure>

This diagram illustrates the interaction between the shopper, store, and Commerce API in using store credit for a transaction.

## Cancel an order that used store credit

1. You can use [Global Commerce](https://gc.digitalriver.com/gc/ent/timeout.do) to cancel an order or line item if it has not been shipped or fulfilled.
2. If you [configured notifications](/commerce-api/events/events.md#creating-email-notifications), the shopper receives a cancellation notification. See [Line item cancel completed](#line-item-cancel-completed-event-notification) for more information.

## Refund an order with store credit

1. You cannot [cancel an order or line item](/commerce-api/shopper-apis/product-discovery/fulfillment-1/physical-fulfillment.md#cancel-fulfillment-order-request) if it has been shipped or fulfilled. You must return or refund the order or line item using [Global Commerce](https://gc.digitalriver.com/gc/ent/timeout.do), the [Refunds API](https://docs.digitalriver.com/commerce-api-references/admin-apis/order-management/refunds), or the [Returns API](https://docs.digitalriver.com/commerce-api-references/shopper-apis/orders/returns).
2. The shopper [requests a refund](/commerce-api/admin-apis/refunds/creating-a-satisfaction-refund.md). If you [configure notifications](/commerce-api/events/events.md#creating-email-notifications), the shopper receives a user refund confirmation.&#x20;
3. Digital River processes the refund request. See [Store credit notification](#store-credit-notifications) for more information.

## Post-order notifications

Post-order notification (PON) polls events and collects data using real-time calls for your company or site. When an event occurs, it triggers a notification and sends it to your endpoint. The notifications are one way. Once you receive a notification, you are free to do whatever you want with that notification. To turn on and configure PON, see the [Post-order notification integration guide](/commerce-api/events/event-types/post-order-notification-integration-guide.md).

A PON tells you when a shopper uses store credit and how much store credit the shopper uses when an event occurs. A PON is triggered when an order is submitted, refunded, or cancelled. The PON generates an XML containing the order data. The store credit amount and payment method amount will appear in the notification's `Order` object under `extendedAttributes`. You can extract the content of an order event to see the amount the shopper paid by store credit and other payment methods.

The following table shows that a PON is sent when: (1) a shopper submits an order, (2) a shopper requests a refund for an order or line item, and (3) a shopper cancels an order or line item.

| Flow sequence | Event description                                                                                            | Post-order notification                                    |
| ------------- | ------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------- |
| 1             | Shopper submits the order.                                                                                   | Notify the the client system to subtract the store credit. |
| 2             | Shopper requests a refund for the order or a line item. Digital River processes the refund for the customer. | Notify the client system to return the store credit.       |
| 3             | Shopper cancels the order or a line item.                                                                    | Notify the client system to return the store credit.       |

### Order submitted notification

The order submitted notification displays the payment method and store credit under `extendedAttributes`. If you want to receive a notification when an order event occurs, contact your Digital River representative.&#x20;

![Order submitted notification](/files/vGnrALgjBqH9NoPPqp5W)

### Line item cancel completed notification

The line item cancel completed notification shows the cancelled store credit under `extendedAttributes`. If you want to receive a notification when the store credit was not consumed so you can reflect it on your system, contact your Digital River representative.&#x20;

![Line item cancel completed notification](/files/EgLC70qQOgXpaECtNKpB)

### Return credit complete notification

The return notification shows the refunded store credit under `extendedAttributes`. If you want a post-order notification sent to your system to notify you that the store credit was not consumed so you can reflect it on your system, contact your Digital River representative.

![Return credit complete notification](/files/oY9eYYDUhI0vrjxH6sod)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.digitalriver.com/commerce-api/shopper-apis/shopper-basics/common-use-cases/applying-store-credit.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
