In-app Subscriptions Made Easy with RevenueCat SDK
Capacitor implementation with lastes RevenueCat SDK v4
https://capgo.app/blog/in-app-purchases-capacitor/
npm install @capgo/capacitor-purchases
pnpm dlx cap sync
Add this to your android manifest android/app/src/main/AndroidManifest.xml
<uses-permission android:name="com.android.vending.BILLING"/>
This plugin will use the following project variables (defined in your app's variables.gradle
file):
$kotlinVersion
version oforg.jetbrains.kotlin:kotlin-stdlib-jdk7
(default:1.7.21
)
If you have compilation issue Duplicate class androidx.lifecycle.ViewModelLazy
i found in this the solution who worked for me:
https://stackoverflow.com/questions/73406969/duplicate-class-androidx-lifecycle-viewmodellazy-found-in-modules-lifecycle-view
Add this
configurations {
all {
exclude group: 'androidx.lifecycle', module: 'lifecycle-runtime-ktx'
exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
}
}
an
line 2 in file android/app/build.gradle
No configuration required for this plugin.
getPurchaserInfo become getCustomerInfo PurchaserInfo become CustomerInfo restoreTransactions become restorePurchases
Read more about it here: https://github.com/RevenueCat/purchases-android/blob/main/migrations/v5-MIGRATION.md
setup(...)
addListener('purchasesUpdate', ...)
getOfferings()
purchasePackage(...)
restorePurchases()
setAttributes(...)
logIn(...)
logOut()
getCustomerInfo()
setDebugLogsEnabled(...)
- Interfaces
- Enums
setup(data: { apiKey: string; appUserID?: string; observerMode?: boolean; }) => any
Sets up with your API key and an app user id.
Param | Type |
---|---|
data |
{ apiKey: string; appUserID?: string; observerMode?: boolean; } |
Returns: any
addListener(eventName: "purchasesUpdate", listenerFunc: (data: { purchases: Package; customerInfo: CustomerInfo; }) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Called when partialResults set to true and result received
Provides partial result.
Param | Type |
---|---|
eventName |
'purchasesUpdate' |
listenerFunc |
(data: { purchases: Package; customerInfo: CustomerInfo; }) => void |
Returns: any
Since: 2.0.2
getOfferings() => any
Gets the Offerings configured in the RevenueCat dashboard
Returns: any
purchasePackage(data: { identifier: string; offeringIdentifier: string; oldSKU?: string | null; }) => any
Make a purchase
Param | Type |
---|---|
data |
{ identifier: string; offeringIdentifier: string; oldSKU?: string | null; } |
Returns: any
restorePurchases() => any
Restores a user's previous and links their appUserIDs to any user's also using those .
Returns: any
setAttributes(data: { attributes: { [key: string]: string | null; }; }) => any
Subscriber attributes are useful for storing additional, structured information on a user. Since attributes are writable using a public key they should not be used for managing secure or sensitive information such as subscription status, coins, etc.
Key names starting with "$" are reserved names used by RevenueCat. For a full list of key restrictions refer to our guide: https://docs.revenuecat.com/docs/subscriber-attributes
Param | Type |
---|---|
data |
{ attributes: { [key: string]: string | null; }; } |
Returns: any
logIn(data: { appUserID: string; }) => any
This function will logIn the current user with an appUserID. Typically this would be used after a log in to identify a user without calling configure.
Param | Type |
---|---|
data |
{ appUserID: string; } |
Returns: any
logOut() => any
Logs out the client clearing the saved appUserID. This will generate a random user id and save it in the cache. If the current user is already anonymous, this will produce a Error.
Returns: any
getCustomerInfo() => any
Gets the current purchaser info. This call will return the cached purchaser info unless the cache is stale, in which case, it will make a network call to retrieve it from the servers.
Returns: any
setDebugLogsEnabled(data: { enabled: boolean; }) => any
Enables/Disables debugs logs
Param | Type |
---|---|
data |
{ enabled: boolean; } |
Returns: any
Contains information about the product available for the user to purchase. For more info see https://docs.revenuecat.com/docs/entitlements
Prop | Type | Description |
---|---|---|
identifier |
string |
Unique identifier for this package. Can be one a predefined package type or a custom one. |
packageType |
PACKAGE_TYPE |
Package type for the product. Will be one of [PACKAGE_TYPE]. |
product |
Product |
Product assigned to this package. |
offeringIdentifier |
string |
Offering this package belongs to. |
Prop | Type | Description |
---|---|---|
identifier |
string |
Product Id. |
description |
string |
Description of the product. |
title |
string |
Title of the product. |
price |
number |
Price of the product in the local currency. |
priceString |
string |
Formatted price of the item, including its currency sign, such as €3.99. |
currencyCode |
string |
Currency code for price and original price. |
currencySymbol |
string |
Currency symbol for price and original price. |
isFamilyShareable |
boolean |
Boolean indicating if the product is sharable with family |
subscriptionGroupIdentifier |
string |
Group identifier for the product. |
subscriptionPeriod |
SubscriptionPeriod |
The Product subcription group identifier. |
introductoryPrice |
SKProductDiscount | null |
The Product introductory Price. |
discounts |
{} |
The Product discounts list. |
Prop | Type | Description |
---|---|---|
numberOfUnits |
number |
The Subscription Period number of unit. |
unit |
number |
The Subscription Period unit. |
Prop | Type | Description |
---|---|---|
identifier |
string |
The Product discount identifier. |
type |
number |
The Product discount type. |
price |
number |
The Product discount price. |
priceString |
string |
Formatted price of the item, including its currency sign, such as €3.99. |
currencySymbol |
string |
The Product discount currency symbol. |
currencyCode |
string |
The Product discount currency code. |
paymentMode |
number |
The Product discount paymentMode. |
numberOfPeriods |
number |
The Product discount number Of Periods. |
subscriptionPeriod |
SubscriptionPeriod |
The Product discount subscription period. |
Prop | Type | Description |
---|---|---|
entitlements |
EntitlementInfos |
Entitlements attached to this purchaser info |
activeSubscriptions |
[string] |
Set of active subscription skus |
allPurchasedProductIdentifiers |
[string] |
Set of purchased skus, active and inactive |
nonSubscriptionTransactions |
{} |
Returns all the non-subscription a user has made. The are ordered by purchase date in ascending order. |
latestExpirationDate |
string | null |
The latest expiration date of all purchased skus |
firstSeen |
string |
The date this user was first seen in RevenueCat. |
originalAppUserId |
string |
The original App User Id recorded for this user. |
requestDate |
string |
Date when this info was requested |
originalApplicationVersion |
string | null |
Returns the version number for the version of the application when the user bought the app. Use this for grandfathering users when migrating to subscriptions. This corresponds to the value of CFBundleVersion (in iOS) in the Info.plist file when the purchase was originally made. This is always null in Android |
originalPurchaseDate |
string | null |
Returns the purchase date for the version of the application when the user bought the app. Use this for grandfathering users when migrating to subscriptions. |
managementURL |
string | null |
URL to manage the active subscription of the user. If this user has an active iOS subscription, this will point to the App Store, if the user has an active Play Store subscription it will point there. If there are no active subscriptions it will be null. If there are multiple for different platforms, it will point to the device store. |
Contains all the entitlements associated to the user.
Prop | Type | Description |
---|---|---|
all |
{ [key: string]: EntitlementInfo; } |
Map of all EntitlementInfo (PurchasesEntitlementInfo ) objects (active and inactive) keyed by entitlement identifier. |
active |
{ [key: string]: EntitlementInfo; } |
Map of active EntitlementInfo (PurchasesEntitlementInfo ) objects keyed by entitlement identifier. |
The EntitlementInfo object gives you access to all of the information about the status of a user entitlement.
Prop | Type | Description |
---|---|---|
identifier |
string |
The entitlement identifier configured in the RevenueCat dashboard |
isActive |
boolean |
True if the user has access to this entitlement |
willRenew |
boolean |
True if the underlying subscription is set to renew at the end of the billing period (expirationDate). Will always be True if entitlement is for lifetime access. |
periodType |
string |
The last period type this entitlement was in. Either: NORMAL, INTRO, TRIAL. |
latestPurchaseDate |
string |
The latest purchase or renewal date for the entitlement. |
originalPurchaseDate |
string |
The first date this entitlement was purchased. |
expirationDate |
string | null |
The expiration date for the entitlement, can be null for lifetime access. If the periodType is trial , this is the trial expiration date. |
store |
string |
The store where this entitlement was unlocked from. Either: appStore, macAppStore, playStore, stripe, promotional, unknownStore |
productIdentifier |
string |
The product identifier that unlocked this entitlement |
isSandbox |
boolean |
False if this entitlement is unlocked via a production purchase |
unsubscribeDetectedAt |
string | null |
The date an unsubscribe was detected. Can be null . |
billingIssueDetectedAt |
string | null |
The date a billing issue was detected. Can be null if there is no billing issue or an issue has been resolved |
Prop | Type | Description |
---|---|---|
transactionIdentifier |
string |
RevenueCat Id associated to the transaction. |
productIdentifier |
string |
Product Id associated with the transaction. |
purchaseDate |
string |
Purchase date of the transaction in ISO 8601 format. |
Prop | Type |
---|---|
remove |
() => any |
Contains all the offerings configured in RevenueCat dashboard. For more info see https://docs.revenuecat.com/docs/entitlements
Prop | Type | Description |
---|---|---|
all |
{ [key: string]: Offering; } |
Map of all Offerings [PurchasesOffering] objects keyed by their identifier. |
current |
Offering | null |
Current offering configured in the RevenueCat dashboard. |
An offering is a collection of Packages (PurchasesPackage
) available for the user to purchase.
For more info see https://docs.revenuecat.com/docs/entitlements
Prop | Type | Description |
---|---|---|
identifier |
string |
Unique identifier defined in RevenueCat dashboard. |
serverDescription |
string |
Offering description defined in RevenueCat dashboard. |
availablePackages |
{} |
Array of Package objects available for purchase. |
lifetime |
Package | null |
Lifetime package type configured in the RevenueCat dashboard, if available. |
annual |
Package | null |
Annual package type configured in the RevenueCat dashboard, if available. |
sixMonth |
Package | null |
Six month package type configured in the RevenueCat dashboard, if available. |
threeMonth |
Package | null |
Three month package type configured in the RevenueCat dashboard, if available. |
twoMonth |
Package | null |
Two month package type configured in the RevenueCat dashboard, if available. |
monthly |
Package | null |
Monthly package type configured in the RevenueCat dashboard, if available. |
weekly |
Package | null |
Weekly package type configured in the RevenueCat dashboard, if available. |
Holds the logIn result
Prop | Type | Description |
---|---|---|
customerInfo |
CustomerInfo |
The Purchaser Info for the user. |
created |
boolean |
True if the call resulted in a new user getting created in the RevenueCat backend. |
Members | Value | Description |
---|---|---|
UNKNOWN |
"UNKNOWN" |
A package that was defined with a custom identifier. |
CUSTOM |
"CUSTOM" |
A package that was defined with a custom identifier. |
LIFETIME |
"LIFETIME" |
A package configured with the predefined lifetime identifier. |
ANNUAL |
"ANNUAL" |
A package configured with the predefined annual identifier. |
SIX_MONTH |
"SIX_MONTH" |
A package configured with the predefined six month identifier. |
THREE_MONTH |
"THREE_MONTH" |
A package configured with the predefined three month identifier. |
TWO_MONTH |
"TWO_MONTH" |
A package configured with the predefined two month identifier. |
MONTHLY |
"MONTHLY" |
A package configured with the predefined monthly identifier. |
WEEKLY |
"WEEKLY" |
A package configured with the predefined weekly identifier. |