Programming

In-app subscription: RevenueCat

Check the Play product through an entitlement. The Android key starts with goog_.

All lessons · JavaScript lessons: learn from scratch

Three words

RevenueCat is there to check Play and App Store payments from one panel. The app does not talk to the store directly. It talks to its SDK. A product is the subscription id in Play, for example monthly_pro. An entitlement is the key of the payment, for example pro_access. If it is active, it sits in the list. An offering is the group of packages shown to the user. The price changes in the panel, not in the code.

Connect it

In Play Console, under Monetize, Subscriptions, create a subscription and give it an id. Open a project in RevenueCat. Take the Service Account JSON from Google Cloud and upload it to the panel. That file is secret: do not put it on GitHub. Then write that product id into the Products section. In the app, install the package and sync. The Android key starts with goog_. The Apple key starts with appl_. Do not write the Apple key into Android.

npm install @revenuecat/purchases-capacitor
npx cap sync

Check and buy

configure is called once, when the app opens. getCustomerInfo shows the active entitlement. The name must match the panel. A letter difference counts. The package comes from the offering. You do not write the price. A cancel is userCancelled. Do not test with a real card. Add the test account to the License testing list in Play.

import { Purchases } from "@revenuecat/purchases-capacitor";

await Purchases.configure({ apiKey: "goog_ACAR" });

const { customerInfo } = await Purchases.getCustomerInfo();
const aktiv = customerInfo.entitlements.active["pro_access"];

const offerings = await Purchases.getOfferings();
const paket = offerings.current?.availablePackages?.[0];
if (paket) {
  const { customerInfo: sonra } = await Purchases.purchasePackage({ aPackage: paket });
  const aldi = sonra.entitlements.active["pro_access"];
}

Questions

What is the difference between goog_ and appl_? goog_ is for Android. appl_ is for Apple. The wrong platform key rejects the request.

Why does pro_access stay missing? The name in the panel and the name in the code are not the same. A capital letter is a difference too.

Where must the JSON file not go? Onto GitHub and into the app. Upload it only to the RevenueCat panel. The goog_ key stays in the app. It is a public key.

Author: Nibras Code