Redirect Payment
  • 09 Mar 2022
  • 2 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Redirect Payment

  • Dark
    Light
  • PDF

Article summary

Request message  

Input request parameterDescription
Merchant Authentication Token
Y2ExNzE2NDBlZjEyNmZhZjRmMmRmY2Iy
MessageID1
TransactionID12345678901234567890
MerchantIDSTSPayOneM
Amount100
LanguageEn
CurrencyISOCode400
PaymentDescriptionSample Payment Description
ResponseBackURLhttps://MerchatWebSite/PaymentResponse.do 
ThemeIDtheme1
Channel0
Quantity1
Version1.0
Parameters Order
Amount, Channel, CurrencyISOCode, Language, MerchantID, MessageID, 

PaymentDescription, Quantity, ResponseBackURL, ThemeID, TransactionID, Version 

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

Y2ExNzE2NDBlZjEyNmZhZjRmMmRmY2Iy1000400EnSTSPayOneM1Sample+Payment+Descri
ption1https://MerchatWebSite/PaymentResponse.dotheme1123456789012345678901.0 

Output
ddf2b07b95a3d93cc1ba6cd38dc69dbc1cf36819aa0bf83f549c827f98e6a84f

Response message

Input response parameterDescription
Merchant Authentication TokenY2ExNzE2NDBlZjEyNmZhZjRmMmRmY2Iy
Response.MessageID1
Response.TransactionID12345678901234567890
Response.StatusCode00000
Response.StatusDescriptionPayment processed successfully
Response.GatewayStatusCode0000
Response.GatewayNameTestGateway
Response.GatewayStatusDescriptionSample Gateway Description
Response.Amount100
Response.ApprovalCode654321
Response.CardExpiryDate0416
Response.CardHolderNameCard Holder
Response.CurrencyISOCode400
Response.CardNumber400555******0001
Response.MerchantIDSTSPayOneM
Response.RRN123456
Response.AuthorizedCurrencyISOCode400
Response.AuthorizedAmount100
Parameters Order
Response.Amount, Response.ApprovalCode, Response.AuthorizedAmount, 

Response.AuthorizedCurrencyISOCode,Response.CardExpiryDate,
Response.CardHolderName, Response.CardNumber,  Response.CurrencyISOCode,
Response.GatewayName, Response.GatewayStatusCode,
Response.GatewayStatusDescription, Response.MerchantID, Response.MessageID,
Response.RRN, Response.StatusCode, Response.StatusDescription, Response.TransactionID 

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

Y2ExNzE2NDBlZjEyNmZhZjRmMmRmY2Iy1006543211004000416Card
Holder
400555******0001400TestGateway0000Sample+Gateway+DescriptionSTSPayOneM11
23456
00000Payment+processed+successfully12345678901234567890 

Output
6c4ef5c7365a15c88eee33cc0b90cd045b3bb548310107695f9e7d1ee71ce8f2

Sample Code (Java)

//Step 1: Generate Secure Hash 
String SECRET_KEY = "Y2FkMTdlOWZiMzJjMzY4ZGFkMzhkMWIz"; // Use Yours, Please Store Your 
Secret Key in safe Place (eg. 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("TransactionID", transactionId); 
parameters.put("MerchantID", "ANBRedirectM"); 
parameters.put("Amount", "2000"); 
parameters.put("CurrencyISOCode", "840"); 
parameters.put("MessageID", "1"); 
parameters.put("Quantity", "1"); 
parameters.put("Channel", "0"); 
 
//fill some optional parameters 
parameters.put("Language", "en"); 
parameters.put("ThemeID", "1000000001"); 
parameters.put("ResponseBackURL", "https://MerchantSite/RedirectPaymentResponsePage");// if 
this url is configured for the merchant it's not required 
parameters.put("Version", "1.0"); 
 
 
 
//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 Sample Code (.Net /PHP)

Sample Code (.Net)

1.   //Step 1: Generate Secure Hash 
2.  String SECRET_KEY = "Y2FkMTdlOWZiMzJjMzY4ZGFkMzhkMWIz"; // Use Yours, Please Store 
Your Secret Key in safe Place (eg.database) 
3.    
4.          // put the parameters in a SortedDoctionary to have the parameters to have 
them sorted alphabetically. 
5.          SortedDictionary<string, string> parameters = new SortedDictionary<String,
 String>(StringComparer.Ordinal); 
6.   
7.          //getting time in milliseconds 
8.   
9.          Long transactionId = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);  
10.                  
11.          // fill required parameters 
12.          parameters.Add("TransactionID", transactionId.ToString()); 
13.    
14.          parameters.Add("MerchantID", "ANBRedirectM"); 
15.          parameters.Add("Amount", "2000"); 
16.          parameters.Add("CurrencyISOCode", "840"); 
17.          parameters.Add("MessageID", "1"); 
18.          parameters.Add("Quantity", "1"); 
19.          parameters.Add("Channel", "0"); 
20.          //fill some optional parameters 
21.          parameters.Add("Language", "en"); 
22.          parameters.Add("ThemeID", "1000000001"); 
23.          parameters.Add("ResponseBackURL", "https://MerchantSite/RedirectPaym
entResponsePage");// if this url is configured for the merchant it's not required 
24.          parameters.Add("Version", "1.0"); 
25.    
26.          //Create an Ordered String of The Parameters Dictionary with Secret 
Key 
27.          StringBuilder orderedString = new StringBuilder(); 
28.          orderedString.Append(SECRET_KEY); 
29.          foreach (KeyValuePair<string, string> kv in parameters) 
30.          { 
31.              orderedString.Append(kv.Value); 
32.          } 
33.          Console.WriteLine("orderdString: " + orderedString); 
34.    
35.          // Generate SecureHash with SHA256 
36.          SHA256 sha256; 
37.          byte[] bytes, hash; 
38.          string secureHash = string.Empty; 
39.    
40.          bytes = Encoding.UTF8.GetBytes(orderedString.ToString().ToString()); 
41.          sha256 = SHA256Managed.Create(); 
42.          hash = sha256.ComputeHash(bytes); 
43.          foreach (byte x in hash) 
44.          { 
45.              secureHash += String.Format("{0:x2}", x); 
46.          } 

Sample Code (PHP)

1.        $PAYONE_SECRET_KEY = "Y2FkMTdlOWZiMzJjMzY4ZGFkMzhkMWIz"; // Use Yours, 
Please Store Your Secret Key in safe Place(eg. database) 
2.        $transaction_id = (int)(microtime(true)*1000); //time in milleseconds 
3.    
4.        $parameters = array(); 
5.        // fill required parameters 
6.        $parameters['TransactionID'] = $transaction_id; //TMP: 
7.        $parameters['MerchantID'] = "ANBRedirectM"; 
8.        $parameters['Amount'] = "2000"; 
9.        $parameters['CurrencyISOCode'] = "840"; 
10.  $parameters['MessageID'] = "1"; 
11.  $parameters['Quantity'] = "1"; 
12.  $parameters['Channel'] = "0"; 
13.  //fill some optional parameters 
14.  $parameters['Language'] = "en"; 
15.  $parameters['ThemeID'] = "1000000001"; 
16.  $parameters['ResponseBackURL'] = "https://MerchantSite/RedirectPaymentRespon
sePage";// if this url is configured for the merchant it's not required 
17.  $parameters['Version'] = "1.0"; 
18.    
19.  //Create an Ordered String of The Parameters string with Secret Key by ksort 
20.  ksort($parameters); 
21.  $orderedString = $PAYONE_SECRET_KEY; 
22.  foreach($parameters as $k=>$param){ 
23.      $orderedString .= $param; 
24.  } 
25.  echo "orderdString: " .$orderedString.chr(10); 
26.    
27.  // Generate SecureHash with SHA256 
28.  $secureHash = hash('sha256', $orderedString, false);