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