RevenueCat JavaScript API
RevenueCat functions exposed through the WebToNative for your seamless in-app purchases and subscription management across iOS and Android.
RevenueCat is a subscription and in-app purchase management platform that sits on top of Apple's StoreKit and Google Play Billing. Instead of writing separate purchase, receipt-validation, and entitlement logic for each store, you manage products, pricing, and subscriber state in one dashboard, and RevenueCat keeps both platforms in sync.
WebToNative's RevenueCat plugin integrates the official RevenueCat Android SDK and iOS SDK natively, and exposes them as a single JavaScript API, so you can trigger native purchase flows and read subscriber status from your website's JavaScript.
You'll need to import the javascript file in your website before starting from this link.
Platform support: Android and iOS. Native paywalls (
showPaywall) require iOS 15 or later; all other functions support iOS 14+ and Android.
Key Concepts
If you're new to RevenueCat, these five terms will make the rest of this page much easier to follow:
Product
A single purchasable item, defined in App Store Connect / Google Play Console (e.g. premium_monthly), and imported into RevenueCat. This is the productId you pass to makePurchase.
Entitlement
A level of access you define in RevenueCat (e.g. "pro"), which one or more Products unlock. Your app should check entitlements — not specific product IDs — to decide what a user can access.
Offering
A named group of Products you want to present together (e.g. your current pricing screen). This is the offeringId you pass to showPaywall. Offerings let you change pricing/products remotely without an app update.
Paywall
A pre-built purchase screen you design visually in the RevenueCat dashboard and attach to an Offering. showPaywall renders this native screen for you, no UI code required.
CustomerInfo
RevenueCat's record of what a specific user has purchased and which entitlements are currently active. Returned by getCustomerInfo, setUserId, and restorePurchase.
There are two different ways to sell something with this plugin, pick based on how much UI you want RevenueCat to build for you:
showPaywall- shows RevenueCat's own paywall screen (built in their dashboard) for an Offering. Handles product selection, purchase, restore, and cancellation UI for you.makePurchase- skips any RevenueCat UI and goes straight to the native App Store / Play Store purchase sheet for one specific Product ID. Use this if you're building your own pricing screen in your web UI and just need the native checkout.
How It Works
configure()initializes the SDK once per app session, normally right after your app loads.Every other function requires
configure()to have already succeeded. If you call any of them first, they immediately return aNOT_CONFIGUREDerror.When a user logs into your app, call
setUserId()to attach your own user ID to their RevenueCat subscriber record (instead of RevenueCat's auto-generated anonymous ID).Use
showPaywallormakePurchaseto sell a subscription or one-time product.Use
getCustomerInfoanywhere in your app to check what the current user has access to (e.g. before showing premium content).Use
restorePurchaseto let returning users recover purchases made previously on the same App Store / Play Store account.
Setting Up RevenueCat
1. Create Your RevenueCat Project
Sign up at app.revenuecat.com and create a Project.
Add your app under both the App Store and Play Store platforms (RevenueCat treats them as two separate "apps" inside one project, each with its own API key).
Import your in-app products/subscriptions from App Store Connect and Google Play Console into RevenueCat as Products.
Group related Products into an Entitlement (e.g.
"pro"), and group the Products you want to sell together into an Offering.(Optional, for
showPaywall) Design a Paywall in the RevenueCat dashboard and attach it to your Offering.
2. Get Your API Keys
RevenueCat issues a separate public API key for iOS and for Android within the same project (Project Settings → API Keys). Since your JavaScript runs in both apps, detect the platform and pass the matching key:
3. Enable the Add-on in WebToNative
Open your WebToNative Dashboard → Add-ons → RevenueCat and enable it. There's no additional dashboard configuration, your API key, user IDs, offerings, and product IDs are all supplied at runtime from your JavaScript, as shown below.
4. Set Up Webhooks (Required)
This SDK only reports what happened during a live app session, it is not a backend integration. To keep your own database's subscription/entitlement state correct, you need a server that listens for RevenueCat Webhooks:
In the RevenueCat dashboard, go to Project Settings → Integrations → Webhooks and add your backend's endpoint URL.
Set an Authorization header value - RevenueCat sends it with every webhook request so you can verify the request actually came from RevenueCat before trusting it.
On your server, handle at least these event types (
event.typein the webhook payload):INITIAL_PURCHASE,RENEWAL,CANCELLATION,UNCANCELLATION,EXPIRATION,BILLING_ISSUE,PRODUCT_CHANGE,TRANSFER, andREFUND_REVERSED. Update the affectedapp_user_id's access in your own database on each one.Treat webhooks, not the JS
callbackas the authoritative signal for whether a user currently has access.
JavaScript API Reference
configure
Initializes the RevenueCat SDK for the current app session. Call this once, as early as possible (e.g. on app load), before calling any other function in this API.
Parameters:
userId
String
No
A stable ID for this user (e.g. your own database user ID). If omitted, RevenueCat generates and persists an anonymous ID on-device. You can attach a real user ID later with setUserId.
callback
Function
No
Function invoked with the result.
Response:
type
String
Always "configure".
success
Boolean
true if the SDK initialized successfully.
error
String
Present on failure. On iOS, this is "API_KEY_MISSING" if apiKey was empty. Android does not currently return an error value for this call — only success: false.
isInitialized
Checks whether configure() has already been called successfully in this session. Use this to avoid re-configuring, or to decide whether to show a loading state while configure() runs.
Parameters:
callback
Function
No
Function invoked with the result.
Response:
type
String
Always "isInitialized".
success
Boolean
true if the check completed (this is true even when isInitialized is false, as long as no error occurred).
isInitialized
Boolean
true if the SDK has been configured.
error
String
Present only if the check itself failed after configuration.
setUserId
Attaches your own user ID to the current subscriber, replacing RevenueCat's anonymous ID. Call this right after a user logs into your app, so their purchases and entitlements follow their account across devices.
Parameters:
userId
String
Yes
The user ID to identify this subscriber as.
callback
Function
No
Function invoked with the result.
Response:
type
String
Always "setUserId".
success
Boolean
true if the ID was set successfully.
error
String
Present on failure, e.g. "NOT_CONFIGURED" if called before configure().
getCustomerInfo
Fetches the current user's latest purchase and entitlement status, without showing any UI. Call this whenever you need to check what a user has access to, for example, before rendering a premium feature.
Parameters:
callback
Function
No
Function invoked with the result.
Response:
type
String
Always "getCustomerInfo".
success
Boolean
true if the info was fetched successfully.
error
String
Present on failure, e.g. "NOT_CONFIGURED" if called before configure().
showPaywall
Displays the native paywall screen you designed in the RevenueCat dashboard for a given Offering. RevenueCat handles product display, purchase, restore, and cancellation entirely within this screen, your callback just reports the final outcome.
Parameters:
offeringId
String
Yes
The identifier of the Offering (with an attached Paywall) to display, as configured in the RevenueCat dashboard.
callback
Function
No
Function invoked once per outcome — purchase, restore, error, or dismissal. See Response below.
Response - purchase completed (restore absent):
type
String
Always "showPaywall".
success
Boolean
true.
Response - restore completed from within the paywall:
type
String
Always "showPaywall".
success
Boolean
true.
restore
Boolean
true.
Response - failure:
success
Boolean
false.
restore
Boolean
Present and true only if the failure happened during a restore attempt.
error
String
See error values below.
Errors you may see:
NOT_CONFIGURED
Android, iOS
configure() hasn't succeeded yet.
OFFERING_NOT_FOUND
Android
No Offering matching offeringId was found.
PURCHASE_CANCELLED_BY_USER
Android
User dismissed the paywall without purchasing.
PURCHASE_FLOW_CANCELLED
iOS
User dismissed the paywall without purchasing (equivalent to PURCHASE_CANCELLED_BY_USER on Android — see hint below).
any other message
Android, iOS
The underlying RevenueCat/store error for a failed purchase or restore.
makePurchase
Skips any RevenueCat UI and opens the native App Store / Play Store purchase sheet directly for one Product ID. Use this when you're building your own pricing/paywall screen in your website and only need the native checkout step.
Parameters:
productId
String
Yes
The store product identifier to purchase, exactly as it exists in App Store Connect / Google Play Console and RevenueCat.
callback
Function
No
Function invoked with the result.
Response - success:
type
String
Always "makePurchase".
success
Boolean
true.
Response - failure:
success
Boolean
false.
error
String
See error values below.
Errors you may see:
NOT_CONFIGURED
Android, iOS
configure() hasn't succeeded yet.
PRODUCT_<productId>_NOT_FOUND.
Android
No store product matching productId was found.
PURCHASE_FLOW_CANCELLED
iOS
User cancelled the purchase sheet.
any other message
Android, iOS
The underlying RevenueCat/store error message.
restorePurchase
Restores any purchases already associated with the device's App Store / Play Store account, without showing a checkout screen. Use this behind a "Restore Purchases" button, typically on a settings or paywall screen.
Parameters:
callback
Function
No
Function invoked with the result.
Response:
type
String
Always "restorePurchase".
success
Boolean
true if the restore completed (this does not mean anything was found — a user with no past purchases still gets success: true with an empty customerInfo).
error
String
Present on failure, e.g. "NOT_CONFIGURED" if called before configure().
Reference Objects
CustomerInfo object
customerInfo is RevenueCat's own subscriber record, passed straight through from the native SDK. The fields you'll use most often:
entitlements.active
An object keyed by entitlement identifier (e.g. "pro") — a key is present only if that entitlement is currently active for this user. Use this to gate premium features.
activeSubscriptions
Array of product identifiers the user currently has an active subscription for.
allExpirationDates / allPurchaseDates
Per-product expiration/purchase timestamps.
originalAppUserId
The RevenueCat App User ID this record belongs to.
requestDate
When this CustomerInfo snapshot was generated.
For the complete, authoritative field list, see RevenueCat's CustomerInfo reference.
Transaction object
Returned in transaction by both showPaywall and makePurchase on a successful purchase. The shape differs by platform:
iOS:
transactionId
The App Store transaction identifier.
productId
The purchased product's identifier.
purchaseDate
Purchase timestamp, in milliseconds since epoch (as a string).
storefrontId
The App Store storefront (country/region) the purchase was made in.
appUserId
The RevenueCat App User ID for this subscriber.
Android:
transactionId
The Google Play purchase token for this transaction.
googleOrderId
The Google Play order ID.
productId
The purchased product's identifier.
purchaseDate
Purchase timestamp, in milliseconds since epoch.
appUserId
The RevenueCat App User ID for this subscriber.
Typical Implementation Flow
On app load - call
configure()with the platform-specific API key. If the user is already logged into your app, pass their ID asuserIddirectly.On login (if you didn't have the user ID at configure-time) — call
setUserId()to attach it.Gate premium content - call
getCustomerInfo()and checkentitlements.activebefore showing premium features.Sell a subscription/product - call
showPaywall()if you've designed a RevenueCat paywall, ormakePurchase()if you built your own pricing UI.Give returning users a way back in - call
restorePurchase()from a "Restore Purchases" button.Keep your backend in sync independently - don't rely on step 4's callback for anything beyond immediate UI feedback. Your backend should listen to RevenueCat Webhooks to know when access should actually be granted, renewed, or revoked.
Implementation Checklist
RevenueCat Dashboard
Your Backend
WebToNative Dashboard
Your Website
Frequently Asked Questions
Last updated