Advertisement
Tashfikk

Untitled

Sep 20th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. var request = require("request");
  2. var appKey="5tunt4masn6pv2hnvte1sb5n3j";
  3. var password="hWD@8vtzw0";
  4. var username="sandboxTestUser";
  5. var appSecret="1vggbqd4hqk9g96o9rrrp2jftvek578v7d2bnerim12a87dbrrka";
  6. var invoiceNumber="mINV00002";
  7. var amount="50";
  8.  
  9.  
  10. var options = { method: 'POST',
  11. url: 'https://checkout.sandbox.bka.sh/v1.0.0-beta/checkout/token/grant',
  12. headers:
  13. { password: password,
  14. username: username },
  15. body:
  16. { app_key: appKey,
  17. app_secret: appSecret },
  18. json: true };
  19.  
  20. request(options, function (error, response, body) {
  21. if (error) throw new Error(error);
  22. console.log("Get Auth");
  23. console.log("-------------------------------------------");
  24. console.log(body);
  25.  
  26. createPayment(body.id_token);
  27.  
  28. });
  29.  
  30.  
  31.  
  32. function createPayment(authorizationKey){
  33.  
  34.  
  35.  
  36. var options = { method: 'POST',
  37. url: 'https://checkout.sandbox.bka.sh/v1.0.0-beta/checkout/payment/create',
  38. headers:
  39. { 'x-app-key': appKey,
  40. authorization: authorizationKey
  41. },
  42. body:
  43. {
  44.  
  45. merchantInvoiceNumber: invoiceNumber,
  46. intent: 'Sale',
  47. currency: 'BDT',
  48. amount: amount },
  49. json: true };
  50.  
  51. request(options, function (error, response, body) {
  52. if (error) throw new Error(error);
  53.  
  54.  
  55. console.log("Create Payment");
  56. console.log("-------------------------------------------");
  57. console.log(body);
  58.  
  59.  
  60. executePayment(authorizationKey,body.paymentID);
  61.  
  62. });
  63.  
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. function executePayment(authorizationKey,paymentId){
  72.  
  73. var options = { method: 'POST',
  74. url: 'https://checkout.sandbox.bka.sh/v1.0.0-beta/checkout/payment/execute/'+paymentId,
  75. headers:
  76. { 'x-app-key': appKey,
  77. authorization:authorizationKey } };
  78.  
  79. request(options, function (error, response, body) {
  80. if (error) throw new Error(error);
  81. console.log("Execute Payment");
  82. console.log("-------------------------------------------");
  83. console.log(body);
  84.  
  85. queryPayment(paymentId,authorizationKey);
  86.  
  87. });
  88.  
  89.  
  90. }
  91.  
  92.  
  93.  
  94. function queryPayment(paymentId,authorizationKey){
  95.  
  96. var options = { method: 'GET',
  97. url: 'https://checkout.sandbox.bka.sh/v1.0.0-beta/checkout/payment/query/paymentId',
  98. headers:
  99. { 'x-app-key': 'appKey',
  100. authorization: 'authorizationKey' } };
  101.  
  102. request(options, function (error, response, body) {
  103. if (error) throw new Error(error);
  104. console.log("Query Payment");
  105. console.log("-------------------------------------------");
  106. console.log(body);
  107. });
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement