Paysafe.ParamEncoder (Paysafe v1.0.0)

Copy Markdown View Source

Shared helpers for converting idiomatic Elixir param maps (snake_case atom keys) into the camelCase JSON shape the Paysafe API expects, with nil values stripped recursively.

Used internally by every API module. Not typically called directly, but public so that custom extensions can reuse the same conventions.

Summary

Functions

Convert a single snake_case atom or string key to a camelCase string.

Recursively convert snake_case atom (or string) keys to camelCase string keys.

Recursively strip nil values from maps and lists, leaving the rest intact.

Convenience: camelize keys then strip nils in one pass.

Camelize keys of a keyword list (used for query string params).

Functions

camelize(key)

@spec camelize(atom() | String.t()) :: String.t()

Convert a single snake_case atom or string key to a camelCase string.

Examples

iex> Paysafe.ParamEncoder.camelize(:merchant_ref_num)
"merchantRefNum"

camelize_keys(map)

@spec camelize_keys(term()) :: term()

Recursively convert snake_case atom (or string) keys to camelCase string keys.

Examples

iex> Paysafe.ParamEncoder.camelize_keys(%{card_expiry: %{month: 12, year: 2030}})
%{"cardExpiry" => %{"month" => 12, "year" => 2030}}

deep_clean(map)

@spec deep_clean(term()) :: term()

Recursively strip nil values from maps and lists, leaving the rest intact.

Examples

iex> Paysafe.ParamEncoder.deep_clean(%{"a" => 1, "b" => nil})
%{"a" => 1}

encode(params)

@spec encode(map()) :: map()

Convenience: camelize keys then strip nils in one pass.

This is the function nearly every API module calls before sending a request body to Paysafe.Client.

encode_query(opts)

@spec encode_query(keyword()) :: String.t()

Camelize keys of a keyword list (used for query string params).