Get user order status

Get user order status

You can use the following ways to get a user order status:

  1. On the server side via webhooks.
  2. On the client side via WebSocket API or IGS API.

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:
  1. WebSocket API.
  2. Short-polling.

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.

Note
If you don’t have your own server to handle webhooks, or you use client-side purchase processing logic, you can use the WebSocket API using the Centrifuge SDK.

Complete the following steps:

  1. To allow the Xsolla websocket server and your client to identify order status messages, create a connection:

Copy
Full screen
Small screen
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
  1. To receive new messages about order statuses, subscribe to events using the client.on function:
Copy
Full screen
Small screen
client.on('publication', (ctx) => {
   //handle the status
});
  1. Trigger actual connection establishment:
Copy
Full screen
Small screen
client.connect()
  1. To receive the history of changes in order statuses, connect the API history method.
Copy
Full screen
Small screen
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:

Copy
Full screen
Small screen
{
order_id: 59614241,
status: 'new'
}

The following order statuses are possible:

  • New — order was created but not paid
  • Paid — order is paid
  • Done — 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 or Done.
  • 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.

    Note
    A 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.
    Was this article helpful?
    Thank you!
    Is there anything we can improve? Message
    We’re sorry to hear that
    Please explain why this article wasn’t helpful to you. Message
    Thank you for your feedback!
    We’ll review your message and use it to help us improve your experience.
    Last updated: November 8, 2024

    Found a typo or other text error? Select the text and press Ctrl+Enter.

Report a problem
We always review our content. Your feedback helps us improve it.
Provide an email so we can follow up
Thank you for your feedback!