livery_stripe_form (livery_stripe v0.1.0)

View Source

Encode parameters as application/x-www-form-urlencoded, the body format Stripe expects, including its bracketed nesting for maps and lists.

The encoding mirrors Stripe's own client libraries:

  • a map #{K => V} becomes parent[K]=... (one pair per key, keys sorted for deterministic output),
  • a list of maps becomes parent[0][k]=...&parent[1][k]=...,
  • a list of scalars becomes parent[]=a&parent[]=b,
  • scalars are coerced: integers, floats, booleans, and atoms render to their textual form; strings must be binaries.

Reserved characters are percent-encoded and spaces become +, matching quote_plus semantics, so brackets render as %5B/%5D (Stripe decodes both forms).

<<"line_items%5B0%5D%5Bprice%5D=price_1&line_items%5B0%5D%5Bquantity%5D=1">> =
    livery_stripe_form:encode([{<<"line_items">>,
        [#{<<"price">> => <<"price_1">>, <<"quantity">> => 1}]}]).

Summary

Functions

Encode an ordered proplist (or a map) of parameters into a form body.

Types

key()

-type key() :: binary() | atom() | integer() | string().

value()

-type value() :: binary() | integer() | float() | boolean() | atom() | map() | list().

Functions

encode(Params)

-spec encode([{key(), value()}] | map()) -> binary().

Encode an ordered proplist (or a map) of parameters into a form body.