Charge intent request schema — the "Intent = Schema" half of MPP.
Defines the shared payment request structure used by all payment methods. A charge intent specifies what needs to be paid (amount, currency) and optional metadata (recipient, description, external ID).
The struct uses Elixir snake_case conventions internally. Use to_request/1
and from_request/1 to convert to/from the spec's camelCase JSON format.
Fields
amount— (required) string in base units (cents for fiat, wei for ETH). Never a float.currency— (required) lowercase string (ISO 4217 for fiat, token address for on-chain)recipient— (optional) payment recipient identifierdescription— (optional) human-readable descriptionexternal_id— (optional) caller-provided correlation IDmethod_details— (optional) method-specific fields (e.g., Stripe'snetworkId)
API Functions
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
from_request | 1 | Deserialize a camelCase JSON map back into a charge intent struct. | map: value |
to_request | 1 | Serialize the charge intent to a JSON-compatible map with camelCase keys per spec. | charge: value |
new | 1 | Create a new charge intent with validation. Amount must be a string, currency is normalized to lowercase. | opts: value |
Summary
Functions
Deserialize a camelCase JSON map back into a charge intent struct.
Create a new charge intent with validation. Amount must be a string, currency is normalized to lowercase.
Serialize the charge intent to a JSON-compatible map with camelCase keys per spec.
Types
Functions
@spec from_request(map()) :: {:ok, t()} | {:error, atom()}
@spec from_request(term()) :: {:error, :missing_required_fields}
Deserialize a camelCase JSON map back into a charge intent struct.
Parameters
map- Map with camelCase string keys (from JSON-decoded challenge request) (value)
Returns
{:ok, charge} on success, {:error, reason} on failure (tagged_tuple)
Errors
:amount_required:invalid_amount:currency_required:invalid_currency:missing_required_fields
Composes With
newto_request
# descripex:contract
%{
params: %{
map: %{
description: "Map with camelCase string keys (from JSON-decoded challenge request)",
kind: :value
}
},
errors: [:amount_required, :invalid_amount, :currency_required,
:invalid_currency, :missing_required_fields],
returns: %{
type: :tagged_tuple,
description: "`{:ok, charge}` on success, `{:error, reason}` on failure"
},
composes_with: [:new, :to_request]
}
Create a new charge intent with validation. Amount must be a string, currency is normalized to lowercase.
Parameters
opts- Keyword list with:amount(required string),:currency(required string),:recipient,:description,:external_id,:method_details(all optional) (value)
Returns
{:ok, charge} on success, {:error, reason} on failure (tagged_tuple)
Errors
:amount_required:invalid_amount:currency_required:invalid_currency
Composes With
to_request
# descripex:contract
%{
params: %{
opts: %{
description: "Keyword list with `:amount` (required string), `:currency` (required string), `:recipient`, `:description`, `:external_id`, `:method_details` (all optional)",
kind: :value
}
},
errors: [:amount_required, :invalid_amount, :currency_required,
:invalid_currency],
returns: %{
type: :tagged_tuple,
description: "`{:ok, charge}` on success, `{:error, reason}` on failure"
},
composes_with: [:to_request]
}
Serialize the charge intent to a JSON-compatible map with camelCase keys per spec.
Parameters
charge- Charge struct to serialize (value)
Returns
Map with camelCase string keys for JSON encoding into challenge request (map)
Composes With
newfrom_request
# descripex:contract
%{
params: %{charge: %{description: "Charge struct to serialize", kind: :value}},
returns: %{
type: :map,
description: "Map with camelCase string keys for JSON encoding into challenge `request`"
},
composes_with: [:new, :from_request]
}