Get token

You need to obtain a token to integrate with the subscriptions. A token is a string containing game/user data and payment settings.

Xsolla API uses basic access authentication. Specify your merchant ID as the username and the API key as the password.

URL to retrieve the token:

Full screen
Small screen{merchant_id}/token

Requesting a token

You can alter the HTTP POST request by including the parameters you want to pass on to the Subscriptions UI. Both the request and the response are in JSON format.

Below you can find sample code of how to get a token in PHP with the help of Xsolla PHP SDK. If you are using another programming language, please take a look at the CURL example by clicking on the CURL tab.

Full screen
Small screen
  • php
  • curl

use Xsolla\SDK\API\XsollaClient;
use Xsolla\SDK\API\PaymentUI\TokenRequest;

$tokenRequest = new TokenRequest($projectId, $userId);

$xsollaClient = XsollaClient::factory(array(
    'merchant_id' => MERCHANT_ID,
    'api_key' => API_KEY
$token = $xsollaClient->createPaymentUITokenFromRequest($tokenRequest);
curl -v{merchant_id}/token \
-u your_merchant_id:merchant_api_key \
-H 'Content-Type:application/json' \
-H 'Accept: application/json' \
-d '
    "user": {
        "id": {
            "value": "1234567"
        "email": {
            "value": ""
    "settings": {
        "project_id": 14004,
        "mode": "sandbox"

You can find the full list of parameters in the API Reference.

Testing the payment process

To test the payment process, you can:

  • Use the Sandbox
  • Make a real payment and then initiate a refund via Publisher Account

Xsolla Sandbox is a standalone environment that supports all features of the live environment, except real payments. You can access the Sandbox by sending "mode":"sandbox" when getting the token.

To test a bank card payment:

  1. Open the Subscriptions UI in sandbox mode.
  2. Choose the item to purchase.
  3. Choose the Credit/debit cards group of payment methods.
  4. Enter the bank card details. Enter any values in the remaining fields. You can also specify incorrect details (card number, expiration date, or CVV) in order to generate an error.

List of bank cards to be used for testing

Sandbox bank card payments can be made in the following currencies: USD, EUR, RUB, GBP, AED, ALL, AMD, ARS, AUD, AZN, BGN, BRL, BYN, CAD, CHF, CLP, CNY, COP, CZK, DKK, DZD, EGP, GEL, HKD, HRK, HUF, IDR, ILS, INR, ISK, JPY, KES, KGS, KRW, KZT, MAD, MDL, MKD, MNT, MXN, MYR, NGN, PEN, PHP, PKR, PLN, RON, RSD, SAR, SEK, SGD, THB, TRY, TWD, UAH, UYU, UZS, VEF, VND, ZAR.
To start receiving real payments, please remove "mode":"sandbox" first.

To test the payment process by making real payments, it is also recommended to use a bank card:

  1. Open the Subscriptions UI.
  2. Choose the item to purchase.
  3. Choose the Credit/Debit cards group of payment methods.
  4. Enter valid bank card details.
  5. After the payment is made, go to the Transaction search section in Publisher Account.
  6. Select your test transaction and click Refund (the transaction must be in the Completed status).

To test the payment process for a subscription with a trial period, use a valid credit card and complete a real payment. Test bank cards are suitable only for testing subscription purchases without a trial period, since you can’t create a billing account in a test environment.
It is recommended to use Visa and MasterCard cards to test the payment process.
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.

Continue reading