Token

It is a piece of information that is created by the Payguru Platform • dedicated for a single merchant • valid for a limited period and enables merchant to access the Payguru Platform for queries and notifications. It is used in all the integration steps as an authentication parameter for the merchant.

Get

Merchant receives the token created by Payguru Platform through this web service.

>URL
 https://api.payguru.com/phs/getToken
>HTTP Method
GET or POST
>Parameters
FieldTypeDescription
merchantInteger - RequiredMerchant ID
keyString - Requiredmd5(Merchant ID + Server IP + Merchant Key)

>Success
FieldTypeDescription
statusStringStatus Code: 000
messageStringMessage
tokenStringAPI Token

>Error
FieldTypeDescription
statusStringStatus Code: #See
messageStringMessage

>Examples for Responses
{
    "status": "000",
    "message": "Success",
    "token": "{3E53E639-5173-D1B6-9368-68FCBCF72342}"
}
{
    "status": "ERR_007",
    "message": "Invalid Request:key not true"
}

>Sample Codes
curl -X GET --globoff "https://api.payguru.com/phs/getToken?merchant=123&key=MD5String"
<?php
$curl = curl_init();
$url = "https://api.payguru.com/phs/getToken";
$data = [
    "merchant" => "123",
    "key" => md5("123" . "123.123.123.123" . "MERCHANT KEY"),
];

curl_setopt_array($curl, array(
  CURLOPT_URL => $url."?".http_build_query($data),
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  echo "cURL Error #:" . $err;
} else {
  $o = json_decode($response,true);
  if($o["status"] == "000"){
      echo $o["token"];
  }else{
      echo $o["message"];
  }
}
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] btr = Encoding.UTF8.GetBytes("123" + "123.123.123.123" + "MERCHANT KEY");
btr = md5.ComputeHash(btr);
StringBuilder sb = new StringBuilder();
foreach (byte ba in btr)
{
    sb.Append(ba.ToString("x2").ToLower());
}
var client = new RestClient("https://api.payguru.com/phs/getToken
                    ?merchant=123&key=" + sb.ToString());
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
var o = JObject.Parse(response);
if (o["status"] == "000") {
    MessageBox.Show((string)o["token"]);
} else {
    MessageBox.Show((string)o["message"]);
}
import requests,json,md5
m = md5.new()
m.update("123" + "123.123.123.123" + "MERCHANT KEY".encode("utf-8"))
url = "https://api.payguru.com/phs/getToken"
querystring = {"merchant":"123","key":m.hexdigest()}
headers = {
}
response = requests.request("GET", url, headers=headers, params=querystring)
if response.status_code == 200:
    o = json.loads(response.text)
    if o["status"] == "000":
        print o["token"]
    else:
        print o["message"]
else:
    print "Request Error"

Check

Merchant may use this service in order to check if the token is still valid or expired. If the token is expired, merchant is expected to call the GET service again to receive a new token.

>URL
 https://api.payguru.com/phs/getToken/check
>HTTP Method
GET or POST
>Parameters
FieldTypeDescription
merchantInteger - RequiredMerchant ID
tokenString - RequiredToken

>Success
FieldTypeDescription
statusStringStatus Code: 000
messageStringMessage

>Error
FieldTypeDescription
statusStringStatus Code: #See
messageStringMessage

>Response Examples
{
    "status": "000",
    "message": "Success",
}
{
    "status": "ERR_016",
    "message": "Invalid Token"
}

>Sample Codes
curl -X GET --globoff "https://api.payguru.com/phs/getToken/check?merchant=123&token={123-123-123}"
<?php
$curl = curl_init();
$url = "https://api.payguru.com/getToken/check";
$data = [
    "merchant" => "123",
    "token" => "{123-123-123}" ,
];

curl_setopt_array($curl, array(
  CURLOPT_URL => $url."?".http_build_query($data),
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  echo "cURL Error #:" . $err;
} else {
  $o = json_decode($response,true);
  if($o["status"] == "000"){
      echo "Valid Token";
  }else{
      echo $o["message"];
  }
}
var client = new RestClient("https://api.payguru.com/phs/getToken/check
                    ?merchant=123&token={123-123-123}");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
var o = JObject.Parse(response);
if (o["status"] == "000") {
    MessageBox.Show("Valid Token");
} else {
    MessageBox.Show((string)o["message"]);
}
import requests,json
url = "https://api.payguru.com/phs/getToken/check"
querystring = {"merchant":"123","token":"{123-123-123}"}
headers = {
}
response = requests.request("GET", url, headers=headers, params=querystring)
if response.status_code == 200:
    o = json.loads(response.text)
    if o["status"] == "000":
        print "Valid Token"
    else:
        print o["message"]
else:
    print "Request Error"