iOS 月度承诺计费计划
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
苹果支持每月订阅,客户在此基础上承诺12个月的期限。 当StoreKit和运行的OS支持此计费计划时, @capgo/native-purchases 暴露定价条款,允许在购买时选择每月计费计划,并在交易和续订信息中返回承诺元数据。
使用此选项提供年度订阅方案,用户偏好每月付款,但您仍希望保留和预测承诺的年度期限。
要求
标题:要求- 在App Store Connect或Xcode中的StoreKit Testing中配置每月12个月承诺计费计划。
- 使用包含StoreKit的Xcode SDK构建iOS应用程序。
pricingTerms在支持StoreKit承诺计费计划的iOS版本上运行。billingPlanType. - 为不返回承诺定价条款的设备或商店保留标准计费选项。
- 注意
加载和显示价格条款
加载和显示价格条款Call 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 | The total commitment price formatted for the user’s storefront. |
commitmentInfo.period | The full commitment period. |
subscriptionOffers | Introductory or promotional offers attached to the pricing term. |
示例付费墙复制:
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示例付费墙复制:
is missing, hide the commitment option and show the regular subscription purchase button.
读取承诺元数据Section titled “Read Commitment Metadata”
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”的部分- 在购买之前显示两者:定期计费价格和总承诺价格。
- 在购买按钮附近明确承诺长度。
- 使用
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的实现细节, 和 入门指南 对于入门指南的实现细节。