メインコンテンツにジャンプ
プラグインに戻る
@capgo/native-purchases
チュートリアル
by github.com/Cap-go

ネイティブ購入

ネイティブアプリ内購入、サブスクリプション、iOS StoreKit コミットメント請求計画を、シンプルなAPIで実装する

ガイド

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

@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

アプリのトランザクション情報を取得します。これには、ユーザーがアプリをダウンロードしたり購入したりした日時に関する詳細が含まれます。

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を渡してください。 planIdentifier月額請求のiOSサブスクリプションを提供し、12か月のコミットメントを含む場合、ベースプランIDを渡してください。 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);
}

フルリファレンス

@capgo/native-purchases を使用している場合

@__CAPGO_KEEP_0__/native-purchases を使用している場合 支払いと購入を計画するには、@capgo/native-purchases を接続する必要があります。 接続する必要があります @capgo/native-purchases @capgo/native-purchasesの実装詳細について Getting Started Getting Startedの実装詳細について Capgo Pricing Capgo Pricingの製品フローについて Payment system Payment systemの実装詳細について Revenue Playbook Revenue Playbookの実装詳細について