メインコンテンツにスキップ

ガイド

Native Purchasesのチュートリアル

デバイスでテスト

Download the Capgo app, then scan the QR code.

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

@capgo/native-purchases

インアプリ購入の簡素化

インストール

bun add @capgo/native-purchases
bunx cap sync

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

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

使用例

restorePurchases

ユーザーの前の購入を復元し、AppUser IDを使用しているすべてのユーザーとリンクします。

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を渡します。 planIdentifierサポートされているiOSサブスクリプションの場合、月額課金のプランを渡します。 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サポートされているiOSバージョンでは、StoreKitは12ヶ月コミットメントの月額課金プランを表示できます。

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);
}

サポートされているiOSバージョンでは、StoreKitは12ヶ月コミットメントの月額課金プランを表示できます。

  • GitHub: https://github.com/Cap-go/capacitor-native-purchases/
  • サポートされているiOSバージョンでは、StoreKitは12ヶ月コミットメントの月額課金プランを表示できます。
  • iOS 月額コミットメントガイド: /docs/plugins/native-purchases/ios-monthly-commitment/

Keep going from Using @capgo/native-purchases

Capgo Native Purchases を使用している場合 Using @capgo/native-purchases Capgo Native Purchases を使用して支払いと購入を計画する @capgo/native-purchases for the implementation detail in @capgo/native-purchases, Capgo Native Purchases の実装詳細については、Getting Started を参照してください Capgo Native Purchases の価格設定 Capgo Pricing for the product workflow in Capgo Pricing, Payment system Paymentシステムの実装詳細については Revenue Playbook Revenue Playbookの実装詳細については