Rc One Time Products

RevenueCat/ai-toolkit/revenuecat-play-billing/skills/rc-one-time-products

作者 RevenueCatccfc038185ec457b2ac9077f3bbf1ba947a44dbbApache-2.0; see LICENSE收录于 2026年10月9日更新于 2026年10月9日

Use this skill when selling one time products on Android with RevenueCat. Covers fetching offerings, running awaitPurchase on a non subscription package, and relying on the SDK to acknowledge or consume automatically.

AI 生成的概览

指导 Android 开发者使用 RevenueCat SDK 销售一次性产品,涵盖获取产品列表到处理购买结果的完整流程。

功能
该技能提供了一套分阶段的指南,用于在 Android 上使用 RevenueCat 实现一次性(非订阅)产品购买。内容涵盖:界定可消耗与不可消耗产品、在 Google Play Console 和 RevenueCat 后台配置产品、获取产品列表、通过 awaitPurchase 发起购买,以及通过权益或非订阅交易记录读取访问权限。此外还说明了如何处理取消、待处理付款和错误,以及如何通过 CustomerInfo 和 webhook 验证购买。
适用场景
当需要在已使用或准备采用 RevenueCat SDK 的 Android 应用中集成一次性产品购买时,可使用该技能。它适合需要了解购买流程、权益检查和边界情况处理,而不想直接编写 BillingClient 代码的开发者。
运行要求
需要一个使用 RevenueCat SDK 的 Android 应用项目、一个配置了一次性产品的 Google Play Console 账号,以及一个拥有 API 密钥和已配置产品/套餐的 RevenueCat 后台账号。不包含脚本,仅为说明文档。

One Time Products with RevenueCat

Sell one time products on Android without writing BillingClient glue. The RevenueCat SDK fetches products, launches the purchase, verifies the receipt, and acknowledges or consumes the token for you.

Phase 1: Scope

Answer these before touching code.

QuestionDecision
Is the product consumable or non consumable?Mark consumables in the RevenueCat dashboard so the SDK calls consumeAsync for you.
Do you read access through entitlements or transactions?Prefer entitlements so access logic stays decoupled from product IDs.
Do you need server notification of the purchase?Use RevenueCat webhooks. The INITIAL_PURCHASE event fires for every new non subscription purchase.

Do not call BillingClient.queryProductDetailsAsync, acknowledgePurchase, or consumeAsync yourself once RevenueCat is integrated. The SDK owns the BillingClient instance.

Phase 2: Prepare

  • Configure the product in Google Play Console as a one time product.
  • In the RevenueCat dashboard, attach the product to an offering and package, and flag it as consumable if it should be consumed on purchase.
  • Confirm Purchases.configure runs once on app start with your Android API key and the current App User ID.

Phase 3: Execute

Fetch offerings, launch the purchase, then read the result off CustomerInfo.

kotlin
val offerings = Purchases.sharedInstance.awaitOfferings()val pkg = offerings.current?.availablePackages?.first() ?: return

Launch the purchase with awaitPurchase. It suspends until the RevenueCat backend verifies the token.

kotlin
val result = Purchases.sharedInstance.awaitPurchase(    PurchaseParams.Builder(activity, pkg).build())val info = result.customerInfo

Read access through entitlements, or fall back to the non subscription transactions list.

kotlin
val hasAccess = info.entitlements["lifetime_access"]?.isActive == trueval owned = info.nonSubscriptionTransactions    .any { it.productIdentifier == "lifetime_product_id" }

The SDK acknowledges non consumables and consumes consumables automatically once the backend verifies the purchase. You do not call acknowledgePurchase or consumeAsync.

Phase 4: Handle Edge Cases

Wrap awaitPurchase to separate cancellation, pending payments, and real errors.

kotlin
try { /* awaitPurchase */ } catch (e: PurchasesTransactionException) {    when {        e.error.code == PurchasesErrorCode.PaymentPendingError -> showPending()        e.userCancelled -> Unit        else -> showError(e.error.message)    }}
OutcomeSDK signalAction
SuccessawaitPurchase returns with updated CustomerInfoGrant access from entitlements or nonSubscriptionTransactions.
User cancelPurchasesTransactionException, userCancelled == trueSwallow silently.
Pending paymentPurchasesTransactionException, PaymentPendingErrorShow a pending message. The SDK updates the entitlement later through UpdatedCustomerInfoListener.
Other errorPurchasesTransactionException, other codesSurface e.error.message to you.

Phase 5: Verify

  • Trust result.customerInfo from awaitPurchase. Do not grant access from optimistic local state.
  • Pending purchases do not grant entitlements. Register an UpdatedCustomerInfoListener so you react when the payment completes.
  • For server side provisioning, subscribe to the RevenueCat INITIAL_PURCHASE webhook. Do not reimplement Google Play Developer API verification.

References

来源与署名

来源:RevenueCat/ai-toolkit位于revenuecat-play-billing/skills/rc-one-time-products提交ccfc038

许可证: Apache-2.0; see LICENSE

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架