iOS月度承诺计费计划
复制一个设置提示,包括安装步骤和此插件的完整 Markdown 指南。
苹果支持每月付费的订阅,同时承诺客户在 12 个月的更长期限内。 当 StoreKit 和正在运行的 OS 支持此付费计划时, @capgo/native-purchases 暴露价格条款,允许您在购买时选择每月付费计划,并在交易和续订信息中返回承诺元数据。
使用此选项为用户提供每年订阅的优惠,用户仍然希望每月付款,但您仍然希望保留和预测的承诺每年期限。
需求
需求- 在 App Store Connect 或 Xcode 中的 StoreKit Testing 中配置每月 12 个月的承诺付款计划。
- 使用包含 StoreKit 的 Xcode SDK 构建 iOS 应用程序。
pricingTerms在支持 StoreKit 承诺付款计划的 iOS 版本上运行。billingPlanType. - 保持标准的付款选项可供不返回承诺价格条款的设备或商店使用。
- 注意
加载和显示价格条款
价格条款加载和显示部分呼叫 getProducts() 如常。对于支持的iOS订阅产品,每个产品都可以包含 pricingTerms.
import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';
const { products } = await NativePurchases.getProducts({ productIdentifiers: ['com.example.app.premium.yearly'], productType: PURCHASE_TYPE.SUBS,});
const premiumYearly = products.find( (product) => product.identifier === 'com.example.app.premium.yearly',);const monthlyCommitment = premiumYearly?.pricingTerms?.find( (term) => term.billingPlanType === 'monthly',);渲染商店提供的值而不是硬编码的价格:
| 字段 | 用它来 |
|---|---|
billingDisplayPrice | 用户看到的定期计费金额,例如每月费用 |
billingPeriod | 显示的计费周期 |
commitmentInfo.priceString | 为用户商店格式化的总承诺价格 |
commitmentInfo.period | 全期承诺 |
subscriptionOffers | 与定价条款相关的推广性或促销性优惠。 |
示例付费墙复制:
function commitmentLabel(term: NonNullable<typeof monthlyCommitment>) { const total = term.commitmentInfo?.priceString; return total ? `${term.billingDisplayPrice} billed monthly, ${total} total commitment` : term.billingDisplayPrice;}购买月度承诺计划
标题为“购买月度承诺计划”的部分当用户选择月度承诺计划时,传递 billingPlanType: 'monthly'.
const transaction = await NativePurchases.purchaseProduct({ productIdentifier: 'com.example.app.premium.yearly', productType: PURCHASE_TYPE.SUBS, billingPlanType: 'monthly', appAccountToken: userStoreUuid,});仅在需要明确选择标准的预付费计费计划时使用。如果您省略 billingPlanType: 'upFront' StoreKit 将使用其默认的购买行为来处理该产品。 billingPlanType提示
读取承诺元数据
标题:读取承诺元数据交易包括billing plan和承诺进度,当StoreKit提供时:
if (transaction.billingPlanType === 'monthly') { console.log('Current billing period:', transaction.commitmentInfo?.billingPeriodNumber); console.log('Total billing periods:', transaction.commitmentInfo?.totalBillingPeriods); console.log('Commitment ends:', transaction.commitmentInfo?.expirationDate); console.log('Commitment total:', transaction.commitmentInfo?.price);}续订信息可以包括下一个承诺状态:
const { purchases } = await NativePurchases.getPurchases({ productType: PURCHASE_TYPE.SUBS, onlyCurrentEntitlements: true,});
for (const purchase of purchases) { const commitment = purchase.renewalInfo?.commitmentInfo; if (!commitment) continue;
console.log('Renews into another commitment:', commitment.willAutoRenew); console.log('Next billing plan:', commitment.renewalBillingPlanType); console.log('Next renewal date:', commitment.renewalDate);}使用顶级 expirationDate 和 isActive 字段进行资格决策。使用 commitmentInfo.expirationDate 向客户解释整个承诺时间线。
App Store Review Notes
App Store Review Notes- 在购买前显示定期计费价格和总体承诺价格。
- 在购买按钮附近明确承诺长度。
- 使用StoreKit中的
product.title,product.priceString,pricingTerms[].billingDisplayPrice和pricingTerms[].commitmentInfo.priceString代替硬编码价格。 - 在付款墙或账户屏幕上提供恢复购买和管理订阅的操作。
相关指南
相关指南继续使用 iOS 月度承诺计费计划
标题:继续使用 iOS 月度承诺计费计划如果您正在使用 iOS 月度承诺计费计划 来规划付款和购买,连接它与 使用 @capgo/native-purchases 为在使用 @capgo/native-purchases 中的原生能力 Capgo 价格 为在 Capgo 价格 中的产品工作流程 付款系统 为付款系统的实现细节 @capgo/native-purchases 关于@capgo/native-purchases的实现细节, Getting Started 关于Getting Started的实现细节。