npx @insforge/cli secrets get ANON_KEY, or in the dashboard: click Install and open API Keys.
概述
TypeScript SDK 為產生的應用前端公開 Stripe 執行時助手:insforge.payments.stripe.createCheckoutSession(...)insforge.payments.stripe.createCustomerPortalSession(...)
有關設定、資料庫表、webhook 投影和履行模式,請參見 Stripe 支付。
createCheckoutSession()
透過 InsForge 後端建立 Stripe Checkout 工作階段。參數
傳回
一次性結帳
subject 並在可用時傳遞 customerEmail。
如果一次性結帳包含 subject 且還沒有現有的 Stripe 客戶對應,InsForge 讓 Stripe 在 Checkout 期間建立客戶,並從完成 webhook 回填主體對應。
訂閱結帳
subject,因為定期存取屬於應用定義的計費擁有者,如使用者、團隊、組織、工作區、租戶或群組。
createCustomerPortalSession()
為對應的計費主體建立 Stripe 帳單入口工作階段。參數
傳回
範例
授權和 RLS
SDK 方法使用目前 InsForge 令牌呼叫執行時路由。後端使用呼叫者內容插入本機工作階段列:payments.stripe_checkout_sessions用於 Checkout 嘗試payments.stripe_customer_portal_sessions用於帳單入口嘗試
SELECT 原則套用於 INSERT ... RETURNING 傳回的列和冪等重試查閱。如果即使存在 INSERT 原則也出現 RLS 錯誤,請為同一計費主體和冪等密鑰新增相符的 SELECT 原則。
讀取付款狀態
支付 SDK 不為payments.customers、payments.stripe_subscriptions 或 payments.transactions 公開通用的終端使用者讀取。這些表是用於儀表板可見性和報告的操作記錄。
對於面向使用者的計費狀態,建立帶有 RLS 的應用擁有的表,並從提供商 webhook 事件觸發器填入它們:
public.orderspublic.credit_ledgerpublic.user_entitlementspublic.team_billing_status
生產/測試環境
在開發時將'test' 作為第一個 SDK 引數傳遞。僅在開發者明確核准生產 Stripe 變更並設定了生產價格後才切換到 'live'。