bkash_app.blade.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=no"/>
  6. <link rel="stylesheet" href="{{ static_asset('assets/css/vendors.css') }}">
  7. <link rel="stylesheet" href="{{ static_asset('assets/css/aiz-core.css') }}">
  8. <link rel="stylesheet" href="{{ static_asset('assets/css/custom-style.css') }}">
  9. </head>
  10. <body>
  11. <section class="py-4 mb-4 bg-light">
  12. <div class="container text-center">
  13. <button id="bKash_button" class="d-none">Pay With bKash</button>
  14. </div>
  15. </section>
  16. <!-- SCRIPTS -->
  17. <script src="{{ static_asset('assets/js/vendors.js') }}"></script>
  18. @if (get_setting('bkash_sandbox') == 1)
  19. <script src="https://scripts.sandbox.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout-sandbox.js"></script>
  20. @else
  21. <script src="https://scripts.pay.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout.js"></script>
  22. @endif
  23. <script type="text/javascript">
  24. $(document).ready(function(){
  25. $('#bKash_button').trigger('click');
  26. });
  27. var paymentID = '';
  28. bKash.init({
  29. paymentMode: 'checkout', //fixed value ‘checkout’
  30. //paymentRequest format: {amount: AMOUNT, intent: INTENT}
  31. //intent options
  32. //1) ‘sale’ – immediate transaction (2 API calls)
  33. //2) ‘authorization’ – deferred transaction (3 API calls)
  34. paymentRequest: {
  35. amount: '{{ $amount }}', //max two decimal points allowed
  36. intent: 'sale'
  37. },
  38. createRequest: function(request) { //request object is basically the paymentRequest object, automatically pushed by the script in createRequest method
  39. $.ajax({
  40. url: '{{ route('api.bkash.checkout',['token'=>$token, 'amount'=>$amount]) }}',
  41. type: 'POST',
  42. contentType: 'application/json',
  43. success: function(data) {
  44. console.log('checkout s');
  45. console.log(data);
  46. console.log('checkout en');
  47. data = JSON.parse(data);
  48. if (data && data.paymentID != null) {
  49. paymentID = data.paymentID;
  50. bKash.create().onSuccess(data); //pass the whole response data in bKash.create().onSucess() method as a parameter
  51. } else {
  52. alert(data.errorMessage);
  53. bKash.create().onError();
  54. }
  55. },
  56. error: function() {
  57. bKash.create().onError();
  58. }
  59. });
  60. },
  61. executeRequestOnAuthorization: function() {
  62. $.ajax({
  63. url: '{{ route('api.bkash.execute', $token) }}',
  64. type: 'POST',
  65. contentType: 'application/json',
  66. data: JSON.stringify({
  67. "paymentID": paymentID
  68. }),
  69. success: function(data) {
  70. console.log('execute s');
  71. console.log(data);
  72. console.log('execute en');
  73. var result = JSON.parse(data);
  74. if (result && result.paymentID != null) {
  75. window.location.href = "{{ route('api.bkash.success') }}?payment_details="+data; //Merchant’s success page
  76. } else {
  77. alert(result.errorMessage);
  78. bKash.execute().onError();
  79. }
  80. },
  81. error: function() {
  82. bKash.execute().onError();
  83. }
  84. });
  85. }
  86. });
  87. </script>
  88. </body>
  89. </html>