pub struct Money { /* private fields */ }Expand description
A currency amount stored in Stripe’s smallest denomination.
Stripe never transmits a floating point amount, so Money keeps an
integer minor-unit count plus the currency that determines how the
value converts back to a major-unit decimal. Two USD is 200
minor units; two JPY is 2, because JPY has no minor unit.
Accessors are generated by #[derive(Getter)]. Both fields are
public because callers persist the raw minor-unit count straight
into Stripe’s amount parameter; currency_code pairs the two when
a human-readable form is needed.
Implementations§
Source§impl Money
impl Money
Sourcepub const fn from_minor(amount: i64, currency: Currency) -> Money
pub const fn from_minor(amount: i64, currency: Currency) -> Money
Build an amount directly from a minor-unit value.
This is the constructor that matches the wire format: Stripe
sends and accepts amount in the smallest denomination.
§Arguments
i64- the amount in the currency’s smallest denomination.Currency- the currency the amount is denominated in.
§Returns
Self- the amount, unchanged.
Sourcepub const fn from_major(amount: i64, currency: Currency) -> Money
pub const fn from_major(amount: i64, currency: Currency) -> Money
Sourcepub fn currency_code(&self) -> &'static str
pub fn currency_code(&self) -> &'static str
Return the ISO 4217 code Stripe expects for this amount.
§Returns
&'static str- the three-letter uppercase currency code.
Sourcepub fn to_major(&self) -> Decimal
pub fn to_major(&self) -> Decimal
Return the amount converted back to major units.
§Returns
Decimal- the minor-unit count rescaled by the currency’s exponent, so200USD reads back as2.00.
Sourcepub fn with_currency(&self, currency: Currency) -> Money
pub fn with_currency(&self, currency: Currency) -> Money
Return the same minor-unit count labelled with another currency.
Stripe never converts between currencies; this only rewrites the label and exists for presentation code, not for sending a charge.
§Arguments
Currency- the currency to relabel the amount with.
§Returns
Self- the same minor-unit count under a new currency.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Return whether the amount is negative, which Stripe rejects.
§Returns
bool-truewhen the amount is below zero.
Sourcepub fn abs(&self) -> Money
pub fn abs(&self) -> Money
Return the amount with any leading minus sign removed.
§Returns
Self- the absolute value of the amount.