Skip to main content

brevo_rust/api/types/
cart.rs

1pub use crate::prelude::*;
2
3/// Specify the payment currency and amount.
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
5pub struct Cart {
6    /// Currency code for the payment amount.
7    pub currency: String,
8    /// Payment amount, in cents. e.g. if you want to request €12.00, then the amount in cents is 1200.
9    #[serde(rename = "specificAmount")]
10    #[serde(default)]
11    pub specific_amount: i64,
12}
13
14impl Cart {
15    pub fn builder() -> CartBuilder {
16        <CartBuilder as Default>::default()
17    }
18}
19
20#[derive(Clone, PartialEq, Default, Debug)]
21#[non_exhaustive]
22pub struct CartBuilder {
23    currency: Option<String>,
24    specific_amount: Option<i64>,
25}
26
27impl CartBuilder {
28    pub fn currency(mut self, value: impl Into<String>) -> Self {
29        self.currency = Some(value.into());
30        self
31    }
32
33    pub fn specific_amount(mut self, value: i64) -> Self {
34        self.specific_amount = Some(value);
35        self
36    }
37
38    /// Consumes the builder and constructs a [`Cart`].
39    /// This method will fail if any of the following fields are not set:
40    /// - [`currency`](CartBuilder::currency)
41    /// - [`specific_amount`](CartBuilder::specific_amount)
42    pub fn build(self) -> Result<Cart, BuildError> {
43        Ok(Cart {
44            currency: self
45                .currency
46                .ok_or_else(|| BuildError::missing_field("currency"))?,
47            specific_amount: self
48                .specific_amount
49                .ok_or_else(|| BuildError::missing_field("specific_amount"))?,
50        })
51    }
52}