跳过内容

iOS 月度承诺计费计划

苹果支持每月付款的订阅,同时要求客户承诺长达12个月的期限。当StoreKit和运行的OS支持此付款计划时, @capgo/native-purchases 暴露了付款条款,允许您在购买时选择每月付款计划,并在交易和续订信息中返回承诺元数据。

使用此选项为用户提供每月付款的年度订阅方案,但您仍然希望保留和预测的承诺年度期限。

  • 在 App Store Connect 或在 Xcode 中的 StoreKit Testing 中配置每月的 12 个月承诺计费计划。
  • 使用包含 StoreKit 的 Xcode SDK 构建 iOS 应用 pricingTermsbillingPlanType.
  • 在支持 StoreKit 承诺计费计划的 iOS 版本上运行。
  • 为不返回承诺定价条款的设备或商店保留标准计费选项。

标题:加载和显示定价条款 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' 仅在需要显式选择标准预付费计费计划时使用。如果省略 billingPlanTypeStoreKit 使用其默认购买行为处理该产品。

交易包含了 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);
}

使用顶级 expirationDateisActive 字段来做出权利决定。使用 commitmentInfo.expirationDate 来向客户解释整个承诺时间线。

  • 在购买前显示两次的定期计费价格和总承诺价格。
  • 在购买按钮附近明确承诺期限。
  • 使用 product.title, product.priceString, pricingTerms[].billingDisplayPricepricingTerms[].commitmentInfo.priceString 从StoreKit代替硬编码价格。
  • 在付款墙或帐户屏幕上提供恢复购买和管理订阅操作。

继续从iOS月度承诺计费计划

标题:继续从iOS月度承诺计费计划

如果您正在使用 iOS 月度承诺计费计划 来规划付款和购买,连接它与 使用 @capgo/native-purchases 为使用 @capgo/native-purchases 的原生能力 Capgo 价格 为 Capgo 价格 的产品工作流 付款系统 为付款系统的实现细节 @capgo/native-purchases 为 @capgo/native-purchases 的实现细节 开始使用 为《开始使用》中的实现细节。