{"canonical_url":"https://engineer.company/ja/portfolio/built-stripe-and-in-app-purchase-entitlements/","content_markdown":"# Stripe・アプリ内購入の利用権限を構築\n\nStripeとApple・Googleのアプリ内購入に対応する決済・利用権限層を構築し、サーバーで検証する11テーブルのアクセスモデルによって、一覧、検索、エクスポートの利用を制御した。\n\n2025\n\n**状況.** 金銭は軽く扱えない。定期購入はカード期限切れ、返金、プラン変更、重複・順不同のWebhookに耐える必要があった。Webのカード決済とApple・Googleのアプリストアという3経路では、購入内容の記録も3通りになるが、製品には「今この人は何ができるか」という1つの答えが必要だった。\n\n**課題.** 購入経路を増やしても製品の全権限制御を書き直さずに済むよう、支払いの受け取りと権限付与を別システムにする必要があった。\n\n**行動.** 18個のGoファイルでStripeのカード・定期購入を扱い、Apple・Googleは各々の領収書検証を通す。3つを9テーブル・34関数のpaymentsスキーマへ集め、そこで止めた。製品は別の11テーブル・34関数のaccessスキーマへ問い合わせ、どこで払ったかを知らずに「このアカウントがこれをできるか」を答える。この答えで企業一覧、検索、データ出力を制御し、毎回サーバーで再検証する。ボタンを隠すのは配慮であって、制御ではないためだった。\n\n**結果.** 新しい購入経路は決済側だけに追加でき、権限制御は変えずに済む。アクセスに関する問い合わせは3つでなく1つのテーブルを見ればよい。小規模製品なら1つにしたい場所に2スキーマを持ち、従来不要だった権限検索をリクエストで行うことが代償となった。\n\n---\n\n- 役割: バックエンドエンジニア\n- カテゴリー: [バックエンド開発](https://data.engineer.company/ja/categories/backend/), [API・システム連携](https://data.engineer.company/ja/categories/api/), [データベース](https://data.engineer.company/ja/categories/databases/), [PostgreSQL](https://data.engineer.company/ja/categories/postgresql/), [セキュリティ](https://data.engineer.company/ja/categories/security/), [プロダクト・要件](https://data.engineer.company/ja/categories/product/)\n- サービス: [バックエンド・API開発](https://data.engineer.company/ja/services/backend-development/), [データベース設計・モデリング](https://data.engineer.company/ja/services/database-design/), [セキュリティ・アクセス管理](https://data.engineer.company/ja/services/security-access/), [プロダクト戦略・要件定義](https://data.engineer.company/ja/services/product-strategy/)\n\n\u003chttps://engineer.company/ja/portfolio/built-stripe-and-in-app-purchase-entitlements/\u003e\n","date_modified":"2026-11-09T21:50:25Z","description":"StripeとApple・Googleのアプリ内購入に対応する決済・利用権限層を構築し、アクセスモデルで一覧、検索、エクスポートを制御した。","formats":{"gemtext":"https://data.engineer.company/ja/portfolio/built-stripe-and-in-app-purchase-entitlements/index.gmi","gopher":"https://data.engineer.company/ja/portfolio/built-stripe-and-in-app-purchase-entitlements/gophermap","html":"https://data.engineer.company/ja/portfolio/built-stripe-and-in-app-purchase-entitlements/","json":"https://data.engineer.company/ja/portfolio/built-stripe-and-in-app-purchase-entitlements/index.json","markdown":"https://data.engineer.company/ja/portfolio/built-stripe-and-in-app-purchase-entitlements/index.md","pdf":"https://data.engineer.company/ja/portfolio/built-stripe-and-in-app-purchase-entitlements/index.pdf"},"kind":"page","language":"ja","title":"Stripe・アプリ内購入の利用権限を構築","url":"https://data.engineer.company/ja/portfolio/built-stripe-and-in-app-purchase-entitlements/","version":1}