Get token

Note
If authorized users will make purchases on your website, implement getting a token. If you plan to sell to unauthorized users, connect the Buy Button product.

You need to obtain a token to integrate the payment UI. An access token is a string that identifies game, user, and purchase parameters.

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

To find this data:

  1. In your Publisher Account, go to Company settings.
  2. In the Company tab, copy Merchant ID.
  3. In the API key tab, copy the API key.

Copy
Full screen
Small screen
https://api.xsolla.com/merchant/v2/merchants/{merchant_id}/token

You can alter the HTTP POST request by including the parameters you want to pass on to the payment UI. Pass the information about the user in the parameters user.id, user.name, and user.email of the Create token method.
Note
For the user.id parameter, use an identifier that users can remember and later use outside the game by themselves (e.g., when replenishing the game balance using push payments).
API reference
See the full list of parameters.

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, take a look at the CURL example by clicking on the CURL tab.

Copy
Full screen
Small screen
php
  • php
  • curl
<?php

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

$tokenRequest = new TokenRequest($projectId, $userId);
$tokenRequest->setUserEmail('email@example.com')
    ->setExternalPaymentId('12345')
    ->setSandboxMode(true)
    ->setUserName('USER_NAME');

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

Your progress
Thank you for your feedback!
Last updated: May 20, 2022

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!