Skip to main content
Find the anon key with npx @insforge/cli secrets get ANON_KEY, or in the dashboard: click Install and open API Keys.

Overview

The TypeScript SDK exposes Stripe runtime helpers for generated app frontends:
  • insforge.payments.stripe.createCheckoutSession(...)
  • insforge.payments.stripe.createCustomerPortalSession(...)
Stripe secret keys, catalog management, webhook setup, and payment monitoring are admin operations. Configure them from the dashboard or CLI before using the SDK.
See Stripe Payments for setup, database tables, webhook projections, and fulfillment patterns.
The SDK methods require the current InsForge user token. Anonymous InsForge tokens can be used for guest one-time checkout, but an InsForge API key is not a substitute because the backend needs user context for local session rows.

createCheckoutSession()

Create a Stripe Checkout Session through the InsForge backend.

Parameters

Metadata keys starting with insforge_ are reserved.

Returns

One-time checkout

For anonymous one-time purchases, omit subject and pass customerEmail when available. If one-time checkout includes a subject and there is no existing Stripe customer mapping yet, InsForge lets Stripe create the customer during Checkout and backfills the subject mapping from the completion webhook.

Subscription checkout

Subscription checkout requires subject because recurring access belongs to an app-defined billing owner, such as a user, team, organization, workspace, tenant, or group.
Do not treat the success URL as proof of payment. Use verified webhook events to fulfill orders and grant subscription access.

createCustomerPortalSession()

Create a Stripe Billing Portal Session for a mapped billing subject.

Parameters

Returns

Example

Customer portal sessions require an authenticated user and an existing customer mapping for the subject. The mapping is usually created after a Checkout Session completes and Stripe returns a customer.

Authorization and RLS

The SDK methods call runtime routes using the current InsForge token. The backend inserts local session rows using the caller context:
  • payments.stripe_checkout_sessions for Checkout attempts
  • payments.stripe_customer_portal_sessions for Billing Portal attempts
If users can pass shared subjects such as teams or organizations, add an authorization boundary before exposing checkout, subscription, or customer portal UI. For example, enable RLS on the Stripe runtime tables with policies that check team membership, or call Payments through your own server endpoint that checks membership first. PostgreSQL applies SELECT policies to rows returned by INSERT ... RETURNING and to idempotent retry lookups. If an RLS error appears even though an INSERT policy exists, add a matching SELECT policy for the same billing subject and idempotency key.
Do not let users submit arbitrary subject.type and subject.id values unless your app checks that they can manage that billing subject.

Reading payment state

The Payments SDK does not expose generic end-user reads for payments.customers, payments.stripe_subscriptions, or payments.transactions. Those tables are operational records used for dashboard visibility and reporting. For user-facing billing state, create app-owned tables with RLS and populate them from provider webhook event triggers:
  • public.orders
  • public.credit_ledger
  • public.user_entitlements
  • public.team_billing_status
See Stripe Payments for fulfillment examples.

Live/test environment

Pass 'test' as the first SDK argument while developing. Only switch to 'live' after the developer explicitly approves production Stripe changes and live Prices are configured.
Never put Stripe secret keys in frontend code or public deployment environment variables. Configure Stripe keys through the InsForge dashboard or CLI.