ガイド
ネイティブ購入のチュートリアル
@capgo/native-purchases を使用
インアプリ購入が簡単になりました。
インストール
bun add @capgo/native-purchases
bunx cap sync
このプラグインが提供するもの
restorePurchases-ユーザーの前の購入を復元し、ユーザーのアプリIDを他のユーザーも使用しているユーザーのアプリIDとリンクします。getAppTransaction-アプリのトランザクション情報を取得します。これは、ユーザーがアプリをダウンロードしたときや購入したときの詳細を提供します。isEntitledToOldBusinessModel-元のアプリバージョンと対象バージョンを比較して、ユーザーが以前のビジネスモデルから機能を受け取る資格があるかどうかを判断します。getProducts- iOS のサブスクリプション価格条件を含むストア製品メタデータを読み込む。purchaseProduct- 選択した製品と請求計画の購入プロセスを開始する。
使用例
restorePurchases
ユーザーの前の購入情報を復元し、ユーザーIDを他のユーザーとリンクする。
import { NativePurchases } from '@capgo/native-purchases';
await NativePurchases.restorePurchases();
getAppTransaction
アプリの購入情報を取得する。これにより、ユーザーがアプリをダウンロードしたときや購入したときの詳細が提供される。
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
アプリの購入情報から元のアプリバージョンと対象バージョンを比較して、ユーザーが以前のビジネスモデルから特定の機能に権利があるかどうかを判断する。
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 を渡す。 planIdentifieriOS のサブスクリプションで月額請求に 12 か月のコミットメントを提供する場合、"" を渡す。 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 のサポートされているサブスクリプションで月額請求に 12 か月のコミットメントを提供する場合、StoreKit は 12 か月のコミットメントを含む月額請求計画を表示する。
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/