Notifications
Use Case
You've embedded our order system as an iframe and want to track the order status within your application.
Solution
Subscribe to our notifications
setting via JS to get the status of an order.
We publish to WebSockets using Ably.
Suscribe to a Channel
Channel
We publish events into a dedicated channel. Our channel is orderStatusEvents
.
Auth Key
Use our public, read-only API key wIOS_Q.W4OKUQ:VInI8-OkmxFcjpR2vTrVlb6jNLYl5pS42VOh-KECCk4
to authenticate.
Msg Name
Our message name is one of txnReady | txnBroadcasted | orderSucceeded | orderFailed
.
Msg Data
Our message data contains the following fields.
Key | Description |
---|---|
orderId | order id of the purchase. used by Supercharge internally |
receiverAddress | receiving wallet. useful for filtering when subscribing to updates |
To get the right messages, filter by receiverAddress (see code example below).
Example
After installing Ably, this example is ready to copy/paste into your application.
var realtime = new Ably.Realtime(
"wIOS_Q.W4OKUQ:VInI8-OkmxFcjpR2vTrVlb6jNLYl5pS42VOh-KECCk4"
);
var channel = realtime.channels.get("orderStatusEvents");
channel.subscribe(function (message) {
if (msg.name === 'txnReady') {
const data = msg.data as { orderId: string }
const { orderId, receiverAddress } = data
// save the orderId
} else if (msg.name === 'txnBroadcasted') {
// order has been broadcasted to the blockchain and awaiting confirmations.
// ... your logic here
} else if (msg.name === 'orderSucceeded') {
// transaction has successfully been included.
// ... do other downstream things
} else if (msg.name === 'orderFailed') {
// order failed to be included.
// ... handle errors here
}
});