test payment
This commit is contained in:
@@ -2,42 +2,41 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
const ws = new WebSocket("wss://juicecorner-0mo.sx-fc.app/cable")
|
const status = $('#status');
|
||||||
|
const amountToReceive = 500;
|
||||||
|
|
||||||
ws.onopen = () => {
|
// Create Action Cable consumer
|
||||||
console.log("WS Connected");
|
const cable = ActionCable.createConsumer("wss://juicecorner-0mo.sx-fc.app/cable");
|
||||||
ws.send(JSON.stringify({
|
|
||||||
command: "subscribe",
|
|
||||||
identifier: JSON.stringify({
|
|
||||||
channel: "TestChannel"
|
|
||||||
})
|
|
||||||
}))
|
|
||||||
document.getElementById('status').textContent = 'Waiting for payment...'
|
|
||||||
}
|
|
||||||
|
|
||||||
ws.onmessage = (e) => {
|
// Subscribe to channel
|
||||||
const msg = JSON.parse(e.data)
|
const subscription = cable.subscriptions.create(
|
||||||
console.log("Received:", msg)
|
{
|
||||||
|
channel: "TestChannel",
|
||||||
|
receipt_no: "0101234123456789012"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
connected() {
|
||||||
|
console.log("Nagato channel connected");
|
||||||
|
},
|
||||||
|
|
||||||
// Handle subscription confirmation
|
received(data) {
|
||||||
if(msg.type === "confirm_subscription") {
|
console.log("Received:", data);
|
||||||
console.log("Successfully subscribed!")
|
|
||||||
return
|
if (data.status === "PAY_SUCCESS") {
|
||||||
|
this.handlePaymentSuccess();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
handlePaymentSuccess() {
|
||||||
|
status.html(`
|
||||||
|
<div class="payment-success text-center">
|
||||||
|
<i class="material-icons" style="font-size: 50px; color: #4CAF50;">check_circle</i>
|
||||||
|
<h3 class="m-t-20" style="color: #4CAF50;">Payment Successful!</h3>
|
||||||
|
<p>Amount Received: ${amountToReceive}</p>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
);
|
||||||
// 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>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user