RevenueCat

RevenueCat Documentation

Here you will find guides for getting RevenueCat setup and references for our SDKs and APIs.

Guides    Discussions

Quickstart

Get up and running with mobile subscriptions

This guide will get you up and running with subscriptions.

1. Register your app in RevenueCat

Add your app via the RevenueCat dashboard.

One app for all platforms

A single app in RevenueCat supports all platforms.

2. Setup your Entitlements

Entitlements are a simple way for you to organize your in-app products and configure them remotely. This simplifies the client side code and enables you to change products without an app update.

See Understanding Entitlements for how to configure and leverage entitlements.

Configure Products First

Before configuring entitlements, you should setup your in-app products in either App Store Connect or Play Developer Console.

A common and simple setup example is one entitlement with identifier pro, one offering monthly, with one product.

3. Integrate the Purchases Framework

Purchases is our mobile framework available on all platforms that correctly implements in-app building for all platforms and handles syncing purchase tokens with the RevenueCat server.

4. Initialize Purchases

Your app should only have one Purchases object in memory at any given time. If your app has accounts you should initialize when a user logs in. If you do not have your own account system, you should initialize it once on app launch and share the same instance throughout your app.

You can get your API key from app settings in the dashboard.

import Purchases

let purchases = RCPurchases(apiKey: "my_app_api_key")!
@import Purchases

RCPurchases *purchases = [[RCPurchases alloc] initWithAPIKey:@"my_app_api_key"];
Purchases purchases = new Purchases.Builder(this, 
                                            "my_app_api_key",
                                            this).build();
const purchaserInfoHandler = (purchaserInfo, error) => {
  if (purchaserInfo)
  {
    this.receivePurchaserInfo(purchaserInfo);
  }
}

Purchases.addPurchaseListener((productIdentifier, purchaserInfo, error) => {
  if (error) {
    console.warn(error);
  } else {
    this.setState({
      purchasedProduct: productIdentifier
    });
    this.receivePurchaserInfo(purchaserInfo);
  }
});
Purchases.addPurchaserInfoUpdateListener(purchaserInfoHandler);
Purchases.addRestoreTransactionsListener(purchaserInfoHandler);

Purchases.setup(REVENUECAT_API_KEY);

Singletons

Purchases does not provide a singleton for you. Depending on your app architecture and platform you may wish to implement the singleton functionality differently.

5. Make a Purchase

Purchases will automatically fetch the latest entitlements and get the product information from Apple or Google. This means when users launch your purchase screen, products will already be loaded.

purchases.entitlements { entitlements in
  guard let pro = entitlements?["pro"] else { return }
  guard let monthly = pro.offerings["monthly"] else { return }
  guard let product = monthly.activeProduct else { return }
  purchases.makePurchase(product)
}
[purchases entitlements:^(NSDictionary<NSString *, RCEntitlement *> *entitlements) {
  SKProduct *product = entitlements[@"pro"].offerings[@"monthly"].activeProduct;
  [purchases makePurchase:product];
}];
purchases.getEntitlements(new Purchases.GetEntitlementsHandler() {
            @Override
            public void onReceiveEntitlements(Map<String, Entitlement> entitlements) {
                Entitlement pro = entitlementMap.get("pro");
                Offering monthly = pro.getOfferings().get("monthly");
              	SkuDetails details = monthly.getSkuDetails();
              	purchases.makePurchase(this, details.getSku(), details.getType());
            }
        });
let entitlements = await Purchases.getEntitlements()
Purchases.makePurchase(entitlements.pro.monthly.identifier)

Purchases handles the underlying framework interaction and receipt verification. Receipt tokens are stored remotely and kept up-to-date by RevenueCat.

6. Unlock Entitlements

Once the purchase is made, verified, and stored, RevenueCat will send you the latest version of a purchasers available entitlements. It is on you to unlock appropriate content or features in response to this. This is done via the Purchases listener/delegate.

func purchases(_ purchases: RCPurchases, completedTransaction transaction: SKPaymentTransaction, withUpdatedInfo purchaserInfo: RCPurchaserInfo) {
	if purchaserInfo.activeEntitlements.contains("pro") {
  	// Unlock that great "pro" content.
  }
}
- (void)purchases:(RCPurchases *)purchases
completedTransaction:(SKPaymentTransaction *)transaction
  withUpdatedInfo:(RCPurchaserInfo *)purchaserInfo {  
	[purchaserInfo.activeEntitlements containsObject:@"pro"];
}
@Override
public void onCompletedPurchase(String sku, PurchaserInfo purchaserInfo) {
  if (purchaserInfo.getActiveEntitlements().contains("pro")) {
    // Unlock pro content
  }
}
let purchasesHandle = (productIdentifier, purchaserInfo, error) => {
  if (purchaserInfo.activeEntitlements.includes("pro")) {
    // Unlock pro content
  }
}

You've done it!

That's all there is to it! You have now implemented a fully featured subscription purchasing system without spending a month writing server code. Congrats!