gaber-elsayed

Untitled

Mar 6th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. exports.GetPaymentUrl = function (connection , response ) {
  2.  
  3. AuthenticationRequest(function (recObj){
  4. // InsertGarbage("Finished the first step");
  5. CreateOrder(recObj , function (dataRecieved1){
  6. // InsertGarbage("data recived after the second step is"+dataRecieved1.orderId) ;
  7. CreatePaymentKey (dataRecieved1 , function(dataRecieved2){
  8. // var sendReq = require ('request') ;
  9.  
  10. // InsertGarbage("paytoc step3"+dataRecieved2.paymentToken) ;
  11.  
  12. var toSend = {
  13. "url" : "https://accept.paymobsolutions.com/api/acceptance/iframes/2260?payment_token="+dataRecieved2.paymentToken
  14. }
  15.  
  16. response.send(toSend) ;
  17. // var uri ="https://accept.paymobsolutions.com/api/acceptance/iframes/1995?payment_token="+dataRecieved2.paymentToken;
  18. // sendReq(uri,function (error, res, body) {
  19. // if (error)
  20. // console.log(error) ;
  21. // if (!error && res.statusCode == 200) {
  22. // console.log(body); // Print the google web page.
  23. // response.send(body);
  24. // }
  25.  
  26. // console.log(body);
  27. // }) ;
  28.  
  29. });
  30.  
  31. });
  32. });
  33. }
  34.  
  35. function AuthenticationRequest (callback){
  36. var unirest = require("unirest");
  37.  
  38. var req = unirest("POST", "https://accept.paymobsolutions.com/api/auth/tokens");
  39.  
  40. req.headers({
  41. "content-type": "application/json"
  42. });
  43.  
  44. req.type("json");
  45. req.send({
  46. "username": "Fast Forward",
  47. "password": "June2011$$",
  48. "expiration": "36000"
  49. });
  50.  
  51. req.end(function (res) {
  52. if (res.error) throw new Error(res.error);
  53. var SendObj = {
  54. "firstToken" : res.body.token ,
  55. "Mid" : res.body.profile.id
  56. }
  57.  
  58. // InsertGarbage ( "hello iam in the first step and this is the token" + SendObj.firstToken);
  59. callback(SendObj);
  60. });
  61.  
  62.  
  63. }
  64.  
  65.  
  66. function CreateOrder (data , callback) {
  67.  
  68. var unirest = require("unirest");
  69.  
  70. //var unirest = require("unirest");
  71.  
  72. var req = unirest("POST", "https://accept.paymobsolutions.com/api/ecommerce/orders");
  73.  
  74. req.query({
  75. "token": data.firstToken
  76. });
  77.  
  78. req.headers({
  79. "content-type": "application/json"
  80. });
  81.  
  82. req.type("json");
  83. req.send({
  84. "delivery_needed": "false",
  85. "merchant_id":data.Mid,
  86. "merchant_order_id": RandomStringGen(20),
  87. "amount_cents": "25000",
  88. "currency": "EGP",
  89. "items": [],
  90. "shipping_data":{
  91. "first_name": "test_user",
  92. "phone_number": "+201003978030",
  93. "last_name": "test_user",
  94. "email": "[email protected]",
  95. "apartment": "803",
  96. "floor": "42",
  97. "street": "sample street",
  98. "building": "4055",
  99. "postal_code": "33221",
  100. "country": "EG",
  101. "city": "Cairo"
  102. }
  103. });
  104.  
  105.  
  106. console.log("hello im here") ;
  107. req.end(function (res) {
  108. if (res.error) throw new Error(res.error);
  109. console.log("hello I came out") ;
  110. console.log(res.body);
  111. data["orderId"] = res.body.id ;
  112. callback(data) ;
  113. });
  114. }
  115.  
  116. function CreatePaymentKey(data , callback){
  117.  
  118. console.log("rec data is ", data) ;
  119. var unirest = require("unirest");
  120.  
  121. var req = unirest("POST", "https://accept.paymobsolutions.com/api/acceptance/payment_keys");
  122.  
  123. req.query({
  124. "token": data.firstToken
  125. });
  126.  
  127. //InsertGarbage ("the firunction CreatePaymentKey(data , callback){
  128.  
  129. console.log("rec data is ", data) ;
  130. var unirest = require("unirest");
  131.  
  132. var req = unirest("POST", "https://accept.paymobsolutions.com/api/acceptance/payment_keys");
  133.  
  134. req.query({
  135. "token": data.firstToken
  136. });
  137.  
  138. //InsertGarbage ("the first token inside payment: "+data.firstToken);
  139. //InsertGarbage ("another basic data" + data.orderId) ;
  140. //InsertGarbage ("some basic string");
  141.  
  142. req.headers({
  143. "content-type": "application/json"
  144. });
  145.  
  146. req.type("json");
  147. req.send({
  148. "amount_cents": "25000",
  149. "currency": "EGP",
  150. "card_integration_id": "184",
  151. "order_id": data.orderId,
  152. "billing_data": {
  153. "apartment": "803",
  154. "email": "[email protected]",
  155. "floor": "42",
  156. "first_name": "Clifford",
  157. "street": "Ethan Land",
  158. "building": "8028",
  159. "phone_number": "+86(8)9135210487",
  160. "shipping_method": "PKG",
  161. "postal_code": "01898",
  162. "city": "Jaskolskiburgh",
  163. "country": "CR",
  164. "last_name": "Nicolas",
  165. "state": "Utah"
  166. }
  167. });
  168.  
  169. req.end(function (res) {
  170. if (res.error) {
  171. InsertGarbage ("a fucken error happened man ") ;
  172. throw new Error(res.error);
  173. }
  174. data["paymentToken"] = res.body.token ;
  175. // InsertGarbage("inside payment now sending the fucken response2 " + data.paymentToken );
  176. console.log(res.body);
  177. callback (data);
  178. });
  179. }
Advertisement
Add Comment
Please, Sign In to add comment