> 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

# CalculateRefund

# Package: orders

# Namespace: OrderBillingService

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/orders/order-billing/calculate-refund?apiView=SDK.md

## Permission Scopes:
Manage Orders: SCOPE.DC-STORES.MANAGE-ORDERS

## Introduction

Calculates the total refund amount and breakdown for specified line items, shipping, and additional fees.

Returns detailed calculations including:
- Total refund amount with tax, discount, and subtotal breakdowns
- Individual item calculations with pricing details
- Validation of whether the requested refund items are available

Use this method to preview refund amounts before calling Refund Payments.

---

## REST API

### Schema

```
 Method: calculateRefund
 Description: Calculates the total refund amount and breakdown for specified line items, shipping, and additional fees.  Returns detailed calculations including: - Total refund amount with tax, discount, and subtotal breakdowns - Individual item calculations with pricing details - Validation of whether the requested refund items are available  Use this method to preview refund amounts before calling Refund Payments.
 URL: https://www.wixapis.com/ecom/v1/order-billing/calculate-refund
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  orderId, refundItems.lineItems.lineItemId, refundItems.lineItems.quantity, refundItems.additionalFees.additionalFeeId
 Method parameters: 
   param name: orderId | type: orderId | description: Order GUID to calculate refund for. | required: true | validation: format GUID
   param name: refundItems | type: RefundItems    
        - name: lineItems | type: array<LineItemRefund> | description: Line items and their quantities to refund.  | validation: minItems 0, maxItems 300
           - name: lineItemId | type: string | description: Line item GUID.  | validation: format GUID
           - name: quantity | type: integer | description: Quantity of this product to refund. Cannot exceed the available refund quantity for this line item.  | validation: minimum 1, maximum 100000
        - name: additionalFees | type: array<AdditionalFeeRefund> | description: Additional fees and their amounts to refund.  | validation: minItems 0, maxItems 100
           - name: additionalFeeId | type: string | description: Additional fee GUID to refund.  | validation: format GUID
           - name: amount | type: Price | description: Amount of the additional fee to refund. If not specified, the full remaining refundable amount for this fee will be refunded.  
              - name: amount | type: string | description: Amount.  | validation: decimalValue {"gte":"0","lte":"1000000000000000"}
        - name: shipping | type: ShippingRefund | description: Shipping amount to refund.  
           - name: amount | type: Price | description: Amount of shipping charges to refund. If not specified, the full remaining refundable shipping amount will be refunded.  
 Return type: CalculateRefundResponse
  - ONE-OF: 
     - name: available | type: boolean | description: Whether the refund is available for all requested items.  `true` indicates all items can be refunded as requested.  
     - name: notAvailable | type: CalculatedRefundNotAvailableStatus | description: Refund unavailability details when some or all items cannot be refunded.  Contains specific error information for each problematic item.  
        - name: errors | type: array<CalculationError> | description: Refund calculation errors.  | validation: maxItems 401
           - ONE-OF: 
              - name: lineItem | type: LineItemRefund | description: Line item  
                 - name: lineItemId | type: string | description: Line item GUID.  | validation: format GUID
                 - name: quantity | type: integer | description: Quantity of this product to refund. Cannot exceed the available refund quantity for this line item.  | validation: minimum 1, maximum 100000
              - name: additionalFee | type: AdditionalFeeRefund | description: Additional fee  
                 - name: additionalFeeId | type: string | description: Additional fee GUID to refund.  | validation: format GUID
                 - name: amount | type: Price | description: Amount of the additional fee to refund. If not specified, the full remaining refundable amount for this fee will be refunded.  
                    - name: amount | type: string | description: Amount.  | validation: decimalValue {"gte":"0","lte":"1000000000000000"}
                    - name: formattedAmount | type: string | description: Amount formatted with currency symbol.  | read-only: true 
              - name: shipping | type: ShippingRefund | description: Shipping  
                 - name: amount | type: Price | description: Amount of shipping charges to refund. If not specified, the full remaining refundable shipping amount will be refunded.  
           - name: error | type: Details | description: Error details  
              - ONE-OF: 
                 - name: applicationError | type: ApplicationError | description:   
                    - name: code | type: string | description: Error code.  
                    - name: description | type: string | description: Description of the error.  
                    - name: data | type: object | description: Data related to the error.  
                 - name: validationError | type: ValidationError | description:   
                    - name: fieldViolations | type: array<FieldViolation> | description:   
                       - name: field | type: string | description:   
                       - name: description | type: string | description:   
                       - name: violatedRule | type: RuleType | description:   
                                 - enum: VALIDATION, OTHER, MAX, MIN, MAX_LENGTH, MIN_LENGTH, MAX_SIZE, MIN_SIZE, FORMAT, DECIMAL_LTE, DECIMAL_GTE, DECIMAL_LT, DECIMAL_GT, DECIMAL_MAX_SCALE, INVALID_ENUM_VALUE, REQUIRED_FIELD, FIELD_NOT_ALLOWED, ONE_OF_ALIGNMENT, EXACT_LENGTH, EXACT_SIZE, REQUIRED_ONE_OF_FIELD
                       - name: ruleName | type: string | description: applicable when violated_rule=OTHER  
                       - name: data | type: object | description:   
                 - name: systemError | type: SystemError | description:   
                    - name: errorCode | type: string | description: Error code.  
  - name: summary | type: AggregatedRefundSummary | description: Aggregated summary of all items provided for refund.  This field is not returned when refund is not available for the given list of items.  
     - name: total | type: Price | description: Total refund amount.  
     - name: tax | type: Price | description: Tax amount for the items being refunded.  
     - name: discount | type: Price | description: Discount amount for the items being refunded.  
     - name: subtotal | type: Price | description: Total cost of the items being refunded (without tax and discount).  
     - name: lineItemsSubtotal | type: Price | description: Total cost of the line items being refunded (without tax and discount).  
     - name: additionalFeesTotal | type: Price | description: Total cost of the additional fees being refunded.  
  - name: calculatedRefundItems | type: CalculatedRefundItems | description: Detailed refund calculations broken down by each requested item type.  
     - name: lineItems | type: array<CalculatedLineItemRefund> | description: Calculated refund details for each line item.  | validation: maxItems 300
        - name: item | type: LineItemRefund | description: Line item refund details.  
        - name: summary | type: CalculatedRefundSummary | description: Calculated refund summary for this line item.  
           - name: total | type: Price | description: Total refundable amount.  
           - name: tax | type: Price | description: Tax amount for the items being refunded.  
           - name: discount | type: Price | description: Discount amount for the items being refunded.  
           - name: subtotal | type: Price | description: Total cost of the items being refunded (without tax and discount).  
     - name: additionalFees | type: array<CalculatedAdditionalFeeRefund> | description: Calculated refund details for each additional fee.  | validation: maxItems 100
        - name: additionalFee | type: AdditionalFeeRefund | description: Additional fee refund details.  
        - name: summary | type: CalculatedRefundSummary | description: Calculated refund summary for this additional fee.  
     - name: shipping | type: CalculatedShippingRefund | description: Calculated refund details for the shipping fee.  
        - name: shipping | type: ShippingRefund | description: Shipping refund details.  
        - name: summary | type: CalculatedRefundSummary | description: Calculated refund summary for shipping.  


```

### Examples

### Calculate Refund
Calculate refund for invalid quantity of line items and shipping that's already been refunded.

```curl
curl -X POST \
  'https://www.wixapis.com/ecom/v1/order-billing/calculate-refund' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: <AUTH>' \
  -d '{
    "orderId": "585daa0c-08d2-42ae-bd6b-18fe59c75836",
    "refundItems": {
			"lineItems": [
				{
					"lineItemId": "00000000-0000-0000-0000-000000000001",
					"quantity": 10000
				}
			],
			"shipping": {
				"amount": {
					"amount": "1"
				}
			}
    }
  }'
```

### Calculate Refund
Calculate valid refund for 1 line item and 1 additional fee.

```curl
curl -X POST \
  'https://www.wixapis.com/ecom/v1/order-billing/calculate-refund' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: <AUTH>' \
  -d '{
    "orderId": "585daa0c-08d2-42ae-bd6b-18fe59c75836",
    "refundItems": {
			"lineItems": [
				{
					"lineItemId": "00000000-0000-0000-0000-000000000001",
					"quantity": 1
				}
			],
			"additionalFees": [
				{
					"additionalFeeId": "d3d9cafb-9e2d-4dae-8129-091df0a6c24f",
					"amount": {
						"amount": "1"
					}
				}
			]
    }
  }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.ecom.orderBilling.calculateRefund(orderId, options)
 Description: Calculates the total refund amount and breakdown for specified line items, shipping, and additional fees.  Returns detailed calculations including: - Total refund amount with tax, discount, and subtotal breakdowns - Individual item calculations with pricing details - Validation of whether the requested refund items are available  Use this method to preview refund amounts before calling Refund Payments.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  orderId, options.refundItems.lineItems.lineItemId, options.refundItems.lineItems.quantity, options.refundItems.additionalFees.additionalFeeId
 Method parameters: 
   param name: orderId | type: string | description: Order GUID to calculate refund for. | required: true | validation: format GUID
   param name: options | type: CalculateRefundOptions  none  
        - name: refundItems | type: RefundItems | description: Items to include in the refund calculation with their respective quantities and amounts.  Specify which line items, shipping charges, and additional fees to refund.  
           - name: lineItems | type: array<LineItemRefund> | description: Line items and their quantities to refund.  | validation: minItems 0, maxItems 300
              - name: lineItemId | type: string | description: Line item GUID.  | validation: format GUID
              - name: quantity | type: integer | description: Quantity of this product to refund. Cannot exceed the available refund quantity for this line item.  | validation: minimum 1, maximum 100000
           - name: additionalFees | type: array<AdditionalFeeRefund> | description: Additional fees and their amounts to refund.  | validation: minItems 0, maxItems 100
              - name: additionalFeeId | type: string | description: Additional fee GUID to refund.  | validation: format GUID
              - name: amount | type: Price | description: Amount of the additional fee to refund. If not specified, the full remaining refundable amount for this fee will be refunded.  
                 - name: amount | type: string | description: Amount.  | validation: decimalValue {"gte":"0","lte":"1000000000000000"}
           - name: shipping | type: ShippingRefund | description: Shipping amount to refund.  
              - name: amount | type: Price | description: Amount of shipping charges to refund. If not specified, the full remaining refundable shipping amount will be refunded.  
 Return type: PROMISE<CalculateRefundResponse>
  - ONE-OF: 
     - name: available | type: boolean | description: Whether the refund is available for all requested items.  `true` indicates all items can be refunded as requested.  
     - name: notAvailable | type: CalculatedRefundNotAvailableStatus | description: Refund unavailability details when some or all items cannot be refunded.  Contains specific error information for each problematic item.  
        - name: errors | type: array<CalculationError> | description: Refund calculation errors.  | validation: maxItems 401
           - ONE-OF: 
              - name: lineItem | type: LineItemRefund | description: Line item  
                 - name: lineItemId | type: string | description: Line item GUID.  | validation: format GUID
                 - name: quantity | type: integer | description: Quantity of this product to refund. Cannot exceed the available refund quantity for this line item.  | validation: minimum 1, maximum 100000
              - name: additionalFee | type: AdditionalFeeRefund | description: Additional fee  
                 - name: additionalFeeId | type: string | description: Additional fee GUID to refund.  | validation: format GUID
                 - name: amount | type: Price | description: Amount of the additional fee to refund. If not specified, the full remaining refundable amount for this fee will be refunded.  
                    - name: amount | type: string | description: Amount.  | validation: decimalValue {"gte":"0","lte":"1000000000000000"}
                    - name: formattedAmount | type: string | description: Amount formatted with currency symbol.  | read-only: true 
              - name: shipping | type: ShippingRefund | description: Shipping  
                 - name: amount | type: Price | description: Amount of shipping charges to refund. If not specified, the full remaining refundable shipping amount will be refunded.  
           - name: error | type: Details | description: Error details  
              - ONE-OF: 
                 - name: applicationError | type: ApplicationError | description:   
                    - name: code | type: string | description: Error code.  
                    - name: description | type: string | description: Description of the error.  
                    - name: data | type: object | description: Data related to the error.  
                 - name: validationError | type: ValidationError | description:   
                    - name: fieldViolations | type: array<FieldViolation> | description:   
                       - name: field | type: string | description:   
                       - name: description | type: string | description:   
                       - name: violatedRule | type: RuleType | description:   
                                 - enum: VALIDATION, OTHER, MAX, MIN, MAX_LENGTH, MIN_LENGTH, MAX_SIZE, MIN_SIZE, FORMAT, DECIMAL_LTE, DECIMAL_GTE, DECIMAL_LT, DECIMAL_GT, DECIMAL_MAX_SCALE, INVALID_ENUM_VALUE, REQUIRED_FIELD, FIELD_NOT_ALLOWED, ONE_OF_ALIGNMENT, EXACT_LENGTH, EXACT_SIZE, REQUIRED_ONE_OF_FIELD
                       - name: ruleName | type: string | description: applicable when violated_rule=OTHER  
                       - name: data | type: object | description:   
                 - name: systemError | type: SystemError | description:   
                    - name: errorCode | type: string | description: Error code.  
  - name: summary | type: AggregatedRefundSummary | description: Aggregated summary of all items provided for refund.  This field is not returned when refund is not available for the given list of items.  
     - name: total | type: Price | description: Total refund amount.  
     - name: tax | type: Price | description: Tax amount for the items being refunded.  
     - name: discount | type: Price | description: Discount amount for the items being refunded.  
     - name: subtotal | type: Price | description: Total cost of the items being refunded (without tax and discount).  
     - name: lineItemsSubtotal | type: Price | description: Total cost of the line items being refunded (without tax and discount).  
     - name: additionalFeesTotal | type: Price | description: Total cost of the additional fees being refunded.  
  - name: calculatedRefundItems | type: CalculatedRefundItems | description: Detailed refund calculations broken down by each requested item type.  
     - name: lineItems | type: array<CalculatedLineItemRefund> | description: Calculated refund details for each line item.  | validation: maxItems 300
        - name: item | type: LineItemRefund | description: Line item refund details.  
        - name: summary | type: CalculatedRefundSummary | description: Calculated refund summary for this line item.  
           - name: total | type: Price | description: Total refundable amount.  
           - name: tax | type: Price | description: Tax amount for the items being refunded.  
           - name: discount | type: Price | description: Discount amount for the items being refunded.  
           - name: subtotal | type: Price | description: Total cost of the items being refunded (without tax and discount).  
     - name: additionalFees | type: array<CalculatedAdditionalFeeRefund> | description: Calculated refund details for each additional fee.  | validation: maxItems 100
        - name: additionalFee | type: AdditionalFeeRefund | description: Additional fee refund details.  
        - name: summary | type: CalculatedRefundSummary | description: Calculated refund summary for this additional fee.  
     - name: shipping | type: CalculatedShippingRefund | description: Calculated refund details for the shipping fee.  
        - name: shipping | type: ShippingRefund | description: Shipping refund details.  
        - name: summary | type: CalculatedRefundSummary | description: Calculated refund summary for shipping.  


```

### Examples

### Calculate Refund
Calculate a refund that isn't available — an invalid line item quantity and already-refunded shipping.

```javascript
import { orderBilling } from "@wix/ecom";

async function calculateRefund() {
  const response = await orderBilling.calculateRefund(
    "585daa0c-08d2-42ae-bd6b-18fe59c75836",
    {
      refundItems: {
        lineItems: [
          {
            lineItemId: "00000000-0000-0000-0000-000000000001",
            quantity: 10000,
          },
        ],
        shipping: { amount: { amount: "1" } },
      },
    },
  );
  return response;
}

/* Promise resolves to:
 * {
 *   "calculatedRefundItems": { "lineItems": [], "additionalFees": [] },
 *   "notAvailable": {
 *     "errors": [
 *       {
 *         "lineItem": {
 *           "lineItemId": "00000000-0000-0000-0000-000000000001",
 *           "quantity": 10000
 *         },
 *         "error": {
 *           "applicationError": {
 *             "code": "INVALID_LINE_ITEM_REFUND_QUANTITY",
 *             "description": "Invalid refund quantity for line item [00000000-0000-0000-0000-000000000001]. Requested [10000], available [2]."
 *           }
 *         }
 *       }
 *     ]
 *   }
 * }
 */

```

### Calculate Refund
Calculate a valid refund for one line item and one additional fee.

```javascript
import { orderBilling } from "@wix/ecom";

async function calculateRefund() {
  const response = await orderBilling.calculateRefund(
    "585daa0c-08d2-42ae-bd6b-18fe59c75836",
    {
      refundItems: {
        lineItems: [
          { lineItemId: "00000000-0000-0000-0000-000000000001", quantity: 1 },
        ],
        additionalFees: [
          {
            additionalFeeId: "d3d9cafb-9e2d-4dae-8129-091df0a6c24f",
            amount: { amount: "1" },
          },
        ],
      },
    },
  );
  return response;
}

/* Promise resolves to:
 * {
 *   "available": true,
 *   "summary": {
 *     "total": { "amount": "23.00", "formattedAmount": "$23.00" }
 *   },
 *   "calculatedRefundItems": {
 *     "lineItems": [
 *       {
 *         "item": {
 *           "lineItemId": "00000000-0000-0000-0000-000000000001",
 *           "quantity": 1
 *         },
 *         "summary": {
 *           "total": { "amount": "22.00", "formattedAmount": "$22.00" }
 *         }
 *       }
 *     ],
 *     "additionalFees": [
 *       {
 *         "additionalFee": {
 *           "additionalFeeId": "d3d9cafb-9e2d-4dae-8129-091df0a6c24f"
 *         }
 *       }
 *     ]
 *   }
 * }
 */

```

### calculateRefund (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { orderBilling } from '@wix/ecom';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { orderBilling },
  // Include the auth strategy and host as relevant
});


async function calculateRefund(orderId,options) {
  const response = await myWixClient.orderBilling.calculateRefund(orderId,options);
};
```

---