claude-skills/

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

last sync 22h ago
スキルOfficialdevelopment

💳revenuecat-purchase-flow

プラグイン
rc

説明

RevenueCat の購入およびリストアフローを実装します。 次のような場合に使用: - パッケージの購入処理を実装したい - サブスクリプションの購入機能を構築したい - オファリング(Offerings)を取得したい - ペイウォールの購入ロジックを構築したい - 購入エラーをハンドリングしたい - ユーザーによるキャンセルを検知したい - 以前の購入履歴をリストア(復元)したい 対応プラットフォーム: 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 コードの例外をスロー、Androidは PurchasesErrorCode.PurchaseCancelledError を持つ PurchasesException をスロー、Flutterは同じコードを持つ PlatformException を表面化、React Nativeは e.userCancelled === true をセットします。 この場合は静かに処理を返すこと。アラートは表示しないでください。

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

  • 購入コールバック内でコンテンツをアンロックしないこと。 customer infoをリフレッシュし、entitlementsリスナー(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. 現在のオファリングのパッケージをサンドボックスで購入するフローがエンドツーエンドで成功し、ユーザーのentitlementがアクティブに切り替わること。
  2. ストアシートをキャンセルしても、エラーアラートが表示されず、UIがローディング状態のままにならないこと。
  3. すでにアクティブなサブスクリプションに対する2度目の購入試行が適切に処理されること(StoreKit / Play Billingは productAlreadyPurchased / receiptAlreadyInUse のパスを表面化するため、フローがクラッシュしないこと)。
  4. 同じストアアカウントでサインインした新規インストール環境で「復元」ボタンを押すと、entitlementが復元され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 による自動翻訳です。