Sumup.Money.Float (Sumup v1.0.0)

Copy Markdown View Source

Money as represented by SumUp's legacy resources (Checkouts, Customers' payment instruments, Transactions, Payouts): a decimal major-unit float plus an ISO 4217 currency code, e.g. %{"amount" => 10.5, "currency" => "EUR"}.

This shape predates SumUp's Sumup.Money.MinorUnit representation used by Readers. It is kept as its own type rather than being coerced into minor units automatically, because floating point major-unit amounts cannot be losslessly converted for all currencies without knowing the currency's exponent (SumUp's API itself does not send that exponent on these legacy endpoints). Use to_minor_units/1 when you know the currency's exponent and need exact integer cents for further arithmetic.

Summary

Functions

Builds a t/0 from a decoded JSON map using the given amount/currency keys.

Converts to integer minor units (e.g. cents) given the currency's decimal exponent (2 for EUR/USD/GBP, 0 for JPY/CLP/COP/HUF, etc).

Encodes back into the wire shape expected by legacy endpoints.

Types

t()

@type t() :: %Sumup.Money.Float{amount: float(), currency: String.t()}

Functions

from_map(map, amount_key \\ "amount", currency_key \\ "currency")

@spec from_map(map(), atom() | String.t(), atom() | String.t()) :: t() | nil

Builds a t/0 from a decoded JSON map using the given amount/currency keys.

to_minor_units(float, exponent)

@spec to_minor_units(t(), non_neg_integer()) :: integer()

Converts to integer minor units (e.g. cents) given the currency's decimal exponent (2 for EUR/USD/GBP, 0 for JPY/CLP/COP/HUF, etc).

Rounds half-away-from-zero to avoid systematic bias.

to_params(float)

@spec to_params(t()) :: map()

Encodes back into the wire shape expected by legacy endpoints.