Accrue.Checkout.Session (accrue v1.0.0)

Copy Markdown View Source

Stripe Checkout Session wrapper.

Wraps the processor-level checkout_session_create/2 and checkout_session_fetch/2 callbacks, projects the raw Stripe payload into a tightly-typed struct, and masks the embedded-mode :client_secret field in Inspect output — anyone holding a client_secret can mount the embedded checkout flow on the customer's behalf until the session expires.

Two ui_mode values are supported:

  • :hosted (default) — Stripe-hosted Checkout page; the returned %Session{} has a :url to redirect the customer to.
  • :embedded — the host app mounts Stripe.js's embedded form; the returned %Session{} has a :client_secret to hand to the front end.

The :mode option mirrors the Stripe Checkout mode parameter: :subscription (default), :payment, or :setup.

Summary

Functions

Creates a Checkout Session through the configured processor.

Bang variant of create/1. Raises Accrue.APIError (or a generic RuntimeError) on failure.

Retrieves a Checkout Session by id.

Types

t()

@type t() :: %Accrue.Checkout.Session{
  amount_tax: term(),
  amount_total: term(),
  automatic_tax: term(),
  client_secret: term(),
  currency: term(),
  customer: term(),
  data: term(),
  expires_at: term(),
  id: term(),
  metadata: term(),
  mode: term(),
  object: term(),
  payment_intent: term(),
  payment_status: term(),
  status: term(),
  subscription: term(),
  ui_mode: term(),
  url: term()
}

Functions

create(params)

@spec create(map() | keyword()) :: {:ok, t()} | {:error, term()}

Creates a Checkout Session through the configured processor.

See module docs for accepted options. Returns {:ok, %Session{}} on success.

create!(params)

@spec create!(map() | keyword()) :: t()

Bang variant of create/1. Raises Accrue.APIError (or a generic RuntimeError) on failure.

retrieve(id)

@spec retrieve(String.t()) :: {:ok, t()} | {:error, term()}

Retrieves a Checkout Session by id.