claude-skills/

Anthropic公式スキル・プラグインの日本語ディレクトリ

last sync 22h ago
スキルOfficialdevelopment

🛒revenuecat-purchase-flow

プラグイン
revenuecat

説明

RevenueCat の購入およびリストアフローを実装します。 次のような場合に使用: - パッケージの購入処理を求められたとき - サブスクリプションの購入を行いたいとき - オファリング(offerings)を取得したいとき - ペイウォールの購入ロジックを構築したいとき - 購入エラーをハンドリングしたいとき - ユーザーによるキャンセルを検知したいとき - 以前の購入をリストア(restore)したいとき 対応プラットフォーム: iOS / Android / Kotlin Multiplatform / Flutter / React Native

原文を表示

Implement the RevenueCat purchase and restore flow. Use when the user asks to buy a package, purchase a subscription, fetch offerings, build paywall purchase logic, handle purchase errors, detect user cancelled, or restore previous purchases on iOS, Android, Kotlin Multiplatform, Flutter, or React Native.

ユースケース

  • パッケージの購入処理を実装するとき
  • サブスクリプション購入を行いたいとき
  • オファリング情報を取得したいとき
  • 購入エラーをハンドリングしたいとき
  • 以前の購入をリストアするとき

本文(日本語訳)

revenuecat-purchase-flow: パッケージの購入と購入の復元

次のような場合に使用: ユーザーがRevenueCatの購入フローを実装したい場合。具体的には、オファリングの取得、purchase の呼び出し、キャンセルおよびエラーの処理、「復元」アクションの公開が該当します。 ペイウォールUIのレンダリング(revenuecat-paywall が担当)や機能のゲーティング(revenuecat-entitlements-gate が担当)はこのスキルの対象外です。


1. プラットフォームの検出

作業ディレクトリを調べ、上から順に最初に一致したものを選択します:

  1. React Native: package.jsonreact-native-purchases エントリがある、または react-native が依存関係に含まれている → platforms/react-native.md を読む。expo も依存関係にある場合は、Expoプロジェクトとして記録する。
  2. Flutter: プロジェクトルートに pubspec.yaml が存在する → platforms/flutter.md を読む。
  3. Kotlin Multiplatform: build.gradle.ktskotlin { … } のマルチプラットフォームソースセットブロックが含まれている、または com.revenuecat.purchases:purchases-kmp* に依存している → platforms/kmp.md を読む。
  4. Android(ネイティブ): build.gradle(.kts)com.android.application を適用している(かつKMPでない) → platforms/android.md を読む。
  5. iOS(ネイティブ): プロジェクトルートに Package.swift*.xcodeproj*.xcworkspace、または Podfile が存在する → platforms/ios.md を読む。

複数が一致する場合(例: Flutterプロジェクト内の ios/ フォルダ)は、ビルドを管理している最も外側のプロジェクトを選択してください。 それでも判断が難しい場合は、どのプラットフォームを設定したいかユーザーに確認してください。


2. 共通コンセプト(全プラットフォーム共通)

  • フローの概要。 getOfferings() を呼び出し、現在のオファリングから Package を選択し、purchase(package) を呼び出します。正常に完了すると、返された customerInfo に購入内容が反映されています。customerInfo.entitlements.active["<id>"] を参照してアクセス権を確認してください。

  • ユーザーによるキャンセルはアプリケーションエラーではありません。 各SDKでの表現方法は異なります: iOSは purchaseCancelledError コードをthrow、AndroidはPurchasesErrorCode.PurchaseCancelledErrorを持つPurchasesExceptionをthrow、Flutterは同じコードを持つPlatformExceptionをsurface、React Nativeはe.userCancelled === true` をセットします。この場合はアラートを表示せず、静かに処理を終了してください。

  • メッセージを表示すべきエラー。 支払いの拒否、ネットワークエラー、ストアの利用不可、レシートの重複使用などが該当します。それ以外はログに記録し、ユーザーが再試行できるようにしてください。購入が実際に失敗したにもかかわらず、成功したように見せることは絶対に避けてください。

  • 購入コールバックの中でコンテンツをアンロックしないでください。 customerInfoを更新し、エンタイトルメントリスナー(revenuecat-entitlements-gate 参照)にゲーティングされたUIの切り替えを任せてください。これにより、アクセス権の唯一の情報源が維持され、購入フローと復元フローの間で状態がずれるのを防げます。

  • restorePurchases() はユーザーアクションであり、自動的なステップではありません。 ストアに現在のレシートを問い合わせ、RevenueCatと同期します。ペイウォールや設定画面に目立つ「購入を復元」ボタンを配置してください。iOSではこのボタンの設置が法的要件となっています。

  • 購入は同時に1件まで。 購入処理中はペイウォールの購入ボタンを無効化し、二重請求を防いでください。


3. 実装

検出結果に対応するプラットフォームファイルを読んでください:

  • platforms/ios.md
  • platforms/android.md
  • platforms/kmp.md
  • platforms/flutter.md
  • platforms/react-native.md

各プラットフォームファイルには、完全な購入関数と復元関数が含まれています。


4. 動作確認

以下がすべて満たされるまで、フローが正常に動作すると宣言しないでください:

  1. 現在のオファリングのパッケージのサンドボックス購入がエンドツーエンドで成功し、ユーザーのエンタイトルメントがアクティブに切り替わること。
  2. ストアシートをキャンセルしてもエラーアラートが表示されず、UIがローディング状態のまま残らないこと。
  3. すでにアクティブなサブスクリプションに対する2回目の購入試行が適切に処理されること(StoreKit / Play Billingは productAlreadyPurchased / receiptAlreadyInUse のパスをsurfaceするため、フローがクラッシュしないこと)。
  4. 同じストアアカウントでサインインした状態でのフレッシュインストールにおいて、復元ボタンによってエンタイトルメントが復元され、UIが更新されること。
原文(English)を表示

revenuecat-purchase-flow: buy a package and restore purchases

Use this skill when the user wants to complete the purchase side of RevenueCat: fetch offerings, call purchase, deal with cancellation and errors, and expose a "Restore" action. It does not cover rendering a paywall UI (that lives in revenuecat-paywall) or gating features (that lives in revenuecat-entitlements-gate).

1. Detect the platform

Inspect the working directory and pick the first match, from top to bottom:

  1. React Native: package.json has a react-native-purchases entry, or react-native as a dependency → read platforms/react-native.md. If expo is also a dependency, note it as an Expo project.
  2. Flutter: pubspec.yaml exists at the project root → read platforms/flutter.md.
  3. Kotlin Multiplatform: build.gradle.kts contains a kotlin { … } multiplatform source sets block, or depends on com.revenuecat.purchases:purchases-kmp* → read platforms/kmp.md.
  4. Android (native): build.gradle(.kts) applies com.android.application (and is not KMP) → read platforms/android.md.
  5. iOS (native): Package.swift, *.xcodeproj, *.xcworkspace, or Podfile at the project root → read platforms/ios.md.

If several match (e.g. an ios/ folder inside a Flutter project), pick the outermost project, the one that owns the build. If still ambiguous, ask the user which platform they want to configure.

2. Shared concepts (all platforms)

  • Flow. Call getOfferings(), pick a Package from the current offering, call purchase(package). When it completes successfully, the returned customerInfo already reflects the purchase. Read customerInfo.entitlements.active["<id>"] to confirm access.
  • User cancellation is not an application error. Each SDK surfaces it differently: iOS throws a purchaseCancelledError code, Android throws a PurchasesException with PurchasesErrorCode.PurchaseCancelledError, Flutter surfaces a PlatformException with that same code, React Native sets e.userCancelled === true. Return silently in this case. Do not show an alert.
  • Errors worth messaging. Payment declined, network errors, store unavailable, receipt already in use. Everything else should be logged and let the user try again. Never silently succeed when the purchase actually failed.
  • Do not unlock content inside the purchase callback. Refresh customer info and let your entitlements listener (see revenuecat-entitlements-gate) flip the gated UI. This keeps one source of truth for access and avoids drift between the purchase path and the restore path.
  • restorePurchases() is a user action, not an automatic step. It asks the store for the current receipt and syncs it to RevenueCat. Expose it from a visible "Restore purchases" button on the paywall and/or settings screen. Legal requirements on iOS mandate such a button.
  • One purchase at a time. Disable the paywall buy buttons while a purchase is in flight to prevent double charges.

3. Implementation

Read the platform file that matches detection:

  • platforms/ios.md
  • platforms/android.md
  • platforms/kmp.md
  • platforms/flutter.md
  • platforms/react-native.md

Each platform file contains a complete purchase function and a restore function.

4. Verify

Do not claim the flow works until:

  1. A sandbox purchase of the current offering's package succeeds end to end, and the user's entitlement flips to active.
  2. Cancelling the store sheet does not show an error alert and does not leave the UI in a loading state.
  3. A second purchase attempt for the same active subscription is handled cleanly (StoreKit / Play Billing will surface a productAlreadyPurchased / receiptAlreadyInUse path; the flow should not crash).
  4. The restore button, on a fresh install signed in to the same store account, restores the entitlement and updates the UI.

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。