In-game purchases
We have partnered with Xsolla to offer you the possibility to integrate in-game purchases more conveniently.
Warning
In-game purchases are an invite only feature. If you are interested in using them, please get in touch with us.
In-game purchases should be available only for the users that are signed in. Guest users should not be able to purchase items. You'll need to integrate the User module.
Getting started
When using the Xsolla SDK, and once you are invited to the CrazyGames Xsolla project dashboard, you will need one of the following ways of authentication:
- Standard linked to CrazyGames user accounts:
- Create your game on the developer portal and contact us so we can generate credentials for the token.
- The token received from the
GetXsollaUserToken()
method from the SDK. This method generates a custom Xsolla token that you use with the Xsolla SDK. The purchases are linked to the CrazyGames user account (see Account integration requirements).
- Custom linked to your in-game accounts: you can generate the necessary Xsolla credentials yourself within our Xsolla project dashboard, and use the Xsolla SDK with the generated credentials. Purchases will be linked to your in-game user accounts (see Account integration requirements). You can also skip the rest of this guide.
Get Xsolla token
To use Xsolla via our own custom-generated token, you can retrieve the Xsolla token like this:
To use Xsolla via our own custom-generated token, the only Xsolla SDK setup required is adding the Project ID, which will be provided by us.
Install the Xsolla Unity SDK can here.
You don't need any additional Xsolla setup, or to handle Xsolla login, since Xsolla will automatically handle the user account creation with the user ID included in token, which is the ID of the CrazyGames user. Thus, all the purchases made using the token will be also linked to the CrazyGames user account.
You can retrieve the Xsolla token like this:
We recommend that you retrieve the token every time before using it, since the tokens are usually short-lived, for example only 1 hour. Our SDK handles the token refresh.
After retrieving the token, you can use it like this:
You don't need to handle any Xsolla login functionality, since Xsolla will automatically handle the user account creation with the user ID included in the token, which is the ID of the CrazyGames user. Thus, all the purchases made using the token will be also linked to the CrazyGames user account.
You can now call the methods from the Xsolla SDK, for example XsollaCatalog.Purchase(...)
.
Registering orders
For the typical use case, you will use the in-game-store API Xsolla offers. Have a look at
- In-game store Integration Handbook
- In-game store API documentation
Testing
The GetXsollaUserToken()
method will work only on CrazyGames.com. You can preview your game through the Developer Portal.
For the initial testing, we recommend testing with sandbox orders, which allow purchasing items with fake money. When you submit the game, please ensure the sandbox orders are disabled.
Order tracking
Order tracking through our SDK is optional.
When using Xsolla, you will mostly deal with 3 order statuses:
new
done
canceled
Every time an order has been successfully completed (done
), call our analytics module:
You can obtain the order for example from the Xsolla Order endpoint
We also encourage you to track the new and canceled orders, as these may be useful in the future.
Guidelines & Tips
When integrating in-game purchases, take into account these common mistakes we've noticed:
- The integration is complex. You can check the embeddable widget Xsolla provides for simpler integration.
- Make sure your game can handle payment status correctly to avoid charging players and not crediting them. For example, when they close the window during payment processing. You can rely on one of these options, and wait for the response properly:
- On mobile, the Back button is sometimes hidden. You can check this resource.
- Players can accidentally close the Xsolla window by clicking outside the overlay or pressing Esc. You can disable
closeByClick
andcloseByKeyboard
- Additional HTML5 resource
- For Unity: in Unity, under the path
Assets/Xsolla/Core/Plugins/
, there is a file calledpaystation.jslib
. In this file, the following lines need to be added as options:closeByClick: false
andcloseByKeyboard: false