Column.Params (Column v1.0.0)

Copy Markdown View Source

Parameter building and validation helpers.

Provides a lightweight, chainable API for constructing validated request parameter maps before sending them to Column resource modules.

Example

import Column.Params

params =
  new()
  |> put_required(:bank_account_id, "bacc_123")
  |> put_required(:counterparty_id, "cpty_456")
  |> put_required(:amount, 10_000)
  |> put_required(:currency_code, "USD")
  |> put_required(:type, "CREDIT")
  |> put_optional(:entry_class_code, "PPD")
  |> put_optional(:effective_date, nil)   # nil values are omitted
  |> validate_amount(:amount)
  |> build!()

Column.ACH.create(params)

Summary

Functions

Build the params map, returning {:ok, map()} or {:error, Column.Error.t()}.

Build the params map, raising Column.Error if there are validation errors.

Merge a map of optional fields, omitting nil values.

Start a new params builder.

Add an optional field. Nil values are silently omitted.

Add a required field. Adds a validation error if value is nil or empty string.

Add a field only when the condition is true.

Validate that an amount field is a positive integer (cents).

Validate that a currency_code field is a 3-letter ISO 4217 code.

Validate that a field matches one of the allowed values.

Types

t()

@type t() :: %{params: map(), errors: [String.t()]}

Functions

build(map)

@spec build(t()) :: {:ok, map()} | {:error, Column.Error.t()}

Build the params map, returning {:ok, map()} or {:error, Column.Error.t()}.

build!(map)

@spec build!(t()) :: map()

Build the params map, raising Column.Error if there are validation errors.

Returns the raw map() suitable for passing to Column resource functions.

merge_optional(acc, extra)

@spec merge_optional(t(), map()) :: t()

Merge a map of optional fields, omitting nil values.

new()

@spec new() :: %{params: %{}, errors: []}

Start a new params builder.

put_optional(acc, key, value)

@spec put_optional(t(), atom() | String.t(), any()) :: t()

Add an optional field. Nil values are silently omitted.

put_required(acc, key, value)

@spec put_required(t(), atom() | String.t(), any()) :: t()

Add a required field. Adds a validation error if value is nil or empty string.

put_when(acc, key, value, bool)

@spec put_when(t(), atom() | String.t(), any(), boolean()) :: t()

Add a field only when the condition is true.

validate_amount(acc, key)

@spec validate_amount(t(), atom() | String.t()) :: t()

Validate that an amount field is a positive integer (cents).

validate_currency(acc, key)

@spec validate_currency(t(), atom() | String.t()) :: t()

Validate that a currency_code field is a 3-letter ISO 4217 code.

validate_inclusion(acc, key, allowed)

@spec validate_inclusion(t(), atom() | String.t(), [any()]) :: t()

Validate that a field matches one of the allowed values.