# Refund

You can request void or refund using this API, or via the [Dashboard](https://dashboard.doku.com/bo/report/transactions) .

{% hint style="info" %}
**Refund Information**

1. If you are using **Cards Aggregator** service, you can process Void or Refund.
2. If you are using **Cards Direct** service, please consult with your acquiring bank through sales to learn more about whether your credential (MID) supports online refund or not, otherwise refund will be processed manually.
3. Refund can be processed partially and multiple times as long as the total amount from original transaction hasnt been reached
   {% endhint %}

To request a refund, you will need to hit this API through your backend:

**API Request**

| Type                          | Value                                                          |
| ----------------------------- | -------------------------------------------------------------- |
| **HTTP Method**               | POST                                                           |
| **API endpoint (Sandbox)**    | `https://api-sandbox.doku.com/cancellation/credit-card/refund` |
| **API endpoint (Production)** | `https://api.doku.com/cancellation/credit-card/refund`         |

Here is the sample of request header to generate payment URL:

```
Client-Id: MCH-0001-10791114622547
Request-Id: 6cc9f8b1-d83d-4c24-b853-a3223f43a744
Request-Timestamp: 2020-08-12T09:45:42Z
Signature: HMACSHA256=9UPUFzOqJc47aJzD9ESOTcWg6TMsg3mqSP+DnUO8ENE=
```

Request Header Explanation

| Parameter             | Description                                                                                                                                                                                                                                                                                                                                           |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Client-Id**         | Client ID retrieved from DOKU Back Office                                                                                                                                                                                                                                                                                                             |
| **Request-Id**        | Unique random string (max 128 characters) generated from merchant side to protect duplicate request                                                                                                                                                                                                                                                   |
| **Request-Timestamp** | Timestamp request on UTC time in ISO8601 UTC+0 format. It means to proceed transaction on UTC+7 (WIB), merchant need to subtract time with 7. Ex: to proceed transaction on September 22th 2020 at 08:51:00 WIB, the timestamp should be 2020-09-22T01:51:00Z                                                                                         |
| **Signature**         | Security parameter that needs to be generated on merchant Backend and placed to the header request to ensure that the request is coming from valid merchant. Please refer to [this section](https://developers.doku.com/getting-started-with-doku-api/signature-component/non-snap/signature-component-from-request-header) to generate the signature |

Here is the sample request body to request a refund:

```json
{
    "order": {
        "invoice_number": "INV-20210118-0001"
    },
    "payment": {
        "original_request_id": "b266c265-3d61-4708-9860-c0d5b9a98f8c"
    },
    "refund": {
        "amount": 90000
    }
}
```

Request Body Explanation

| Parameter                     | Type     | Mandatory | Description                                                               |
| ----------------------------- | -------- | --------- | ------------------------------------------------------------------------- |
| `order.invoice_number`        | `string` | Mandatory | Invoice number of the transaction that being refunded                     |
| `payment.original_request_id` | `string` | Mandatory | Request ID from payment initiation of the transaction that being refunded |
| `refund.amount`               | `number` | Mandatory | Transaction amount that wants to be refunded                              |

**API Response**

After hitting the above API request, DOKU will give the response.

| Type            | Value   |
| --------------- | ------- |
| **HTTP Status** | 200     |
| **Result**      | SUCCESS |

Here is the sample response header:

```
Client-Id: MCH-0001-10791114622547
Request-Id: 6cc9f8b1-d83d-4c24-b853-a3223f43a744
Response-Timestamp: 2020-08-11T08:45:42Z
Signature: HMACSHA256=1jap2tpgvWt83tG4J7IhEwUrwmMt71OaIk0oL0e6sPM=
```

Response Header Explanation

| Parameter              | Description                                                   |
| ---------------------- | ------------------------------------------------------------- |
| **Client-Id**          | Same as the request                                           |
| **Request-Id**         | Same as the request                                           |
| **Response-Timestamp** | Timestamp Response on UTC with format ISO8601 UTC+0 from DOKU |
| **Signature**          | Signature generated by DOKU based on the response body        |

Here is the sample of successful response body:

```
{
    "order": {
        "invoice_number": "INV-20210118-0001"
    },
    "payment": {
        "original_request_id": "b266c265-3d61-4708-9860-c0d5b9a98f8c"
    },
    "refund": {
        "amount": 90000,
        "type": "FULL_REFUND",
        "status": "SUCCESS",
        "message": "Approved",
        "approval_code": "12321"
    }
}
```

Here is the sample of **failed** response body:

```json
{
    "order": {
        "invoice_number": "saweran_rest_api_2"
    },
    "payment": {
        "original_request_id": "5450"
    },
    "refund": {
        "amount": 20000,
        "reason": "REFUND TEST",
        "type": "FULL_REFUND",
        "status": "FAILED"
    },
    "error": {
        "code": "PAYMENT_FAILED",
        "message": "Total Refund amount is Bigger than Original Transaction",
        "type": "Payment Failed"
    }
}
```

Response Body Explanation

| Parameter                     | Type     | Mandatory | Description                                                                                                                                                    |
| ----------------------------- | -------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `order.invoice_number`        | `string` | Mandatory | Same as the request                                                                                                                                            |
| `payment.original_request_id` | `string` | Mandatory | Same as the request                                                                                                                                            |
| `refund.amount`               | `number` | Mandatory | Same as the request                                                                                                                                            |
| `refund.type`                 | `string` | Mandatory | <p>Refund type based on the transaction<br>Possible value: <code>VOID, PARTIAL\_REFUND, FULL\_REFUND, MANUAL\_PARTIAL\_REFUND, MANUAL\_FULL\_REFUND</code></p> |
| `refund.status`               | `string` | Mandatory | <p>Refund status<br>Possible value: <code>SUCCESS, FAILED</code></p>                                                                                           |
| `refund.message`              | `string` | Optional  | Refund message description                                                                                                                                     |
| `refund.approval_code`        | `string` | Optional  | Acquiring approval code for the refund transaction if the `refund.status` = `SUCCESS`                                                                          |

{% hint style="info" %}
**Refund Type**

**Online Refund**

Amount will be returned automatically by system to customer's balance

* **VOID**: If the funds has not settled to your bank account. The `refund.amount` must equal to `order.amount`, otherwise will fail
* **PARTIAL\_REFUND**: If the funds has settled to your bank account, and the `refund.amount` is less than `order.amount`
* **FULL\_REFUND**: If the funds has settled to your bank account, and the `refund.amount` is equal to `order.amount`

**Manual Refund**

Amount will be processed manually by DOKU's Refund Ops, may take several days to process

* **MANUAL\_PARTIAL\_REFUND**: If the funds has settled to your bank account, and the `refund.amount` is less than `order.amount`
* **MANUAL\_FULL\_REFUND**: If the funds has settled to your bank account, and the `refund.amount` is equal to `order.amount`

{% endhint %}
