跳过内容

iOS 月度承诺计费计划

GitHub

包含安装、同步和源 Markdown 指南。 @capgo/native-purchases 苹果支持每月付款的订阅,客户在 12 个月内承诺付款。 当 StoreKit 和运行的操作系统支持此付款计划时,

显示定价条款,允许您在购买时选择每月付款计划,并在交易和续订信息中返回承诺元数据。

Requirements

要求
  • 标题:要求
  • 使用 Xcode SDK 构建 iOS 应用,包含 StoreKit pricingTerms 并 billingPlanType.
  • 在支持 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,
});

Use billingPlanType: 'upFront' 只有在您需要明确选择标准的前付费计费计划时才会发生。 如果您省略 billingPlanType提示

Section titled “读取承诺元数据”

Copy to clipboard

交易包括 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 评论备注

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

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

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

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