跳过内容

创建 Android Auto-Renewable 订阅

GitHub

自动续费订阅提供对应用程序的持续访问内容、服务或高级功能。 本指南将帮助您在 Google Play Console 中创建和配置订阅。

订阅将在每个计费周期结束时自动续费,直到用户取消。 它们适用于:

  • 高级内容访问
  • 无广告体验
  • 云存储
  • 持续服务

创建订阅

创建订阅
  1. 前往订阅

    在Google Play控制台中,选择您的应用程序并选择 monetize > 订阅 左侧菜单。

    点击 创建订阅 按钮开始。

    前往订阅

  2. 输入基本信息

    提供订阅名称和产品ID。产品ID用于在应用程序中配置,并且不能在以后更改。

    输入订阅详细信息

  3. 创建基本计划

    Google Play 需要每个订阅都有一个基本计划。 native-purchases 插件仅支持一个基本计划,以保持与 iOS 的兼容性。

    点击 继续添加基本计划 to continue.

    创建基本计划

  4. 配置基本计划详细信息

    输入:

    • 基本计划 ID: 本计划的唯一标识符
    • 计费周期: 用户每次被收费的频率(每周、每月、每年等)
    • 宽限期: Google 在重试支付期间维持订阅的时间窗口,直到取消

    配置基本计划

  5. 设置定价

    访问定价部分并选择您希望提供订阅的所有国家/地区

    选择地区

  6. 配置价格

    设置您的基本价格,使用您的主要货币。Google Play 将自动将其转换为当地货币

    设置价格

  7. 查看区域定价

    查看每个国家/地区的自动转换价格。您可以根据需要调整单独价格

    Review Regional Pricing

  8. 保存配置

    保存您的价格配置.

    保存价格

  9. 激活订阅

    点击 激活 按钮以使您的订阅产品活跃并可供购买.

    激活订阅

The native-purchases plugin requires exactly one base plan per subscription to ensure consistency with iOS subscription handling. Multiple base plans are not supported.

宽限期允许Google Play重试失败的付款,同时保持用户的订阅访问。常见的宽限期是:

  • 每月订阅3天
  • 较长订阅7天

创建后,订阅将处于“草稿”状态,直到激活。您可以在沙盒模式下测试草稿订阅。

创建后,请使用产品ID引用订阅:

import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';
// Load subscription info
const { products } = await NativePurchases.getProducts({
productIdentifiers: ['com.example.premium.monthly'],
productType: PURCHASE_TYPE.SUBS,
});
const product = products[0];
console.log(`${product.title} — ${product.priceString}`);
// Purchase (planIdentifier = Base Plan ID from Google Play Console)
const transaction = await NativePurchases.purchaseProduct({
productIdentifier: 'com.example.premium.monthly',
planIdentifier: 'monthly-plan', // REQUIRED on Android, ignored on iOS
productType: PURCHASE_TYPE.SUBS,
});
console.log('Transaction ID', transaction.transactionId);
// Later, check purchase state
const { purchases } = await NativePurchases.getPurchases({
productType: PURCHASE_TYPE.SUBS,
});
const subscription = purchases.find(
(purchase) => purchase.productIdentifier === 'com.example.premium.monthly',
);
if (subscription && subscription.purchaseState === 'PURCHASED' && subscription.isAcknowledged) {
console.log('Subscription active locally');
// For expiration/cancellation, validate purchaseToken through your backend
}

订阅未出现在应用程序中:

  • 验证产品 ID 与原始 ID 匹配
  • __CAPGO_KEEP_0__
  • __CAPGO_KEEP_0__
  • __CAPGO_KEEP_0__

__CAPGO_KEEP_0__

  • 确保您有恰好一个基本计划
  • __CAPGO_KEEP_0__
  • __CAPGO_KEEP_0__

__CAPGO_KEEP_0__

  • __CAPGO_KEEP_0__
  • __CAPGO_KEEP_0__
  • __CAPGO_KEEP_0__

如果您正在使用 Create Android Auto-Renewable Subscription 来规划商店审批和发布,连接它与 使用 @capgo/native-purchases 为使用 @capgo/native-purchases 的本机能力 @capgo/capacitor-in-app-review 为 @capgo/capacitor-in-app-review 的实现细节 使用 @capgo/capacitor-in-app-review 为使用 @capgo/capacitor-in-app-review 的本机能力 @capgo/capacitor-native-market 为 @capgo/capacitor-native-market 的实现细节 使用 @capgo/capacitor-native-market 为使用 @capgo/capacitor-native-market 的原生能力