RevenueCat(サブスクリプション管理ツール)の購入・復元フローを実装します。 次のような場合に使用: - ユーザーがパッケージやサブスクリプションの購入をリクエストした - オファリング(利用可能な商品情報)を取得する必要がある - ペイウォール(購入画面)の購入ロジックを構築する - 購入エラーを処理する必要がある - ユーザーによるキャンセルを検知する - 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 の呼び出し、キャンセル・エラーの処理、および「復元」アクションの公開。
ペイウォールUIのレンダリング(revenuecat-paywall が担当)や機能のゲーティング(revenuecat-entitlements-gate が担当)はこのスキルの対象外です。
作業ディレクトリを調べ、上から順に最初に一致したものを採用してください:
package.json に react-native-purchases のエントリがある、または react-native が依存関係に含まれている → platforms/react-native.md を読む。expo も依存関係にある場合は、Expoプロジェクトとして記録する。pubspec.yaml が存在する → platforms/flutter.md を読む。build.gradle.kts に kotlin { … } のマルチプラットフォームソースセットブロックが含まれている、または com.revenuecat.purchases:purchases-kmp* に依存している → platforms/kmp.md を読む。build.gradle(.kts) が com.android.application を適用している(かつKMPでない) → platforms/android.md を読む。Package.swift、*.xcodeproj、*.xcworkspace、または Podfile が存在する → platforms/ios.md を読む。複数一致する場合(例: Flutterプロジェクト内に ios/ フォルダがある場合など)は、ビルドを所有する最外層のプロジェクトを選択してください。
それでも判断できない場合は、どのプラットフォームを設定したいかユーザーに確認してください。
フロー。
getOfferings() を呼び出し、現在のオファリングから Package を選択し、purchase(package) を呼び出します。
正常に完了すると、返された customerInfo にはすでに購入内容が反映されています。
customerInfo.entitlements.active["<id>"] を読み取ってアクセス権を確認してください。
ユーザーによるキャンセルはアプリケーションエラーではありません。
SDKによって表面化の方法が異なります:
iOSは purchaseCancelledError コードの例外をスロー、Androidは PurchasesErrorCode.PurchaseCancelledError を持つ PurchasesException をスロー、Flutterは同じコードを持つ PlatformException を表面化、React Nativeは e.userCancelled === true をセットします。
この場合は静かに処理を返すこと。アラートは表示しないでください。
メッセージ表示が必要なエラー。 支払い拒否、ネットワークエラー、ストア利用不可、レシートの重複使用など。 それ以外はログに記録してユーザーに再試行させてください。 購入が実際に失敗したのに成功したように見せることは絶対に避けてください。
購入コールバック内でコンテンツをアンロックしないこと。
customer infoをリフレッシュし、entitlementsリスナー(revenuecat-entitlements-gate 参照)にゲーティングされたUIの切り替えを任せてください。
これによりアクセス権の単一の真実の源が維持され、購入パスと復元パスの間のズレを防げます。
restorePurchases() はユーザーアクションであり、自動ステップではありません。
ストアに現在のレシートを問い合わせ、RevenueCatに同期します。
ペイウォールおよび/または設定画面に目立つ「購入を復元」ボタンとして配置してください。
iOSでは法的要件としてこのボタンの設置が義務付けられています。
同時購入は1件まで。 二重課金を防ぐため、購入処理中はペイウォールの購入ボタンを無効化してください。
検出結果に対応するプラットフォームファイルを読んでください:
platforms/ios.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.md各プラットフォームファイルには、購入関数と復元関数の完全な実装が含まれています。
以下がすべて確認できるまで、フローが機能していると宣言しないでください:
productAlreadyPurchased / receiptAlreadyInUse のパスを表面化するため、フローがクラッシュしないこと)。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).
Inspect the working directory and pick the first match, from top to bottom:
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.pubspec.yaml exists at the project root → read platforms/flutter.md.build.gradle.kts contains a kotlin { … } multiplatform source sets block, or depends on com.revenuecat.purchases:purchases-kmp* → read platforms/kmp.md.build.gradle(.kts) applies com.android.application (and is not KMP) → read platforms/android.md.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.
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.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.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.Read the platform file that matches detection:
platforms/ios.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.mdEach platform file contains a complete purchase function and a restore function.
Do not claim the flow works until:
productAlreadyPurchased / receiptAlreadyInUse path; the flow should not crash).原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。