# 1. Get Payment URL

### Swagger Link

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

```shortcode
Production Base URL
```

{% endtab %}

{% tab title="Sandbox" %}

```
Sandbox Base URL
```

{% endtab %}
{% endtabs %}

### API Endpoints

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

```
Production Base URL /api/GenToken/Validate
```

{% endtab %}

{% tab title="Sandbox Endpoint" %}

<pre><code><strong>Sandbox Base URL /api/GenToken/Validate
</strong></code></pre>

{% endtab %}
{% endtabs %}

#### **Sample Request & Response**

Use the below parameters and hashing function for order creation. The request should contain the following inputs to make sure inputs should be encrypted using our hashing function show in the following example to prevent exposure. For parameters description please refer [here](https://checkoutdocs.oneglobal.com/parameters-and-description)

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

```coffeescript
"ValidatePaymentRequest" : {
  "merchantCode": "xxxxx"    
  "authKey": "xxxxxxxxx",
  "currency": "KWD",   
  "pc": "KWKFHMPGSCCKWD",  
  "tunnel": "",    
  "amount": 1 ,   
  "doConvert": "N",
  "sourceCurrency":"conditional",
  "description": "optional",
  "referenceID": "(15 digit random number)",     
  "timeStamp": "yyyy/MM/dd HH:mm:ss tt",
  "language": "en",
  "callbackURL": "Your website URL",
  "hash": "ComputedHash",  
  "userReference": 0,   
  "billingDetails": 
  {
  "fName": "First Name",
  "lName": "last Name",
  "mobile": "mobile",
  "email": "email",
  "city": "city",
  "pincode": "pincode",
  "state": "state",
  "address1": "address1",
  "address2": "address2"
  }
}
```

{% endtab %}

{% tab title="Sample Response" %}

```
{
  "errorCode": 0,
  "errorMessgae": "string",
  "result": 
  {
    "redirectURL": "string",
    "tokenID": "string",    
    "orderAmount": 0,
    "paidAmount": 0,
    "serviceAmount": 0,
    "commissionAmount": 0,   
    "originalAmount": "string"
  }
}
```

{% endtab %}
{% endtabs %}

### **Sample Code to post data**

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

<pre class="language-csharp"><code class="lang-csharp"><strong>public async Task> ValidatePayment(ValidatePaymentRequest obj)
</strong>  {
  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;
  }
</code></pre>

{% endtab %}

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

```objectivec
  Class SurroundingClass
  Public Task As async
  
  Private Sub New(ByVal obj As ValidatePaymentRequest)
  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
<?php
// store order id
$order = 12 xxxx;
// referenceID must be 15 digit unique number
$referenceID = 123456412250000;
$timestamp = date( "y/m/d H:m:s t" );
// referenceID must be 10 digit unique number
$userReference = 1234564122;
$amount = 20.50;
$authKey = 'Your Authorization Key';
$merchantID = 'Your Merchent Key';
$currency = 'KWD';
// it should be ALL for all payment methods or specific payment method code i.e KNET
$paymentMethodCode = 'KNET';
// it will be null if store currency is same as your merchant currency.
$sourceCurrency = "";
// It will be Y if source currency and merchant currency is different
$doConvert = 'N';
// Concat all data string 
$datatocomputeHash = ( float )$amount . $authKey . $currency . $merchantID . $paymentMethodCode . ( int )$referenceID . $sourceCurrency . $timestamp . $tunnel . ( int )$userReference;
// 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,
  'currency' => $paymentMethodCurrency,
  'pc' => $paymentMethodCode,
  'tunnel' => $tunnel,
  'amount' => ( float )$amount,
  'doConvert' => $doConvert,
  'sourceCurrency' => $sourceCurrency,
  'description' => $description,
  'referenceID' => ( int )$ref,
  'timeStamp' => $timestamp,
  'language' => 'en',
  'callbackURL' => 'https://www.example.com',
  'hash' => $hash,
  'userReference' => ( int )$userReference,
  'billingDetails' => array(
    'fName' => 'First Name',
    'lName' => 'Last Name',
    'mobile' => '0000000000',
    'email' => 'abcd@gmail.com',
    'city' => 'city',
    'pincode' => '000000',
    'state' => 'State',
    'address1' => 'Address 1',
    'address2' => 'Address 2'
  ),
);
$request = json_encode( $data, true );
if ( !$endpoint ) {
  $curl = curl_init( 'https://ogcheckoutstage.oneglobal.com/OgPay/V1/api/GenToken/Validate' );
} 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" %}

```typescript
pagecode:` public async Task> ValidatePayment(ValidatePaymentRequest 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 %}

###
