ガイド
Capacitor で Native Purchases を使う方法
@capgo/native-purchases を使用する
アプリ内サブスクリプションをより簡単に。
インストール
bun add @capgo/native-purchases
bunx cap sync
このプラグインで利用可能な機能
restorePurchases- ユーザーの以前の購入情報を復元し、それらを使用している他のユーザーの appUserIDs と紐付けます。getAppTransaction- App Transaction 情報を取得します。これにより、ユーザーが最初にアプリをダウンロードまたは購入した詳細がわかります。isEntitledToOldBusinessModel- App Transaction の元のアプリバージョンとターゲットバージョンを比較し、ユーザーが以前のビジネスモデルの機能を利用できる権利があるか判断します。getProducts- サポートされている iOS サブスクリプションの価格条件を含む、ストア製品のメタデータをロードします。purchaseProduct- 選択した製品と請求プランの購入プロセスを開始します。
使用例
restorePurchases
ユーザーの以前の購入情報を復元し、それらを使用している他のユーザーの appUserIDs と紐付けます。
import { NativePurchases } from '@capgo/native-purchases';
await NativePurchases.restorePurchases();
getAppTransaction
App Transaction 情報を取得します。これにより、ユーザーが最初にアプリをダウンロードまたは購入した詳細がわかります。
import { NativePurchases } from '@capgo/native-purchases';
const { appTransaction } = await NativePurchases.getAppTransaction();
// Check if user downloaded before version 2.0.0 (when subscription was added)
if (compareVersions(appTransaction.originalAppVersion, '2.0.0') < 0) {
// User gets free access - they downloaded before subscriptions
grantFreeAccess();
}
isEntitledToOldBusinessModel
App Transaction の元のアプリバージョンとターゲットバージョンを比較し、ユーザーが以前のビジネスモデルの機能を利用できる権利があるか判断します。
import { NativePurchases } from '@capgo/native-purchases';
// Check if user downloaded before version 2.0.0/build 42 (when subscription was added)
const result = await NativePurchases.isEntitledToOldBusinessModel({
targetVersion: '2.0.0',
targetBuildNumber: '42'
});
if (result.isOlderVersion) {
console.log(`User downloaded v${result.originalAppVersion}, granting free access`);
grantFreeAccess();
}
purchaseProduct
指定した製品の購入プロセスを開始します。Android のサブスクリプションの場合は、Google Play のベースプラン ID を planIdentifier渡してください。12ヶ月の継続利用を条件とした月額請求のサポート対象 iOS サブスクリプションの場合は、 billingPlanType: 'monthly'.
import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';
await NativePurchases.purchaseProduct({
productIdentifier: 'com.example.premium.monthly',
planIdentifier: 'monthly-plan',
productType: PURCHASE_TYPE.SUBS,
});
iOSの月額継続契約サブスクリプション
対応しているiOSバージョンでは、StoreKitを通じて12ヶ月の継続契約を含む月額請求プランを公開できます。 pricingTerms購入前に、ペイウォールに以下の条件を表示してください:
import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';
const { products } = await NativePurchases.getProducts({
productIdentifiers: ['com.example.premium.yearly'],
productType: PURCHASE_TYPE.SUBS,
});
const yearlyProduct = products.find(
(product) => product.identifier === 'com.example.premium.yearly',
);
const monthlyCommitment = yearlyProduct?.pricingTerms?.find(
(term) => term.billingPlanType === 'monthly',
);
if (yearlyProduct && monthlyCommitment) {
console.log('Monthly price:', monthlyCommitment.billingDisplayPrice);
console.log('Total commitment:', monthlyCommitment.commitmentInfo?.priceString);
const transaction = await NativePurchases.purchaseProduct({
productIdentifier: yearlyProduct.identifier,
productType: PURCHASE_TYPE.SUBS,
billingPlanType: 'monthly',
});
console.log('Billing plan:', transaction.billingPlanType);
console.log('Commitment ends:', transaction.commitmentInfo?.expirationDate);
}
リファレンス全文
- GitHub: https://github.com/Cap-go/capacitor-native-purchases/
- ドキュメント: /docs/plugins/native-purchases/
- iOS月額継続契約ガイド: /docs/plugins/native-purchases/ios-monthly-commitment/
@capgo/native-purchases の使用方法から進む
使用している場合 @capgo/native-purchases を使用する 支払いや購入を計画するには、これを以下と連携させます @capgo/native-purchases @capgo/native-purchases の実装の詳細については、 スタートガイド スタートガイドの実装詳細については、 Capgo の料金 Capgo の料金ページのプロダクトワークフローについては、 決済システム 決済システムの実装詳細については、 収益化プレイブック 実装の詳細については Revenue Playbook を参照してください。