🛒revenuecat-purchase-flow
- プラグイン
- revenuecat
- ソース
- GitHub で見る ↗
説明
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. プラットフォームの検出
作業ディレクトリを調べ、上から順に最初に一致したものを選択します:
- React Native:
package.jsonにreact-native-purchasesエントリがある、またはreact-nativeが依存関係に含まれている →platforms/react-native.mdを読む。expoも依存関係にある場合は、Expoプロジェクトとして記録する。 - Flutter: プロジェクトルートに
pubspec.yamlが存在する →platforms/flutter.mdを読む。 - Kotlin Multiplatform:
build.gradle.ktsにkotlin { … }のマルチプラットフォームソースセットブロックが含まれている、またはcom.revenuecat.purchases:purchases-kmp*に依存している →platforms/kmp.mdを読む。 - Android(ネイティブ):
build.gradle(.kts)がcom.android.applicationを適用している(かつKMPでない) →platforms/android.mdを読む。 - 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.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.md
各プラットフォームファイルには、完全な購入関数と復元関数が含まれています。
4. 動作確認
以下がすべて満たされるまで、フローが正常に動作すると宣言しないでください:
- 現在のオファリングのパッケージのサンドボックス購入がエンドツーエンドで成功し、ユーザーのエンタイトルメントがアクティブに切り替わること。
- ストアシートをキャンセルしてもエラーアラートが表示されず、UIがローディング状態のまま残らないこと。
- すでにアクティブなサブスクリプションに対する2回目の購入試行が適切に処理されること(StoreKit / Play Billingは
productAlreadyPurchased/receiptAlreadyInUseのパスをsurfaceするため、フローがクラッシュしないこと)。 - 同じストアアカウントでサインインした状態でのフレッシュインストールにおいて、復元ボタンによってエンタイトルメントが復元され、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:
- React Native:
package.jsonhas areact-native-purchasesentry, orreact-nativeas a dependency → readplatforms/react-native.md. Ifexpois also a dependency, note it as an Expo project. - Flutter:
pubspec.yamlexists at the project root → readplatforms/flutter.md. - Kotlin Multiplatform:
build.gradle.ktscontains akotlin { … }multiplatform source sets block, or depends oncom.revenuecat.purchases:purchases-kmp*→ readplatforms/kmp.md. - Android (native):
build.gradle(.kts)appliescom.android.application(and is not KMP) → readplatforms/android.md. - iOS (native):
Package.swift,*.xcodeproj,*.xcworkspace, orPodfileat the project root → readplatforms/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 aPackagefrom the current offering, callpurchase(package). When it completes successfully, the returnedcustomerInfoalready reflects the purchase. ReadcustomerInfo.entitlements.active["<id>"]to confirm access. - User cancellation is not an application error. Each SDK surfaces it differently: iOS throws a
purchaseCancelledErrorcode, Android throws aPurchasesExceptionwithPurchasesErrorCode.PurchaseCancelledError, Flutter surfaces aPlatformExceptionwith that same code, React Native setse.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.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.md
Each platform file contains a complete purchase function and a restore function.
4. Verify
Do not claim the flow works until:
- A sandbox purchase of the current offering's package succeeds end to end, and the user's entitlement flips to active.
- Cancelling the store sheet does not show an error alert and does not leave the UI in a loading state.
- A second purchase attempt for the same active subscription is handled cleanly (StoreKit / Play Billing will surface a
productAlreadyPurchased/receiptAlreadyInUsepath; the flow should not crash). - The restore button, on a fresh install signed in to the same store account, restores the entitlement and updates the UI.
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。