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

ネイティブ購入

ネイティブアプリ内課金、サブスクリプション、iOS StoreKit のコミットメント請求計画を、シンプルな API で実装します。

ガイド

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

デバイスでテスト

Capgoアプリをダウンロードし、QR codeをスキャンしてください。

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

Using @capgo/native-purchases

インアプリ購入の簡単化

インストール

bun add @capgo/native-purchases
bunx cap sync

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

  • restorePurchases -ユーザーの前の購入を復元し、ユーザーのアプリユーザーIDを、同じアプリユーザーIDを持つ他のユーザーとリンクします。
  • getAppTransaction -アプリトランザクション情報を取得します。これにより、ユーザーがアプリをダウンロードしたり購入したりした時期に関する詳細が提供されます。
  • isEntitledToOldBusinessModel -アプリトランザクションから元のアプリバージョンと、対象バージョンを比較して、ユーザーが以前のビジネスモデルから特定の機能に権利があるかどうかを判断します。
  • getProducts -iOSのサブスクリプション価格条件を含む、サポートされているストア製品メタデータを読み込みます。
  • purchaseProduct -選択した製品と請求計画で購入プロセスを開始します。

使用例

restorePurchases

のユーザーの前のとを復元し、 でも使用しているユーザーの とのリンクを設定します。

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

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 のサブスクリプションをサポートしている場合、月額課金の 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 か月間のコミットメントを含むパラメーターを渡してください。

サポートしている 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);
}

フル リファレンス

Using @capgo/native-purchases から続けてください。

Capacitor を使用している場合 Using @capgo/native-purchases 支払いと購入を計画するには、 @capgo/native-purchases for the implementation detail in @capgo/native-purchases, Getting Started Getting Started の実装詳細は、Getting Started のドキュメントで確認してください。 Capgo Pricing for the product workflow in Capgo Pricing, Payment system 決済システムの実装詳細について、 Revenue Playbook Revenue Playbookの実装詳細について、