跳到主要内容

Quick Start 🚀

信息

To get access to the Xsolla SDK for Unity during Developer Preview phase, please fill out the form ↗ (https://xsolla.com/mobile-sdk).

Getting Started

信息

Xsolla SDK for Unity is an evolution of the enterprise-level Xsolla SDK solution, which was designed for integration into large-scale projects.

🔥 Proven in production: follow the exact integration path used by games like Crossout and Modern Warship, complete with DMA-compliant billing and 1,000+ payment methods ready out of the box.

This quick start guide makes it simple to integrate the Xsolla SDK for Unity and start accepting payments in your Unity-based game. We'll use a pre-configured test project to cover all the essentials: setting up basic user authentication, importing your products (SKUs), and processing a test payment.

By the time you're done, you'll have a working payment system right in your game, seeing firsthand how Xsolla can streamline your monetization. Let's dive in and get your game accepting payments in just a few easy steps!

Install the SDK

提示

During the Preview phase, please contact your Account Manager to get access to the Xsolla SDK for Unity.

  1. Open the Unity Editor.
  2. In the main menu, click Window > Package Manager.
  3. Add a package as a dependence:
    • Click the ➕ icon and select Add package from tarball.
    • Select the downloaded SDK package (.tgz).
    • Click Open and wait for the import to complete.

Configure the SDK

In the Unity Editor:

  • Go to Window > Xsolla > MobileSDK > Edit Settings from the main menu

  • Go to Inspector panel

  • In the opened asset, set these pre-defined sample project properties below to their respective values:

    PropertyValue
    Project ID77640
    Login ID026201e3-7e40-11ea-a85b-42010aa80004

    提示

    The provided project and login IDs are predefined and can be used for quick test integrations.

  • Your settings asset should look similar to this:

    publisher account 6

  • Now, add these few lines to your scene initialization code, e.g. Start() method of a class that inherits from MonoBehaviour:

    public class YourSDKIntegrationBehaviour : MonoBehaviour, IDetailedStoreListener {
    public Start() {
    var settings = XsollaStoreClientSettingsAsset.Instance().settings;

    var configuration = XsollaStoreClientConfiguration.Builder.Create()
    .SetSettings(settings)
    .SetSandbox(true)
    .SetLogLevel(XsollaLogLevel.Debug)
    .Build();
    // ...
    }
    // ...
    }
    iOS

    For compliance in the U.S. regarding redirecting players to the web, use WebViewType.External:

    settings = XsollaClientSettings.Builder.Update(settings)
    .SetWebViewType(XsollaClientSettings.WebViewType.External)
    .Build();

    For in-app payment compliance in Europe under the DMA, use WebViewType.Auto

    settings = XsollaClientSettings.Builder.Update(settings)
    .SetWebViewType(XsollaClientSettings.WebViewType.Auto)
    .Build();

Initialize the SDK

Now, when we have our configuration ready, it's time to move onto initialization of the SDK itself.

信息

There are currently no plans to support In-App Purchasing Unity 5.0.0 due to potential compatibility risks that may impact the overall integration experience. We will continue to monitor developments and reassess support based on future updates and demand.

  • Make sure Unity InAppPurchasing plugin is already installed:

    信息

    For information on how to install Unity InAppPurchasing plugin, refer to this page ↗ (https://docs.unity3d.com/Packages/com.unity.purchasing@4.5/manual/GettingStarted.html)

  • Create the SDK module using the XsollaPurchasingModule.Builder with the configuration you prepared earlier as its parameter inside YourSDKIntegrationBehaviour's Start method:

    var module = XsollaPurchasingModule.Builder.Create()
    .SetConfiguration(configuration)
    .Build();
  • Feed the created SDK module into the ConfigurationBuilder and populate the returned instance with the SKUs pre-created for testing purposes:

    var configurationBuilder = ConfigurationBuilder.Instance(module)
    .AddProduct("key_1", ProductType.Consumable);
  • Register the SDK with the Unity's InAppPurchasing:

    UnityPurchasing.Initialize(this, configurationBuilder);

Make a Purchase

Once the SDK is fully initialized, a purchase can be made.

Modify the MonoBehavior used for configuration and initialization steps to also inherit from IDetailedStoreListener. And add the lines below to it:

public class YourSDKIntegrationBehaviour : MonoBehaviour, IDetailedStoreListener {
// ...

public void OnInitialized(IStoreController controller, IExtensionProvider extensions) {
controller.InitiatePurchase("key_1");
}

// ...

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) {
if (args.purchasedProduct.definition.id == "key_1") {
Debug.Log("Successfully purchased 'key_1'");
}
return PurchaseProcessingResult.Complete;
}

// ...

Collect Payment

The SDK relies on Xsolla Pay Station for secure payment collection.

These steps will guide you through a test payment collection flow:

What's next?

Congratulations! 🎉 You've successfully integrated Xsolla SDK for Unity and processed your first test payment. This achievement unlocks access to over 1000 global payment methods and sets the foundation for integrating more Xsolla solutions, including our powerful Web Shop.

You've mastered the basics:

  • ✅ User authentication
  • ✅ SKU management
  • ✅ Secure payment processing

This is just the beginning of optimizing your game's monetization. Ready to explore more? Check out our documentation for advanced features and other Xsolla products to further boost your game's success!

important

The next thing you need to do is to create your own publisher account and set up a new project.

备注

You might also be interested in exploring the extended example (based on Unity IAP) provided for your convenience to gain a better understanding of the whole purchasing flow based on Xsolla SDK for Unity.