> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Sample Flows

## Article: Sample Flows

## Article Link: https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/order-transactions/sample-flows.md

## Article Content:

# Order Transactions: Sample Flows

This article presents possible use cases and corresponding sample flows that you can support. It provides a useful starting point as you plan your implementation.

## Retrieve transactions related to eCommerce orders

Your app can retrieve details about payments and refunds associated with an order. For example, you can check for payments that were made by credit card, payments made by gift card, or orders that were not successfully refunded.

To retrieve info about an order's transactions:

1. Call [List Transactions For Single Order](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/order-transactions/list-transactions-for-single-order.md) with an [eCommerce order ID](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/orders/introduction.md).
    * To retrieve transaction details about more than 1 order, call [List Transactions For Multiple Orders](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/order-transactions/list-transactions-for-multiple-orders.md) with an array of [eCommerce order IDs](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/orders/introduction.md).
2. You can use the returned info to check payment and refund details in the relevant provider or gateway systems, pass the details on to your accounting or invoice apps, and more.

## Add payment records to imported orders

If you are importing orders from other systems, you may want to add payment records to those orders. To add a payment record to an order that is already in the eCommerce system:

1. Once you have the order ID, pass it to the [Add Payments](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/order-transactions/add-payments.md) method.
2. In the request, specify payment details such as `createdDate`, `amount`, and `regularPaymentDetails.paymentMethodName`.
3. When using [Add Payments](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/order-transactions/add-payments.md) you can add up to 50 payment records to a single order with 1 API call.

## Break down sales by payment method

Your app can report how a site's sales split across payment methods, such as how much buyers paid by card, by gift card, or in cash. Orders don't include payment method details, so you read them from each order's transactions and group the payments yourself.

To break down sales by payment method:

1. Call [Search Orders](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/orders/search-orders.md). Filter by `createdDate` for the reporting period and by the `paymentStatus` values you want to include. Page through the results with `cursorPaging` and collect each order's `id` and `currency`.
2. Call [List Transactions For Multiple Orders](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/order-transactions/list-transactions-for-multiple-orders.md) with up to 100 order IDs per call.
3. For each payment in `orderTransactions.payments`, identify the payment type by the details object the payment contains. Each payment contains exactly one of `regularPaymentDetails`, `giftcardPaymentDetails`, or `membershipPaymentDetails`, directly on the payment object. For example, a card payment looks like this:

    ```json
    {
      "id": "b3f1c2d4-5e6a-4b7c-8d9e-0f1a2b3c4d5e",
      "regularPaymentDetails": {
        "offlinePayment": false,
        "creditCardDetails": {
          "lastFourDigits": "4242",
          "brand": "visa"
        },
        "paymentMethodName": {
          "buyerLanguageName": "Credit/Debit Cards",
          "siteLanguageName": "Credit/Debit Cards"
        }
      },
      "amount": {
        "amount": "18.57",
        "formattedAmount": "$18.57"
      },
      "status": "APPROVED"
    }
    ```

4. For regular payments, take the payment method name from `regularPaymentDetails.paymentMethodName`:
    * When `userDefinedName` is set, use it, because it takes precedence. It contains either a `predefined` value (`CASH`, `BANK_TRANSFER`, or `CHECK`) or a `custom` name. Map `predefined` values to display names, such as `CASH` to "Cash".
    * Otherwise, use `siteLanguageName`. It's in the site's language, so payments made with the same method are usually grouped together regardless of the buyer's language. For some older payments, and when no translation into the site's language is available, `siteLanguageName` holds the same value as `buyerLanguageName`, so the same method can appear under more than one name.
    * To break down card payments by card network, use `regularPaymentDetails.creditCardDetails.brand`.
5. Add each payment's amount to the total for its payment method. Summing payments instead of order totals correctly splits orders that buyers paid with more than one method, such as a gift card and a card.
    * Keep a separate total for each order `currency`, because buyers on a multi-currency site can pay in different currencies.
    * Include only payments whose `status` is `APPROVED`, `PARTIALLY_REFUNDED`, or `REFUNDED`. A refunded gift card payment has the status `VOIDED`, so it isn't included in these totals, even before you subtract refunds.
    * When the payment has `cashRounding.unroundedAmount`, use it instead of `amount`, because the order's balance is calculated from it.
    * Membership payments don't have an `amount`, so they don't add to any total.
6. To report net sales, subtract refunds:
    * For a payment whose `status` is `REFUNDED`, subtract the full amount you added in the previous step. For a cash-rounded payment, a full refund can differ slightly from the payment amount, so don't use the refund transaction amounts.
    * For a payment whose `status` is `PARTIALLY_REFUNDED`, go through the `transactions` array of each refund in `orderTransactions.refunds`. Find the transactions whose `paymentId` matches the payment's `id` and whose `refundStatus` is `SUCCEEDED`. Subtract their `amount`.

> **Notes:**
> + Some orders have no payment records, even when their `paymentStatus` is `PAID`. For these orders, [List Transactions For Multiple Orders](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/order-transactions/list-transactions-for-multiple-orders.md) returns an empty `payments` array.
> + This flow doesn't subtract chargebacks. To account for them, see each payment's `regularPaymentDetails.chargebacks`.