Unity SDK

Add in-app purchases and paywalls to your Unity game with one C# API for iOS, Android, and desktop.

The Unity SDK is on the roadmap and is not published yet. com.cashsdk.unity does not resolve from any registry today, so the code on this page describes the intended API rather than a package you can install.

Shipping now? Use the iOS or Android SDK, which are available today. To be notified when this one lands, contact support@cashsdk.com.

The CashSDK Unity SDK gives your game a single, fully typed C# API that runs on iOS (StoreKit 2), Android (Play Billing), and desktop. Fetch offerings, run purchases, and read entitlements with the same async/await code on every build target.

Install#

Package Manager (git URL)

In the Unity Editor, open Window → Package Manager, click + → Add package from git URL…, and paste:

text
https://github.com/cashsdk/cashsdk-unity.git

Unity resolves the package into Packages/manifest.json under the id com.cashsdk.unity.

manifest.json

Add the dependency directly to Packages/manifest.json and let Unity resolve it on next focus:

json
{
  "dependencies": {
    "com.cashsdk.unity": "https://github.com/cashsdk/cashsdk-unity.git#1.0.0"
  }
}

The package bundles the native iOS and Android layers and wires them into your Xcode and Gradle output automatically when you build.

Configure#

Initialize CashSDK once, as early as possible in your game's lifecycle. A RuntimeInitializeOnLoadMethod runs before the first scene loads, which makes it a good home for configuration. Use your publishable key.

csharp
using UnityEngine;
using CashSDKUnity;

public static class Bootstrap
{
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    static void Init()
    {
        CashSDK.Configure("csk_pk_…");
    }
}

Only ship publishable keys (csk_pk_… / csk_pk_…) in your build. Secret keys (csk_sk_…) belong on your backend.

Fetch offerings#

An offering is the set of packages you show on a paywall, for example Monthly and Annual.

csharp
var offering = await CashSDK.Offerings();

var monthly = offering.Monthly;
var annual  = offering.Annual;

Purchase#

Pass a package to Purchase. CashSDK drives the native store flow, validates the receipt server-side, and returns the customer's updated entitlements.

csharp
var result = await CashSDK.Purchase(offering.Monthly);

if (result.Entitlements["pro"].IsActive)
{
    UnlockPro();
}

Check entitlements#

Read entitlements from any purchase or restore result to gate content.

csharp
if (result.Entitlements["pro"].IsActive)
{
    // Show premium content
}
else
{
    // Show the paywall
}

Restore purchases#

Give players a way to recover access on a new device or after a reinstall.

csharp
var result = await CashSDK.RestorePurchases();

if (result.Entitlements["pro"].IsActive)
{
    UnlockPro();
}

Identify the customer#

Link the SDK to your own player ID so entitlements follow the customer across devices and platforms. Call Identify after the player signs in.

csharp
CashSDK.Identify("u_812");

A paywall screen#

Fetch the offering, present its packages as buttons, and unlock on success.

csharp
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using CashSDKUnity;

public class PaywallScreen : MonoBehaviour
{
    [SerializeField] Button monthlyButton;
    [SerializeField] Text priceLabel;

    async void Start()
    {
        var offering = await CashSDK.Offerings();
        priceLabel.text = offering.Monthly.LocalizedPrice;
        monthlyButton.onClick.AddListener(() => _ = Buy(offering.Monthly));
    }

    async Task Buy(Package package)
    {
        var result = await CashSDK.Purchase(package);
        if (result.Entitlements["pro"].IsActive)
        {
            // Dismiss and unlock
        }
    }
}

Next steps#