SDKs code references for Unity
Easily embed Xsolla services with this ready-to-use libraries for Unity applications and games
|
The SDK is a set of classes and methods for making requests to the Xsolla REST APIs. It includes the following namespaces:
Auth
namespace that contains methods and classes for working with user authentication and for obtaining user information.Catalog
namespace that contains methods and classes for working with virtual items and virtual currencies, making purchases, etc.Subscriptions
namespace that contains methods and classes for purchasing and managing user subscriptions.UserAccount
namespace that contains methods and classes for managing user's personal data and public profile data and linking social network accounts, platform accounts, and devices.Inventory
namespace that contains methods and classes to display and consume the user’s items that they bought or received according to the game logic.Orders
namespace that contains methods and classes for payment processing and opening the payment UI.Cart
namespace that contains methods and classes for managing a shopping cart.Core
namespace that contains lower-level classes that are common to the rest of the SDK. For example, common methods for calling APIs, built-in browser, SDK settings, methods for integrating with third-party solutions, etc.To send requests to Xsolla servers and receive responses, the SDK provides the XsollaAuth
, XsollaCatalog
, XsollaCart
, and XsollaOrders
classes. If you want to implement your own logic for buying items or inventory management, and don’t want to write boilerplate code for API calls, these classes are a good place to start.
The XsollaAuth
, XsollaCatalog
, XsollaSubscriptions
, XsollaUserAccount
, XsollaInventory
, XsollaOrders
, and XsollaCart
classes contain methods to refer to the WebRequestHelper
class, which uses the standard UnityWebRequest class. Since the methods for API calls use coroutines for requests to Xsolla servers, delegates act for them as parameters. Delegates are called when a response is received from the server.
Example:
public void GetUserInfo(string token, Action <UserInfo> onSuccess, Action <Error> onError = null)
The GetUserInfo
method for getting user information has two delegate parameters:
OnSuccess
delegate is called if the server responds successfully. The UserInfo
parameter contains information about the user (nickname, email, etc.).OnError
delegate is called if an error arises from the server. The Error
parameter contains the error code and its description.In addition to methods for calling the APIs, the SDK contains data and classes for making requests to the API and receiving a response — data transfer objects.
Example:
CartItem
class describes a cart item (name, type, and other attributes).UserSocialFriends
is data that describes a user's list of friends.The built-in browser is a separate module designed to open web pages inside the application. It is usually used to open a payment UI and to log a user in via third-party services.
Browser limitations:
To enable/disable the build-in browser use the Enable In-App browser box in the Inspector panel.
When the application starts, it checks for the built-in browser. If the built-in browser isn't installed, it is downloaded. The file that needs to be downloaded is 300 MB, so it may take some time when the user first starts your application. You can also pack the browser in your application. In this case, when building the application, the browser is downloaded in advance and placed in the build folder. To do this, check the Pack In-App Browser in Build box in the Inspector panel.
The BrowserHelper
class is a convenient entry point for interacting with the built-in browser. That class contains the necessary methods for using the browser.
Use the Open
method to open a web page, passing the required URL as a parameter.
To open the payment UI via the built-in browser, use the BrowserHelper
class and the OpenPurchase
method and pass the following parameters:
Url
— Pay Station API endpoint.Token
— Pay Station token.The SDK provides utility classes to work with Unity or third-party modules and solutions.
Example:
SteamManager
class manages authentication via Steam.