> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automate.ax/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Refund Payment

> Refunds a payment.

`square.refundPayment` refunds a payment.

## Example

```ts automations/square-refund-payment.automation.ts theme={null}
import { automation, onDashboardRun } from "automate.ax"
import { square } from "automate.ax/square"

export default automation("Refund Square Payment", () => {
  onDashboardRun({ title: "Refund Square Payment" })

  square.refundPayment({
    idempotencyKey: "9b7f2dcf-49da-4411-b23e-a2d6af21333a",
    amountMoney: {
      amount: BigInt("1000"),
      currency: "USD",
    },
    appFeeMoney: {
      amount: BigInt("10"),
      currency: "USD",
    },
    paymentId: "R2B3Z8WMVt3EAmzYWLZvz7Y69EbZY",
    reason: "Example",
  })
})
```

## Inputs

Every input accepts a compatible signal. It requires `PAYMENTS_WRITE`.

| Field                 | Type                                             | Required | Default | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| --------------------- | ------------------------------------------------ | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `idempotencyKey`      | `string`                                         | Yes      | —       | A unique string that identifies this `RefundPayment` request. The key can be any valid string but must be unique for every `RefundPayment` request. Keys are limited to a max of 45 characters - however, the number of allowed characters might be less than 45, if multi-byte characters are used. For more information, see [Idempotency](https://developer.squareup.com/docs/working-with-apis/idempotency).                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `amountMoney`         | `Square.Money`                                   | Yes      | —       | The amount of money to refund. This amount cannot be more than the `total_money` value of the payment minus the total amount of all previously completed refunds for this payment. This amount must be specified in the smallest denomination of the applicable currency (for example, US dollar amounts are specified in cents). For more information, see [Working with Monetary Amounts](https://developer.squareup.com/docs/build-basics/working-with-monetary-amounts). The currency code must match the currency associated with the business that is charging the card.                                                                                                                                                                                                                                                                  |
| `appFeeMoney`         | `Square.Money`                                   | No       | —       | The amount of money the developer contributes to help cover the refunded amount. This amount is specified in the smallest denomination of the applicable currency (for example, US dollar amounts are specified in cents). The value cannot be more than the `amount_money`. You can specify this parameter in a refund request only if the same parameter was also included when taking the payment. This is part of the application fee scenario the API supports. For more information, see [Take Payments and Collect Fees](https://developer.squareup.com/docs/payments-api/take-payments-and-collect-fees). To set this field, `PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS` OAuth permission is required. For more information, see [Permissions](https://developer.squareup.com/docs/payments-api/take-payments-and-collect-fees#permissions). |
| `appFeeAllocations`   | `unknown[] \| null`                              | No       | —       | Details pertaining to contributors to the refund of the application fee. The sum of the amounts in the app\_fee\_allocations must equal the app\_fee\_money amount, if present. If populated, an allocation must be present for every party that expects to contribute a portion of the refunded application fee, including the application developer.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `paymentId`           | `string \| null`                                 | No       | —       | The unique ID of the payment being refunded. Required when unlinked=false, otherwise must not be set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `destinationId`       | `string \| null`                                 | No       | —       | The ID indicating where funds will be refunded to. Required for unlinked refunds. For more information, see [Process an Unlinked Refund](https://developer.squareup.com/docs/refunds-api/unlinked-refunds). For refunds linked to Square payments, `destination_id` is usually omitted; in this case, funds will be returned to the original payment source. The field may be specified in order to request a cross-method refund to a gift card. For more information, see [Cross-method refunds to gift cards](https://developer.squareup.com/docs/payments-api/refund-payments#cross-method-refunds-to-gift-cards).                                                                                                                                                                                                                          |
| `unlinked`            | `boolean \| null`                                | No       | —       | Indicates that the refund is not linked to a Square payment. If set to true, `destination_id` and `location_id` must be supplied while `payment_id` must not be provided.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `locationId`          | `string \| null`                                 | No       | —       | The location ID associated with the unlinked refund. Required for requests specifying `unlinked=true`. Otherwise, if included when `unlinked=false`, will throw an error.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `customerId`          | `string \| null`                                 | No       | —       | The Customer ID of the customer associated with the refund. This is required if the `destination_id` refers to a card on file created using the Cards API. Only allowed when `unlinked=true`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `reason`              | `string \| null`                                 | No       | —       | A description of the reason for the refund.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `paymentVersionToken` | `string \| null`                                 | No       | —       | Used for optimistic concurrency. This opaque token identifies the current `Payment` version that the caller expects. If the server has a different version of the Payment, the update fails and a response with a VERSION\_MISMATCH error is returned. If the versions match, or the field is not provided, the refund proceeds as normal.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `teamMemberId`        | `string \| null`                                 | No       | —       | An optional TeamMember ID to associate with this refund.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `cashDetails`         | `Square.DestinationDetailsCashRefundDetails`     | No       | —       | Additional details required when recording an unlinked cash refund (`destination_id` is CASH).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `externalDetails`     | `Square.DestinationDetailsExternalRefundDetails` | No       | —       | Additional details required when recording an unlinked external refund (`destination_id` is EXTERNAL).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |

Use the official [RefundPayment reference](https://developer.squareup.com/reference/square/refunds-api/refund-payment) for provider field semantics and limits.

## Output

Returns the official `Square.RefundPaymentResponse` response as a codec-safe object. Square integer money amounts remain `bigint` values.
