Documentation Index
Fetch the complete documentation index at: https://setup.despia.com/llms.txt
Use this file to discover all available pages before exploring further.
AI Prompt
Add native mobile monetization to my app using the Despia SDK from: https://www.npmjs.com/package/despia-nativeFirst, install the package: If running in Despia (iOS or Android), launch the native RevenueCat Paywall. If not running in Despia (i.e. the user is on your web app), fall back to a RevenueCat Web Purchase Link with the user’s ID appended:In RevenueCat, create a single entitlement (e.g. Payment confirmation will happen via RevenueCat’s Webhooks, so make sure to include or instruct me to set up the correct backend structure.You can find the documentation about this here: https://www.revenuecat.com/docs/integrations/webhooksPlease follow the installation instructions for the “despia-native” npm package closely, and do not modify my instructions. Implementation as mentioned is critical.
npm install despia-nativeThen import it: import despia from 'despia-native'Create a payment system that launches RevenueCat Paywalls using: despia("revenuecat://launchPaywall?external_id={USER_ID}&offering={OFFERING}")Detect the platform using the Despia user agent:Always append the user’s ID to the RevenueCat Web Purchase Link URL. This links the web payment directly to their account - so if they later open your mobile app, the purchase and entitlements are already there waiting for them.
"premium") and link both iOS and Android products to it. Check for it with p.entitlementId === "premium". For one-time purchases, match the exact entitlementId (e.g. "no_ads").The Despia Native Runtime will call the global function
onRevenueCatPurchase() when an in-app purchase or subscription is successfully made on the client side. This should not grant access immediately on its own - but it is the right moment to either poll your backend until the RevenueCat webhook confirms the purchase, or run a client-side entitlement check via getpurchasehistory:// to instantly verify active entitlements with no backend needed. You should also call getpurchasehistory:// proactively on app load, page navigation, and before gating any premium feature. These checks are instant, offline-capable, and require no network round-trip to your server.This feature requires native capabilities which will be fully provided by the “despia-native” npm package, no additional native libraries are needed!
- Read and follow all best practices for Webhook events here: https://www.revenuecat.com/docs/integrations/webhooks/event-types-and-fields
- Check out the sample Webhook event schemas here: https://www.revenuecat.com/docs/integrations/webhooks/sample-events
despia("getpurchasehistory://", ["restoredData"])Use the restore response to check active entitlements and re-grant access where appropriate:Setting Up Your Paywall in RevenueCat
Before you can launch a paywall in Despia, you need to build one in the RevenueCat dashboard. RevenueCat’s Paywall Editor lets you design a fully customizable native paywall without writing any UI code.Key concepts
| Concept | Description |
|---|---|
| Components | RevenueCat’s predefined UI elements that can be added to a paywall - text, images, purchase buttons, etc. |
| Component properties | The configurable properties of each component that control its style and behavior - width, height, border, etc. |
| Templates | Pre-built paywalls from RevenueCat that you can use as a starting point and fully customize. |
| Offerings | The set of packages (products) you want to present to a user. Each paywall is linked to one Offering. |
1. Create a new paywall
- Go to RevenueCat Dashboard -> your project -> Paywalls
- Click + New Paywall
- Select the Offering you want to attach the paywall to. If you don’t have one without a paywall yet, you can duplicate an existing offering or create a new one
The offering ID you set here (e.g.
default, premium, annual_sale) is the same value you’ll pass to the offering parameter when launching the paywall via Despia.2. Choose a starting point
You can begin by:- Choosing a template - the fastest way to get started. All templates are fully customizable.
- Starting from scratch - full creative control over layout and components.
- Importing from Figma - if you already have a design, use the RevenueCat Figma plugin to import your frames directly.
3. Build with the editor
The Paywall Editor is divided into three areas:- Left sidebar - add components, view layers, manage branding, upload media, configure localization, and adjust paywall settings
- Preview - a live preview of your paywall as you build
- Control panel - toggle locale, light/dark mode, and sheet vs. full-screen preview
Available components
| Component | Description |
|---|---|
| Text | Customizable text string |
| Image | Uploaded image |
| Video | Uploaded video |
| Icon | Icon from RevenueCat’s provided list |
| Stack | Container for grouping and jointly configuring child components |
| Footer | A fixed-position section with unique styling |
| Package | A selectable package with custom styling and text |
| Purchase button | The CTA that triggers the purchase of the selected package |
| Button | Other interactions - Privacy Policy link, back button, etc. |
| Carousel | Swipeable pages |
| Countdown | Live countdown timer to a specific date/time |
| Timeline | A connected list of timeline items |
| Tabs | Display different package groups in separate tabs |
| Switch | Toggle between two sets of options |
| Social proof | Pre-styled components for testimonials and reviews |
| Feature list | Pre-styled components for listing features or benefits |
| Awards | Pre-styled components to highlight app awards |
| Express checkout | Apple Pay and Google Pay quick-purchase buttons (web) |
Editor shortcuts
| Action | Mac | Windows |
|---|---|---|
| Undo | Cmd + Z | Ctrl + Z |
| Redo | Cmd + Y | Ctrl + Y |
| Save | Cmd + S | Ctrl + S |
4. Save and publish
| State | Description |
|---|---|
| Inactive (Draft) | Saved but not served to users. Use this while building. |
| Published | Live and available via the SDK. Served based on your Default Offering, Targeting, or Experiments config. |
5. Configure exit offers (optional)
Exit offers let you present an alternative offer when a user dismisses the paywall without purchasing - useful for recovering potentially lost conversions. To set one up:- Create a separate Offering with a discounted or alternative package, and build a paywall for it
- In the main paywall’s editor, open Exit offer settings and select that offering
- Offer something not available in the main paywall (a discount, a free trial, etc.)
- Keep the exit paywall simple and focused on value
- Don’t overuse them - they should feel like a special opportunity, not a pressure tactic
6. Duplicate paywalls
To reuse a paywall as a starting point, click the … menu next to any paywall and choose:- Duplicate to this project - copies the paywall within the same project
- Duplicate to another project - copies to a different project you own
Installation
Install the Despia package from NPM:Usage
1. Import the SDK
2. Detect Platform & Launch Paywall
Always check for Despia first before attempting to launch the native paywall. If not running in Despia (e.g. the user is on your web app), fall back to a RevenueCat Web Purchase Link instead.Always include the user’s ID in the Web Purchase Link URL. This ties the web payment to their account so entitlements are instantly available across both your web app and mobile app - no extra steps needed for the user.
Web Checkout Link (non-Despia fallback)
To get yourpay.rev.cat token, go to RevenueCat and create a new Web Purchase Link - select an existing offering or create a new one with your web products:
RevenueCat -> Web -> Create Purchase Link
Once created, append the user’s app_user_id directly to the URL - this is the critical part that links the web purchase to their account:
| Parameter | Description |
|---|---|
email | Pre-fills the email field on checkout - ?email=<customerEmail> |
currency | Override automatic currency selection - ?currency=EUR |
package_id | Pre-select a package and skip straight to checkout |
skip_purchase_success=true | Skip the success page and trigger your configured redirect immediately |
The
app_user_id in the URL is what RevenueCat includes in every webhook event. The user must already exist in your database before redirecting them to the checkout link - otherwise when the INITIAL_PURCHASE webhook fires, your backend won’t find the user and won’t be able to grant access.3. Handle the Purchase Callback
The Despia Native Runtime callsonRevenueCatPurchase() globally as soon as the store confirms a transaction. This is your signal that something happened - but not yet proof that access should be granted.
There are two patterns for what to do inside this callback:
With a backend - poll until the webhook confirms
Without a backend - run the client-side entitlement check
If you don’t have a backend, skip the polling and check the native store directly usinggetpurchasehistory://. This queries Apple or Google in real time and returns the user’s active entitlements instantly - no server, no network dependency beyond the store itself.
Never grant access based on the
onRevenueCatPurchase callback alone if you have a backend. Always wait for your backend to confirm via the RevenueCat webhook before unlocking features. The callback is a trigger to start checking - not confirmation of a valid purchase.4. Run entitlement checks proactively
Don’t wait for a purchase event to check entitlements. Callgetpurchasehistory:// proactively in three places:
| When | Why |
|---|---|
| App load / page mount | Restore state for returning users immediately, before any interaction |
| Page navigation | Re-gate features as users move through the app without requiring a full reload |
| Before any gated feature | Catch edge cases where entitlement state changed mid-session (e.g. expiry, refund) |
Complete Client-Side Example
Set up offerings and entitlements in RevenueCat
Before launching paywalls in code, configure them in your RevenueCat dashboard:- Go to RevenueCat Dashboard -> your project -> Entitlements
- Click New Entitlement and name it
premium(orno_adsfor one-time purchases) - Click into the entitlement and click Attach products
- Attach your iOS and Android products - both platforms will resolve to the same
entitlementId - Go to Offerings and create or configure your offering (e.g.
default,premium,annual_sale) - Build your paywall UI in the RevenueCat dashboard under Paywalls (see Setting Up Your Paywall in RevenueCat above)
no_ads).
Full example
Subscriptions: Set Up Webhooks for Best Practice
Client-side entitlement checks work well for simple apps, but server-side webhook events are always recommended for subscriptions. Webhooks let you:- Revoke access the moment a subscription expires - rather than waiting for the next client-side check
- Log users out of your web app when their subscription lapses
- Sync subscription state across all platforms and databases in real time
- React to cancellations, refunds, and billing issues automatically
Despia Webhook Starter Template
A full backend webhook handler template covering all RevenueCat event types, database schema, and best practices.
1. Add a webhook endpoint to your server
Create aPOST /webhooks/revenuecat endpoint. RevenueCat sends an Authorization header with a secret you define - just make up a random string and store it as an environment variable.
2. Database schema
Create auser_subscriptions table to store subscription state:
3. Register the webhook in RevenueCat
- Go to RevenueCat Dashboard -> Project -> Integrations -> Webhooks
- Click Add new webhook
- Set the URL to your endpoint - e.g.
https://yourapp.com/webhooks/revenuecat - Set the Authorization header to the same random secret you put in your env var
- Select All events
- Save - RevenueCat will now send events to your server in real time
4. Consider a cron job as backup
Webhooks can occasionally fail (server downtime, timeouts, etc.). A cron job that periodically syncs subscription status from the RevenueCat API is a reliable safety net - especially important for catching cancellations and expirations that your webhook might have missed.Cron Job Template
Our full backend template includes a self-healing cron job that runs every 5 minutes, prioritizes expiring subscriptions, and stays within RevenueCat’s API rate limits. Combined with webhooks it gives 99.9%+ sync reliability.
Restore Purchases
Despia queries the native platform’s billing system to retrieve all purchases associated with the current user’s App Store or Google Play account. This includes active subscriptions, expired subscriptions, consumables, and non-consumable (lifetime) purchases.1. Retrieve Purchase History
2. Example Response (iOS)
3. Example Response (Android)
4. Check Active Entitlements
Testing Your Integration
AI cannot test payment integrations for you. RevenueCat, native StoreKit/Google Billing, webhooks, and your backend are cross-platform processes that require real end-to-end testing with multiple accounts and devices. There is no shortcut here - a payment integration is one of the most critical parts of your app and must be thoroughly verified by you before going live.
- Log in to your web app and complete a purchase via the Web Purchase Link
- Open the mobile app logged in with the same account
- Verify entitlements are active and premium features are unlocked
- Complete a purchase on the mobile app via TestFlight (no real money - use sandbox test accounts)
- Open your web app logged in with the same account
- Verify your backend has the correct subscription state
- Go to RevenueCat Dashboard -> Integrations -> Webhooks
- Check the event log - verify events are arriving at your server
- Confirm your database is updating
is_active,subscription_status, andexpires_atcorrectly for each event type - Test
EXPIRATIONandCANCELLATIONevents to make sure access is revoked properly
- Delete and reinstall the app
- Tap the Restore Purchases button
- Verify native IAP entitlements are recovered correctly
TestFlight and sandbox purchases use test accounts and never charge real money. Always test on TestFlight before submitting to the App Store. See Apple’s sandbox testing guide and Google Play’s test purchases guide for setup instructions.
Resources
- NPM Package
- RevenueCat Paywalls - Creating Paywalls
- RevenueCat Webhooks Template
- RevenueCat Webhooks
- Webhook Event Types & Fields
- Sample Webhook Events