pub struct Price {
pub net: CurrencyAmount,
pub tax_rate: Decimal,
}Expand description
A net price plus a percentage tax rate (e.g. VAT 20%).
All amounts share a single Currency; operations return
MoneyError::CurrencyMismatch if currencies diverge.
Mirrors ecom_core::Money::percentage_of — tax = net * rate / 100
— but surfaces the rate explicitly for invoicing.
use billing_kit::{Price, Currency};
use rust_decimal_macros::dec;
let p = Price::new(dec!(100), Currency::GBP, dec!(20)).unwrap();
assert_eq!(p.tax_amount().amount, dec!(20));
assert_eq!(p.gross().amount, dec!(120));Fields§
§net: CurrencyAmountNet (pre-tax) amount.
tax_rate: DecimalTax rate as percentage (0-100).
Implementations§
Source§impl Price
impl Price
Sourcepub fn new(
net_amount: impl Into<Decimal>,
currency: Currency,
tax_rate: Decimal,
) -> Result<Self, PriceError>
pub fn new( net_amount: impl Into<Decimal>, currency: Currency, tax_rate: Decimal, ) -> Result<Self, PriceError>
Sourcepub fn tax_amount(&self) -> CurrencyAmount
pub fn tax_amount(&self) -> CurrencyAmount
Tax amount = net * tax_rate / 100.
Sourcepub fn gross(&self) -> CurrencyAmount
pub fn gross(&self) -> CurrencyAmount
Gross amount = net + tax.
Sourcepub fn discount_of_gross(&self, percent: Decimal) -> CurrencyAmount
pub fn discount_of_gross(&self, percent: Decimal) -> CurrencyAmount
Discount amount at percent% of gross (0-100).
Sourcepub fn gross_minus_discount(&self, percent: Decimal) -> CurrencyAmount
pub fn gross_minus_discount(&self, percent: Decimal) -> CurrencyAmount
Apply a promo discount to gross, returning the discounted gross.
Clamps percent to 0..=100 and never returns a negative amount.
Trait Implementations§
impl Eq for Price
impl StructuralPartialEq for Price
Auto Trait Implementations§
impl Freeze for Price
impl RefUnwindSafe for Price
impl Send for Price
impl Sync for Price
impl Unpin for Price
impl UnsafeUnpin for Price
impl UnwindSafe for Price
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more