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

ネイティブ購入

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

ガイド

Native Purchasesのチュートリアル

使用方法: @capgo/native-purchases

インアプリサブスクリプションを簡単に実装

Install

bun add @capgo/native-purchases
bunx cap sync

このプラグインが公開するもの

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

Example Usage

restorePurchases

ユーザーの以前の情報を復元し、ユーザーIDを他のユーザー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 か月間のコミットメントで月額課金を実行するには 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」を使用している場合 Using @capgo/native-purchases to plan payments and purchases, connect it with @capgo/native-purchases @capgo/native-purchasesの実装詳細については Getting Startedの実装詳細については __CAPGO_KEEP_0__ Pricingの製品フローについては Capgo Pricing for the product workflow in Capgo Pricing, Footerのフッターです。 for the implementation detail in Payment system, and Revenue Playbook for the implementation detail in Revenue Playbook.