Files
sx-fc/app/views/foodcourt/qrpay/test_payment.html.erb
Dev Team 1768345299 qr pay updates
- subscribe to action cable from cloud and listen
- callback from cloud to local and show success payment in real time
- payment service and process payment after callback
2025-05-26 11:32:22 +06:30

44 lines
1.1 KiB
Plaintext

<div id="status">Connecting...</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const ws = new WebSocket("wss://juicecorner-0mo.sx-fc.app/cable")
ws.onopen = () => {
console.log("WS Connected");
ws.send(JSON.stringify({
command: "subscribe",
identifier: JSON.stringify({
channel: "TestChannel"
})
}))
document.getElementById('status').textContent = 'Waiting for payment...'
}
ws.onmessage = (e) => {
const msg = JSON.parse(e.data)
console.log("Received:", msg)
// Handle subscription confirmation
if(msg.type === "confirm_subscription") {
console.log("Successfully subscribed!")
return
}
// Handle payment success
if(msg?.message?.status === "PAY_SUCCESS") {
document.getElementById('status').innerHTML = `
<h3 style="color: green;">Payment Received!</h3>
<p>Amount: ${msg.message.amount} ${msg.message.currency}</p>
`
ws.close()
}
}
ws.onerror = (e) => {
console.error("WS Error:", e)
document.getElementById('status').textContent = 'Connection failed'
}
})
</script>