@capgo/capacitor-purchases

中文文档
5.0.8发布于 2023/07/31MITTypeScriptESM + CJS零依赖近 30 天下载 2461

In-app Subscriptions Made Easy with RevenueCat sdk

此软件包已被标记为弃用

Transfered to RevenueCat ORG use @revenuecat/purchases-capacitor

原始使用文档
文档目录20 节
  1. Check out: Capgo — live updates for capacitor
  2. Tutorial step by step
  3. Install
  4. Android
  5. Variables
  6. Configuration
  7. Migration v2
  8. API
  9. setup(...)
  10. addListener('purchasesUpdate', ...)
  11. getOfferings()
  12. purchasePackage(...)
  13. restorePurchases()
  14. setAttributes(...)
  15. logIn(...)
  16. logOut()
  17. getCustomerInfo()
  18. setDebugLogsEnabled(...)
  19. Interfaces
  20. Enums

capacitor-purchases

Capgo - Instant updates for capacitor

In-app Subscriptions Made Easy with RevenueCat SDK

RevenueCat is a third-party tool, who handle all difficulty for us is Free until $10,000 Revenue by month

Capacitor implementation with lastes RevenueCat SDK v4

RevenueCat:

Tutorial step by step

https://capgo.app/blog/in-app-purchases-capacitor/

Install

npm install @capgo/capacitor-purchases
pnpm dlx cap sync

Android

Add this to your android manifest android/app/src/main/AndroidManifest.xml

<uses-permission android:name="com.android.vending.BILLING"/>

Variables

This plugin will use the following project variables (defined in your app's variables.gradle file):

  • $kotlinVersion version of org.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

Configuration

No configuration required for this plugin.

Migration v2

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

API

setup(...)

setup(data: { apiKey: string; appUserID?: string; observerMode?: boolean; enableAdServicesAttribution?: boolean; collectDeviceIdentifiers?: boolean; }) => any

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

ParamType
data{ apiKey: string; appUserID?: string; observerMode?: boolean; enableAdServicesAttribution?: boolean; collectDeviceIdentifiers?: boolean; }

Returns: any


addListener('purchasesUpdate', ...)

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.

ParamType
eventName'purchasesUpdate'
listenerFunc(data: { purchases: Package; customerInfo: CustomerInfo; }) => void

Returns: any

Since: 2.0.2


getOfferings()

getOfferings() => any

Gets the Offerings configured in the RevenueCat dashboard

Returns: any


purchasePackage(...)

purchasePackage(data: { identifier: string; offeringIdentifier: string; oldSKU?: string | null; }) => any

Make a purchase

ParamType
data{ identifier: string; offeringIdentifier: string; oldSKU?: string | null; }

Returns: any


restorePurchases()

restorePurchases() => any

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

Returns: any


setAttributes(...)

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

ParamType
data{ attributes: { [key: string]: string | null; }; }

Returns: any


logIn(...)

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.

ParamType
data{ appUserID: string; }

Returns: any


logOut()

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()

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(...)

setDebugLogsEnabled(data: { enabled: boolean; }) => any

Enables/Disables debugs logs

ParamType
data{ enabled: boolean; }

Returns: any


Interfaces

Package

Contains information about the product available for the user to purchase. For more info see https://docs.revenuecat.com/docs/entitlements

PropTypeDescription
identifierstringUnique identifier for this package. Can be one a predefined package type or a custom one.
packageTypePACKAGE_TYPEPackage type for the product. Will be one of [PACKAGE_TYPE].
productProductProduct assigned to this package.
offeringIdentifierstringOffering this package belongs to.

Product

PropTypeDescription
identifierstringProduct Id.
descriptionstringDescription of the product.
titlestringTitle of the product.
pricenumberPrice of the product in the local currency.
priceStringstringFormatted price of the item, including its currency sign, such as €3.99.
currencyCodestringCurrency code for price and original price.
currencySymbolstringCurrency symbol for price and original price.
isFamilyShareablebooleanBoolean indicating if the product is sharable with family
subscriptionGroupIdentifierstringGroup identifier for the product.
subscriptionPeriodSubscriptionPeriodThe Product subcription group identifier.
introductoryPriceSKProductDiscount | nullThe Product introductory Price.
discounts{}The Product discounts list.

SubscriptionPeriod

PropTypeDescription
numberOfUnitsnumberThe Subscription Period number of unit.
unitnumberThe Subscription Period unit.

SKProductDiscount

PropTypeDescription
identifierstringThe Product discount identifier.
typenumberThe Product discount type.
pricenumberThe Product discount price.
priceStringstringFormatted price of the item, including its currency sign, such as €3.99.
currencySymbolstringThe Product discount currency symbol.
currencyCodestringThe Product discount currency code.
paymentModenumberThe Product discount paymentMode.
numberOfPeriodsnumberThe Product discount number Of Periods.
subscriptionPeriodSubscriptionPeriodThe Product discount subscription period.

CustomerInfo

PropTypeDescription
entitlementsEntitlementInfosEntitlements 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.
latestExpirationDatestring | nullThe latest expiration date of all purchased skus
firstSeenstringThe date this user was first seen in RevenueCat.
originalAppUserIdstringThe original App User Id recorded for this user.
requestDatestringDate when this info was requested
originalApplicationVersionstring | nullReturns 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
originalPurchaseDatestring | nullReturns the purchase date for the version of the application when the user bought the app. Use this for grandfathering users when migrating to subscriptions.
managementURLstring | nullURL 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.

PropTypeDescription
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.

PropTypeDescription
identifierstringThe entitlement identifier configured in the RevenueCat dashboard
isActivebooleanTrue if the user has access to this entitlement
willRenewbooleanTrue 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.
periodTypestringThe last period type this entitlement was in. Either: NORMAL, INTRO, TRIAL.
latestPurchaseDatestringThe latest purchase or renewal date for the entitlement.
originalPurchaseDatestringThe first date this entitlement was purchased.
expirationDatestring | nullThe expiration date for the entitlement, can be null for lifetime access. If the periodType is trial, this is the trial expiration date.
storestringThe store where this entitlement was unlocked from. Either: appStore, macAppStore, playStore, stripe, promotional, unknownStore
productIdentifierstringThe product identifier that unlocked this entitlement
isSandboxbooleanFalse if this entitlement is unlocked via a production purchase
unsubscribeDetectedAtstring | nullThe date an unsubscribe was detected. Can be null.
billingIssueDetectedAtstring | nullThe date a billing issue was detected. Can be null if there is no billing issue or an issue has been resolved

Transaction

PropTypeDescription
transactionIdentifierstringRevenueCat Id associated to the transaction.
productIdentifierstringProduct Id associated with the transaction.
purchaseDatestringPurchase date of the transaction in ISO 8601 format.

PluginListenerHandle

PropType
remove() => any

Offerings

Contains all the offerings configured in RevenueCat dashboard. For more info see https://docs.revenuecat.com/docs/entitlements

PropTypeDescription
all{ [key: string]: Offering; }Map of all Offerings [PurchasesOffering] objects keyed by their identifier.
currentOffering | nullCurrent 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

PropTypeDescription
identifierstringUnique identifier defined in RevenueCat dashboard.
serverDescriptionstringOffering description defined in RevenueCat dashboard.
availablePackages{}Array of Package objects available for purchase.
lifetimePackage | nullLifetime package type configured in the RevenueCat dashboard, if available.
annualPackage | nullAnnual package type configured in the RevenueCat dashboard, if available.
sixMonthPackage | nullSix month package type configured in the RevenueCat dashboard, if available.
threeMonthPackage | nullThree month package type configured in the RevenueCat dashboard, if available.
twoMonthPackage | nullTwo month package type configured in the RevenueCat dashboard, if available.
monthlyPackage | nullMonthly package type configured in the RevenueCat dashboard, if available.
weeklyPackage | nullWeekly package type configured in the RevenueCat dashboard, if available.

LogInResult

Holds the logIn result

PropTypeDescription
customerInfoCustomerInfoThe Purchaser Info for the user.
createdbooleanTrue if the call resulted in a new user getting created in the RevenueCat backend.

Enums

PACKAGE_TYPE

MembersValueDescription
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.

版本与发布记录

@capgo/capacitor-purchases 共发布 94 个版本,首次发布于 2022/07/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.8latest2023/07/313 年前
5.0.72023/07/173 年前
5.0.62023/07/033 年前
5.0.52023/06/153 年前
5.0.42023/06/153 年前
5.0.32023/06/123 年前

关于 @capgo/capacitor-purchases 的常见问题

@capgo/capacitor-purchases 是什么?

In-app Subscriptions Made Easy with RevenueCat sdk注意:该包已被作者标记为弃用——Transfered to RevenueCat ORG use @revenuecat/purchases-capacitor

如何安装 @capgo/capacitor-purchases?

在项目目录运行 npm install @capgo/capacitor-purchases,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(^5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-purchases 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-purchases 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-purchases 可以商用吗?

@capgo/capacitor-purchases 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-purchases 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-purchases 在 2026/10/09 – 2026/11/07 这 30 天内被下载 2,461 次,日均约 82 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-purchases 还在维护吗?

最新版本 5.0.8 发布于 2023/07/31(3 年前);至今共发布 94 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/07/24。作者已将其标记为弃用,新项目建议寻找替代方案。