Accrue.Billing.SubscriptionProjection (accrue v1.0.0)

Copy Markdown View Source

Translates a Stripe subscription API response into local Ecto changesets.

A "projection" in Accrue means decomposing a Stripe API response into a flat attrs map that Accrue.Billing.Subscription.changeset/2 accepts. This module handles the type coercions (Unix timestamps → DateTime, status strings → atoms, nested discount objects → a plain id string) and normalizes the data jsonb to string-keyed maps for round-trip safety.

Handles both the atom-keyed shape produced by Accrue.Processor.Fake and the string-keyed shape produced by Accrue.Processor.Stripe (after Map.from_struct/1).

Summary

Functions

Recursively converts atom-keyed maps to string-keyed maps and DateTimes to ISO8601 strings so the result is jsonb round-trip safe.

Functions

decompose(stripe_sub)

@spec decompose(map()) :: {:ok, map()}

to_string_keys(dt)

@spec to_string_keys(term()) :: term()

Recursively converts atom-keyed maps to string-keyed maps and DateTimes to ISO8601 strings so the result is jsonb round-trip safe.

Public so Accrue.Billing.InvoiceProjection can reuse the same normalization rather than storing atom-keyed data and getting shape drift on reload.