How to use Pay Station in combination with PlayFab authentication
If you have already implemented user authentication in your application using PlayFab, you can generate a payment token on PlayFab side and then pass it to the client side of the application to open the payment UI.
Using this integration option, you need to independently implement the logic for determining the user’s country and currency to pay for the purchase.
Integration flow:
- Sign up to Publisher Account and create a new project. You will need the ID of the created project in further steps.
- Set up a catalog:
- Create an item catalog on Xsolla side. You can add items manually or import them from Google Play or PlayFab.
- Implement getting and displaying the catalog on the client side of the application using the SDK.
- Set up an item purchase:
- Create an order with user and item data on the client side of the application using the PlayFab cloud script.
- Implement opening of the payment UI on the client side of your application using the SDK.
To complete the integration and start accepting real payments, you need to sign a licensing agreement with Xsolla.
You can sign the licensing agreement at any integration step, but keep in mind that the review process can take up to 3 business days.
Create project
Sign up to Publisher Account
Publisher Account is the main tool to configure Xsolla features, as well as to work with analytics and transactions.
The data about the company and your application specified during registration will be used to create a draft licensing agreement with Xsolla and to generate recommendations on solutions that are suitable for you. You can change the data later, but providing the correct data when you sign up will speed up the process of signing the licensing agreement.
To sign up, go to Publisher Account and create an account.
The password from Publisher Account can consist of Latin letters, numerals, and special characters and must contain at least:
- 8 characters
- one digit
- one capital letter
- one lowercase letter
To ensure password security, we recommend:
- changing your password at least once every 90 days
- using a new password that does not match the last 4 passwords on your account
- using a unique password that does not match passwords used anywhere else
- not storing your password where it is easily accessible
- using password managers to store your password
Publisher account uses two-factor authentication and sends a confirmation code with each authentication attempt.
Create project in Publisher Account
If you have multiple applications, we recommend creating a separate project for each application. Based on the data specified during project creation, Xsolla generates recommendations on solutions that are suitable for you.
To create a new project:
- Open Publisher Account.
- In the side menu, click Create project.
- Enter your project name in English (required).
- Select one or several release platforms of your game (required).
- Add a link to your game. If your game doesn’t have a website yet, add a link to the source that includes information about the game (required).
- Select the game engine.
- Select the monetization options you use or plan to use.
- Specify if the game is already released. If the game hasn’t been released yet, specify the planned release date.
- Click Create project. You will see a page with the Xsolla products recommended for you.
During the integration process, you need to provide the project ID that can be found in your Publisher Account next to the project name.
Set up catalog
Create items in Publisher Account
You need to create a catalog on Xsolla side. You can add items manually or import them from Google Play or PlayFab. When importing from Google Play, you can import a maximum of 100 items at a time.
These instructions provide steps for basic setup of a virtual item. Later, you can add other items to your catalog (virtual currency, bundles, game keys), create item groups, set up promotional campaigns, regional prices, etc.
To add a virtual item with basic settings to the catalog:
- Open your project in Publisher Account.
- Click Store in the side menu.
- In the Virtual Items pane, click Connect.
- In the drop-down menu, select Create item.
- Set the basic settings of the item in the following fields:
- Image (optional)
- SKU (item unique ID)
- Item name
- Description (optional)
- Specify item price:
- Set the Price in real currency toggle to On.
- In the Default currency field, change the currency (optional) and specify the item price.
- If you changed the currency in the Default currency field, select the same currency in the Price in real currency field.
- Change the item status to Available.
- Click Create item.
Install and set up SDK
- Download the Epic Games Launcher.
- Create a new Unreal Engine project.
- Download and install the SDK:
- To download and install the SDK from the Unreal Engine Marketplace:
- Go to the SDK page on the Unreal Engine Marketplace.
- Click
Open in Launcher .
- To download and install the SDK from the Unreal Engine Marketplace:
- Go to Epic Games Launcher.
- Click
Install to Engine . - Open your Unreal Engine project in Unreal Editor.
- Go to the
Settings > Plugins > Installed > Xsolla SDK section. Check theEnabled box and clickRestart Now to save settings and reload the Unreal Editor.
- Click
- To download and install the SDK from GitHub:
- Download the package with the SDK for your version of the engine.
- Unzip the package.
- Move the SDK folder to the
plugins
directory in the root of your Unreal Engine project.
- To download and install the SDK from GitHub:
- Go to
Settings > Project Settings > Plugins > Xsolla Settings > General . - In the
Project ID field, specify the project ID that can be found in Publisher Account next to the name of your project.
Display catalog on client side of application
In this instruction, the GetVirtualItems
SDK method is used to get a list of virtual items. You can also get information about catalog items using other SDK methods.
For a step-by-step tutorial on creating a catalog page, refer to the Display of item catalog section.
Create class for catalog item
- In
Content Browser , go to theContent directory. - Call the context menu and select
Blueprint Class .
- In the
All Classes section, selectObject and clickSelect .
- Specify
StoreItemData as the class name. - Open the blueprint of the created class.
- In the
My Blueprint panel, clickAdd New and selectVariable . - In the
Details panel:
- Specify
StoreItem in theVariable Type field. - Check the
Instance Editable andExpose on Spawn boxes.
- Specify
- Save and close the
StoreItemData blueprint.
Create widget of catalog item
- In
Content Browser , go toContent directory. Call the context menu and selectUser Interface > Widget Blueprint . - Specify
StoreItem as the blueprint name. - Open the created blueprint.
- In the
Hierarchy panel, call the context menu for theCanvasPanel element. SelectReplace With > Overlay .
- Place the UI primitives from the
Palette panel as shown below. For an item's image, title, and description, check theIs Variable box in theDetails panel.
- Open the
Graph view. - Click
Class settings . - In the
Details panel, go toInterfaces > Implemented Interfaces . - Click
Add and selectUserObjectListEntry . This is a standard UE interface that allows the UI primitive to implement a behavior normal for the element of the list.
- Add logic for the
OnListItemObjectSet
event:- In the
My Blueprint panel, call the context menu for theInterfaces section and selectImplement event .
- In the
- Add nodes as shown below:
- Save and close the
StoreItem blueprint.
Create widget for catalog page
- In
Content Browser , go to theContent directory and selectUser Interface > Widget Blueprint from the context menu. - Specify
WBP_Store as the name of the blueprint. - Open the created blueprint.
- In the item display area, add the
List View element and name itStoreListView .
- In the
Details panel, in theEntry Widget Class field, select the previously created class for the item (StoreItem
). - Go to the
Graph view. - Bind the
GetVirtualItems
SDK method call to theEventConstruct
node, as shown in the figure below.
StoreItemData
class is created to correctly transfer the array of objects.- In the
My Blueprint panel, clickAdd New and selectVariable . - In the
Details panel:- In the
Variable Type field, selectString . - Check the
Instance Editable andExpose on Spawn boxes. - Specify
PlayFabId as the name.
- In the
- Save and close the
WBP_Store widget. - Add directory display logic. Below is an example of implementation of directory display after successful user authentication.
Set up item purchase
To create an order with user and item data on Xsolla side, add a cloud function to the project that uses the Create payment token for purchase API call. This call will return a payment token, which is required to open the payment UI and make a purchase.
Limitations:
- You need to pass either the user country or the user’s IP address when requesting the payment token.
- If you don’t pass the currency in the token, it is determined by the country.
- If you pass the currency in the token, the user pays in this currency.
PlayFab project should be created and PlayFab SDK should already be integrated into your Unity project.
PlayFab Cloud Scripts do not directly support functions with HTTP triggers, so Azure functions are used to implement the receiving of webhooks.
To get started with Azure functions, create an Azure account and prepare your development environment. This instruction describes the steps in the development environment with the following settings:
- Visual Studio Code is installed.
- The extension for working with Azure functions is installed.
Add cloud script to your project
- Open Visual Studio Code and go to the
Azure tab. - In the
Workspace section, click the + icon and selectCreate Function .
- Select the new project directory. A menu for creating a new project will appear with a choice of settings.
- Specify the new project settings:
- Select a language for your function project —
JavaScript . - Select a JavaScript programming model —
model V4 . - Select a template for your project's first function —
HTTP trigger . - Enter a function name —
getXsollaPaymentToken
. - Select how you would like to open your project —
Open in current window .
- Select a language for your function project —
- As a result, Visual Studio Code will generate a JS project and open the generated
getXsollaPaymentToken.js
file.
- Modify the
getXsollaPaymentToken.js
file:
- js
const { app } = require('@azure/functions');
const projectId = ""; //your xsolla project id from publisher account
const apiKey = ""; your api key from publisher account
app.http('getXsollaPaymentToken', {
methods: ['POST'],
authLevel: 'anonymous',
handler: async (request, context) => {
var body = await request.json();
const userId = body.uid;
const email = body.email;
const sku = body.sku;
const returnUrl = body.returnUrl;
if (!userId) {
return {status: 400, body: 'Request body is missing' };
}
const payload = {
user: {
id: {value: userId},
name: {
value: email
},
email: {
value: email
},
country: {
value: 'US',
allow_modify: false
}
},
purchase: {
items: [
{
sku: sku,
quantity: 1
}
]
},
sandbox: true,
settings: {
language: 'en',
currency: 'USD',
return_url: returnUrl,
ui: {
theme: '63295aab2e47fab76f7708e3'
}
}
}
let url = "https://store.xsolla.com/api/v2/project/" + projectId.toString() + "/admin/payment/token";
return fetch(
url,
{
method: "POST",
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + btoa(`${projectId}:${apiKey}`)
},
body: JSON.stringify(payload)
},
)
.then(xsollaRes => {
// Handle the response data
if (xsollaRes.ok) {
return xsollaRes.json();
} else {
return { status: 400, body: `HTTP request failed with error: ${xsollaRes.statusText}` };
}
})
.then(data => {
return { status: 200, body: JSON.stringify(data) };
})
.catch(error => {
return { status: 501, body: `Error = ${error}` };
});
}
});
- In the script, specify the values of the constants:
PROJECT_ID
— project ID that you can find in your Publisher Account next to the project name.
API_KEY
— API key. It is shown in Publisher Account only once when it is created and must be stored on your side. You can create a new key in the following section:- Company settings > API keys
- Project settings > API keys
After adding the cloud script, you can test the call of the getXsollaPaymentToken
function locally.
Deploy cloud script
- In Visual Studio Code go to
Azure > Resources section and click the + icon. - Select
Create Function App in Azure as a resource. A menu for creating a new application will appear with a choice of settings. - Set application settings:
- Enter the name for the new function app —
XsollaFunctions
. - Select a runtime stack —
.NET 8 Isolated . - Select a location for new resources (you can choose any option).
- Enter the name for the new function app —
- Wait until the resource group is created.
- In the list of resources, select the
XsollaFunctions
, call the context menu and selectDeply to Function App .
After adding the cloud script, you can test the call of the getXsollaPaymentToken
function remotely.
Test cloud script
To test the cloud script (locally or remotely), call the getXsollaPaymentToken
function using Postman or another tool. To do this:
- In Visual Studio Code, go to the
Azure > Workspace > Local Project > Functions section and clickStart debugging to update this list . - Call the context menu for the
function and select
Copy Function Url . When testing locally, the URL will look like this —http://localhost:7071/api/getXsollaPaymentToken
. When testing remotely —https://xsollafunctions.azurewebsites.net/api/GetXsollaPaymentToken
.
- Use the copied URL to call the function with the specified parameters. To call a function from Postman:
- Create a new
GET
request. - Provide the URL you copied in step 2.
- Go to the
Body tab and specify the request parameters.
- Create a new
Example request body:
- json
{
"FunctionArgument": {
"uid": "1D384D9EF12EAB8B",
"sku": "booster_max_1",
"returnUrl": "https://login.xsolla.com/api/blank"
}
}
uid
). As the item SKU (sku
), specify the SKU of the virtual item that you previously added in Publisher Account.- Click
Send . In the response you should receive JSON with the following parameters:token
— payment token. Required to open the payment UI.order_id
— ID of the created order. Required to track order status.
Example response body:
- json
{"token":"xsnpCF8tS4ox7quoibgTgPFVFxG9gTvS_lc_en_bg_2C2640_tb_6E7BF7","order_id":90288613}
Register function for getting payment token in PlayFab
- Open your project in PlayFab.
- In the side menu, click
Automation . - In the
Register New Cloud Script Function . section, clickRegister Function . - Enter the name of the function —
GetXsollaPaymentToken
. - Enter the function URL that you copied into Visual Code Studio (see steps 1-2 of Test cloud script).
Create order and open payment UI in Unreal Engine project
- Open your Unreal Engine project.
- Open the
WBP_Store widget. - In the
Hierarchy panel, selectStoreListView . - In the
Details panel, click the + icon next to theOn Clicked event.
- Go to the
Graph view. - Add the logic for creating a
PlayfabJsonObject
object and passing data to it to create an order to theOnItemClicked
node, as shown below:
- Add a call to the
ExecuteFunction
method. Pass thefunctionName = getXsollaPaymentToken
andFunctionParameter = PlayfabJsonObject
parameters to it.
Set up order status tracking
Tracking the order status is required to ensure that the payment was successful and to grant items to the user.
Get order status on client side
To track changes of the order status, use the CheckPendingOrder
SDK method in the client part of the application. Pass the following parameters to the method:
AuthToken
— user authorization tokenOrderId
— order ID received from purchase via the shopping cart, one-click purchase, or purchase for virtual currencySuccessCallback
— callback in case the order moves to the done statusErrorCallback
— callback in case Xsolla server returns an error
For detailed information about how the method works, refer to the Track order status section.
Get order status on server side
The SDK allows you to track the order status on the client side of your application. However, we recommend setting up the Payment webhook handler to receive order information in the back end of your application. This allows you to implement additional validation of completed purchases.
For the full list of webhooks and general information about working with them, refer to the webhooks documentation.
To configure webhooks on Xsolla side:
- Open your project in Publisher Account.
- Click Project settings in the side menu and go to the Webhooks section.
- In the Webhook server field, enter the URL to which Xsolla will send webhooks.
To test webhooks, you can also choose any dedicated site, such as webhook.site, or a platform, such as ngrok.
For testing purposes, you can also add a cloud script that simulates successful webhook processing. The script code is available on GitHub.
For a real project, you need to add purchase validation logic.
- Copy and save the value from the Secret key field. This key is generated by default and is used to sign webhooks. If you want to change it, click the update icon.
- Click Enable webhooks.
Found a typo or other text error? Select the text and press Ctrl+Enter.