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
This commit is contained in:
43
app/views/foodcourt/qrpay/test_payment.html.erb
Normal file
43
app/views/foodcourt/qrpay/test_payment.html.erb
Normal file
@@ -0,0 +1,43 @@
|
||||
<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>
|
||||
Reference in New Issue
Block a user