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:
Xsolla event API
The Xsolla Event API is an alternative to using webhooks. It allows you to receive information about payment events directly from your application’s client via requests to Xsolla’s server. This approach eliminates the need to set up and maintain your own server for handling webhooks. For detailed information about using the Xsolla Event API, refer to our documentation.
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
1const client = new Centrifuge(
2connectionURL,
3{
4data: {
5 user_external_id: user_external_id,
6 auth: auth,
7 project_id: project_id
8}
9}
10)
11connectionURL - wss://ws-store.xsolla.com/connection/websocket
12auth - user JWT token
- To receive new messages about order statuses, subscribe to events using the
client.onfunction:
- javascript
1client.on('publication', (ctx) => {
2 //handle the status
3});
- Trigger actual connection establishment:
- javascript
1client.connect()
- To receive the history of changes in order statuses, connect the API history method.
- javascript
1client.on('subscribed', function (ctx) {
2 client.history(ctx.channel, { limit: -1, since: { offset: 0 }, reverse: false }).then(function (resp) {
3resp.publications.forEach((ctx) => {
4 /handle the status
5});
6
7 }, function (err) {
8 //handle the status
9 });
10});
Message body example:
- javascript
1{
2order_id: 59614241,
3status: "new"
4}
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
CanceledorDone. - 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.
The XsollaCatalog.Purchase method encapsulates several methods for tracking order status. The tracking mechanism is detailed in the documentation of SDK for Unity.
Additionally, you can implement the handling of the order status and content, which are passed to the onSuccess callback function of the purchase method.
You can track the order status using the CheckPendingOrder SDK method. Pass the following parameters to the method:
AccessToken— the payment token, which was received when purchasing the item.OrderId— the order ID, which was received when purchasing the item.SuccessCallback— the successful payment callback.ErrorCallback— the request error callback.bIsUserInvolvedToPayment— whether the user is involved in the payment process. Passtruefor purchasing with real currency, andfalsefor free item purchasing and purchasing with virtual currency.
The tracking mechanism is detailed in the documentation of enterprise-level SDK for Unreal Engine.
To request the status and content of an order, call the CheckOrder SDK method, passing the following parameters to it:
AccessToken— the payment token, which was received when purchasing the item.OrderId— the order ID, which was received when purchasing the item.SuccessCallback— the callback for successful order checking. The response contains the order status.ErrorCallback— the request error callback.
To track the status of created orders and validate them, you will need to configure webhooks processing on the server side of your application.
On Xsolla’s side, there are two options to receive webhooks in case of item purchase and refund: information with payment and transaction data and information about purchased items can either come separately, or be combined into one webhook. By default, all new projects receive combined webhook.
To switch to the new option with receiving combined webhooks, contact your Customer Success Managers or email to csm@xsolla.com.
More information on webhook receiving options
Receiving information in combined webhooks:
If you registered in Publisher Account after January 22, 2025, you receive all the information in the Successful payment for order (order_paid) and Order cancellation (order_canceled) webhooks. In this case, you do not need to process the Payment (payment) and Refund (refund) webhooks.
Receiving information in separate webhooks:
If you registered in Publisher Account on or before January 22, 2025, you receive the following webhooks:
- Payment (
payment) and Refund (refund) with information about payment data and transaction details. - Successful payment for order (
order_paid) and Order cancellation (order_canceled) with information about purchased items.
You need to process all incoming webhooks.
For the full operation of the in-game store and payment management, it is necessary to implement the processing of the main webhooks:
| Webhook name | Description |
|---|---|
User validation > User validation (user_validation) | Is sent at different stages of the payment process to ensure the user is registered in the game. |
Game services > Combined webhooks > Successful payment for order (order_paid) | It contains payment data, transaction details, and information about purchased items. Use the data from the webhook to add items to the user. |
Game services > Combined webhooks > Order cancellation (order_canceled) | It contains data of the canceled payment, transaction details, and information about purchased items. Use the data from the webhook to remove the purchased items. |
The scheme below shows the process of purchasing and returning items using combined webhooks.
sequenceDiagram
participant User
participant GameClient as Game Client
participant Xsolla
participant GameServer as Game Server
%% Item Purchase
Note over User, GameServer: Item purchase
User ->> GameClient: Logs in
GameClient ->> Xsolla: Sends user authentication request
Xsolla -->> GameClient: Returns JWT / OAuth 2.0 token
GameClient ->> Xsolla: Sends JWT, project ID, pagination parameters
Xsolla -->> GameClient: Returns array of items
GameClient -->> User: Displays storefront
User ->> GameClient: Selects item and clicks Buy
GameClient ->> Xsolla: Creates order request
Xsolla -->> GameClient: Returns payment token
GameClient ->> Xsolla: Opens payment UI URL with received token
Xsolla ->> GameServer: Sends User validation webhook
GameServer -->> Xsolla: Returns success status code
Xsolla -->> User: Displays payment UI
User ->> Xsolla: Chooses payment method and clicks Pay
Xsolla ->> GameServer: Sends Successful payment for order webhook
GameServer ->> GameServer: Grants purchases to user
GameServer -->> Xsolla: Returns success status code
Xsolla -->> User: Shows successful purchase screen
%% Refund / Chargeback
Note over User, GameServer: Refund / Chargeback
User ->> Xsolla: Requests refund or chargeback
Xsolla ->> GameServer: Sends Order cancellation webhook
GameServer ->> GameServer: Removes items from user inventory
GameServer -->> Xsolla: Returns success status code
Xsolla -->> User: Refunds the payment
If item catalog personalization is implemented on your application’s side, set up processing of Catalog personalization on the partner’s side.
- Payment, Successful payment for order, and User validation if you receive separate webhooks
- Successful payment for order, and User validation if you receive combined webhooks
For the full list of webhooks and general information about working with them, refer to the webhooks documentation.
Set up webhooks sending
To configure webhooks on the Xsolla side:
- In the project in Publisher Account go to Settings > Webhooks section.
- In the Webhook server field, specify the URL of your server where you want to receive webhooks in the
https://example.comformat. You can also specify the URL you find in a tool for testing webhooks.
- A secret key to sign project webhooks is generated by default. If you want to generate a new secret key, click the refresh icon.
- Click Enable webhooks.
Add webhook listener
Webhook listener is program code that allows receiving incoming webhooks at a specified URL address, generating a signature, and sending a response to the Xsolla webhook server.
Generation of signature
When receiving a webhook, you should ensure the security of data transmission. To achieve this, a signature must be generated from the webhook data and verified that it matches the signature sent in the HTTP request header.
To generate a signature:
- Concatenate the JSON from the request body and the project’s secret key.
- Apply the SHA-1 cryptographic hash function to the string obtained in the first step.
Sending responses to webhook
To confirm receipt of the webhook, your server must return:
200,201, or204HTTP code in case of a successful response.400HTTP-code with description of the problem if the specified user was not found or an invalid signature was passed.
Your webhook handler may also return a 5xx code in case of temporary issues on your server.
If the Xsolla server doesn’t receive a response to the Successful payment for order and Order cancellation webhooks or receives a response with a 5xx code, the webhooks are resent according to the following schedule:
- 2 attempts with a 5-minute interval
- 7 attempts with a 15-minute interval
- 10 attempts with a 60-minute interval
Maximum of 20 attempts to send webhooks are made within 12 hours from the first attempt.
The retry logic for the Payment and Refund webhooks is described on the respective webhook page.
If the Xsolla server doesn’t receive a response to the User validation webhook or receives a response with a code of 400 or 5xx, the User validation webhook is not resent.
In this case, an error is shown to the user and the Payment and Successful payment for order webhooks are not sent.
Configuring item information in webhooks
You can configure which item data is included in the Successful payment for order and Order cancellation webhooks via the items array.
Enabling additional parameter inclusion
Enable the inclusion of additional parameters that indicate:
- whether the item is free (
is_free) - whether the item is a bonus (
is_bonus) - whether the item is part of a bundle (
is_bundle_content)
To receive these parameters, you must switch your webhooks to version 2 using the Update information about webhook settings API call. In version 1 (default), these parameters are not available.
Example of an items array with additional parameters:
- json
1"items": [
2 {
3 "sku": "com.xsolla.item_new_1",
4 "type": "bundle",
5 "is_pre_order": false,
6 "is_free": false,
7 "is_bonus": false,
8 "is_bundle_content": false,
9 "quantity": 1,
10 "amount": "1000",
11 "promotions": []
12 },
13 {
14 "sku": "com.xsolla.gold_1",
15 "type": "virtual_currency",
16 "is_pre_order": false,
17 "is_free": false,
18 "is_bonus": false,
19 "is_bundle_content": true,
20 "quantity": 1500,
21 "amount": "[null]",
22 "promotions": []
23 }
24 ]
Disabling bundle content inclusion
By default, webhooks include all items from the bundle as a list of individual items. You can configure the webhook to include only the bundle itself, without listing its contents.
In this case, the items included in the bundle are not included in the items array. In the array shown above, the item with the SKU com.xsolla.gold_1, which is part of the bundle, is excluded.
Example of the items array when bundle content is disabled:
- json
1
2"items": [
3 {
4 "sku": "com.xsolla.item_new_1",
5 "type": "bundle",
6 "is_pre_order": false,
7 "is_free": false,
8 "is_bonus": false,
9 "is_bundle_content": false,
10 "quantity": 1,
11 "amount": "1000",
12 "promotions": []
13 }
14 ]
To disable bundle content inclusion, contact your Customer Success Manager or email to csm@xsolla.com.
Found a typo or other text error? Select the text and press Ctrl+Enter.