
Add native mobile monetization to my app using the Despia SDK from: https://www.npmjs.com/package/despia-native
First, install the package: npm install despia-native
Then import it: import despia from 'despia-native'
Create a payment system that uses RevenueCat URLs like: despia("revenuecat://purchase?external_id={USER_ID}&product={PRODUCT_ID}") to handle purchases through Apple App Store and Google Play billing.
Add buttons for different subscription tiers of my app:
e.g. "monthly_basic", "lifetime"
The Despia Native Runtime will call the global function iapSuccess() when an in-app purchase or subscription is successfully made on the client side. Although this should not grant access immediately, it's a good time to start polling your backend to check if the RevenueCat webhook has already updated the user's status or plan permissions.
The function will include following data:
// Example value added into the iapSuccess() function call by the native runtime
{
"planID": "com.example.premium_monthly",
"transactionID": "2000000123456789",
"subreceipts": "eyJyZWNlaXB0Ijp7InJlY2VpcHRfdHlwZSI6IlByb2R1Y3Rpb24iLCJhZGFtX2lkIjowLCJhcHBfaXRlbV9pZCI6MCwiYnVuZGxlX2lkIjoiY29tLmV4YW1wbGUuYXBwIiwiYXBwbGljYXRpb25fdmVyc2lvbiI6IjEuMCIsImRvd25sb2FkX2lkIjowLCJ2ZXJzaW9uX2V4dGVybmFsX2lkZW50aWZpZXIiOjAsInJlY2VpcHRfY3JlYXRpb25fZGF0ZSI6IjIwMjUtMTAtMDEgMTQ6MzA6MDAgRXRjL0dNVCIsInJlY2VpcHRfY3JlYXRpb25fZGF0ZV9tcyI6IjE3Mjc3OTU0MDAwMDAiLCJyZWNlaXB0X2NyZWF0aW9uX2RhdGVfcHN0IjoiMjAyNS0xMC0wMSAwNzozMDowMCBBbWVyaWNhL0xvc19BbmdlbGVzIiwicmVxdWVzdF9kYXRlIjoiMjAyNS0xMC0wMSAxNDozMDowNSBFdGMvR01UIiwicmVxdWVzdF9kYXRlX21zIjoiMTcyNzc5NTQwNTAwMCIsInJlcXVlc3RfZGF0ZV9wc3QiOiIyMDI1LTEwLTAxIDA3OjMwOjA1IEFtZXJpY2EvTG9zX0FuZ2VsZXMiLCJvcmlnaW5hbF9wdXJjaGFzZV9kYXRlIjoiMjAyN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WJfb3JkZXJfbGluZV9pdGVtX2lkIjoiMjAwMDAwMDEyMzQ1Njc4OSIsImlzX3RyaWFsX3BlcmlvZCI6ImZhbHNlIiwiaXNfaW5faW50cm9fb2ZmZXJfcGVyaW9kIjoiZmFsc2UifV19fQ=="
}
This feature requires native capabilities which will be fully provided by the “despia-native” npm package, no additional native libraries are needed!
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/webhooks
-
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
Once the payment is confirmed on the backend, the backend should send a webhook to the frontend to let it know that this user's in-app purchase session was completed.
Please follow the installation instructions for the "despia-native" npm package closely, and do not modify my instructions. Implementation as mentioned is critical.
How it works: Despia acts as a bridge between your Lovable app and native mobile payment systems. When users tap a purchase button, Despia processes the payment through Apple's App Store or Google Play Store using RevenueCat's infrastructure, ensuring secure transactions and automatic subscription management.
Installation
Install the Despia package from NPM:
npm install despia-native
Usage
1. Import the SDK
import despia from 'despia-native';
2. Execute Payment
Call the despia() function with a RevenueCat Command:
despia("revenuecat://purchase?external_id=user_777&product=monthly_premium");
Resources
-
View full NPM documentation for additional configuration options
Lovable Integration
This SDK is optimized for Lovable's prompt-based AI builder, enabling quick integration of native mobile payments into your generated apps.
For additional support or questions, please contact our support team at support@despia.com