This plugin has been transferred to RevenueCat official repository. Please refer to the official documentation __CAPGO_KEEP_0__ Purchases is a plugin for the __CAPGO_KEEP_1__ framework that supports in-app purchases on iOS and Android. It provides a simple and unified
Capacitor Purchases is a plugin for the Capacitor framework that allows in-app purchases on iOS and Android. It provides a simple and consistent API across multiple platforms, making it easy for developers to implement in-app subscriptions and purchases in their mobile apps.
One of the key features of the Capacitor Purchases plugin is that it integrates with RevenueCat, a platform that provides tools for in-app subscriptions and in-app purchases. RevenueCat simplifies the process of implementing in-app subscriptions and purchases by providing a simple and consistent API across multiple platforms, and automating tasks such as receipt validation and user management.
__CAPGO_KEEP_1__ across multiple platforms, and automating tasks such as receipt validation and user management.
- With RevenueCat, developers can easily manage subscriptions, track revenue, and perform other related tasks. Some features offered by RevenueCat include:
- Automated receipt validation
- User management
- Support for custom pricing models
Detailed analytics -Scalability is not a feature of RevenueCat, but rather a benefit of using their service. It is not a feature that can be turned on or off, but rather a characteristic of the service as a whole. If you are looking for a service that offers scalability, you may want to consider RevenueCat or another service that offers this feature. However, if you are looking for a service that offers detailed analytics, you may want to consider a different service. By using the Capacitor Purchases plugin with RevenueCat, developers can save time and effort when implementing in-app subscriptions and purchases in their mobile apps, and provide additional features that can help to improve the user experience and increase revenue.
使用Capacitor购买插件和RevenueCat,开发者可以轻松管理和跟踪应用内订阅和购买,验证收据,并在多个平台上管理用户。它还允许创建自定义定价模型并获取详细的分析以改进性能和收入。
安装
请确保使用最新版本的Capacitor和Capacitor购买插件。您可以在Capacitor和Capacitor购买插件的最新版本上Capacitor网站上查看。
安装Capacitor购买插件,请运行以下命令:
npm i @capgo/capacitor-purchases
将插件添加到您的应用本机code
npx cap sync
在Xcode中添加应用内购买能力:
然后

1. 创建RevenueCat帐户
本指南将指导您如何使用订阅和RevenueCat的SDK仅需几行code。
注册新RevenueCat帐户 __CAPGO_KEEP_0__.
📘
💡 这是一个小提示!
RevenueCat 建议为每个应用程序/项目创建一个单独的 RevenueCat 帐户,尤其是如果您打算出售该应用程序。这将加快转移过程,因为您可以一次性转移整个帐户,而不是等待 RevenueCat 支持人员转移单个项目。
组织/企业
我们建议在注册 RevenueCat 和设置应用程序时使用公司帐户。您将能够邀请您的团队成员加入您的项目,但 只有项目负责人才能管理账单 2. 项目和应用程序配置 ▶️ 创建一个项目导航到 RevenueCat 控制台
▶️
导航到
▶️ 添加一个新项目 __CAPGO_KEEP_0__ __CAPGO_KEEP_0__.

创建新项目弹出窗口
▶️ 添加一个应用/平台
来自 项目设置 > 应用 在项目仪表板的左侧菜单中,选择将要添加的应用的平台。

选择应用平台的项目仪表板
选择应用平台的字段 App 名称 必须添加您的应用程序到 RevenueCat。 其余的配置字段可以稍后添加。 为了进行测试和生产购买,Bundle ID(iOS)/ Package 名称(Android)以及共享密钥(iOS)/ 服务凭证(Android)必须配置。

Apple App Store 应用程序的应用程序配置页面
📘
💡 这是一个提示!
注册应用程序后,RevenueCat 建议设置 平台服务器通知. 这些通知并非必需,但会加快 webhooks 和集成交付时间,减少更新订阅者时的延迟。
📘
测试和生产应用程序和用户
RevenueCat 本身并不具备单独的测试和生产环境。 相反,针对用户的底层交易是通过沙盒和生产环境来区分的。
任何RevenueCat应用程序都可以从商店中进行沙盒和生产购买。如果您有单独的应用程序用于测试和生产环境,则可以在RevenueCat中创建多个项目以反映您的设置。
此外,用户不受环境的影响。同一用户可以同时拥有激活的沙盒购买和激活的生产购买。
▶️ 服务凭证
需要为RevenueCat设置服务凭证,以便RevenueCat可以代表您与应用程序商店进行通信。请参阅RevenueCat指南 App Store Connect 共享密钥, Play Service 凭证和 Amazon Appstore 共享密钥 获取更多信息。
请注意,Play Service 凭证可能需要花费多达36小时才能在Google服务器上传播。
3. 产品配置
▶️ 商店设置
在使用RevenueCat获取产品之前,您必须在各个商店中配置您的产品。请参阅以下指南: App Store Connect, Google Play Console, Amazon Appstore,以及 Stripe 帮助您在此过程中导航。
如果您正在销售iOS产品,请务必签署您的“付费应用程序协议”并在 App Store Connect > 协议、税务和银行. 中填写您的银行和税务信息。这需要在测试任何购买之前完成。.
📘
想在测试期间跳过商店设置吗?
在iOS上,您可以通过使用StoreKit配置文件而不是配置产品在App Store Connect中来延迟配置产品。这些配置文件需要最少的设置并且可以通过Xcode直接配置。
了解如何设置 StoreKit 配置文件的更多信息在 RevenueCat 沙盒测试 指南。
▶️ 在 RevenueCat 中配置产品和许可
您在 App Store Connect、Google Play Console、Amazon Appstore 或 Stripe 中配置的内购产品一旦准备好后,您需要将该配置复制到 RevenueCat 控制台中。 RevenueCat 使用许可系统来控制对高级功能的访问,以及 Offerings 来管理您向客户提供的产品集。, 许可是客户在购买特定产品后获得的访问权限级别。, Offerings 是一种简单的方式,让您可以组织您希望在付费墙上提供的内购产品,并远程配置它们。RevenueCat RevenueCatRevenueCat
RevenueCat 建议使用这些功能来简化您的__CAPGO_KEEP_0__并使您能够在不发布应用程序更新的情况下更改产品。 utilizing these features to simplify your code and enable you to change products without releasing an app update.
配置产品 配置产品 RevenueCat 步骤 4

RevenueCatSDK可以无缝地在各个平台上实现购买和订阅,同时与 RevenueCat 服务器同步令牌。
如果您遇到与SDK相关的问题,请参阅
If you run into issues with the SDK, see Troubleshooting the SDKs 仅使用您的公共__CAPGO_KEEP_0__密钥来配置购买
📘
Only use your public SDK key to configure Purchases
You can get your public SDK key from the API 下面的 __CAPGO_KEEP_0__ 选项卡下的
项目设置 中获取您的公共 __CAPGO_KEEP_0__ .shared instance in the SDK.
Purchases Configuring SDK __CAPGO_KEEP_0__
确保您只使用您的公共__CAPGO_KEEP_0__密钥进行配置。您可以阅读有关RevenueCat可用的不同__CAPGO_KEEP_1__密钥的更多信息。 购买 仅使用您的公共SDK密钥进行配置。您可以阅读有关RevenueCat可用的不同API密钥的更多信息。 身份验证指南.
import { CapacitorPurchases } from '@capgo/capacitor-purchases'
import { isPlatform } from '@ionic/vue' // use the right one for your framework
CapacitorPurchases.setDebugLogsEnabled({ enabled: import.meta.env.DEV }) // Enable to get debug logs in dev mode
if (isPlatform('ios')) {
CapacitorPurchases.setup({ apiKey:'appl_******'})
} else if (isPlatform('android')) {
CapacitorPurchases.setup({ apiKey:'goog_******'})
}
在开发过程中,RevenueCat建议启用更详细的调试日志。有关这些日志的更多信息,请参阅他们的 调试 指南。
如果您打算在您的现有购买code中使用RevenueCat,请参阅他们关于 观察模式.
📘
配置购买与用户ID
如果您在应用中有用户身份验证系统,则可以在配置时或稍后通过调用
.logIn()向RevenueCat提供用户标识符。要了解更多信息,请参阅RevenueCat关于 识别用户.
The SDK will automatically fetch the 配置的产品 以下是获取产品信息的示例。您可以使用产品信息来组织您的付费墙屏幕。有关更多信息和最佳实践,请参阅RevenueCat指南。
▶️ 获取和显示可用产品 使用用户ID配置购买 如果您在应用中有用户身份验证系统,则可以在配置时或稍后使用调用提供用户标识符。
要了解更多信息,请参阅RevenueCat指南。
📘
识别用户
__CAPGO_KEEP_0__
.logIn()配置的产品 ▶️ 获取和显示可用产品.
The SDK 将自动从 Apple、Google 或 Amazon 等平台获取已配置的产品,并从这些平台获取产品信息。因此,当客户打开购买屏幕时,已加载的产品将可用。 已配置的产品 将从 Apple、Google 或 Amazon 等平台获取产品信息。
以下是获取 Offerings 的示例。您可以使用 Offerings 来组织您的付费墙屏幕。有关更多信息和最佳实践,请参阅 RevenueCat 的指南《显示产品》。 如果获取您的 Offerings
const { offerings } = await CapacitorPurchases.getOfferings()
if (offerings.current !== null) {
// Display current offering with offerings.current
}
产品 或可用, 包为空,则是由于各个商店的配置问题。 已配置的产品 将从 Apple、Google 或 Amazon 等平台获取产品信息。
在 App Store Connect 中,这通常是因为 '付费应用程序协议' 未更新或产品未达到 '准备提交' 状态。 在 GooglePlay 中,这通常发生在应用程序未发布在封闭测试轨道且未添加有效测试用户时。
有关解决此问题的更多信息,请参见 RevenueCat 帮助中心 帮助中心.
▶️ 完成购买
SDK 包含一个简单的方法来促进购买。 purchase:package __CAPGO_KEEP_0__ 从获取的 Offering 中取出一个包,并使用相应的应用商店处理交易。
code 示例如下,展示了购买一个包并确认它解锁 'your_entitlement_id' 内容的过程。有关此方法的更多详细信息,请参见 RevenueCat 的指南。 purchase:package ▶️ 检查订阅状态 您可以在需要时使用此方法获取最新状态,并且在应用程序生命周期中安全地多次调用此方法。.
const purchase = async (p: Package): Promise<PurchaserInfo | null> => {
try {
// console.log('purchase', p)
const data = await CapacitorPurchases.purchasePackage({
identifier: p.identifier,
offeringIdentifier: p.offeringIdentifier,
})
const purchaserInfo = data.purchaserInfo
// console.log('listenBuy', purchaserInfo)
if (purchaserInfo.activeSubscriptions.includes(p.identifier)) {
// set the user as paid
}
return purchaserInfo
}
catch (e) {
console.error('listenBuy error', e)
}
return null
}
购买
__CAPGO_KEEP_0__ __CAPGO_KEEP_0__ 自动缓存最新的 CustomerInfo 每次更新时都会自动缓存最新的 — 所以在大多数情况下,这种方法会从缓存中拉取并运行非常快。
通常在决定显示哪个 UI 组件给用户以及用户执行需要特定权限的操作时调用此方法。
📘
💡 这是一个小提示!
您可以通过 RevenueCat 的指南了解更多关于订阅状态的信息,了解订阅是否设置为续费、用户信用卡是否有问题等。 订阅状态 RevenueCat 允许您的用户恢复他们的应用内购买,重新激活他们之前从同一商店账户(Apple、Google 或 Amazon)购买的任何内容。我们建议所有应用都提供一些方法让用户触发恢复方法。请注意,Apple 需要在用户无法访问他们购买的内容(例如卸载并重新安装应用、丢失账户信息等)时提供恢复机制。
如果两个不同的 应用用户 ID __CAPGO_KEEP_0__
const res = await CapacitorPurchases.restoreTransactions()
const purchaserInfo = res.purchaserInfo
const ids: string[] = [] // extract active subscriptions ids
purchaserInfo.activeSubscriptions.forEach((id) => {
ids.push(id)
})
__CAPGO_KEEP_1__ __CAPGO_KEEP_2__ 从同一底层存储账户(Apple、Google或Amazon账户)中恢复交易。 RevenueCat可能尝试在两个App用户ID之间创建一个别名,并将它们视为同一用户。有关不同可配置恢复行为的更多信息,请参见 Restoring Purchases 指南。
由于SDK在任何平台上都能完美工作,用户购买信息的变化可能来自各种来源。您可以通过遵循可选委托方法来响应客户信息的任何变化, CustomerInfo 此方法将在__CAPGO_KEEP_0__接收到来自 purchases:receivedUpdated:.
This method will fire whenever the SDK receives an updated CustomerInfo 或 getCustomerInfo(), purchase(package:), purchase(product:)的更新 restorePurchases().
对象时触发。 客户信息更新 不会
Depending on your app, it may be sufficient to ignore the delegate and simply handle changes to customer information the next time your app is launched or in the completion blocks of the SDK methods.
CapacitorPurchases.addListener('purchasesUpdate', (data) => {
console.log('purchasesUpdate', data)
})
👍
您成功了!
您已经成功地实现了一个功能齐全的订阅购买系统,而不需要花一个月的时间编写服务器code。恭喜!
示例应用
要下载更多有关如何整合SDK的完整示例,请访问RevenueCat示例应用资源。
我将很快发布一个使用Capacitor和Vue.js的示例应用。
如果您需要深入使用Capacitor,SDK请查看文档 这里.
下一步
\
- 如果您还没有,请确保您的产品已正确配置,查看RevenueCat 关于权利的指南.
- 如果您想使用自己的用户标识符,请阅读关于 设置应用用户 ID .
- 如果您从其他系统转移到 RevenueCat,请参阅 RevenueCat 指南 迁移您的现有订阅.
- 一旦您准备好测试您的集成, 请参阅 RevenueCat 指南.
- 测试和调试 如果您符合 App Store 小型企业计划的资格,请参阅 RevenueCat 指南
了解如何申请并通知 RevenueCat
如果您需要在应用中实时更新
加入我们 👇
capacitor
如果您正在使用 在应用内购买capacitor 来计划付款和购买,连接它与 Capgo Pricing 为Capgo Pricing中的产品工作流程 付款系统 付款系统的实现细节 @capgo/native-purchases 在@capgo/native-purchases中的实现细节 Getting Started 在Getting Started中的实现细节 收入战略手册 for the implementation detail in Revenue Playbook.