check payment status is not working if the ws server is down
This commit is contained in:
@@ -258,6 +258,7 @@ $(document).ready(function() {
|
||||
const receiptNo = $('#receipt_no').text();
|
||||
let paymentProcessed = false;
|
||||
let fallbackTimeout;
|
||||
let connected = false;
|
||||
|
||||
function handlePaymentSuccess() {
|
||||
if (paymentProcessed) return;
|
||||
@@ -314,11 +315,9 @@ $(document).ready(function() {
|
||||
handlePaymentSuccess();
|
||||
} else if (response.status === "CONFIG_ERROR") {
|
||||
clearTimeout(fallbackTimeout);
|
||||
} else {
|
||||
if (!paymentProcessed) {
|
||||
} else if (!paymentProcessed) {
|
||||
fallbackTimeout = setTimeout(checkPaymentStatus, 5000);
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
if (!paymentProcessed) {
|
||||
@@ -328,6 +327,7 @@ $(document).ready(function() {
|
||||
});
|
||||
}
|
||||
|
||||
// ----- WebSocket Setup -----
|
||||
const cable = ActionCable.createConsumer("wss://juicecorner-0mo.sx-fc.app/cable");
|
||||
|
||||
const subscription = cable.subscriptions.create(
|
||||
@@ -338,6 +338,7 @@ $(document).ready(function() {
|
||||
{
|
||||
connected() {
|
||||
console.log("Nagato channel connected");
|
||||
connected = true;
|
||||
fallbackTimeout = setTimeout(checkPaymentStatus, 30000);
|
||||
},
|
||||
|
||||
@@ -351,17 +352,26 @@ $(document).ready(function() {
|
||||
|
||||
disconnected() {
|
||||
console.log("Nagato channel disconnected");
|
||||
if (!paymentProcessed) {
|
||||
fallbackTimeout = setTimeout(checkPaymentStatus, 30000);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Fallback if WebSocket doesn't connect within 5 seconds
|
||||
setTimeout(() => {
|
||||
if (!connected) {
|
||||
console.warn("WebSocket failed to connect — falling back to polling.");
|
||||
checkPaymentStatus(); // start polling
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
function customer_display_view(data, status) {
|
||||
$.post('/foodcourt/customer_view', {
|
||||
data: data,
|
||||
status: status
|
||||
}, function(result) {
|
||||
}, 'json');
|
||||
}, function(result) {}, 'json');
|
||||
}
|
||||
|
||||
$('#cancel-btn').on('click', function(e) {
|
||||
@@ -389,4 +399,5 @@ $(document).ready(function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user