ガイド
How to use Native Purchases in Capacitor
@capgo/native-purchases を使用
インアプリ購入が簡単になりました。
インストール
bun add @capgo/native-purchases
bunx cap sync
このプラグインが提供するもの
restorePurchases- これまでに購入したユーザーの情報を復元し、ユーザーのアプリIDを他のユーザーと関連付けます。getAppTransaction- アプリのトランザクション情報を取得します。これにより、ユーザーがアプリをダウンロードしたり購入したりした時期についての詳細が提供されます。isEntitledToOldBusinessModel- アプリのトランザクション情報から元のアプリバージョンと対象バージョンを比較して、ユーザーが以前のビジネスモデルから特定の機能にアクセスできるかどうかを判断します。getProducts- iOS のサブスクリプション価格条件を含むストア製品メタデータを読み込みます。purchaseProduct- 選択した製品と請求プランの購入プロセスを開始します。
使用例
restorePurchases
これまでに購入したユーザーの情報を復元し、ユーザーのアプリIDを他のユーザーと関連付けます。
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を渡してください。 planIdentifieriOSのサブスクリプションを渡してください。サポートされているiOSのサブスクリプションは、毎月の請求と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 月額コミットメントサブスクリプション
サポートされているiOSバージョンでは、StoreKitは12ヶ月のコミットメントを含む毎月の請求プランを表示できます。 pricingTermsサポートされているiOSバージョンでは、StoreKitは12ヶ月のコミットメントを含む毎月の請求プランを表示できます。
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);
}
サポートされているiOSバージョンでは、StoreKitは12ヶ月のコミットメントを含む毎月の請求プランを表示できます。
- GitHub: https://github.com/Cap-go/capacitor-native-purchases/
- ドキュメント: /docs/plugins/native-purchases/
- サポートされているiOSバージョンでは、StoreKitは12ヶ月のコミットメントを含む毎月の請求プランを表示できます。
@capgo/ネイティブ購入
Capacitor Native Purchasesを使用している場合 Using @capgo/native-purchases 支払いと購入を計画するためにCapacitor Native Purchasesを使用 @capgo/ネイティブ購入 Capacitor-native-purchasesの実装詳細については、@capgo/native-purchasesを参照してください。 Capacitor Native Purchasesの実装詳細 Capacitor Native Purchasesの価格設定 Capgo 価格設定 Capacitor Native Purchasesの製品ワークフローにおけるCapgoの価格設定 支払いシステムの実装詳細 Capacitor Native Purchasesの価格設定 収益戦略ガイド 収益戦略ガイドの実装詳細について