$(document).ready(function() { var timer = null; const uuid = window.localStorage.getItem('budss_uid'); const storedStatus = window.localStorage.getItem('payment_status'); if (!storedStatus) { timer = setInterval(function() { $.get('/api/paymentstatus/?uuid=' + uuid, function(data) { const result = JSON.parse(data); if (result.status === 'FINISHED') { window.localStorage.setItem('payment_status', result.status); window.localStorage.setItem('payment_transaction_id', result.simple_transaction_id); window.localStorage.setItem('payment_order_id', result.order_id); clearInterval(timer); window.location.href = '/payment/success'; } else if (result.status === 'NOTAUTHORIZED') { window.localStorage.setItem('payment_status', result.status); window.localStorage.setItem('payment_transaction_id', result.simple_transaction_id); window.localStorage.setItem('payment_order_id', result.order_id); clearInterval(timer); window.location.href = '/payment/failed'; } else if (result.status === 'CANCELLED') { window.localStorage.setItem('payment_status', result.status); window.localStorage.setItem('payment_transaction_id', result.simple_transaction_id); window.localStorage.setItem('payment_order_id', result.order_id); clearInterval(timer); window.location.href = '/payment/failed'; } else if (result.status === 'TIMEOUT') { window.localStorage.setItem('payment_status', result.status); window.localStorage.setItem('payment_transaction_id', result.simple_transaction_id); window.localStorage.setItem('payment_order_id', result.order_id); clearInterval(timer); window.location.href = '/payment/failed'; } }); }, 3000); } else { const order_id = window.localStorage.getItem('payment_order_id'); const simple_transaction_id = window.localStorage.getItem('payment_transaction_id'); if (storedStatus === 'FINISHED') { $('#payment_status').html('Successful transaction'); $('#simple_transaction_id').html('SimplePay Transaction ID: ' + simple_transaction_id); $('#order_id').html('Order ID: ' + order_id); $('#success').show(); } else if (storedStatus === 'NOTAUTHORIZED') { $('#payment_status').html('Transaction failed'); $('#simple_transaction_id2').html('SimplePay Transaction ID: ' + simple_transaction_id); $('#order_id2').html('Order ID: ' + order_id); $('#failed').show(); } else if (storedStatus === 'CANCELLED') { $('#payment_status').html('You have interrupted your payment.'); $('#error').show(); } else if (storedStatus === 'TIMEOUT') { $('#payment_status').html('You have exceeded the maximum time allowed to initiate the transaction.'); $('#error').show(); } } });