1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct Invoice {
12  #[doc(hidden)]
13  #[serde(rename(serialize = "@type", deserialize = "@type"))]
14  td_name: String,
15  #[doc(hidden)]
16  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
17  extra: Option<String>,
18  currency: String,
20  price_parts: Vec<LabeledPricePart>,
22  max_tip_amount: i64,
24  suggested_tip_amounts: Vec<i64>,
26  is_test: bool,
28  need_name: bool,
30  need_phone_number: bool,
32  need_email_address: bool,
34  need_shipping_address: bool,
36  send_phone_number_to_provider: bool,
38  send_email_address_to_provider: bool,
40  is_flexible: bool,
42  
43}
44
45impl RObject for Invoice {
46  #[doc(hidden)] fn td_name(&self) -> &'static str { "invoice" }
47  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
48  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
49}
50
51
52
53impl Invoice {
54  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
55  pub fn builder() -> RTDInvoiceBuilder {
56    let mut inner = Invoice::default();
57    inner.td_name = "invoice".to_string();
58    inner.extra = Some(Uuid::new_v4().to_string());
59    RTDInvoiceBuilder { inner }
60  }
61
62  pub fn currency(&self) -> &String { &self.currency }
63
64  pub fn price_parts(&self) -> &Vec<LabeledPricePart> { &self.price_parts }
65
66  pub fn max_tip_amount(&self) -> i64 { self.max_tip_amount }
67
68  pub fn suggested_tip_amounts(&self) -> &Vec<i64> { &self.suggested_tip_amounts }
69
70  pub fn is_test(&self) -> bool { self.is_test }
71
72  pub fn need_name(&self) -> bool { self.need_name }
73
74  pub fn need_phone_number(&self) -> bool { self.need_phone_number }
75
76  pub fn need_email_address(&self) -> bool { self.need_email_address }
77
78  pub fn need_shipping_address(&self) -> bool { self.need_shipping_address }
79
80  pub fn send_phone_number_to_provider(&self) -> bool { self.send_phone_number_to_provider }
81
82  pub fn send_email_address_to_provider(&self) -> bool { self.send_email_address_to_provider }
83
84  pub fn is_flexible(&self) -> bool { self.is_flexible }
85
86}
87
88#[doc(hidden)]
89pub struct RTDInvoiceBuilder {
90  inner: Invoice
91}
92
93impl RTDInvoiceBuilder {
94  pub fn build(&self) -> Invoice { self.inner.clone() }
95
96   
97  pub fn currency<T: AsRef<str>>(&mut self, currency: T) -> &mut Self {
98    self.inner.currency = currency.as_ref().to_string();
99    self
100  }
101
102   
103  pub fn price_parts(&mut self, price_parts: Vec<LabeledPricePart>) -> &mut Self {
104    self.inner.price_parts = price_parts;
105    self
106  }
107
108   
109  pub fn max_tip_amount(&mut self, max_tip_amount: i64) -> &mut Self {
110    self.inner.max_tip_amount = max_tip_amount;
111    self
112  }
113
114   
115  pub fn suggested_tip_amounts(&mut self, suggested_tip_amounts: Vec<i64>) -> &mut Self {
116    self.inner.suggested_tip_amounts = suggested_tip_amounts;
117    self
118  }
119
120   
121  pub fn is_test(&mut self, is_test: bool) -> &mut Self {
122    self.inner.is_test = is_test;
123    self
124  }
125
126   
127  pub fn need_name(&mut self, need_name: bool) -> &mut Self {
128    self.inner.need_name = need_name;
129    self
130  }
131
132   
133  pub fn need_phone_number(&mut self, need_phone_number: bool) -> &mut Self {
134    self.inner.need_phone_number = need_phone_number;
135    self
136  }
137
138   
139  pub fn need_email_address(&mut self, need_email_address: bool) -> &mut Self {
140    self.inner.need_email_address = need_email_address;
141    self
142  }
143
144   
145  pub fn need_shipping_address(&mut self, need_shipping_address: bool) -> &mut Self {
146    self.inner.need_shipping_address = need_shipping_address;
147    self
148  }
149
150   
151  pub fn send_phone_number_to_provider(&mut self, send_phone_number_to_provider: bool) -> &mut Self {
152    self.inner.send_phone_number_to_provider = send_phone_number_to_provider;
153    self
154  }
155
156   
157  pub fn send_email_address_to_provider(&mut self, send_email_address_to_provider: bool) -> &mut Self {
158    self.inner.send_email_address_to_provider = send_email_address_to_provider;
159    self
160  }
161
162   
163  pub fn is_flexible(&mut self, is_flexible: bool) -> &mut Self {
164    self.inner.is_flexible = is_flexible;
165    self
166  }
167
168}
169
170impl AsRef<Invoice> for Invoice {
171  fn as_ref(&self) -> &Invoice { self }
172}
173
174impl AsRef<Invoice> for RTDInvoiceBuilder {
175  fn as_ref(&self) -> &Invoice { &self.inner }
176}
177
178
179