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 コードをthrow、AndroidはPurchasesErrorCode.PurchaseCancelledErrorを持つPurchasesExceptionをthrow、Flutterは同じコードを持つPlatformExceptionをsurface、React Nativeはe.userCancelled === true` をセットします。この場合はアラートを表示せず、静かに処理を終了してください。
メッセージを表示すべきエラー。 支払いの拒否、ネットワークエラー、ストアの利用不可、レシートの重複使用などが該当します。それ以外はログに記録し、ユーザーが再試行できるようにしてください。購入が実際に失敗したにもかかわらず、成功したように見せることは絶対に避けてください。
購入コールバックの中でコンテンツをアンロックしないでください。
customerInfoを更新し、エンタイトルメントリスナー(revenuecat-entitlements-gate 参照)にゲーティングされたUIの切り替えを任せてください。これにより、アクセス権の唯一の情報源が維持され、購入フローと復元フローの間で状態がずれるのを防げます。
restorePurchases() はユーザーアクションであり、自動的なステップではありません。
ストアに現在のレシートを問い合わせ、RevenueCatと同期します。ペイウォールや設定画面に目立つ「購入を復元」ボタンを配置してください。iOSではこのボタンの設置が法的要件となっています。
購入は同時に1件まで。 購入処理中はペイウォールの購入ボタンを無効化し、二重請求を防いでください。
検出結果に対応するプラットフォームファイルを読んでください:
platforms/ios.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.md各プラットフォームファイルには、完全な購入関数と復元関数が含まれています。
以下がすべて満たされるまで、フローが正常に動作すると宣言しないでください:
productAlreadyPurchased / receiptAlreadyInUse のパスをsurfaceするため、フローがクラッシュしないこと)。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 による自動翻訳です。