Skip to content

Latest commit

 

History

History
378 lines (253 loc) · 27.8 KB

README.md

File metadata and controls

378 lines (253 loc) · 27.8 KB

capacitor-purchases

Capgo - Instant updates for capacitor In-app Subscriptions Made Easy with RevenueCat sdk

Capacitor implementation with new RevenueCat swift SDK v4

Install

npm install @capgo/capacitor-purchases
npx cap sync

API

setup(...)

setup(data: { apiKey: string; }) => Promise<void>

Sets up with your API key and an app user id.

Param Type
data { apiKey: string; }

addListener('purchasesUpdate', ...)

addListener(eventName: "purchasesUpdate", listenerFunc: (data: { purchases: Package; purchaserInfo: PurchaserInfo; }) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Called when partialResults set to true and result received

Provides partial result.

Param Type
eventName 'purchasesUpdate'
listenerFunc (data: { purchases: Package; purchaserInfo: PurchaserInfo; }) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Since: 2.0.2


getOfferings()

getOfferings() => Promise<{ offerings: Offerings; }>

Gets the Offerings configured in the RevenueCat dashboard

Returns: Promise<{ offerings: Offerings; }>


purchasePackage(...)

purchasePackage(data: { identifier: string; offeringIdentifier: string; }) => Promise<{ purchaserInfo: PurchaserInfo; }>

Make a purchase

Param Type
data { identifier: string; offeringIdentifier: string; }

Returns: Promise<{ purchaserInfo: PurchaserInfo; }>


restoreTransactions()

restoreTransactions() => Promise<{ purchaserInfo: PurchaserInfo; }>

Restores a user's previous and links their appUserIDs to any user's also using those .

Returns: Promise<{ purchaserInfo: PurchaserInfo; }>


setAttributes(...)

setAttributes(data: { attributes: { [key: string]: string | null; }; }) => Promise<void>

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; }; }

logIn(...)

logIn(data: { appUserID: string; }) => Promise<LogInResult>

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: Promise<LogInResult>


logOut()

logOut() => Promise<{ purchaserInfo: PurchaserInfo; }>

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: Promise<{ purchaserInfo: PurchaserInfo; }>


getPurchaserInfo()

getPurchaserInfo() => Promise<{ purchaserInfo: PurchaserInfo; }>

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: Promise<{ purchaserInfo: PurchaserInfo; }>


setDebugLogsEnabled(...)

setDebugLogsEnabled(data: { enabled: boolean; }) => Promise<void>

Enables/Disables debugs logs

Param Type
data { enabled: boolean; }

Interfaces

PluginListenerHandle

Prop Type
remove () => Promise<void>

Package

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.

Product

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 SKProductDiscount[] The Product discounts list.

SubscriptionPeriod

Prop Type Description
numberOfUnits number The Subscription Period number of unit.
unit number The Subscription Period unit.

SKProductDiscount

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.

PurchaserInfo

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 Transaction[] 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.

EntitlementInfos

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.

EntitlementInfo

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

Transaction

Prop Type Description
revenueCatId string RevenueCat Id associated to the transaction.
productId string Product Id associated with the transaction.
purchaseDate string Purchase date of the transaction in ISO 8601 format.

Offerings

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.

Offering

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 Package[] 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.

LogInResult

Holds the logIn result

Prop Type Description
purchaserInfo PurchaserInfo The Purchaser Info for the user.
created boolean True if the call resulted in a new user getting created in the RevenueCat backend.

Enums

PACKAGE_TYPE

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.

TODO

Prepare android migration to v5