# 5. Refund Request

### API Endpoints

{% tabs %}
{% tab title="Production" %}

```
Production Base URL /api/GenToken/Refund
```

{% endtab %}

{% tab title="Sandbox" %}

```
Sandbox Base URL /api/GenToken/Refund
```

{% endtab %}
{% endtabs %}

### **Sample Request & Response**

{% tabs %}
{% tab title="Sample Request" %}

```coffeescript
{
    "merchantCode":"xxxxx",
    "authKey":"xxxxxxxxx",
    "ReferenceID":"(15 digit number passing during the payment creation)",
    "hash":"ComputedHash(To be calculated as described below)",
    "Amount":1,
    "Description":"optional",
    "RequestedBy":"optional"
}
```

{% endtab %}

{% tab title="Sample Response" %}

```
{
    "errorCode": 0 is Success 1 is Failed,
    "errorMessgae": "Message",
    "Result":
    {
    "IsRefunded":"1 is refunded | 2 is under process | 0 is rejected"
    }
}
```

{% endtab %}
{% endtabs %}

### Hash Creation

Use the below string format to generate an hash value using Hashing Key.

Amount + AuthenticationKey + MerchantCode + ReferenceID

### **Response Parameters**

| Parameters           | Data Type | Description                                                   |
| -------------------- | --------- | ------------------------------------------------------------- |
| errorCode            | Integer   | 0 is success 1 is failed and 2 is initiated for manual refund |
| `errorMessage`       | String    |                                                               |
| result -> IsRefunded | Integer   | 1 is refunded \| 2 is under process \| 0 is rejected          |

Merchant will receive an email from Og regarding the updates (under process, cancelled and refunded) of refund.

**Sample Code to post data**

{% tabs %}
{% tab title="C#" %}

```
public async Task> RefundPayment(RefundPaymentRequest obj)
  {
  Output dto = new Output();
  var url = {Provided End Point};
  var client = new HttpClient();
  client.BaseAddress = new Uri(url);
  try
  {
  obj.hash = ComputeHash(obj);
  var resultser = JsonConvert.SerializeObject(obj);
  client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
  client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
  var response = client.PostAsJsonAsync(url, obj).Result;
  if (response.IsSuccessStatusCode)
  {
  var ss = response.Content.ReadAsStringAsync();
  var result = JsonConvert.DeserializeObject>(ss.Result);
  dto = result;
  }
  else
  {
  var ss = response.Content.ReadAsStringAsync();
  var resps = ss.Result.ToString();
  }
  }
  catch (HttpRequestException ex)
  {
  }
  return dto;
  }
```

{% endtab %}

{% tab title="VB.Net" %}

```
 Class SurroundingClass
  Public Task As async
  
  Private Sub New(ByVal obj As RefundPaymentRequest )
  Dim dto As Output = New Output()
  Dim url = {Provided End Point};
  Dim client = New HttpClient()
  client.BaseAddress = New Uri(url)
  
  Try
  obj.hash = ComputeHash(obj)
  Dim resultser = JsonConvert.SerializeObject(obj)
  client.DefaultRequestHeaders.Accept.Add(New System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"))
  client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8")
  Dim response = client.PostAsJsonAsync(url, obj).Result
  
  If response.IsSuccessStatusCode Then
  Dim ss = response.Content.ReadAsStringAsync()
  Dim result = JsonConvert.DeserializeObject > (ss.Result)
  dto = result
  Else
  Dim ss = response.Content.ReadAsStringAsync()
  Dim resps = ss.Result
  Dim resultse = JsonConvert.SerializeObject(resps.ToString())
  End If
  
  Catch ex As HttpRequestException
  End Try
  
  Return dto
  End Sub
  End Class
```

{% endtab %}

{% tab title="PHP" %}

```
<?php

// referenceID must be 15 digit Payment Number
$referenceID = 123456412250000;

$amount = 20.50;
$authKey = 'Your Authorization Key';
$merchantID = 'Your Merchent Key';
// Concat all data string 
$datatocomputeHash = ( float )$amount . $authKey  . $merchantID . $referenceID ;
// convert the concated string in to hash and convert all string in upper character. 
$hash = strtoupper( hash_hmac( "sha256", $datatocomputeHash, $secretkey ) );
$data = array(
  'merchantCode' => $merchantID,
  'authKey' => $authKey,
  'hash' => $hash
  'amount' => ( float )$amount,
  'description' => $description,
  'RequestedBy' => $RequestedBy,
);
$request = json_encode( $data, true );
if ( !$endpoint ) {
  $curl = curl_init( 'Provided End Point' );
} else {
  $curl = curl_init( $endpoint );
}
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $request );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Content-Type:application/json' ) );
$ch = curl_exec( $curl );
curl_close( $curl );
$response = json_decode( $ch, true );
?>
```

{% endtab %}

{% tab title="TypeScript" %}

```
pagecode:` public async Task> RefundRequest(RefundPaymentRequest obj)
  {
  Output dto = new Output();
  var url = {Provided End Point};
  var client = new HttpClient();
  client.BaseAddress = new Uri(url);
  try
  {
  obj.hash = ComputeHash(obj);
  var resultser = JsonConvert.SerializeObject(obj);
  client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
  client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
  var response = client.PostAsJsonAsync(url, obj).Result;
  if (response.IsSuccessStatusCode)
  {
  var ss = response.Content.ReadAsStringAsync();
  var result = JsonConvert.DeserializeObject>(ss.Result);
  dto = result;
  }
  else
  {
  var ss = response.Content.ReadAsStringAsync();
  var resps = ss.Result;
  var resultse = JsonConvert.SerializeObject(resps.ToString());
  
  }
  }
  catch (HttpRequestException ex)
  {
  
  }
  
  return dto;
  
  }`;
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://checkoutdocs.oneglobal.com/sample-code/5.-refund-request.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
