Set up order status tracking
To grant items to the user, you need to make sure that the payment was successful.
Choose a method for tracking order status:
Choose the most suitable method for your project to access Xsolla data:
If you have no server or you implement the logic for purchase processing on the client side, you can use the following ways:
Get an order status on the client side using WebSocket API
The solution uses websockets to obtain order statuses without obtaining detailed information about the order. This method is preferable: only one connection is created between the client (for example, your website or mobile application) and the Xsolla server, so there is no additional load on either the client or the server.
Complete the following steps:
- To allow the Xsolla websocket server and your client to identify order status messages, create a connection:
- javascript
const client = new Centrifuge(
connectionURL,
{
data: {
user_external_id: user_external_id,
auth: auth,
project_id: project_id
}
}
)
connectionURL - wss://ws-store.xsolla.com/connection/websocket
auth - user JWT token
- To receive new messages about order statuses, subscribe to events using the
client.on
function:
- javascript
client.on('publication', (ctx) => {
//handle the status
});
- Trigger actual connection establishment:
- javascript
client.connect()
- To receive the history of changes in order statuses, connect the API history method.
- javascript
client.on('subscribed', function (ctx) {
client.history(ctx.channel, { limit: -1, since: { offset: 0 }, reverse: false }).then(function (resp) {
resp.publications.forEach((ctx) => {
/handle the status
});
}, function (err) {
//handle the status
});
});
Message body example:
- javascript
{
order_id: 59614241,
status: 'new'
}
The following order statuses are possible:
New
— order was created but not paidPaid
— order is paidDone
— order has been delivered (all receipts sent, deliveries made on Xsolla’s side, external platforms, etc.)Canceled
— order is canceled and payment refunded to a user
Websocket usage recommendations:
- The maximum waiting time for a response via websocket is 5 minutes.
- The connection should be established when opening the payment interface.
- The connection should be aborted once the final order status is received, either
Canceled
orDone
. - If the websocket’s lifespan expires or if there are any issues with the connection, use short-polling.
Short-polling
To get detailed information about items in the order after switching to the status, call the Get order API.
NoteA periodic order status poll is used — a simple HTTP request that receives the order status and information about the order. The recommended delay between requests is 3 seconds.
Found a typo or other text error? Select the text and press Ctrl+Enter.