---
title: Refund
description: Initiate full or partial refunds for transactions via the API.
---

This API can be used to initiate refund from the merchant's platform. The partial and full refund can be requested. For partial amount, the amount needs to be filled by the merchant.

#### POST

```
https://kraken.airpay.co.in/airpay/pay/v4/api/refund/?token=<access_token>
```

## Header

| Parameter | Type Value | Description | Value Like |
| --- | --- | --- | --- |
| Content-Type  required | String | The Content-Type header indicates the media type of the request or response body so the receiver knows how to process the data. | `application/json` |

## Request Body

| Parameter | Type Value | Description | Value Like |
| --- | --- | --- | --- |
| mode  required | String | Mode "refund" | `refund` |
| transactions  optional | String | Base64 encoded refund JSON. Example data   ```  [{"ap_transactionid": 10265,"amount": "100.00"},{"ap_transactionid": 10264,"amount": "10.00"}]  ``` <br>base64 encoded transactions   ```  W3siYXBfdHJhbnNhY3Rpb25pZCI6IDEwMjY1LCJhbW91bnQiOiAiMTAwLjAwIn0seyJhcF90cmFuc2FjdGlvbmlkIjogMTAyNjQsImFtb3VudCI6ICIxMC4wMCJ9XQ==  ``` <br>ap_transactionid = airpay transaction reference number<br>amount = Full/Partial refund amount | `yJhbW91bnQiOiAiMTAwLjAwIiB9XQ==` |

## Success 200

| Parameter | Type Value | Description | Value Like |
| --- | --- | --- | --- |
| transactions  required | Object | List of transactions |
| ap_transactionid  required | Numeric | airpay transaction reference number | `3213213212` |
| success  required | String | Refund status<br>"true" = Successfully initiated refund.<br>"false" = Refund was not initiated. | `false` |
| message  required | String | can not be performed. Refund already initiated. refund message | `Refund` |
| refund_id  required | Numeric | Trfund reference number. | `12071` |
| mode  optional | String | Mode |

## PHP

```php
 <?php
$merchant_id   = "<merchant_id>";
$username      = "<username>";
$password      = "<password>";
$secret        = "<secret>";
$secretKey     = '<secretKey>';
$data = array();
$data['transactions'] =  base64_encode('[{"ap_transactionid": 10265,"amount": "100.00"},{"ap_transactionid": 10264,"amount": "10.00"}]');

$privatekey = hash('sha256', $secret.'@'.$username.':|:'.$password);
$encdata	   = encrypt(json_encode($data), $secretKey);
$checksum   = checksum($data);

$payload    = [
                'merchant_id'=>$merchant_id,
	            'encdata' => $encdata,
	            'checksum' => $checksum,
                'privatekey' => $privatekey
              ];

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://kraken.airpay.co.in/airpay/pay/v4/api/refund/?token=<access_token>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => $payload
));

$result = curl_exec($curl);

curl_close($curl);
$response = json_decode($result)->response;
```

### Success Response

```json
HTTP/1.1 200 OK
 {
    "status_code": "200",
    "response_code": "00",
    "status": "Success",
    "message": "success",
    "data": {
        "transactions": [
            {
                "ap_transactionid": 10265,
                "amount": "100.00",
                "success": "false",
                "message": "Refund can not be performed. Refund already initiated.",
                "refund_id": "12071"
            },
            {
                "ap_transactionid": "10264",
                "success": "true",
                "message": "Transaction accepted for refund",
                "refund_id": "12076"
            }
        ]
    }
}
```

### Error Response

```json
 HTTP/1.1 200 OK
 {
  {
    "status_code":"400",
    "response_code":501,
    "status":"fail",
    "message":"Invalid Merchant Id",
    "data":[]
   }
}
```