Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. @using SageProcessModuleMEF.Scripts;
  2. @using Newtonsoft.Json;
  3. @{
  4. Nonces Nonces = Shared.GetNonces();
  5.  
  6. var request = new
  7. {
  8. merchantId = Shared.MerchantID,
  9. merchantKey = Shared.MerchantKEY, // don't include the Merchant Key in the JavaScript initialization!
  10. requestType = "payment",
  11. orderNumber = "Invoice" + (new Random()).Next(100).ToString(),
  12. amount = Shared.Amount,
  13. salt = Nonces.Salt,
  14. postbackUrl = Shared.PostbackUrl,
  15. preAuth = Shared.PreAuth
  16. };
  17.  
  18. string jsonReq = JsonConvert.SerializeObject(request);
  19. string AuthKey = Shared.GetAuthKey(jsonReq, Shared.DeveloperKEY, Nonces.IV, Nonces.Salt);
  20. }
  21. <h2>
  22. <style>
  23. #paymentDiv {
  24. width: 60%;
  25. margin-left: auto;
  26. margin-right: auto;
  27. padding: 30px;
  28. border-width: thin;
  29. border-style: dotted;
  30. border-color: #3c424f;
  31. }
  32. </style>
  33. <div class="wrapper text-center">
  34. <h1>Inline</h1>
  35. <div>
  36. <div id="paymentDiv"></div>
  37. <br /><br />
  38. <h5>Results:</h5>
  39. <p style="width:100%"><pre><code id="paymentResponse">The response will appear here as JSON, and in your browser console as a JavaScript object.</code></pre></p>
  40. </div>
  41. </div>
  42.  
  43. <script src="https://sagepayments.net/pay/1.0.0/js/pay.js">
  44. // full api reference is available at https://github.com/SagePayments/PaymentsJS
  45.  
  46. // the entire library is accessed through the PayJS() function:
  47.  
  48. PayJS(['PayJS/UI', 'jquery'], // name the modules you want to use...
  49. function($UI, $) { // ... and then assign them to variables.
  50.  
  51. // we'll start by initializing the UI:
  52. $UI.Initialize({
  53. // developer:
  54. clientId: "WzMlU4KE2amf8DwUMczDZYEwC8BLUSJlD",
  55. postbackUrl: "@request.postbackUrl", // you get a copy of the response here
  56.  
  57. // merchant:
  58. merchantId: "@request.merchantId",
  59.  
  60. // security:
  61. authKey: "@AuthKey",
  62. salt: "@request.salt",
  63.  
  64. // request:
  65. requestType: "@request.requestType",
  66. orderNumber: "@request.orderNumber",
  67. amount: "@request.amount",
  68.  
  69. // ui:
  70. elementId: "paymentDiv", // the DOM that $UI should attach itself to,
  71.  
  72. // dev QoL:
  73. // debug: true, // verbose logging
  74. // show: true, // show the modal immediately, instead of waiting for a click
  75. addFakeData: true // pre-fill the form with test values
  76. });
  77.  
  78. // and then we'll set a callback function to execute after the user
  79. // has submitted their card data and received a respnonse back
  80. $UI.setCallback(function($RESP) { // the callback function receives an instance of the RESPONSE module
  81. console.log("Ajax Response:");
  82. console.log($RESP.getAjaxResponse());
  83. console.log("API Response:");
  84. console.log($RESP.getApiResponse());
  85. console.log("Gateway Response:");
  86. console.log($RESP.getGatewayResponse());
  87. console.log("API Response + Hash:");
  88. console.log($RESP.getResponseHash())
  89. $("#paymentResponse").text(
  90. $RESP.getApiResponse()
  91. );
  92. // the response includes the gateway response, plus a SHA512 HMAC of the gateway response
  93. // the HMAC uses your developer key to sign the response payload
  94. // it's always a good idea to verify the hash, server-side, to ensure that the response is legitimate
  95. // this is especially important if you're changing an account balance, shipping a product, etc.
  96. });
  97. });
  98. </script>
  99.  
  100. </h2>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement