コンテンツに進む

Getting Started

GitHub

CapgoのAI-Assisted Setupを使用してプラグインをインストールできます。AIツールにCapgoスキルを追加するには、以下のコマンドを使用してください。

ターミナルウィンドウ
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次のプロンプトを使用してください:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/native-purchases` plugin in my project.

手動設定を選択する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム固有の手順に従ってください。

  1. パッケージをインストール

    ターミナル画面
    bun add @capgo/native-purchases
  2. ネイティブプロジェクトと同期

    ターミナル画面
    bunx cap sync
  3. 請求サポートを確認

    import { NativePurchases } from '@capgo/native-purchases';
    const { isBillingSupported } = await NativePurchases.isBillingSupported();
    if (!isBillingSupported) {
    throw new Error('Billing is not available on this device');
    }
  4. ストアから直接製品を読み込む

    import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';
    const { products } = await NativePurchases.getProducts({
    productIdentifiers: [
    'com.example.premium.monthly',
    'com.example.premium.yearly',
    'com.example.one_time_unlock'
    ],
    productType: PURCHASE_TYPE.SUBS, // Use PURCHASE_TYPE.INAPP for one‑time products
    });
    products.forEach((product) => {
    console.log(product.title, product.priceString);
    });
  5. 購入と復元フローを実装する

    import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';
    const monthlyPlanId = 'monthly-plan'; // Base Plan ID from Google Play Console
    const transaction = await NativePurchases.purchaseProduct({
    productIdentifier: 'com.example.premium.monthly',
    planIdentifier: monthlyPlanId, // REQUIRED for Android subscriptions, ignored on iOS
    productType: PURCHASE_TYPE.SUBS,
    quantity: 1,
    });
    console.log('Transaction ID', transaction.transactionId);
    await NativePurchases.restorePurchases();
    • App Store Connectでインアプリ製品とサブスクリプションを作成します。
    • StoreKit Local TestingまたはSandboxテスターを使用してQAを行います。
    • マニフェストの編集は必要ありません。製品が承認されていることを確認してください。
import { NativePurchases, PURCHASE_TYPE, Transaction } from '@capgo/native-purchases';
import { Capacitor } from '@capacitor/core';
class PurchaseService {
private premiumProduct = 'com.example.premium.unlock';
private monthlySubId = 'com.example.premium.monthly';
private monthlyPlanId = 'monthly-plan'; // Base Plan ID (Android only)
async initialize() {
const { isBillingSupported } = await NativePurchases.isBillingSupported();
if (!isBillingSupported) throw new Error('Billing unavailable');
const { products } = await NativePurchases.getProducts({
productIdentifiers: [this.premiumProduct, this.monthlySubId],
productType: PURCHASE_TYPE.SUBS,
});
console.log('Loaded products', products);
if (Capacitor.getPlatform() === 'ios') {
NativePurchases.addListener('transactionUpdated', (transaction) => {
this.handleTransaction(transaction);
});
}
}
async buyPremium(appAccountToken?: string) {
const transaction = await NativePurchases.purchaseProduct({
productIdentifier: this.premiumProduct,
productType: PURCHASE_TYPE.INAPP,
appAccountToken,
});
await this.processTransaction(transaction);
}
async buyMonthly(appAccountToken?: string) {
const transaction = await NativePurchases.purchaseProduct({
productIdentifier: this.monthlySubId,
planIdentifier: this.monthlyPlanId, // REQUIRED for Android subscriptions
productType: PURCHASE_TYPE.SUBS,
appAccountToken,
});
await this.processTransaction(transaction);
}
async restore() {
await NativePurchases.restorePurchases();
await this.refreshEntitlements();
}
async openManageSubscriptions() {
await NativePurchases.manageSubscriptions();
}
private async processTransaction(transaction: Transaction) {
this.unlockContent(transaction.productIdentifier);
this.validateOnServer(transaction).catch(console.error);
}
private unlockContent(productIdentifier: string) {
// persist entitlement locally
console.log('Unlocked', productIdentifier);
}
private async refreshEntitlements() {
const { purchases } = await NativePurchases.getPurchases({
productType: PURCHASE_TYPE.SUBS,
});
console.log('Current purchases', purchases);
}
private async handleTransaction(transaction: Transaction) {
console.log('StoreKit transaction update:', transaction);
await this.processTransaction(transaction);
}
private async validateOnServer(transaction: Transaction) {
await fetch('/api/validate-purchase', {
method: 'POST',
body: JSON.stringify({
transactionId: transaction.transactionId,
receipt: transaction.receipt,
purchaseToken: transaction.purchaseToken,
}),
});
}
}
オプションプラットフォーム説明
productIdentifieriOS + AndroidApp Store Connect / Google Play Console で設定した SKU / Product ID
productTypeAndroid 限定PURCHASE_TYPE.INAPP または PURCHASE_TYPE.SUBSまたは INAPPデフォルト SUBS 常に
planIdentifierサブスクリプション用Android サブスクリプション用
billingPlanTypeiOS サブスクリプションStoreKit の請求計画を購入に使用します。 'monthly' 月額請求に 12 か月のコミットメントを設定する場合に使用します。 product.pricingTerms iOS
quantityiOS のみのインアプリ購入に使用します。デフォルトは。Android は常に 1 つのアイテムを購入します。 1iOS + Android
appAccountTokeniOS購入をユーザーにリンクするための UUID/文字列。iOS では必須の UUID になりますが、Android では 64 文字以内にオブフスコードされた文字列を許可します。
isConsumableAndroidを設定すると、消耗可能なアイテムの特権を付与した後で自動的にトークンを消費します。デフォルトは true です。 false.

使用 getPurchases() すべての取引を表示するクロスプラットフォームのビューのために:

import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';
const { purchases } = await NativePurchases.getPurchases({
productType: PURCHASE_TYPE.SUBS,
});
purchases.forEach((purchase) => {
if (purchase.isActive && purchase.expirationDate) {
console.log('iOS sub active until', purchase.expirationDate);
}
const isAndroidIapValid =
['PURCHASED', '1'].includes(purchase.purchaseState ?? '') && purchase.isAcknowledged;
if (isAndroidIapValid) {
console.log('Grant in-app entitlement for', purchase.productIdentifier);
}
});
  • iOS: サブスクリプションには isActive, expirationDate, willCancel, および StoreKit 2 リスナーのサポートが含まれます。アプリ内課金にはサーバー受領の検証が必要です。
  • Android: isActive/expirationDate は埋められていません。Google Play Developer API に、 purchaseToken for authoritative status. purchaseState must be PURCHASEDisAcknowledged must be true.
  • isBillingSupported() – StoreKit / Google Play の利用可能性を確認します。
  • getProduct() / getProducts() – 価格、ローカライズされたタイトル、説明、イントロダクション オファー、サポートされている iOS の価格条件を取得します。
  • purchaseProduct() – StoreKit 2 または Billing クライアント購入フローの開始、iOS の月額コミットメント請求計画を含みます。
  • restorePurchases() – 歴史的な購入を再生し、現在のデバイスに Sync します。
  • getPurchases() – iOS のすべての取引または Play Billing の購入をリストします。
  • manageSubscriptions() – ネイティブのサブスクリプション管理 UI を開きます。
  • addListener('transactionUpdated') – iOS アプリが起動したときに、StoreKit 2 の保留中のトランザクションを処理する (iOS 限定).
  1. ショップの価格を表示 – Apple は表示することを要求しています product.title そして product.priceString;ハードコードしないこと。
  2. 使用 appAccountToken – ユーザー ID から UUID (v5) を決定的に生成して、購入をアカウントにリンクする。
  3. サーバー側で検証 – (iOS) / receiptpurchaseToken バックエンドに送信して検証
  4. エラーを柔軟に処理 – ユーザーのキャンセル、ネットワークの失敗、非対応の請求環境を確認
  5. 徹底的にテストiOS サンドボックス ガイドAndroid サンドボックス ガイド.
  6. 請求の復元と管理を提供 – UI ボタンに接続 restorePurchases()manageSubscriptions().

収益の次のステップ

収益の次のステップ

購入フローの正常動作後、 Revenue Playbook を使用して、最初の有料チャネルを計画する: 製品範囲、ASO、価格設定、壁の配置、分析、脱落フィードバック。

トラブルシューティング

  • 製品が読み込まれない
  • バンドルID / アプリケーションIDがストアの設定と一致していることを確認してください。
  • 製品IDが有効かつ承認済み (App Store) または有効化済み (Google Play) であることを確認してください。

製品を作成してから数時間待ってください。ストアのプロパゲーションは即時ではありません。

  • 購入がキャンセルされたり、途中で止まったりする try/catch そして表面に親切なエラーメッセージを表示します。
  • Androidの場合、テストアカウントはPlay Store (内部トラック)からアプリをインストールして、Billingが正常に動作するようにしてください。
  • デバイス上で実行している場合、Billingエラーを確認するにはlogcat/Xcodeを参照してください。

サブスクリプションの状態が不正です。

  • を使用して getPurchases() ストアデータとローカルエンタイトルメントキャッシュを比較するために
  • Androidの場合、常にGoogle Play Developer APIに purchaseToken を使用して、期限切れ日または払い戻しステータスを取得します。
  • iOSの場合、を確認し、受け取りを検証して払い戻しまたは取り消しを検出します。 isActive/expirationDate Getting Startedから続けてください。

「Getting Startedから続けてください」というセクションのタイトル

items

Capgoを使用している場合 はじめに 店舗承認と配布の計画に役立つため、 Using @capgo/native-purchases for the native capability in Using @capgo/native-purchases, @capgo/capacitor-in-app-review for the implementation detail in @capgo/capacitor-in-app-review, Using @capgo/capacitor-in-app-review for the native capability in Using @capgo/capacitor-in-app-review, @capgo/capacitor-native-market for the implementation detail in @capgo/capacitor-native-market, and Using @capgo/capacitor-native-market for the native capability in Using @capgo/capacitor-native-market.