メインコンテンツにスキップ
@capgo/native-purchases Commerce オープンソース

Native Purchases Capacitor プラグイン

API プラグイン

Install

bun add @capgo/native-purchases bunx cap sync
npm, pnpm または yarn
  • npm install @capgo/native-purchases
  • pnpm add @capgo/native-purchases
  • yarn add @capgo/native-purchases

ガイド

How to use Native Purchases in Capacitor

@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

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 月額コミットメントサブスクリプション

サポートされている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/
  • ドキュメント: /docs/plugins/native-purchases/
  • サポートされているiOSバージョンでは、StoreKitは12ヶ月のコミットメントを含む毎月の請求プランを表示できます。

@capgo/ネイティブ購入

Capacitor Native Purchasesを使用している場合 Using @capgo/native-purchases 支払いと購入を計画するためにCapacitor Native Purchasesを使用 @capgo/ネイティブ購入 Capacitor-native-purchasesの実装詳細については、@capgo/native-purchasesを参照してください。 Capacitor Native Purchasesの実装詳細 Capacitor Native Purchasesの価格設定 Capgo 価格設定 Capacitor Native Purchasesの製品ワークフローにおけるCapgoの価格設定 支払いシステムの実装詳細 Capacitor Native Purchasesの価格設定 収益戦略ガイド 収益戦略ガイドの実装詳細について

FAQ

ネイティブ購入プラグインのFAQ

Native Purchases プラグインを Capacitor アプリにインストールする方法は何ですか?

「bun add @capgo/native-purchases」 (または「npm install @capgo/native-purchases」) を実行し、次に「bunx cap sync」を実行して iOS と Android プロジェクトがネイティブ code を取得するようにします。次に、@capgo/native-purchases をアプリの code でインポートします。

@capgo/native-purchases は React、Vue、Angular とどのように動作しますか?

Yes. Native Purchases is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/native-purchases support?

Capgo plugins follow Capacitor&#39;s major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

@capgo/native-purchases は無料でオープンソースですか?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-native-purchases/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Native Purchases を使用する code を App Store のレビューなしで更新できますか?

プラグインをインストールまたはアップグレードすると、ネイティブ code が変更されるため、新しいストア ビルドが必要になります。その後、JavaScript、HTML、CSS の変更がプラグインを呼び出すと、Capgo のライブ アップデートで即時配信できます。

アプリレビューの待たずにネイティブ購入の変更を配信

プラグインがストアに追加された後、Capgo ライブアップデートは、ユーザーにJavaScript、HTML、CSSの変更を数分で反映します。

Capgo で始めましょう