# Refund API (/docs/api-documentation/complementary-apis/refund-api)



##### Overview [#overview]

The **Hubtel Refund API** allows you to refund monies to customers based on a previous order made. This document focuses on **Mobile money transactions Refund**.

> **Note**
> You can only refund transactions **within** the last **45 days** using this API. For older transactions, please send an email to [business@hubtel.com](mailto:business@hubtel.com).
<br />

##### Getting Started [#getting-started]

<br />

###### Business IP Whitelisting [#business-ip-whitelisting]

You must share your public IP address with your Retail System Engineer for whitelisting.

> **Note**
> All API Endpoints are live and only requests from whitelisted IP(s) can reach the endpoints shared in this reference.
<br />

##### API Reference [#api-reference]

This endpoint can be used to refund a successful mobile money transaction on your account. To initiate a request, send an HTTP **POST** request to the below URL with the required parameters. Passing your Collection Account Number for Refund requests in the endpoint is also mandatory. Find your **Collection Account Number** [here](/docs/get-started/programmable-api-keys?curr_idx=3).

|              |                                                                                                                                                                                              |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| API Endpoint | [https://refund-api.hubtel.com/refund/\{'\{Collection_Account_Number}'}/order/\{'\{orderId}'}](https://refund-api.hubtel.com/refund/\{'\{Collection_Account_Number}'}/order/\{'\{orderId}'}) |
| Request Type | **POST**                                                                                                                                                                                     |
| Content Type | **JSON**                                                                                                                                                                                     |

<br />

###### REQUEST PARAMETERS [#request-parameters]

| Parameter                 | Type   | Requirement | Description                                                                                                                 |
| ------------------------- | ------ | ----------- | --------------------------------------------------------------------------------------------------------------------------- |
| Collection_Account_Number | Number | Mandatory   | The merchant's Hubtel **Collection Account Number**. Find yours [here](/docs/get-started/programmable-api-keys?curr_idx=3). |
| OrderID                   | String | Mandatory   | This is the OrderID from Hubtel for the payment which was processed. Eg. b230733cd56b4a0fad820e39f66bc27c                   |
| CallbackURL               | String | Mandatory   | The callback URL to receive the final notification on the status of the payment                                             |

<br />

###### SAMPLE REQUEST [#sample-request]

**HTTP**

  ```http
  POST /refund/11684/order/79213a0568c44c13a8a04ba056d681 HTTP /1.1
  Host: refund-api.hubtel.com
  Accept: application/json
  Content-Type: application/json
  Authorization: Basic endjeOBiZa250fT3==
  Cache-Control: no-cache

  {
      "callbackUrl":"https://webhook.site/b503d1a9-e726-f315254a6ede"
  }
  ```

**cURL**

  ```bash
  curl --location 'https://refund-api.hubtel.com/refund/11684/order/79213a0568c44c13a8a04ba056d681' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Basic endjeOBiZa250fT3==' \
  --data '{
      "callbackUrl": "https://webhook.site/b503d1a9-e726-f315254a6ede"
  }'
  ```

**PHP**

  ```php
  <?php

  $curl = curl_init();

  curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://refund-api.hubtel.com/refund/11684/order/79213a0568c44c13a8a04ba056d681',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS =>'{
      "callbackUrl": "https://webhook.site/b503d1a9-e726-f315254a6ede"
  }',
    CURLOPT_HTTPHEADER => array(
      'Content-Type: application/json',
      'Authorization: Basic endjeOBiZa250fT3=='
    ),
  ));

  $response = curl_exec($curl);

  curl_close($curl);
  echo $response;
  ```

**Python**

  ```bash
  import requests
  import json

  url = "https://refund-api.hubtel.com/refund/11684/order/79213a0568c44c13a8a04ba056d681"

  payload = json.dumps({
    "callbackUrl": "https://webhook.site/b503d1a9-e726-f315254a6ede"
  })
  headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Basic endjeOBiZa250fT3=='
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)
  ```

**JS**

  ```javascript
  const myHeaders = new Headers();
  myHeaders.append("Content-Type", "application/json");
  myHeaders.append("Authorization", "Basic endjeOBiZa250fT3==");

  const raw = JSON.stringify({
    "callbackUrl": "https://webhook.site/b503d1a9-e726-f315254a6ede"
  });

  const requestOptions = {
    method: "POST",
    headers: myHeaders,
    body: raw,
    redirect: "follow"
  };

  fetch("https://refund-api.hubtel.com/refund/11684/order/79213a0568c44c13a8a04ba056d681", requestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.error(error));
  ```

<br />

###### RESPONSE PARAMETERS [#response-parameters]

| Parameter    | Type   | Description                                                                                                 |
| ------------ | ------ | ----------------------------------------------------------------------------------------------------------- |
| ResponseCode | String | The unique response code on the status of the request                                                       |
| Message      | String | The status of the request                                                                                   |
| Data         | Object | An object parameter that gives the details of the transaction whose status is being checked. ie. the order. |
| OrderId      | String | This isthe OrderId from Hubtel for the payment which was processed.                                         |

<br />

###### SAMPLE RESPONSE [#sample-response]

```js
{
  "message": "Transaction pending. Expect callback request for final state.",
  "responseCode": "0001",
  "data": {
      "orderId": "b230733cd56b4a0fad820e39f66bc27c"
  }
}
```

<br />

###### SAMPLE RESPONSE(Not Found) [#sample-responsenot-found]

```js
{
  "message": "Could not find order with ID 847ad350142a4970ac365d2294d3f3a5",
  "responseCode": "3000",
  "data": null
}
```

###### SAMPLE CALLBACK [#sample-callback]

```js
{
  "responseCode": "0000",
  "message": "Successful",
  "data": {
      "amount": 0.5,
      "charges": 0.01,
      "orderId": "a4e406711db74687bbd307ead23bd015",
      "externalTransactionId": "0000002673867446"
    }
}
```

<br />

##### Response Codes [#response-codes]

The Hubtel Refund API uses standard HTTP error reporting. Successful requests return HTTP status codes in the 2xx. Failed requests return status codes in 4xx and 5xx.

Response Codes are included in the JSON response body, which contains information about the error or status

| ResponseCode | Status | Description                                                                                                                                                                         |
| ------------ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 0001         | 202    | Transaction pending. Expect callback request for final state. Data contains order ID                                                                                                |
| 3000         | 404    | Could not find order with ID {'{orderId}'}. Data is null                                                                                                                            |
| 4000         | 404    | Cannot honour refund request because amount on order is less than 1 cedi. Data is **null**                                                                                          |
| 4509         | 404    | Order with ID {'{orderId}'} is not eligible for a refund. Data is null                                                                                                              |
| 4515         | 423    | Order with ID {'{orderId}'} is currently being processed. Please wait for callback on your supplied URL. This means you have made an initial refund request with the same order ID. |
