payment.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. $(document).ready(function() {
  2. var timer = null;
  3. const uuid = window.localStorage.getItem('budss_uid');
  4. const storedStatus = window.localStorage.getItem('payment_status');
  5. if (!storedStatus) {
  6. timer = setInterval(function() {
  7. $.get('/api/paymentstatus/?uuid=' + uuid, function(data) {
  8. const result = JSON.parse(data);
  9. if (result.status === 'FINISHED') {
  10. window.localStorage.setItem('payment_status', result.status);
  11. window.localStorage.setItem('payment_transaction_id', result.simple_transaction_id);
  12. window.localStorage.setItem('payment_order_id', result.order_id);
  13. clearInterval(timer);
  14. window.location.href = '/payment/success';
  15. }
  16. else if (result.status === 'NOTAUTHORIZED') {
  17. window.localStorage.setItem('payment_status', result.status);
  18. window.localStorage.setItem('payment_transaction_id', result.simple_transaction_id);
  19. window.localStorage.setItem('payment_order_id', result.order_id);
  20. clearInterval(timer);
  21. window.location.href = '/payment/failed';
  22. }
  23. else if (result.status === 'CANCELLED') {
  24. window.localStorage.setItem('payment_status', result.status);
  25. window.localStorage.setItem('payment_transaction_id', result.simple_transaction_id);
  26. window.localStorage.setItem('payment_order_id', result.order_id);
  27. clearInterval(timer);
  28. window.location.href = '/payment/failed';
  29. }
  30. else if (result.status === 'TIMEOUT') {
  31. window.localStorage.setItem('payment_status', result.status);
  32. window.localStorage.setItem('payment_transaction_id', result.simple_transaction_id);
  33. window.localStorage.setItem('payment_order_id', result.order_id);
  34. clearInterval(timer);
  35. window.location.href = '/payment/failed';
  36. }
  37. });
  38. }, 3000);
  39. }
  40. else {
  41. const order_id = window.localStorage.getItem('payment_order_id');
  42. const simple_transaction_id = window.localStorage.getItem('payment_transaction_id');
  43. if (storedStatus === 'FINISHED') {
  44. $('#payment_status').html('Successful transaction');
  45. $('#simple_transaction_id').html('SimplePay Transaction ID: ' + simple_transaction_id);
  46. $('#order_id').html('Order ID: ' + order_id);
  47. $('#success').show();
  48. }
  49. else if (storedStatus === 'NOTAUTHORIZED') {
  50. $('#payment_status').html('Transaction failed');
  51. $('#simple_transaction_id2').html('SimplePay Transaction ID: ' + simple_transaction_id);
  52. $('#order_id2').html('Order ID: ' + order_id);
  53. $('#failed').show();
  54. }
  55. else if (storedStatus === 'CANCELLED') {
  56. $('#payment_status').html('You have interrupted your payment.');
  57. $('#error').show();
  58. }
  59. else if (storedStatus === 'TIMEOUT') {
  60. $('#payment_status').html('You have exceeded the maximum time allowed to initiate the transaction.');
  61. $('#error').show();
  62. }
  63. }
  64. });