Get a token

To integrate a payment UI, you need to get a token. A token is a string that contains information about the game, user, and purchase parameters.

To get a token, use the createCommonPaymentUIToken method as shown in the example below. Specify the following parameters:

  • MERCHANT_ID (int) is the Merchant ID that you can find in Publisher Account in Project settings > Webhooks.
  • API_KEY (string) is the API key that you can find in Publisher Account in Company settings > API key.
  • PROJECT_ID (int) is the Project ID that you can find in Publisher Account in Project settings > Project ID.
  • USER_ID (string) is a unique user ID in your app. Use a username or other parameter to identify a user. It allows you to enable push purchases (cash kiosks, storefronts in third party apps, etc.).

Copy
Full screen
Small screen
<?php

use Xsolla\SDK\API\XsollaClient;

$client = XsollaClient::factory(array(
    'merchant_id' => MERCHANT_ID,
    'api_key' => API_KEY
));
$paymentUIToken = $client->createCommonPaymentUIToken(PROJECT_ID, USER_ID,
$sandboxMode = true);

You can also get a token with other parameters as shown in the example:

Copy
Full screen
Small screen
<?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')
    ->setCustomParameters(array('key1' => 'value1', 'key2' => 'value2'));

$xsollaClient = XsollaClient::factory(array(
    'merchant_id' => MERCHANT_ID,
    'api_key' => API_KEY
));
$token = $xsollaClient->createPaymentUITokenFromRequest($tokenRequest);

Note:
The ExternalPaymentId parameter from the example above must be activated in Publisher Account. Go to Pay Station > Settings and set the Transaction external ID toggle in the Additional settings section to On. If you don’t use the ExternalPaymentId parameter in your project, delete the setExternalPaymentId method.

If you want to use additional parameters for opening the payment UI, e.g., the settings.ui.theme parameter, get a token as shown below:

Copy
Full screen
Small screen
<?php
use Xsolla\SDK\API\XsollaClient;
$tokenContent = array (
       'user' => array
        (
            'id' => Array
                (
                    'value' => 'SuperJohn'
                ),            'name' => Array
                (
                    'value' => 'John Smith'
                ),            'email' => Array
                (
                    'value' => 'john_smith@example.com'
                )
        ),
        'settings' => array (
            'project_id' => 14004,
            'ui' => array(
                            'theme' => 'default_dark'
                        )
                )
);


$xsollaClient = XsollaClient::factory(array(
    'merchant_id' => MERCHANT_ID,
    'api_key' => API_KEY
));
$response = $xsollaClient->CreatePaymentUIToken(array('request' => $tokenContent));
$token = $response['token'];

Continue reading