Integrate store into game

After you have created and configured goods (virtual items, virtual currencies, bundles, keys) in your Publisher Account, add an In-Game Store to your game:

  1. Implement the display of items catalog.
  2. Implement the logic for selling items.

Display of items catalog

Note
To call the Xsolla API, you can use the ready-made SDK methods for game engines and platforms:

Implement a display of items catalog via In-Game Store & Buy Button API calls:

TaskAPI
To display a complete list of virtual items added to your StoreGet virtual items list
To display a list of groups of virtual items available for sale on the client sideGet item groups list
To get a list of virtual currencies available for sale in your Store on the client sideGet virtual currency list
To display a complete list of virtual currency packages added to your Store on the client sideGet virtual currency package list
To display a complete list of bundles added to your StoreGet list of bundles
Note
The getting catalog methods return the items that are displayed in the store at the time of the request. To obtain information about items whose display period has not yet started or has already expired, pass the show_inactive_time_limited_items parameter with a value of 1 when requesting the catalog.

Selling items

You can sell items in the following ways:

  1. Fast purchase of one item. In this case, you can sell one SKU in any quantity (for example, 100 identical potions or a custom amount of virtual currency).
  2. Buying a cart. In this case, the player can pre-fill a cart, add or remove items, or change their quantities.

Fast purchase

  1. Call the Create order with specified item API. A token for opening the payment UI will be passed to the response.
  2. Open payment UI using received payment token.
Note
The information about the discount (personalized or related to the purchase) will be available to the user only in the payment UI. The use of promo codes is not provided.
Note
To call the Xsolla API, you can use the ready-made SDK methods for game engines and platforms:

Cart purchase

Implement the logic:
  1. To set up a cart and get the token:
  2. To open payment UI.

Set up and purchase a cart on the client

Implement the logic of adding and removing items by yourself. You also need to consider that before calling API for setting up a cart, you will not have information about which promotions will be applied to the purchase. This means that the total cost and details of the added bonus items will not be known.

  1. After the player has filled a cart, call the Fill cart with items API. The current information about the selected items (prices before and after discounts, bonus items) will be passed to the response.
  2. Call the Create order with all items from current cart API. The order ID and payment token will be passed to the response. The created order will receive a New order status.
  3. Open payments UI.
Note
To call the Xsolla API, you can use the ready-made SDK methods for game engines and platforms:

Set up and purchase a cart on server

This variant may take longer for setting the cart up, since each change to the cart must be accompanied by API calls.

Complete the following steps:

  1. Change the cart:

Note
If you want to get current status of the cart, call the Get current user’s cart API.
  1. Call the Create order with all items from the current cart API. The order ID and payment token will be passed to the response. The created order will receive a New order status.
  2. Open payment UI.

Opening the payment interface

For paying items, open the payment UI. A token for opening the payment UI will be passed to the Create order with all items from current cart API response.

Implement the opening of the payment UI in one of the following ways:

Testing payment process

You can test payment flow in the Sandbox mode. You can use a test bank card and any account.

Note

After the first real payment is made, a strict sandbox payment policy takes effect. A payment in the sandbox mode is available only to users who are specified in Publisher Account > Company settings > Users.

Buying virtual currency and items for real currency is possible only after signing a license agreement with Xsolla. To do this, in Publisher Account, go to the Agreements & Taxes > Agreements section, complete the agreement form, and wait for the confirmation. It may take up to 3 business days to review the agreement.

To enable/disable sandbox mode, you need to change the value of the sandbox parameter in the request to fast purchase and purchase a cart. Sandbox mode is off by default.

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&BB 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&BB 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

The required time for a response via websocket is 5 minutes. After that or if there are any problems with the websocket, it is recommended to 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.
Your progress
Thank you for your feedback!
Last updated: February 21, 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!