Get user order status
Get user order status
You can use the following ways to get a user order status:
Get user order status on the server side via webhooks
After you have configured webhooks on your server, you can use them to get the order details and status.Get user order status on the client side via WebSocket API or IGS API
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.Last updated: November 8, 2024Was this article helpful?Thank you for your feedback!We’ll review your message and use it to help us improve your experience.Found a typo or other text error? Select the text and press Ctrl+Enter.