paypal_rust/resources/
amount_breakdown.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::resources::money::Money;
5
6#[skip_serializing_none]
7#[derive(Clone, Debug, Default, Deserialize, Serialize)]
8pub struct AmountBreakdown {
9    /// The subtotal for all items. Required if the request includes purchase_units[].items[].unit_amount.
10    /// Must equal the sum of (items[].unit_amount * items[].quantity) for all items. item_total.value can not be a negative number.
11    pub item_total: Option<Money>,
12
13    /// The shipping fee for all items within a given purchase_unit. shipping.value can not be a negative number.
14    pub shipping: Option<Money>,
15
16    /// The handling fee for all items within a given purchase_unit. handling.value can not be a negative number.
17    pub handling: Option<Money>,
18
19    /// The total tax for all items. Required if the request includes purchase_units.items.tax.
20    /// Must equal the sum of (items[].tax * items[].quantity) for all items. tax_total.value can not be a negative number.
21    pub tax_total: Option<Money>,
22
23    /// The insurance fee for all items within a given purchase_unit. insurance.value can not be a negative number.
24    pub insurance: Option<Money>,
25
26    /// The shipping discount for all items within a given purchase_unit. shipping_discount.value can not be a negative number.
27    pub shipping_discount: Option<Money>,
28
29    /// The discount for all items within a given purchase_unit. discount.value can not be a negative number.
30    pub discount: Option<Money>,
31}
32
33impl AmountBreakdown {
34    #[must_use]
35    pub const fn new() -> Self {
36        Self {
37            item_total: None,
38            shipping: None,
39            handling: None,
40            tax_total: None,
41            insurance: None,
42            shipping_discount: None,
43            discount: None,
44        }
45    }
46
47    #[must_use]
48    pub fn item_total(mut self, item_total: Money) -> Self {
49        self.item_total = Some(item_total);
50        self
51    }
52
53    #[must_use]
54    pub fn shipping(mut self, shipping: Money) -> Self {
55        self.shipping = Some(shipping);
56        self
57    }
58
59    #[must_use]
60    pub fn handling(mut self, handling: Money) -> Self {
61        self.handling = Some(handling);
62        self
63    }
64
65    #[must_use]
66    pub fn tax_total(mut self, tax_total: Money) -> Self {
67        self.tax_total = Some(tax_total);
68        self
69    }
70
71    #[must_use]
72    pub fn insurance(mut self, insurance: Money) -> Self {
73        self.insurance = Some(insurance);
74        self
75    }
76
77    #[must_use]
78    pub fn shipping_discount(mut self, shipping_discount: Money) -> Self {
79        self.shipping_discount = Some(shipping_discount);
80        self
81    }
82
83    #[must_use]
84    pub fn discount(mut self, discount: Money) -> Self {
85        self.discount = Some(discount);
86        self
87    }
88}