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:
Dev Team
2025-05-26 11:29:33 +06:30
parent a43f8ed4f6
commit 1768345299
5 changed files with 208 additions and 21 deletions

View 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>