メインコンテンツにスキップ
プラグインに戻る
@capgo/native-purchases
チュートリアル
@capgo/native-purchases

ネイティブ購入

Implement native in-app purchases, subscriptions, and iOS StoreKit commitment billing plans with a simple API

ガイド

ネイティブ購入のチュートリアル

デバイスでテスト

Download the Capgo app, then scan the QR code.

ネイティブ購入プラグインのプレビューQRcode

@capgo/native-purchasesを使用

アプリ内購入の簡素化

インストール

bun add @capgo/native-purchases
bunx cap sync

このプラグインが提供するもの

  • restorePurchases -ユーザーの前の購入を復元し、ユーザーのアプリIDを他のユーザーとリンクする。
  • getAppTransaction -アプリのトランザクション情報を取得します。これは、ユーザーがアプリをダウンロードしたときや購入したときの詳細を提供します。
  • isEntitledToOldBusinessModel -元のアプリバージョンと対象バージョンを比較して、ユーザーが以前のビジネスモデルから特定の機能に権利があるかどうかを判断します。
  • 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を渡します。 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バージョンでは、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);
}

Capgo:

Keep going from Using @capgo/native-purchases

Capacitor Native Purchases を使用している場合 Using @capgo/native-purchases Capacitor Native Purchases と接続して @capgo/native-purchases for the implementation detail in @capgo/native-purchases, Getting Started の実装詳細については、Getting Started を参照してください。 __CAPGO_KEEP_0__ の価格設定 Capgo for the product workflow in Capgo Pricing, 決済システム Capacitor Native Purchasesの実装詳細 収益プレイブック Capacitor Native Purchasesの実装詳細