Wraith.Billing behaviour (Wraith v0.1.0)

View Source

Paid memberships through Stripe Checkout, with Req against the Stripe API (no SDK). Settings hold stripe_secret_key, stripe_webhook_secret and stripe_price_id (a recurring price); configured?/0 is false until all three are set, and then:

  • checkout_url/3 — a Checkout Session in subscription mode for the member (the Stripe customer is created on first use and remembered)
  • handle_webhook/2 — verifies Stripe-Signature (HMAC-SHA256, 5 min tolerance) and syncs the member: checkout.session.completed and customer.subscription.updated (active/trialing) → paid; customer.subscription.deleted / unpaid → free

Billing.API (internal) is the HTTP seam (swapped for a fake in tests).

Summary

Functions

Where to send a member to pay.

Verify and apply a webhook. Returns {:ok, event_type} | {:error, reason}.

A Stripe customer-portal session: the member manages card and subscription there.

Build a signed header the way Stripe does (tests, and the docs' sanity check).

Callbacks

post(t, map, t)

@callback post(String.t(), map(), String.t()) :: {:ok, map()} | {:error, term()}

Functions

api()

checkout_url(member, success_url, cancel_url)

Where to send a member to pay.

configured?()

handle_webhook(raw_body, signature_header)

Verify and apply a webhook. Returns {:ok, event_type} | {:error, reason}.

portal_url(arg1, return_url)

A Stripe customer-portal session: the member manages card and subscription there.

sign_for_test(body, secret, ts \\ System.system_time(:second))

Build a signed header the way Stripe does (tests, and the docs' sanity check).

verify_signature(body, header, secret)