AshBilling.Provider behaviour (ash_billing v0.1.1)

Copy Markdown View Source

Defines the behavior for billing providers (Stripe, Paddle, LemonSqueezy, etc.).

Summary

Callbacks

Cancels a subscription in the billing provider.

Creates a checkout session for subscriptions or one-time payments.

Creates a customer in the billing provider.

Creates a billing portal session where customers can manage their payment methods and subscriptions.

Retrieves a subscription from the billing provider.

Resumes a subscription that was scheduled to cancel at period end.

Swaps an active subscription to a new price/plan, with optional proration behavior.

Verifies an incoming webhook payload and signature. Returns {:ok, event_map} if valid, or {:error, reason} if invalid.

Types

customer_id()

@type customer_id() :: String.t()

opts()

@type opts() :: keyword()

session_id()

@type session_id() :: String.t()

session_url()

@type session_url() :: String.t()

subscription_id()

@type subscription_id() :: String.t()

Callbacks

cancel_subscription(subscription_id, opts)

@callback cancel_subscription(subscription_id(), opts :: opts()) ::
  {:ok, map()} | {:error, term()}

Cancels a subscription in the billing provider.

create_checkout_session(params, opts)

@callback create_checkout_session(params :: map(), opts :: opts()) ::
  {:ok, %{url: session_url(), id: session_id()}} | {:error, term()}

Creates a checkout session for subscriptions or one-time payments.

create_customer(params, opts)

@callback create_customer(params :: map(), opts :: opts()) ::
  {:ok, customer_id()} | {:error, term()}

Creates a customer in the billing provider.

create_portal_session(params, opts)

@callback create_portal_session(params :: map(), opts :: opts()) ::
  {:ok, %{url: session_url()}} | {:error, term()}

Creates a billing portal session where customers can manage their payment methods and subscriptions.

get_subscription(subscription_id, opts)

@callback get_subscription(subscription_id(), opts :: opts()) ::
  {:ok, map()} | {:error, term()}

Retrieves a subscription from the billing provider.

resume_subscription(subscription_id, opts)

@callback resume_subscription(subscription_id(), opts :: opts()) ::
  {:ok, map()} | {:error, term()}

Resumes a subscription that was scheduled to cancel at period end.

swap_plan(subscription_id, new_price_id, opts)

@callback swap_plan(subscription_id(), new_price_id :: String.t(), opts :: opts()) ::
  {:ok, map()} | {:error, term()}

Swaps an active subscription to a new price/plan, with optional proration behavior.

verify_webhook(payload, signature_header, secret, opts)

@callback verify_webhook(
  payload :: binary(),
  signature_header :: String.t() | nil,
  secret :: String.t(),
  opts :: opts()
) :: {:ok, map()} | {:error, term()}

Verifies an incoming webhook payload and signature. Returns {:ok, event_map} if valid, or {:error, reason} if invalid.