API Approve
  • 20 Jan 2022
  • 3 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

API Approve

  • Dark
    Light
  • PDF

Article summary

Request message

Input request parameterDescription
Merchant Authentication TokenY2ExNzE2NDBlZjEyNmZhZjRmMmRmY2Iy
MessageID 10
TransactionID12345678901234567890
MerchantIDSTSPayOneM
estn

cmdWd0xLS0dUU2JrZjJDTUhzczNKYXpPNUhCaGhuM1BITzYyUXZnTDZSMVNLQ
jk4NW9KOHVqYmhBZmM4ZWVKZS9mSGNmYytvVXhxUUVaY2xSendDSU9SMDFo
RmZ3eUl4MXBURXV5OStaU21VbVV5b3crODZKZzZ1VldmbVFHeWU2UTFSZ1R4
WHp4L1g3OG1ueHo4cVZDSWF5Rlp5VFFyUWNqVzFZenAvbkttYVpac3NsVDFWM
0FIUFR3MllLeE16RFdLQ0thbWlZVktrS2VEeE5HcysrN2JTYWo4MklCRUhmc1lRd
XRtU1VOak0yWm05ODFDeUdNRUlTTmxQOFROVlZYL25VTmkzUXUxWGxjeStoO
DdkRUF4amlhRTJTUml2R2VyT0NScE5WT01zKzlienhEYnFQcW5kNVY0THI4Vyt
ycEs0Z0t5VWNQR0h0ZDRDN2tOWTV3PT0=

PaymentMethod2
Parameters Order
MerchantID, MessageID, PaymentMethod, TransactionID, estn  
Note: The parameters are ordered alphabetically in the secure hash.
The input to the Secure Hash generation routine 

Y2ExNzE2NDBlZjEyNmZhZjRmMmRmY2IySTSPayOneM10212345678901234567890 cmdWd0xLS0dUU2JrZjJDTUhzczNKYXpPNUhCaGhuM1BITzYyUXZnTDZSMVNLQjk4NW9KOHV
qYmhBZmM4ZWVKZS9mSGNmYytvVXhxUUVaY2xSendDSU9SMDFoRmZ3eUl4MXBURXV5OS
taU21VbVV5b3crODZKZzZ1VldmbVFHeWU2UTFSZ1R4WHp4L1g3OG1ueHo4cVZDSWF5Rlp5V
FFyUWNqVzFZenAvbkttYVpac3NsVDFWM0FIUFR3MllLeE16RFdLQ0thbWlZVktrS2VEeE5Hcysr
N2JTYWo4MklCRUhmc1lRdXRtU1VOak0yWm05ODFDeUdNRUlTTmxQOFROVlZYL25VTmkzU
XUxWGxjeStoODdkRUF4amlhRTJTUml2R2VyT0NScE5WT01zKzlienhEYnFQcW5kNVY0THI4Vyt
ycEs0Z0t5VWNQR0h0ZDRDN2tOWTV3PT0= 

Output
460bd68a6c0a020408b55f3751184f39e9c537914d45b586f5960c1a1d3a66fe

Response message

Input response parameterDescription
Merchant Authentication TokenY2ExNzE2NDBlZjEyNmZhZjRmMmRmY2Iy
Response.MessageID 10
Response.TransactionID12345678901234567890
Response.StatusCode00000
Response.StatusDescriptionPayment processed successfully
Response.GatewayStatusCode0000
Response.GatewayNameTestGateway
Response.Amount2000
Response.CurrencyISOCode840
Response.MerchantID STSPayOneM
Parameters Order
Response.Amount, Response.CurrencyISOCode, Response.GatewayName, 

Response.GatewayStatusCode, Response.MerchantID, Response.MessageID,
Response.StatusCode, Response.StatusDescription, Response.TransactionID 

Note: The parameters are ordered alphabetically in the secure hash.
The input to the Secure Hash generation routine 

Y2ExNzE2NDBlZjEyNmZhZjRmMmRmY2Iy2000840TestGateway0000STSPayOneM1000000Pa
yment+processed+successfully12345678901234567890

Output
b8289e077922b40d382cd2275354d845811bc25f6ca13ea8d45420e3f5100229

Sample Code (Java)

//Step 1: Generate Secure Hash 
String SECRET_KEY = "Y2FkMTdlOWZiMzJjMzY4ZGFkMzhkMWIz"; // Use Yours, Please Store Your 
Secret Key in safe Place(e.g. database) 
 
// put the parameters in a TreeMap to have the parameters to have them sorted 
alphabetically. 
Map <String,String> parameters = new TreeMap<String,String> (); 
 
String transactionId=String.valueOf(System.currentTimeMillis()); 
 
// fill required parameters 
parameters.put("MessageID", "1"); 
parameters.put("TransactionID", transactionId); 
parameters.put("MerchantID", "ANBRedirectM"); 
parameters.put("PaymentMethod", "1"); 
 //it's real length is very longer than this this value is just a sample 
parameters.put("PARes", URLEncoder.encode("eJzFV2mTokoW/Ssd9T4a3ewiHZQvkh2","UTF-8")); 
 
//in case of sadad payment 
//parameters.put("estn", "Test123"); 
 
//for Card Payment (conditional;paymentMethod=1) 
parameters.put("CardNumber", "4012001045873335"); 
parameters.put("ExpiryDateYear", "01"); 
parameters.put("ExpiryDateMonth", "19"); 
parameters.put("SecurityCode", "123"); 
parameters.put("CardHolderName", "1"); 
 
//Create an Ordered String of The Parameters Map with Secret Key 
StringBuilder orderedString = new StringBuilder(); 
orderedString.append(SECRET_KEY); 
for (String treeMapKey : parameters.keySet()) { 
    orderedString.append(parameters.get(treeMapKey)); 
} 
 
System.out.println("orderdString "+orderedString); 
// Generate SecureHash with SHA256 
// Using DigestUtils from appache.commons.codes.jar Library 
String secureHash = new String(DigestUtils.sha256Hex(orderedString.toString()).getBytes()); 

Other Request Code (.Net /PHP)

Sample Code (.Net)

1.          String SECRET_KEY = "Y2FkMTdlOWZiMzJjMzY4ZGFkMzhkMWIz"; // Use Yours, Please 
Store Your Secret Key in safe Place(e.g.database) 
2.    
3.          // put the parameters in a SortedDictionary to have the parameters to have 
them sorted alphabetically. 
4.          SortedDictionary<string, string> parameters = new SortedDictionary<String, S
tring>(StringComparer.Ordinal); 
5.          
6.          long 
transactionId = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond); //getting time 
in milliseconds 
7.    
8.                // fill required parameters 
9.                parameters.Add("MessageID", "1"); 
10.          parameters.Add("TransactionID", transactionId.ToString()); 
11.          parameters.Add("MerchantID", "ANBRedirectM"); 
12.          parameters.Add("PaymentMethod", "1"); 
13.    
14.          //it's real length is very longer than this this value is just a 
sample 
15.          parameters.Add("PARes", HttpContext.Current.Server.UrlEncode("eJzFV2mT
okoW/Ssd9T4a3ewiHZQvkh2")); 
16.          //in case of sadad payment 
17.          //parameters.Add("estn", "Test123"); 
18.          //for Card Payment (conditional;paymentMethod=1) 
19.          parameters.Add("CardNumber", "4012001045873335"); 
20.          parameters.Add("ExpiryDateYear", "01"); 
21.          parameters.Add("ExpiryDateMonth", "19"); 
22.          parameters.Add("SecurityCode", "123"); 
23.          parameters.Add("CardHolderName", "1"); 
24.    
25.          //Create an Ordered String of The Parameters SortedDictionary with 
Secret Key 
26.          StringBuilder orderedString = new StringBuilder(); 
27.          orderedString.Append(SECRET_KEY); 
28.          foreach (KeyValuePair<string, string> kv in parameters) 
29.          { 
30.              orderedString.Append(kv.Value); 
31.          } 
32.          Console.WriteLine("orderdString " + orderedString); 
33.    
34.          // Generate SecureHash with SHA256 
35.          SHA256 sha256; 
36.          byte[] bytes, hash; 
37.          string secureHash = string.Empty; 
38.    
39.          bytes = Encoding.UTF8.GetBytes(orderedString.ToString().ToString()); 
40.          sha256 = SHA256Managed.Create(); 
41.          hash = sha256.ComputeHash(bytes); 
42.          foreach (byte x in hash) 
43.          { 
44.              secureHash += String.Format("{0:x2}", x); 
45.          } 
46.    
47.          Console.WriteLine("Secure Hash: " + secureHash.ToString()); 
48.    

Sample Code (PHP)

1.  <?php 
2.        //Step 1: Generate Secure Hash 
3.        $SECRET_KEY = "Y2FkMTdlOWZiMzJjMzY4ZGFkMzhkMWIz"; // Use Yours, Please Store 
Your Secret Key in safe Place(e.g. database) 
4.        // put the parameters in a TreeMap to have the parameters to have them sorted 
alphabetically. 
5.        $parameters = []; 
6.        $transactionId = (int)microtime(true)*1000; //output to be like: 1495004320389 
7.    
8.        // fill required parameters 
9.        $parameters["MessageID"] = "1"; 
10.  $parameters["TransactionID"] = $transactionId; 
11.  $parameters["MerchantID"] = "ANBRedirectM"; 
12.  $parameters["PaymentMethod"]  = "1"; 
13.    
14.  //it's real length is very longer than this this value is just a sample 
15.  $parameters["PARes"] = urlencode("eJzFV2mTokoW/Ssd9T4a3ewiHZQvkh2"); 
16.    
17.  //in case of sadad payment 
18.  //$_SESSION["estn"] = "Test123"; 
19.    
20.  //for Card Payment (conditional;paymentMethod=1) 
21.  $parameters["CardNumber"] = "4012001045873335"; 
22.  $parameters["ExpiryDateYear"] = "01"; 
23.  $parameters["ExpiryDateMonth"] = "19"; 
24.  $parameters["SecurityCode"] = "123"; 
25.  $parameters["CardHolderName"] = "1"; 
26.  ksort($parameters); 
27.    
28.  //Create an Ordered String of The Parameters Map with Secret Key 
29.  $orderedString = $SECRET_KEY; 
30.  foreach($parameters as $param) { 
31.   $orderedString .= $param; 
32.  } 
33.  echo ("orderdString " . $orderedString); 
34.    
35.  // Generate SecureHash with SHA256 
36.  $secureHash = hash('sha256', $orderedString, false); 
37.    

What's Next