Rc Subscriptions

RevenueCat/ai-toolkit/revenuecat-play-billing/skills/rc-subscriptions

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

Use this skill when modeling subscriptions through RevenueCat's object model on Android. Covers Offerings, Packages, StoreProduct, SubscriptionOption, PricingPhase, and how they map to Google Play's Subscription, Base Plan, and Offer hierarchy.

AI 生成的概览

指导在 Android 上使用 RevenueCat 的 Offerings、Packages 与 SubscriptionOption 对象模型来建模订阅付费墙。

功能
说明 Google Play 的 Subscription、Base Plan 与 Offer 层级如何映射到 RevenueCat 的 Offering、Package、StoreProduct、SubscriptionOption 和 PricingPhase 等类型。依次讲解付费墙规划、获取 offerings、选择 packages、使用默认或指定 offer 购买、渲染试用与优惠价格、处理预付费方案以及检查权益。提供 Kotlin 代码片段和决策摘要表。
适用场景
适用于在使用 RevenueCat SDK 的 Android 应用中实现或审查订阅购买流程。也适合将付费墙布局映射到 offerings 与 packages,或定位特定 offer(如挽留优惠)时使用。
运行要求
仅为说明性内容,不含脚本。假定已有配置 RevenueCat SDK 的 Android 项目、已设置的 API key,以及仪表盘中配置好的 offerings 与产品。

Subscriptions on Android with RevenueCat

Google Play exposes subscriptions through a three tier hierarchy: Subscription, Base Plan, and Offer. RevenueCat wraps that hierarchy in a flatter model you configure from the dashboard: Offerings, Packages, and SubscriptionOptions. You fetch an Offering, pick a Package, and in most flows let the SDK choose the right SubscriptionOption for you.

Phase 1: Understand

The mapping from Google Play to RevenueCat:

Google PlayRevenueCat
Subscription (product ID)StoreProduct
Base PlanSubscriptionOption (base plan)
OfferSubscriptionOption (offer)
Group of base plans grouped in dashboardPackage inside an Offering

Key types you will touch:

  • Offering: a dashboard configured group of Package objects. offerings.current is the one you show by default.
  • Package: a purchasable slot (monthly, annual, weekly, custom). Exposes a product: StoreProduct.
  • StoreProduct: the Google Play subscription product. Has subscriptionOptions: List<SubscriptionOption>? and a defaultOption.
  • SubscriptionOption: either a base plan or an offer. Has pricingPhases, tags, and an id.
  • PricingPhase: one billing segment (intro trial, intro price, or recurring). Has billingPeriod, price, offerPaymentMode, and recurrenceMode.

See the Subscriptions chapter on revenuecat.com for the object model diagram showing the full Offerings hierarchy alongside the CustomerInfo hierarchy used for entitlement checks.

Phase 2: Plan

Before you write code, map your paywall to the object model. Answer these three questions.

2.1 Which Offering drives the paywall?

  • Default paywall: use offerings.current. This is the Offering marked current in the dashboard and is the standard choice.
  • Experiment or segment specific paywall: fetch offerings.all["experiment-a"]. You keep the dashboard in charge of which products appear, so no app update ships when the catalog changes.

2.2 Which Packages do you show?

Two access patterns, pick the one that matches your layout:

PatternAPIWhen to use
Named slotsoffering.monthly, offering.annual, offering.weeklyFixed paywall with known durations
Iterationoffering.availablePackagesDynamic layout, unknown durations, or custom package types

Standard PackageType values: MONTHLY, ANNUAL, WEEKLY, TWO_MONTH, THREE_MONTH, SIX_MONTH, LIFETIME. Anything else is PackageType.CUSTOM.

2.3 Does the paywall need a specific offer, or is the default fine?

SituationWhat to pass to PurchaseParams
Standard paywall, user gets best eligible offer automaticallyPackage
You need a specific offer (win back, promo, tag selected)SubscriptionOption

The SDK's defaultOption logic:

  1. Filters out options tagged "rc-ignore-offer" or "rc-customer-center".
  2. Picks the option with the longest free trial or the cheapest first phase.
  3. Falls back to the base plan if no offer qualifies.

Trial eligibility is not filtered by the SDK. Google Play only returns offers the user is eligible for, so if a user already consumed a free trial, that option simply will not appear in subscriptionOptions and the base plan becomes the default.

Phase 3: Execute

3.1 Pull Offerings and pick a Package

kotlin
val offerings = Purchases.sharedInstance.awaitOfferings()val offering = offerings.current ?: returnval monthly = offering.monthly ?: returnval product = monthly.productval price = product.price.formattedval period = product.period?.iso8601 // "P1M", "P1Y", null for one time

For a dynamic list:

kotlin
for (pkg in offering.availablePackages) {    render(pkg.product.title, pkg.product.price.formatted, pkg.packageType)}

3.2 Purchase with the default option

When the paywall shows a Package and you want the SDK to pick the best offer, pass the Package directly.

kotlin
val params = PurchaseParams.Builder(activity, monthly).build()val result = Purchases.sharedInstance.awaitPurchase(params)

3.3 Drill into subscriptionOptions for a specific offer

Use this when the paywall targets an offer by tag or offer ID, for example a win back offer.

kotlin
val product = offering.monthly?.product ?: returnval winBack = product.subscriptionOptions    ?.firstOrNull { it.tags.contains("win-back") }val option = winBack ?: product.defaultOption ?: returnval params = PurchaseParams.Builder(activity, option).build()

Always fall back to defaultOption so the paywall still works when the targeted offer is absent (for example, the user is not eligible).

3.4 Render trial and intro pricing from pricingPhases

The first PricingPhase is the trial or intro price when present. Use offerPaymentMode for trial detection.

kotlin
val option = pkg.product.defaultOption ?: returnval first = option.pricingPhases.first()val isTrial = first.offerPaymentMode == OfferPaymentMode.FREE_TRIAL

billingPeriod.value is the count in the period's unit, not days. A P1W period gives value = 1, unit = WEEK. Build labels off both fields:

kotlin
val p = first.billingPeriodval label = when (p.unit) {    Period.Unit.DAY -> "${p.value} day"    Period.Unit.WEEK -> "${p.value} week"    Period.Unit.MONTH -> "${p.value} month"    Period.Unit.YEAR -> "${p.value} year"    else -> p.iso8601}

3.5 Prepaid plans

Prepaid base plans use the same SubscriptionOption API. Their pricingPhases report RecurrenceMode.NON_RECURRING. To accept pending purchases for prepaid plans, enable the flag at configuration time.

kotlin
PurchasesConfiguration.Builder(context, apiKey)    .pendingTransactionsForPrepaidPlansEnabled(true)    .build()

3.6 Check access after purchase

Prefer entitlements. They reflect server computed access state including grace period, account hold, and cancellation with remaining time.

kotlin
val info = result.customerInfoval isPro = info.entitlements["pro"]?.isActive == true

If you need the raw product ID, use customerInfo.activeSubscriptions. It returns a Set<String> of "subscriptionId:basePlanId" entries.

Decision summary

QuestionAnswer
How do I fetch products?Purchases.sharedInstance.awaitOfferings() then offerings.current.
How do I present durations?offering.monthly/annual/weekly or iterate availablePackages.
How do I purchase?Pass the Package to PurchaseParams and let defaultOption apply.
How do I target a specific offer?Filter product.subscriptionOptions by tag or ID, pass the SubscriptionOption.
How do I detect a free trial?pricingPhases.first().offerPaymentMode == OfferPaymentMode.FREE_TRIAL.
How do I check access?customerInfo.entitlements["<id>"]?.isActive.

References

来源与署名

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

许可证: Apache-2.0; see LICENSE

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

举报或申请下架