API mPayment
- 20 Jan 2022
- 3 Minutes to read
- Contributors
- Print
- DarkLight
- PDF
API mPayment
- Updated on 20 Jan 2022
- 3 Minutes to read
- Contributors
- Print
- DarkLight
- PDF
Article summary
Did you find this summary helpful?
Thank you for your feedback
Request message
Input request parameter | Description |
Merchant Authentication Token | Y2ExNzE2NDBlZjEyNmZhZjRmMmRmY2Iy |
MessageID | 9 |
TransactionID | 12345678901234567890 |
MerchantID | STSPayOneM |
Amount | 2000 |
PaymentMethod | 1 |
CurrencyISOCode | 840 |
CardNumber | 4111111111111111 |
ExpiryDateYear | 22 |
ExpiryDateMonth | 01 |
SecurityCode | 854 |
PaymentDescription | Sample Payment |
ClientIPaddress | 188.888.50.125 |
Parameters Order | |
Amount, CardNumber, ClientIPaddress, CurrencyISOCode, ExpiryDateMonth, Note: The parameters are ordered alphabetically in the secure hash. | |
The input to the Secure Hash generation routine | |
Y2ExNzE2NDBlZjEyNmZhZjRmMmRmY2Iy20004111111111111111188.888.50.1258400122ST | |
Output | |
899f3b541f659fc2c1e2254905d6beb640189dd0af5f46fa50139afc485a9ebc |
Response message
Input response parameter | Description |
Merchant Authentication Token | Y2ExNzE2NDBlZjEyNmZhZjRmMmRmY2Iy |
Response.MessageID | 9 |
Response.TransactionID | 12345678901234567890 |
Response.StatusCode | 00000 |
Response.StatusDescription | Payment processed successfully |
Response.GatewayStatusCode | 0000 |
Response.GatewayName | TestGateway |
Response.Amount | 2000 |
Response.CurrencyISOCode | 840 |
Response.MerchantID | STSPayOneM |
Response.PaymentMethod | 1 |
Parameters Order | |
Response.Amount, Response.CurrencyISOCode, Response.GatewayName, Note: The parameters are ordered alphabetically in the secure hash. | |
The input to the Secure Hash generation routine | |
Y2ExNzE2NDBlZjEyNmZhZjRmMmRmY2Iy2000840TestGateway0000STSPayOneM9100000 Payment+processed+successfully12345678901234567890 | |
Output | |
0c14aaf3a5bf8ca4c93b79cde4e91b8627bdcee34cffbe2f38a0e803b8fde862 |
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("TransactionID", transactionId);
parameters.put("MerchantID", "ANBRedirectM");
parameters.put("Amount", "2000");
parameters.put("CurrencyISOCode", "840");
parameters.put("MessageID", "9");
parameters.put("Quantity", "1");
parameters.put("Channel", "0");
parameters.put("PaymentMethod", "1");
parameters.put("ClientIPaddress", "127.0.0.1");
//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");
//for Sadad Payment (conditional;paymentMethod=2)
//parameters.put("SadadOlpId", "testSadad");
//parameters.put("mfu","https://MerchantSite/RedirectPaymentRequestPage");
//fill some optional parameters
parameters.put("Language", "en");
parameters.put("ThemeID", "1000000001");
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 Request Code (.Net /PHP)
Sample Code (.Net)
1. String SECRET_KEY = "Y2FkMTdlOWZiMzJjMzY4ZGFkMzhkMWIz"; // Use Yours,
Please Store Your Secret Key in safe Place(eg.database)
2. // put the parameters in a SortedDoctionary to have the parameters to have
them sorted alphabetically.
3. SortedDictionary<string, string> parameters = new SortedDictionary<String,
String>(StringComparer.Ordinal);
4.
5. long
transactionId = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond); //getting
time in milliseconds
6.
7. // fill required parameters
8. parameters.Add("TransactionID", transactionId.ToString());
9. parameters.Add("MerchantID", "ANBRedirectM");
10. parameters.Add("Amount", "2000");
11. parameters.Add("CurrencyISOCode", "840");
12. parameters.Add("MessageID", "8");
13. parameters.Add("Quantity", "1");
14. parameters.Add("Channel", "0");
15. parameters.Add("PaymentMethod", "1");
16. parameters.Add("ClientIPaddress", "127.0.0.1");
17. //for Card Payment (conditional;paymentMethod=1)
18. parameters.Add("CardNumber", "4012001045873335");
19. parameters.Add("ExpiryDateYear", "01");
20. parameters.Add("ExpiryDateMonth", "19");
21. parameters.Add("SecurityCode", "123");
22. parameters.Add("CardHolderName", "1");
23. //for Sadad Payment (conditional;paymentMethod=2)
24. //parameters.Add("SadadOlpId", "testSadad");
25. //parameters.Add("mfu","https://MerchantSite/RedirectPaymentRequestP
age");
26. //fill some optional parameters
27. parameters.Add("Language", "en");
28. parameters.Add("ThemeID", "1000000001");
29. parameters.Add("Version", "1.0");
30. //Create an Ordered String of The Parameters SortedDictionary with
Secret Key
31. StringBuilder orderedString = new StringBuilder();
32. orderedString.Append(SECRET_KEY);
33. foreach (KeyValuePair<string, string> kv in parameters)
34. {
35. orderedString.Append(kv.Value);
36. }
37. Console.WriteLine("orderdString " + orderedString);
38.
39. // Generate SecureHash with SHA256
40. SHA256 sha256;
41. byte[] bytes, hash;
42. string secureHash = string.Empty;
43.
44. bytes = Encoding.UTF8.GetBytes(orderedString.ToString().ToString());
45. sha256 = SHA256Managed.Create();
46. hash = sha256.ComputeHash(bytes);
47. foreach (byte x in hash)
48. {
49. secureHash += String.Format("{0:x2}", x);
50. }
51.
52. Console.WriteLine("Secure Hash: " + secureHash.ToString());
53.
54.
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(eg. database)
4.
5. // put the parameters in a array to have the parameters sorted
alphabetically later via ksort.
6. $parameters = array();
7.
8. $transactionId = (int)(microtime(true)*1000); //time in milleseconds
9.
10. // fill required parameters
11. $parameters["TransactionID"] = $transactionId;
12. $parameters["MerchantID"] = "ANBRedirectM";
13. $parameters["Amount"] = "2000";
14. $parameters["CurrencyISOCode"] = "840";
15. $parameters["MessageID"] = "8";
16. $parameters["Quantity"] = "1";
17. $parameters["Channel"] = "0";
18. $parameters["PaymentMethod"] = "1";
19. $parameters["ClientIPaddress"] = "127.0.0.1";
20.
21. //for Card Payment (conditional;paymentMethod=1)
22. $parameters["CardNumber"] = "4012001045873335";
23. $parameters["ExpiryDateYear"] = "01";
24. $parameters["ExpiryDateMonth"] = "19";
25. $parameters["SecurityCode"] = "123";
26. $parameters["CardHolderName"] = "1";
27.
28. //for Sadad Payment (conditional;paymentMethod=2)
29. //$parameters["SadadOlpId"] = "testSadad";
30. //$parameters["mfu"] = "https://MerchantSite/RedirectPaymentRequestPage";
31.
32. //fill some optional parameters
33. $parameters["Language"] = "en";
34. $parameters["ThemeID"] = "1000000001";
35. $parameters["Version"] = "1.0";
36.
37.
38. //Create an Ordered String of The Parameters Map with Secret Key
39. ksort($parameters);
40. $orderedString = $SECRET_KEY;
41. foreach($parameters as $k=>$param){
42. $orderedString .= $param;
43. }
44.
45. echo "Ordered String: ".chr(10).$orderedString.chr(10);
46.
47. // Generate SecureHash with SHA256
48. $secureHash = hash('sha256', $orderedString, false);
49.