# Full Refund

Refund an entire order.

**POST** `/api/paylater/merchant-portal/v2/web-checkout/refund`

- Sandbox: `https://connect.uat.paylaterapp.com/api/paylater/merchant-portal/v2/web-checkout/refund`
- Production: `https://connect.paylaterapp.com/api/paylater/merchant-portal/v2/web-checkout/refund`

> **Info: Refund rules**
>
> Orders can be refunded within 29 days, and no sooner than 10 minutes after the transaction. To refund part of an order, see [Partial Refund](https://docs.paylaterapp.com/partial-refund.html).

## Request

#### Headers

| Header | Value |
| --- | --- |
| `Authorization` | `Bearer <ACCESS_TOKEN>` |
| `Content-Type` | `application/json` |

**Body parameters**

- `order_id` (String, required): Your merchant Order ID.

### Example request

**cURL**

```bash
curl --location 'https://connect.uat.paylaterapp.com/api/paylater/merchant-portal/v2/web-checkout/refund' \
  --header 'Authorization: Bearer <ACCESS_TOKEN>' \
  --header 'Content-Type: application/json' \
  --data '{ "order_id": "ORD-TEST-1" }'
```

**Node.js**

```javascript
const res = await fetch(
  'https://connect.uat.paylaterapp.com/api/paylater/merchant-portal/v2/web-checkout/refund',
  {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${accessToken}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ order_id: 'ORD-TEST-1' }),
  },
);

const data = await res.json();
```

**Python**

```python
import requests

resp = requests.post(
    "https://connect.uat.paylaterapp.com/api/paylater/merchant-portal/v2/web-checkout/refund",
    headers={
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/json",
    },
    json={"order_id": "ORD-TEST-1"},
)

data = resp.json()
```

**PHP**

```php
$ch = curl_init('https://connect.uat.paylaterapp.com/api/paylater/merchant-portal/v2/web-checkout/refund');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $accessToken,
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'order_id' => 'ORD-TEST-1',
    ]),
]);

$response = json_decode(curl_exec($ch), true);
```

## Response

A `200 OK` confirms the refund request was accepted.

**200 OK**

```json
{
  "message": "Refund request accepted for reference Id: ORD-TEST-1"
}
```

## Errors

| Example response | Cause |
| --- | --- |
| `{ "error": "Transaction Reference is required" }` | Missing `order_id`. |
| `{ "error": "Invalid API Key" }` | Bad/missing token. |
| `{ "error": "Refund Error", "message": "Order contains transactions other than down payment and cannot be refunded." }` | Not refundable. |
| `{ "error": "Refund Error", "message": "Transaction happened less than 10 minutes ago. Please try again later." }` | Too soon. |
| `{ "error": "Refund Error", "message": "Invalid Transaction Reference." }` | Unknown order. |

See [Error handling & response codes](https://docs.paylaterapp.com/errors.html) for the full catalogue.
