paypal_rust/resources/
amount_with_breakdown.rs

1use serde::{Deserialize, Serialize};
2
3use crate::resources::amount_breakdown::AmountBreakdown;
4use crate::resources::enums::currency_code::CurrencyCode;
5
6#[derive(Clone, Debug, Default, Deserialize, Serialize)]
7pub struct AmountWithBreakdown {
8    /// The three-character ISO-4217 currency code that identifies the currency.
9    pub currency_code: String,
10
11    ///  The value, which might be:
12    ///  An integer for currencies like JPY that are not typically fractional.
13    ///  A decimal fraction for currencies like TND that are subdivided into thousandths.
14    pub value: String,
15
16    ///  The breakdown of the amount. Breakdown provides details such as total
17    ///  item amount, total tax amount, shipping, handling, insurance, and discounts, if any.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub breakdown: Option<AmountBreakdown>,
20}
21
22impl AmountWithBreakdown {
23    #[must_use]
24    pub fn new(currency_code: CurrencyCode, value: String) -> Self {
25        Self {
26            currency_code: currency_code.as_str().to_string(),
27            value,
28            breakdown: None,
29        }
30    }
31
32    #[must_use]
33    pub fn breakdown(mut self, breakdown: AmountBreakdown) -> Self {
34        self.breakdown = Some(breakdown);
35        self
36    }
37}