Accrue.Billing.IntentResult (accrue v1.0.0)

Copy Markdown View Source

Wraps Stripe intent-capable responses into the intent_result tagged union (D3-06..D3-08).

Every Phase 3 write path that may surface a PaymentIntent (SCA/3DS) runs its processor result through wrap/1. The result is one of:

  • {:ok, struct_or_map} — happy path
  • {:ok, :requires_action, pi_map} — customer action required
  • {:error, exception} — anything else

The wrapper inspects either:

  • A Stripe subscription with an expanded latest_invoice.payment_intent whose status is "requires_action"
  • A direct PaymentIntent / SetupIntent response whose status is "requires_action" / "requires_confirmation" / "requires_payment_method"

Fake adapter returns atom-keyed maps; the Stripe adapter returns string-keyed maps after Map.from_struct/1. The wrapper handles both key shapes.

Summary

Functions

Wrap a processor or Repo.transact result into the tagged intent_result.

Types

ok_value()

@type ok_value() :: map() | struct()

t()

@type t() ::
  {:ok, ok_value()} | {:ok, :requires_action, map()} | {:error, Exception.t()}

Functions

wrap(err)

@spec wrap(term()) :: t()

Wrap a processor or Repo.transact result into the tagged intent_result.

Pass-through for errors. Leaves {:ok, %Subscription{}} and other Ecto structs alone unless they carry an embedded requires_action payment intent in their data column.