The template already carries the code: the server verifies purchases with RevenueCat (/api/billing/revenuecat, billing.sync, the cron reconciliation) and the app has the Subscription screen behind the billing.mobile flag. A project adds store products, a RevenueCat project, keys and a webhook. How the pieces fit is in Payments and ADR-0004.
The app shows store prices and runs the purchase, then asks the server (billing.sync). The
server reads the customer from RevenueCat's REST API and writes billing_entitlement. Only that
row, in the server's BILLING_ENVIRONMENT and verified recently, is Paid Access.
How identity works
The RevenueCat App User ID is our User id. After sign-in the app configures the SDK (or calls logIn) with user.id and keeps it identified for the whole session; sign-out calls logOut. Nobody buys while signed out, so purchases never start on an anonymous RevenueCat user.
A store account (Apple Account, Google account) can still be used by two Users of the app. What happens then is RevenueCat's Restore behavior (Project settings → General). The template keeps RevenueCat's default, "Transfer to new App User ID", and is built for it:
- Restore (or a purchase) on the second User moves the purchases to that User. RevenueCat sends
TRANSFER, the server re-reads both Users, and the first one loses access: one User has access at a time. - The SDK stays logged in with the User id for the whole session, so a transfer always lands on a signed-in User, never on an anonymous id that no account owns.
- A restore that finds nothing on the store account says so ("This store account has nothing to restore"), unless the server finds access anyway.
The other two settings refuse the move instead. "Transfer if there are no active subscriptions" refuses it while a subscription is active; "Keep with original App User ID" refuses every restore under another id, and the app then says the purchase belongs to another account. Choose one of them only if a purchase must never move between accounts, and test restore on two accounts again. Source: Restore behavior, read 2026-11-27.
Set up
Pick the entitlement ids
An entitlement is what a purchase unlocks. The template's default is
pro. Use the same id in RevenueCat and in the web plan catalog (packages/api/src/features/billing/billing.plans.ts), so a Stripe, Polar or Pagar.me purchase and a store purchase unlock the same Paid Access.Create the store products
Bundle id and package name are in
apps/mobile/app.config.ts(BUNDLE_IDENTIFIER,PACKAGE_NAME). The development build adds.devto both.App Store Connect:
- Sign the Paid Apps agreement (Business).
- Create the app with the bundle id.
- Add a subscription group with one auto-renewable subscription per plan (for example
pro_monthlyandpro_yearly), each with a price and a localization. - Create an In-App Purchase key (Users and Access → Integrations → In-App Purchase). RevenueCat needs it.
Google Play Console:
- Create the app with the package name.
- Upload a build to the internal or closed testing track. Play only lists products for an app that has a build with the billing permission, which
react-native-purchasesadds. - Create one subscription per plan, each with a base plan and a price.
- Create a Google Cloud service account with access to the Play Console's financial data, and download its JSON key for RevenueCat.
Keep the product ids at hand: RevenueCat asks for them when you attach products.
Create the RevenueCat project
In the RevenueCat dashboard:
- Create a project.
- Add an App Store app (bundle id and In-App Purchase key) and a Play Store app (package name and service account JSON).
- Optionally set up App Store Server Notifications and Google real-time developer notifications with the URLs RevenueCat shows. Events then arrive within minutes, not hours.
- Note each app's id (Project settings → Apps,
app…); these go inREVENUECAT_APP_IDS. - Copy each app's public SDK key:
appl_…for iOS,goog_…for Android. - Create the entitlement (
pro) and attach every product to it. - Create an offering (for example
default), mark it Current, and add one package per product ($rc_monthly,$rc_annual, …). The app shows the current offering, with the store's localized prices. - Create a secret API key (Project settings → API keys,
sk_…) for the server. The server calls REST API v1 (GET /v1/subscribers/{app_user_id}), so use a v1 key; RevenueCat says v1 keys do not work with API v2.
The public keys go in the app; the secret key and the app ids go on the server.
Register the webhook
Project → Integrations → Webhooks → add one per server:
- URL:
https://<origin>/api/billing/revenuecat. - Authorization header value: 32 to 512 random characters. RevenueCat sends it verbatim as
Authorization; it goes inREVENUECAT_WEBHOOK_AUTHORIZATION. - HMAC webhook signing: turn it on and copy the secret into
REVENUECAT_WEBHOOK_SIGNING_SECRET. RevenueCat shows the secret once; rotating it invalidates the old one right away. When the variable is set, the server refuses unsigned deliveries. Without it, only the Authorization header authenticates them. - Environment: production purchases for the production server, sandbox for preview or staging servers.
Send a test event. The endpoint answers
200. RevenueCat counts any other status as a failure and retries five times over about 80 minutes. The server also answers200, and does nothing, for an event from another store environment or from an app that is not inREVENUECAT_APP_IDS.- URL:
Configure the server
Locally in
apps/web/.dev.vars; in production as Worker secrets (see Payments and thepaymentsskill forwrangler secret bulk):BILLING_PROVIDERS="revenuecat" # add stripe/polar/pagarme for the web BILLING_ENVIRONMENT="SANDBOX" # PRODUCTION only when going live REVENUECAT_SECRET_API_KEY="sk_…" # v1 secret key, never in the app REVENUECAT_WEBHOOK_AUTHORIZATION="…" # the header value from the webhook REVENUECAT_WEBHOOK_SIGNING_SECRET="…" # optional, when HMAC signing is on REVENUECAT_APP_IDS="app…,app…" # iOS and Android apps (and .dev apps) REVENUECAT_ENTITLEMENT_IDS="pro" # BILLING_MAX_VERIFIED_AGE_SECONDS="7200" # 300 to 86400A store purchase counts only in its own environment: in
SANDBOXthe server accepts sandbox transactions from the App Store and Google Play, inPRODUCTIONonly real ones. RevenueCat Test Store and web stores never grant Paid Access through this provider.A promotional entitlement (granted in the customer's page of the dashboard, or with
POST /v1/subscribers/{app_user_id}/entitlements/{entitlement_id}/promotional) does grant Paid Access, in both environments: RevenueCat says grants work in sandbox and production apps and always count as production. It shows as storepromotionalwith arc_promo_…product id, lasts until the grant ends (for good when it has no end), never shows as renewing, and ends when you revoke it (…/revoke_promotionals). Its webhook (a productionNON_RENEWING_PURCHASEwith storePROMOTIONALand noapp_id) is accepted by a sandbox server too.Configure the app
In
apps/mobile/.env:EXPO_PUBLIC_REVENUECAT_IOS_API_KEY="appl_…" EXPO_PUBLIC_REVENUECAT_ANDROID_API_KEY="goog_…" # Optional: RevenueCat's own screens instead of the template's rows # EXPO_PUBLIC_REVENUECAT_PAYWALL="true" # the Paywall of the current offering # EXPO_PUBLIC_REVENUECAT_CUSTOMER_CENTER="true" # Customer Center (RevenueCat Pro plan)Without the Paywall flag the screen lists the current offering's packages with our own rows. Design a Paywall for the offering in the dashboard before turning it on: RevenueCat shows a default one otherwise. Without the Customer Center flag, "Manage subscription" opens the store's subscription settings.
The SDKs are native modules, so the app needs a development build that includes them (
pnpm --filter mobile exec expo run:ios, or an EAS build). An older build without them shows "This version of the app can't open the store" and grants nothing.Turn on the screen
In
/admin/flags, turn onbilling.mobile. Profile → Subscription appears. The store connects only while the flag is on and the server listsrevenuecat.
Test in the sandbox
A real purchase needs a device or simulator, store test accounts and the products above. CI cannot do it.
iOS on a device: create a sandbox tester in App Store Connect (Users and Access → Sandbox), then sign in on the device under Settings → Developer → Sandbox Apple Account (iOS 18 and later). The products must belong to the bundle id of the build you run. The development build uses ….dev, so either add that app to App Store Connect and RevenueCat (and its id to REVENUECAT_APP_IDS), or test with a production build.
iOS on the simulator: use a StoreKit configuration file.
pnpm --filter mobile exec expo prebuild --platform ios, then open the workspace in Xcode.- Add a StoreKit Configuration File with the same product ids.
- Select it in the scheme (Run → Options).
- Upload its public certificate to the RevenueCat app (StoreKit testing framework).
- Run the app from Xcode. RevenueCat notes that StoreKit testing only works when Xcode launches the app, and that cancellations and refunds made in Xcode produce no events.
Android: add the Google account as a license tester (Play Console → Settings → License testing) and as a tester on the closed track, open the opt-in link, and install the build from that track.
Then:
- Buy a package. The screen shows "Subscription active" once the server has verified it. With a webhook pointing at your server, its log shows the
INITIAL_PURCHASEdelivery answered with200. - Restore on a second device signed in to the same account.
- Cancel in the store. Access continues until the period ends ("Access ends on …").
- Wait for the sandbox renewal or expiry (minutes in sandbox).
When an account is deleted
Deleting an account (Settings on the web or in the app, or an admin removing the User) also deletes the RevenueCat customer, whose App User ID is the User id:
- Better Auth's delete hook queues the customer in
billing_customer_erasure, in the same transaction as the deletion, whenrevenuecatis inBILLING_PROVIDERS. RevenueCat is never called during the deletion, so an outage cannot block or fail it. - The cron's billing job calls
DELETE /v1/subscribers/{app_user_id}with the secret key. 200 and 404 (already gone) both count as done, so a repeat is harmless. A failure keeps the row and is retried after one minute, doubling up to once a day, until it succeeds; the row'slast_errorsays why (response:401is a wrong key). - Success writes
billing.customer_erasedto the audit log, with the deleted User id as target andprovider: "revenuecat".
RevenueCat says this removes the customer's purchase history and is sufficient for GDPR erasure requests (Customers, read 2026-11-27). It does not cancel an App Store or Google Play subscription, and Apple offers no API to cancel one for the person: tell people to cancel in the store before they delete the account. If you turn RevenueCat off later, queued rows wait until it is on again.
Before App Review
Store rules that block a release, collected from a production app (KADA):
- Turning Family Sharing on for an App Store product cannot be undone.
- Each App Store localization of a product takes a display name of up to 30 characters and a description of up to 45.
- Each in-app purchase needs a review note and a review screenshot of the purchase screen. The first one must be submitted together with an app version: add it on the version page before "Add for Review".
- Google Play subscriptions need the payments (merchant) profile first.
How the server stays current
- Webhook: every authenticated event, of any type (a promotional grant included), queues a re-read of every known User it names:
app_user_id,original_app_user_id,aliases, both sides of aTRANSFER, and the users aPURCHASE_REDEEMEDnames. The event is not trusted for its content; the re-read decides. A refund arrives asCANCELLATIONwithcancel_reasonCUSTOMER_SUPPORT. The re-read seesrefunded_atand removes access. - Purchase in the app:
billing.syncre-reads at once. The SDK's customer info listener also asks for a sync when the device and the server disagree, for example after a renewal or an approved Ask to Buy. - Cron: a User with access is re-read at half of
BILLING_MAX_VERIFIED_AGE_SECONDS(one hour by default) and just after a period ends, in case its renewal webhook was lost. A User without access is re-read only on an event, a sync, or weekly. Access ends when the last verification is older thanBILLING_MAX_VERIFIED_AGE_SECONDS. - Capacity: each one-minute tick re-reads up to 24 Users, four at a time, about 1,400 an hour. With the default age limit that covers roughly 1,400 active subscribers. For more, raise
BILLING_MAX_VERIFIED_AGE_SECONDS, for example to 86400, which re-reads each subscriber every 12 hours. RevenueCat documents 480 requests per minute per key for customer reads.
Key files
packages/api/src/features/billing/billing.webhook.ts: webhook authentication and the event subjects.packages/api/src/features/billing/billing.reconcile.ts: the re-read and its schedule.packages/api/src/features/billing/billing.revenuecat-payload.ts: which transactions grant access, promotional grants included.packages/api/src/features/billing/billing.erasure.ts: deleting a deleted User's RevenueCat customer.packages/auth/src/billing-erasure.ts: the queue entry written with the account deletion.packages/api/src/features/billing/billing.fixture-revenuecat.ts: RevenueCat's documented sample events, used by the tests.apps/mobile/src/features/billing/billing.hooks.ts: the session connection and the screen's actions.packages/purchases/src/index.ts: the SDK wrapper.