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

# Refund a Payment Intent

> Give the money back on a payment a terminal already charged

## Overview

[Cancel](https://docs.compago.com/payment-intent/cancel.md) withdraws a payment intent the terminal has not charged yet. Once the card was approved, the intent is `CONFIRMED` and cancelling it answers `400 Payment intent already confirmed`. To give the money back, refund it.

The refund returns the **whole charge** to the same card, the same way the terminal's and the dashboard's **Reembolsar** do.

## Rules

* **Same day only.** Before 10:30 PM Mexico City time on the day of the sale (and never more than 24 hours after it). American Express cards charged at the terminal: before 10:00 PM. After that the refund is refused with `REFUND_WINDOW_EXPIRED`; a later refund, when your agreement allows one, is made from the dashboard.
* **Full only.** There are no partial refunds.
* **Compago may keep its fee.** The customer gets the whole charge back; depending on your agreement, Compago keeps the fee it charged on the sale and deducts it from your pending settlement. See [Refunds and fees](https://docs.compago.com/refunds/refunds-and-fees.md).
* **One refund per sale.** A repeated request answers `409 ALREADY_REFUNDED` and never reaches the bank twice.

## Authentication

* **Your own API key** (`x-api-key`) may refund any payment intent of your organization.
* **An installed app** (OAuth, `Authorization: Bearer`) needs the `payments:refund` scope, and refunds only the payment intents it created. Without the scope it answers `403 insufficient_scope` with `"scope": "payments:refund"`. The merchant grants the scope when connecting the app.

## Request

> [!NOTE]
>
> These examples call the production host. While you build, replace `https://api-harmony.compago.com` with `https://demo-api-harmony.compago.com` and use a key from the Demo dashboard. See [Environments](https://docs.compago.com/get-started/environments.md).

```
POST /api/developer/v1/payment-intent/{id}/refund
```

**API reference:** [`POST /payment-intent/{id}/refund`](https://docs.compago.com/api-reference/payment-intent/refund)

```bash theme={null}
curl -X POST https://api-harmony.compago.com/api/developer/v1/payment-intent/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/refund \
  -H "x-api-key: YOUR_API_KEY"
```

## Response

```json theme={null}
{
  "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "paymentId": "11111111-2222-3333-4444-555555555555",
  "status": "REFUNDED",
  "refund": {
    "amount": 350.50,
    "kind": "SAME_DAY",
    "feeRetained": { "fee": 10.52, "iva": 1.68, "total": 12.20 },
    "chargedFrom": "PENDING_SETTLEMENT"
  }
}
```

After the refund, `GET /payment-intent/{id}` keeps answering `status: "CONFIRMED"`, because the intent's status says whether the terminal charged it. To know whether the sale was given back, read `refundedAt`: the time of the refund, or `null` while the sale stands. It is filled however the sale was refunded: this endpoint, the terminal or the dashboard.

## Errors

| Status | Code | What it means |
| - | - | - |
| 400 | `REFUND_WINDOW_EXPIRED` | Past the same-day window. Refund it from the dashboard if your agreement allows late refunds. |
| 400 | `NOT_REFUNDABLE` | The terminal has not charged this payment intent. If it is still `PENDING`, [cancel it](https://docs.compago.com/payment-intent/cancel.md). |
| 400 | `REFUND_INSTALLMENTS_COLLECTED` | Installments were already collected on this sale. |
| 403 | `insufficient_scope` | The installed app lacks `payments:refund`. |
| 404 | | No such payment intent in your organization, or an installed app asking for one it did not create. |
| 409 | `ALREADY_REFUNDED` | The sale was already refunded. |
| 409 | `REFUND_FEE_NOT_COVERED` | Your pending settlement does not cover the fee Compago keeps. Nothing reached the bank. |
| 409 | `REFUND_DECLINED` | The bank did not accept the refund. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.