hasancse1991

checkout-updated

Nov 12th, 2018
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.74 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4.     <script src="https://code.jquery.com/jquery-3.3.1.min.js"
  5.            integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  6.            crossorigin="anonymous"></script>
  7.     <script src="file:///android_asset/www/js/bKash-checkout-sandbox.js"></script>
  8.     <style type="text/css">
  9.         @font-face {
  10.             font-family: MyFont;
  11.             src: url("file:///android_asset/fonts/Mark_Simonson_Proxima_Nova_Alt_Regular_webfont.ttf")
  12.         }
  13.         body {
  14.             text-align:center;
  15.             font-family: MyFont;
  16.         }
  17.         p {
  18.            font-weight: bold;
  19.            font-size: 16px;
  20.         }
  21.         button {
  22.             background-color: #0099cc;
  23.             padding: 16px;
  24.             color: white;
  25.         }
  26.     </style>
  27. </head>
  28.  
  29. <body>
  30. <img src="file:///android_asset/www/images/bkash_payment.png" width="80%"/><br><br>
  31. <p id="amount"></p><br><br>
  32. <button id="bKash_button">Pay With bKash</button>
  33. <script type="text/javascript">
  34.  
  35.         var paymentConfig = {
  36.             createCheckoutURL: "",
  37.             executeCheckoutURL: "",
  38.         };
  39.  
  40.         var apiConfig = {
  41.             apiKey : "",
  42.             token : "",
  43.         };
  44.  
  45.         var paymentID = '';
  46.         var orderId = 0;
  47.  
  48.         bKash.init({
  49.             paymentMode: 'checkout',
  50.             paymentRequest: { amount: '0', intent: 'sale', orderId: 0 },
  51.  
  52.             createRequest: function (request) {
  53.                 console.log('Token and key');
  54.                 console.log(apiConfig.token);
  55.                 console.log(apiConfig.apiKey);
  56.                 $('#amount').html('Amount: ' + request.amount + ' BDT');
  57.                 $.ajax({
  58.                     url: paymentConfig.createCheckoutURL,
  59.                     type: 'POST',
  60.                     headers: {
  61.                         'Auth-Token': apiConfig.apiKey,
  62.                         'token': apiConfig.token,
  63.                         'Content-Type':'application/json'
  64.                     },
  65.                     data: JSON.stringify(request),
  66.                     success: function (response) {
  67.                         if (response && response.response_code == 200 && response.data.paymentID != null) {
  68.                            orderId = request.orderId;
  69.                             paymentID = response.data.paymentID;
  70.                             bKash.create().onSuccess(response.data);
  71.                         } else {
  72.                             bKash.create().onError();//run clean up code
  73.                             window.location.href = "file:///android_asset/www/checkout_failed.html"
  74.                         }
  75.                     },
  76.                     error: function () {
  77.                         alert('error');
  78.                         bKash.create().onError();//run clean up code
  79.                         window.location.href = "file:///android_asset/www/checkout_failed.html"
  80.                     }
  81.                 });
  82.             },
  83.             executeRequestOnAuthorization: function () {
  84.                 $.ajax({
  85.                     url: paymentConfig.executeCheckoutURL,
  86.                     type: 'POST',
  87.                     headers: {
  88.                         'auth-token': apiConfig.apiKey,
  89.                         'token': apiConfig.token,
  90.                         'Content-Type':'application/json'
  91.                     },
  92.                     data: JSON.stringify({ "paymentID": paymentID, "orderId": orderId }),
  93.                     success: function (response) {
  94.                         if (response.data && response.response_code == 200 && response.data.paymentID != null) {
  95.                            window.location.href = "file:///android_asset/www/checkoutSuccess.html";
  96.                         } else {
  97.  
  98.                             bKash.execute().onError();//run clean up code
  99.                             window.location.href = "file:///android_asset/www/checkout_failed.html"
  100.                         }
  101.                     },
  102.                     error: function () {
  103.                         bKash.execute().onError();//run clean up code
  104.                         window.location.href = "file:///android_asset/www/checkout_failed.html"
  105.                     }
  106.                 });
  107.             }
  108.         });
  109.         function callReconfigure(val) {
  110.             bKash.reconfigure(val);
  111.         }
  112.         function clickPayButton() {
  113.             $("#bKash_button").trigger('click');
  114.         }
  115.  
  116.         function setConfigs (createCheckoutURL, executeCheckoutURL, apiKey, token ) {
  117.             paymentConfig.createCheckoutURL = createCheckoutURL;
  118.             paymentConfig.executeCheckoutURL = executeCheckoutURL;
  119.             apiConfig.apiKey = apiKey;
  120.             apiConfig.token = token;
  121.  
  122.         }
  123.  
  124.  
  125. </script>
  126. </body>
  127.  
  128. </html>
Advertisement
Add Comment
Please, Sign In to add comment