inttegro.money

Currency and amount primitives for the Inttegro API.

 1"""Currency and amount primitives for the Inttegro API."""
 2
 3from dataclasses import dataclass, field
 4
 5from ._model_base import ApiModel
 6from ._request_base import ApiRequest
 7from ._enum_base import WireEnum
 8
 9
10class Currency(WireEnum):
11    """ISO-style currency identifiers accepted by Inttegro.
12
13    Currency members are strings and serialize to lowercase API wire values.
14    Input is case-insensitive, so ``Currency("GHS")`` resolves to
15    :attr:`Currency.GHS`, while serialized requests always contain ``"ghs"``.
16    """
17
18    GHS = "ghs"
19    """Ghanaian cedi. Wire value: ``ghs``."""
20    USD = "usd"
21    """United States dollar. Wire value: ``usd``."""
22    GBP = "gbp"
23    """British pound sterling. Wire value: ``gbp``."""
24    EUR = "eur"
25    """Euro. Wire value: ``eur``."""
26    CNY = "cny"
27    """Chinese yuan renminbi. Wire value: ``cny``."""
28
29    @classmethod
30    def _missing_(cls, value: object) -> "Currency | None":
31        if isinstance(value, str):
32            normalized = value.strip().lower()
33            for currency in cls:
34                if currency.value == normalized:
35                    return currency
36        return None
37
38
39@dataclass(frozen=True, slots=True, kw_only=True)
40class AmountParams(ApiRequest):
41    """A monetary amount supplied in an API request.
42
43    ``value`` is always an integer in the currency's minor unit. For example,
44    ``AmountParams(currency=Currency.GHS, value=5000)`` represents GHS 50.00.
45    ``to_dict()`` serializes this value as
46    ``{"currency": "ghs", "value": 5000}``.
47    """
48
49    currency: Currency
50    """Required currency. Python type: :class:`Currency`; wire name: ``currency``; JSON type: string."""
51    value: int
52    """Required integer minor-unit amount. Python type: ``int``; wire name: ``value``; JSON type: integer."""
53
54
55@dataclass(frozen=True, slots=True, init=False, repr=False, eq=False)
56class Amount(ApiModel):
57    """A monetary amount returned by the API.
58
59    ``from_dict()`` converts the lowercase wire currency to :class:`Currency`.
60    ``value`` remains an integer in that currency's minor unit, which avoids
61    binary floating-point rounding in financial calculations.
62    """
63
64    currency: Currency = field(init=False)
65    """Required currency. Python type: :class:`Currency`; wire name: ``currency``; JSON type: string."""
66    value: int = field(init=False)
67    """Required integer minor-unit amount. Python type: ``int``; wire name: ``value``; JSON type: integer."""
68
69
70__all__ = ["Amount", "AmountParams", "Currency"]
@dataclass(frozen=True, slots=True, init=False, repr=False, eq=False)
class Amount(inttegro._model_base.ApiModel):
56@dataclass(frozen=True, slots=True, init=False, repr=False, eq=False)
57class Amount(ApiModel):
58    """A monetary amount returned by the API.
59
60    ``from_dict()`` converts the lowercase wire currency to :class:`Currency`.
61    ``value`` remains an integer in that currency's minor unit, which avoids
62    binary floating-point rounding in financial calculations.
63    """
64
65    currency: Currency = field(init=False)
66    """Required currency. Python type: :class:`Currency`; wire name: ``currency``; JSON type: string."""
67    value: int = field(init=False)
68    """Required integer minor-unit amount. Python type: ``int``; wire name: ``value``; JSON type: integer."""

A monetary amount returned by the API.

from_dict() converts the lowercase wire currency to Currency. value remains an integer in that currency's minor unit, which avoids binary floating-point rounding in financial calculations.

currency: Currency

Required currency. Python type: Currency; wire name: currency; JSON type: string.

value: int

Required integer minor-unit amount. Python type: int; wire name: value; JSON type: integer.

@dataclass(frozen=True, slots=True, kw_only=True)
class AmountParams(inttegro._request_base.ApiRequest):
40@dataclass(frozen=True, slots=True, kw_only=True)
41class AmountParams(ApiRequest):
42    """A monetary amount supplied in an API request.
43
44    ``value`` is always an integer in the currency's minor unit. For example,
45    ``AmountParams(currency=Currency.GHS, value=5000)`` represents GHS 50.00.
46    ``to_dict()`` serializes this value as
47    ``{"currency": "ghs", "value": 5000}``.
48    """
49
50    currency: Currency
51    """Required currency. Python type: :class:`Currency`; wire name: ``currency``; JSON type: string."""
52    value: int
53    """Required integer minor-unit amount. Python type: ``int``; wire name: ``value``; JSON type: integer."""

A monetary amount supplied in an API request.

value is always an integer in the currency's minor unit. For example, AmountParams(currency=Currency.GHS, value=5000) represents GHS 50.00. to_dict() serializes this value as {"currency": "ghs", "value": 5000}.

AmountParams(*, currency: Currency, value: int)
currency: Currency

Required currency. Python type: Currency; wire name: currency; JSON type: string.

value: int

Required integer minor-unit amount. Python type: int; wire name: value; JSON type: integer.

class Currency(inttegro._enum_base.WireEnum):
11class Currency(WireEnum):
12    """ISO-style currency identifiers accepted by Inttegro.
13
14    Currency members are strings and serialize to lowercase API wire values.
15    Input is case-insensitive, so ``Currency("GHS")`` resolves to
16    :attr:`Currency.GHS`, while serialized requests always contain ``"ghs"``.
17    """
18
19    GHS = "ghs"
20    """Ghanaian cedi. Wire value: ``ghs``."""
21    USD = "usd"
22    """United States dollar. Wire value: ``usd``."""
23    GBP = "gbp"
24    """British pound sterling. Wire value: ``gbp``."""
25    EUR = "eur"
26    """Euro. Wire value: ``eur``."""
27    CNY = "cny"
28    """Chinese yuan renminbi. Wire value: ``cny``."""
29
30    @classmethod
31    def _missing_(cls, value: object) -> "Currency | None":
32        if isinstance(value, str):
33            normalized = value.strip().lower()
34            for currency in cls:
35                if currency.value == normalized:
36                    return currency
37        return None

ISO-style currency identifiers accepted by Inttegro.

Currency members are strings and serialize to lowercase API wire values. Input is case-insensitive, so Currency("GHS") resolves to Currency.GHS, while serialized requests always contain "ghs".

GHS = <Currency.GHS: 'ghs'>

Ghanaian cedi. Wire value: ghs.

USD = <Currency.USD: 'usd'>

United States dollar. Wire value: usd.

GBP = <Currency.GBP: 'gbp'>

British pound sterling. Wire value: gbp.

EUR = <Currency.EUR: 'eur'>

Euro. Wire value: eur.

CNY = <Currency.CNY: 'cny'>

Chinese yuan renminbi. Wire value: cny.