跳过内容

iOS 每月承诺计费计划

GitHub

Apple 支持每月付款的订阅,客户在此付款方式下将被锁定到更长的 12 个月期限。 当 StoreKit 和运行中的 OS 支持此付款方式时, @capgo/native-purchases 会暴露定价条款,允许您在购买时选择每月付款方式,并在交易和续订信息中返回承诺元数据。

适用于用户偏好每月付款但您仍希望保留和预测的年度承诺期限的年度订阅方案。

要求

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

加载和显示定价条款

标题:加载和显示定价条款

调用 getProducts() context 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仅在需要明确选择标准的前置付款计划时使用。如果省略

阅读承诺元数据

标题:阅读承诺元数据

交易包括 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 向客户说明完整的承诺时间表。

App Store Review Notes

标题:App Store Review Notes
  • 在购买前显示重复计费价格和总承诺价格。
  • 在购买按钮附近明确承诺长度。
  • 使用 product.title, product.priceString, pricingTerms[].billingDisplayPrice,和 pricingTerms[].commitmentInfo.priceString 从StoreKit获取价格而不是硬编码价格。
  • 在付款墙或账户屏幕上提供恢复购买和管理订阅的操作。

继续使用 iOS 月度承诺计费计划

继续使用 iOS 月度承诺计费计划

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