Skip to content

xsolla/xsolla-sdk-unity

Repository files navigation

Xsolla Mobile SDK for Unity

Unity 2022.3+ C# UPM compatible

Pre-built Unity SDK for integrating in-game payments into your app via Xsolla Pay Station.

SDK Explorer

See exactly how payments work before writing a single line of code. The SDK Explorer lets you walk through authentication, catalog loading, purchasing, and finalization — all in an interactive environment.

SDK Explorer — interactive demo of Xsolla Mobile SDK payment flow

Integrate Now →

Essential Links

Overview

Xsolla Mobile SDK provides a Unity IAP-compatible purchasing module for in-game purchases via Xsolla Pay Station. It integrates with Unity's standard IStoreListener pattern so the purchase flow feels familiar to Unity developers.

Key features:

  • 1000+ payment methods across 200+ geographies
  • 130+ currencies including local and alternative payment methods
  • Built-in anti-fraud protection
  • 25+ languages supported out of the box
  • Player authentication (Xsolla Login widget, social login, custom tokens)
  • Product catalog and virtual items
  • Buy Button and Web Shop integration

Requirements

  • Unity 2022.3 LTS or later
  • Unity IAP (com.unity.purchasing) 4.13.0+ (5.x is not supported)

Installation

Add the package via Unity Package Manager using the Git URL:

  1. In Unity, go to Window > Package Manager
  2. Click + > Add package from git URL...
  3. Enter:
    https://github.com/xsolla/xsolla-sdk-unity.git
    
  4. Click Add

Quick Start

1. Connect

Configure the SDK with your project credentials, set up a purchase listener (see step 4), and initialize Unity Purchasing:

using UnityEngine;
using UnityEngine.Purchasing;
using Xsolla.SDK.Common;
using Xsolla.SDK.UnityPurchasing;

var settings = XsollaClientSettings.Builder.Create()
    .SetProjectId(77640)
    .SetLoginId("026201e3-7e40-11ea-a85b-42010aa80004")
    .Build();

var configuration = XsollaClientConfiguration.Builder.Create()
    .SetSettings(settings)
    .SetSandbox(true)
    .Build();

var module = XsollaPurchasingModule.Builder.Create()
    .SetConfiguration(configuration)
    .Build();

var builder = ConfigurationBuilder.Instance(module);
builder.AddProduct("com.xsolla.crystals.10", ProductType.Consumable);
// ...more products

UnityPurchasing.Initialize(this, builder); // `this` implements IStoreListener

2. Handle Initialization

Store the controller and Xsolla extensions when Unity Purchasing is ready:

private IStoreController _storeController;
private IXsollaPurchasingStoreExtension _xsollaExtensions;

public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
    _storeController = controller;
    _xsollaExtensions = extensions.GetExtension<IXsollaPurchasingStoreExtension>();

    // Products are now available via controller.products.all
}

public void OnInitializeFailed(InitializationFailureReason error, string message)
{
    // Handle error
}

3. Purchase

Initiate a purchase using the store controller:

Product product = _storeController.products.WithID("com.xsolla.crystals.10");
_storeController.InitiatePurchase(product);

4. Finalize

Handle completed transactions in ProcessPurchase, validate the receipt, and confirm:

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
    _xsollaExtensions.GetValidator().Validate(args.purchasedProduct.receipt, (success, error) =>
    {
        if (success)
        {
            // Award the product to the user
            _storeController.ConfirmPendingPurchase(args.purchasedProduct);
        }
    });

    return PurchaseProcessingResult.Pending;
}

public void OnPurchaseFailed(Product product, PurchaseFailureReason reason)
{
    // Handle error
}

For the full integration guide, see the SDK Documentation.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

 
 
 

Contributors