RevenueCat

Build With RevenueCat

Build a customized mobile subscription business with RevenueCat. We do the heavy lifting of normalizing subscribers from any source and maintain a single source of truth for subscription status, so you can get back to building your app.

RevenueCat is a powerful, secure, reliable, and free to use in-app purchase server with global support. All you need to get started is an API key.

Unity

Instructions for installing Purchases SDK for Unity

The Purchases SDK provided by RevenueCat allows you to implement subscriptions in your Unity app easily.

Installation

1. Add the Purchases Unity package

Download the latest version of Purchases.unitypackage. Add it to your Unity project. Make sure the PlayServiceResolver plugin is also added, it will add all the Android dependencies automatically in Plugins/Android when using the Android platform.

2. Create a GameObject with the Purchases behavior

The Purchases package will include a MonoBehavior called Purchases. This will be your access point to RevenueCat from inside Unity. It should be instantiated once and kept as a singleton. You can use properties to configure your API Key, app user ID (if you have one), and product identifiers you want to fetch.

The Purchases behavior is configured with your RevenueCat API key and the product identifiers you want to fetch.

The Purchases behavior is configured with your RevenueCat API key and the product identifiers you want to fetch.

3. On iOS, add StoreKit.framework to Linked Frameworks and Libraries in XCode

4. Subclass Purchases.Listener MonoBehavior

The Purchases behavior takes one additional parameter, a GameObject with a Purchases.Listener component. This will be where you handle purchase events, and updated subscriber information from RevenueCat. Here is a simple example:

using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public class PurchasesListener : Purchases.UpdatedPurchaserInfoListener
{
  
  private void Start()
    {
        CreateButton("Restore Purchases", RestoreClicked, 100);

        CreateButton("Do Other Stuff", DoOtherStuff, 300);

        var purchases = GetComponent<Purchases>();
        purchases.SetDebugLogsEnabled(true);
        purchases.GetOfferings((offerings, error) =>
        {
            if (error != null)
            {
                LogError(error);
            }
            else
            {
               var package = offerings.Current.Monhtly;
               if (package == null) continue;
                    var label = package.PackageType + " " + package.Product.priceString;
                    CreateButton(label, () => ButtonClicked(package), 500);
                }
            }
        });
    }
  
    void ButtonClicked(Purchases.Package package)
    {
        Purchases purchases = GetComponent<Purchases>();
        purchases.PurchasePackage(package, (productIdentifier, purchaserInfo, userCancelled, error) =>
        {
            if (!userCancelled)
            {
                if (error != null)
                {
                    LogError(error);
                }
                else
                {
                    DisplayPurchaserInfo(purchaserInfo);
                }
            } else
            {
                Debug.Log("Subtester: User cancelled, don't show an error");
            }
        });
    }
    
    void DoOtherStuff()
    {
        var purchases = GetComponent<Purchases>();
        var data = new AdjustData
        {
            adid = "test",
            network = "network",
            adgroup = "adgroup",
            campaign = "campaign",
            creative = "creative",
            clickLabel = "clickLabel",
            trackerName = "trackerName",
            trackerToken = "trackerToken"
        };

        purchases.AddAttributionData(JsonUtility.ToJson(data), Purchases.AttributionNetwork.ADJUST);
        
        purchases.GetPurchaserInfo((info, error) =>
        {
            Debug.Log("purchaser info " + info.ActiveSubscriptions);
            if (error != null) {
                LogError(error);
            }
        });
        
        Debug.Log("user ID " + purchases.GetAppUserId());
    }

    void RestoreClicked()
    {
        var purchases = GetComponent<Purchases>();
        purchases.RestoreTransactions((purchaserInfo, error) =>
        {
            if (error != null)
            {
                LogError(error);
            }
            else
            {
                DisplayPurchaserInfo(purchaserInfo);
            }
        });
    }

    
    public override void PurchaserInfoReceived(Purchases.PurchaserInfo purchaserInfo)
    {
        DisplayPurchaserInfo(purchaserInfo);
    }
    
    private void logError(Purchases.Error error)
    {
        Debug.Log("Subtester: " + JsonUtility.ToJson(error));
    }


    private void DisplayPurchaserInfo(Purchases.PurchaserInfo purchaserInfo)
    {
        // Show purchaser info on screen
    }
}

Next Steps

Updated about 22 hours ago

Unity


Instructions for installing Purchases SDK for Unity

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.