1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

use crate::types::*;
use crate::errors::*;
use uuid::Uuid;




/// Product invoice
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Invoice {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// ISO 4217 currency code
  currency: String,
  /// A list of objects used to calculate the total price of the product
  price_parts: Vec<LabeledPricePart>,
  /// True, if the payment is a test payment
  is_test: bool,
  /// True, if the user's name is needed for payment
  need_name: bool,
  /// True, if the user's phone number is needed for payment
  need_phone_number: bool,
  /// True, if the user's email address is needed for payment
  need_email_address: bool,
  /// True, if the user's shipping address is needed for payment
  need_shipping_address: bool,
  /// True, if the user's phone number will be sent to the provider
  send_phone_number_to_provider: bool,
  /// True, if the user's email address will be sent to the provider
  send_email_address_to_provider: bool,
  /// True, if the total price depends on the shipping method
  is_flexible: bool,
  
}

impl RObject for Invoice {
  #[doc(hidden)] fn td_name(&self) -> &'static str { "invoice" }
  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}



impl Invoice {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
  pub fn builder() -> RTDInvoiceBuilder {
    let mut inner = Invoice::default();
    inner.td_name = "invoice".to_string();
    inner.extra = Some(Uuid::new_v4().to_string());
    RTDInvoiceBuilder { inner }
  }

  pub fn currency(&self) -> &String { &self.currency }

  pub fn price_parts(&self) -> &Vec<LabeledPricePart> { &self.price_parts }

  pub fn is_test(&self) -> bool { self.is_test }

  pub fn need_name(&self) -> bool { self.need_name }

  pub fn need_phone_number(&self) -> bool { self.need_phone_number }

  pub fn need_email_address(&self) -> bool { self.need_email_address }

  pub fn need_shipping_address(&self) -> bool { self.need_shipping_address }

  pub fn send_phone_number_to_provider(&self) -> bool { self.send_phone_number_to_provider }

  pub fn send_email_address_to_provider(&self) -> bool { self.send_email_address_to_provider }

  pub fn is_flexible(&self) -> bool { self.is_flexible }

}

#[doc(hidden)]
pub struct RTDInvoiceBuilder {
  inner: Invoice
}

impl RTDInvoiceBuilder {
  pub fn build(&self) -> Invoice { self.inner.clone() }

   
  pub fn currency<T: AsRef<str>>(&mut self, currency: T) -> &mut Self {
    self.inner.currency = currency.as_ref().to_string();
    self
  }

   
  pub fn price_parts(&mut self, price_parts: Vec<LabeledPricePart>) -> &mut Self {
    self.inner.price_parts = price_parts;
    self
  }

   
  pub fn is_test(&mut self, is_test: bool) -> &mut Self {
    self.inner.is_test = is_test;
    self
  }

   
  pub fn need_name(&mut self, need_name: bool) -> &mut Self {
    self.inner.need_name = need_name;
    self
  }

   
  pub fn need_phone_number(&mut self, need_phone_number: bool) -> &mut Self {
    self.inner.need_phone_number = need_phone_number;
    self
  }

   
  pub fn need_email_address(&mut self, need_email_address: bool) -> &mut Self {
    self.inner.need_email_address = need_email_address;
    self
  }

   
  pub fn need_shipping_address(&mut self, need_shipping_address: bool) -> &mut Self {
    self.inner.need_shipping_address = need_shipping_address;
    self
  }

   
  pub fn send_phone_number_to_provider(&mut self, send_phone_number_to_provider: bool) -> &mut Self {
    self.inner.send_phone_number_to_provider = send_phone_number_to_provider;
    self
  }

   
  pub fn send_email_address_to_provider(&mut self, send_email_address_to_provider: bool) -> &mut Self {
    self.inner.send_email_address_to_provider = send_email_address_to_provider;
    self
  }

   
  pub fn is_flexible(&mut self, is_flexible: bool) -> &mut Self {
    self.inner.is_flexible = is_flexible;
    self
  }

}

impl AsRef<Invoice> for Invoice {
  fn as_ref(&self) -> &Invoice { self }
}

impl AsRef<Invoice> for RTDInvoiceBuilder {
  fn as_ref(&self) -> &Invoice { &self.inner }
}