1use std::{
2 future::{Future, IntoFuture},
3 pin::Pin,
4};
5
6use serde::Serialize;
7
8use crate::{
9 api::API, entities::labeled_price::LabeledPrice, errors::ConogramError, impl_into_future,
10 request::RequestT, utils::deserialize_utils::is_false,
11};
12
13#[derive(Debug, Clone, Serialize)]
14pub struct CreateInvoiceLinkParams {
15 #[serde(skip_serializing_if = "Option::is_none")]
16 pub business_connection_id: Option<String>,
17 pub title: String,
18 pub description: String,
19 pub payload: String,
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub provider_token: Option<String>,
22 pub currency: String,
23 pub prices: Vec<LabeledPrice>,
24 #[serde(skip_serializing_if = "Option::is_none")]
25 pub subscription_period: Option<i64>,
26 #[serde(skip_serializing_if = "Option::is_none")]
27 pub max_tip_amount: Option<i64>,
28 #[serde(skip_serializing_if = "Vec::is_empty")]
29 pub suggested_tip_amounts: Vec<i64>,
30 #[serde(skip_serializing_if = "Option::is_none")]
31 pub provider_data: Option<String>,
32 #[serde(skip_serializing_if = "Option::is_none")]
33 pub photo_url: Option<String>,
34 #[serde(skip_serializing_if = "Option::is_none")]
35 pub photo_size: Option<i64>,
36 #[serde(skip_serializing_if = "Option::is_none")]
37 pub photo_width: Option<i64>,
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub photo_height: Option<i64>,
40 #[serde(default, skip_serializing_if = "is_false")]
41 pub need_name: bool,
42 #[serde(default, skip_serializing_if = "is_false")]
43 pub need_phone_number: bool,
44 #[serde(default, skip_serializing_if = "is_false")]
45 pub need_email: bool,
46 #[serde(default, skip_serializing_if = "is_false")]
47 pub need_shipping_address: bool,
48 #[serde(default, skip_serializing_if = "is_false")]
49 pub send_phone_number_to_provider: bool,
50 #[serde(default, skip_serializing_if = "is_false")]
51 pub send_email_to_provider: bool,
52 #[serde(default, skip_serializing_if = "is_false")]
53 pub is_flexible: bool,
54}
55
56impl_into_future!(CreateInvoiceLinkRequest<'a>);
57
58#[derive(Clone)]
60pub struct CreateInvoiceLinkRequest<'a> {
61 api: &'a API,
62 params: CreateInvoiceLinkParams,
63}
64
65impl<'a> RequestT for CreateInvoiceLinkRequest<'a> {
66 type ParamsType = CreateInvoiceLinkParams;
67 type ReturnType = String;
68 fn get_name() -> &'static str {
69 "createInvoiceLink"
70 }
71 fn get_api_ref(&self) -> &API {
72 self.api
73 }
74 fn get_params_ref(&self) -> &Self::ParamsType {
75 &self.params
76 }
77 fn is_multipart() -> bool {
78 false
79 }
80}
81impl<'a> CreateInvoiceLinkRequest<'a> {
82 pub fn new(
83 api: &'a API,
84 title: impl Into<String>,
85 description: impl Into<String>,
86 payload: impl Into<String>,
87 currency: impl Into<String>,
88 prices: impl IntoIterator<Item = impl Into<LabeledPrice>>,
89 ) -> Self {
90 Self {
91 api,
92 params: CreateInvoiceLinkParams {
93 title: title.into(),
94 description: description.into(),
95 payload: payload.into(),
96 currency: currency.into(),
97 prices: prices.into_iter().map(Into::into).collect(),
98 business_connection_id: Option::default(),
99 provider_token: Option::default(),
100 subscription_period: Option::default(),
101 max_tip_amount: Option::default(),
102 suggested_tip_amounts: Vec::default(),
103 provider_data: Option::default(),
104 photo_url: Option::default(),
105 photo_size: Option::default(),
106 photo_width: Option::default(),
107 photo_height: Option::default(),
108 need_name: bool::default(),
109 need_phone_number: bool::default(),
110 need_email: bool::default(),
111 need_shipping_address: bool::default(),
112 send_phone_number_to_provider: bool::default(),
113 send_email_to_provider: bool::default(),
114 is_flexible: bool::default(),
115 },
116 }
117 }
118
119 #[must_use]
121 pub fn business_connection_id(mut self, business_connection_id: impl Into<String>) -> Self {
122 self.params.business_connection_id = Some(business_connection_id.into());
123 self
124 }
125
126 #[must_use]
128 pub fn title(mut self, title: impl Into<String>) -> Self {
129 self.params.title = title.into();
130 self
131 }
132
133 #[must_use]
135 pub fn description(mut self, description: impl Into<String>) -> Self {
136 self.params.description = description.into();
137 self
138 }
139
140 #[must_use]
142 pub fn payload(mut self, payload: impl Into<String>) -> Self {
143 self.params.payload = payload.into();
144 self
145 }
146
147 #[must_use]
149 pub fn provider_token(mut self, provider_token: impl Into<String>) -> Self {
150 self.params.provider_token = Some(provider_token.into());
151 self
152 }
153
154 #[must_use]
156 pub fn currency(mut self, currency: impl Into<String>) -> Self {
157 self.params.currency = currency.into();
158 self
159 }
160
161 #[must_use]
163 pub fn prices(mut self, prices: impl IntoIterator<Item = impl Into<LabeledPrice>>) -> Self {
164 self.params.prices = prices.into_iter().map(Into::into).collect();
165 self
166 }
167
168 #[must_use]
170 pub fn subscription_period(mut self, subscription_period: impl Into<i64>) -> Self {
171 self.params.subscription_period = Some(subscription_period.into());
172 self
173 }
174
175 #[must_use]
177 pub fn max_tip_amount(mut self, max_tip_amount: impl Into<i64>) -> Self {
178 self.params.max_tip_amount = Some(max_tip_amount.into());
179 self
180 }
181
182 #[must_use]
184 pub fn suggested_tip_amounts(
185 mut self,
186 suggested_tip_amounts: impl IntoIterator<Item = impl Into<i64>>,
187 ) -> Self {
188 self.params.suggested_tip_amounts =
189 suggested_tip_amounts.into_iter().map(Into::into).collect();
190 self
191 }
192
193 #[must_use]
195 pub fn provider_data(mut self, provider_data: impl Into<String>) -> Self {
196 self.params.provider_data = Some(provider_data.into());
197 self
198 }
199
200 #[must_use]
202 pub fn photo_url(mut self, photo_url: impl Into<String>) -> Self {
203 self.params.photo_url = Some(photo_url.into());
204 self
205 }
206
207 #[must_use]
209 pub fn photo_size(mut self, photo_size: impl Into<i64>) -> Self {
210 self.params.photo_size = Some(photo_size.into());
211 self
212 }
213
214 #[must_use]
216 pub fn photo_width(mut self, photo_width: impl Into<i64>) -> Self {
217 self.params.photo_width = Some(photo_width.into());
218 self
219 }
220
221 #[must_use]
223 pub fn photo_height(mut self, photo_height: impl Into<i64>) -> Self {
224 self.params.photo_height = Some(photo_height.into());
225 self
226 }
227
228 #[must_use]
230 pub fn need_name(mut self, need_name: impl Into<bool>) -> Self {
231 self.params.need_name = need_name.into();
232 self
233 }
234
235 #[must_use]
237 pub fn need_phone_number(mut self, need_phone_number: impl Into<bool>) -> Self {
238 self.params.need_phone_number = need_phone_number.into();
239 self
240 }
241
242 #[must_use]
244 pub fn need_email(mut self, need_email: impl Into<bool>) -> Self {
245 self.params.need_email = need_email.into();
246 self
247 }
248
249 #[must_use]
251 pub fn need_shipping_address(mut self, need_shipping_address: impl Into<bool>) -> Self {
252 self.params.need_shipping_address = need_shipping_address.into();
253 self
254 }
255
256 #[must_use]
258 pub fn send_phone_number_to_provider(
259 mut self,
260 send_phone_number_to_provider: impl Into<bool>,
261 ) -> Self {
262 self.params.send_phone_number_to_provider = send_phone_number_to_provider.into();
263 self
264 }
265
266 #[must_use]
268 pub fn send_email_to_provider(mut self, send_email_to_provider: impl Into<bool>) -> Self {
269 self.params.send_email_to_provider = send_email_to_provider.into();
270 self
271 }
272
273 #[must_use]
275 pub fn is_flexible(mut self, is_flexible: impl Into<bool>) -> Self {
276 self.params.is_flexible = is_flexible.into();
277 self
278 }
279}
280
281impl API {
282 pub fn create_invoice_link(
284 &self,
285 title: impl Into<String>,
286 description: impl Into<String>,
287 payload: impl Into<String>,
288 currency: impl Into<String>,
289 prices: impl IntoIterator<Item = impl Into<LabeledPrice>>,
290 ) -> CreateInvoiceLinkRequest {
291 CreateInvoiceLinkRequest::new(self, title, description, payload, currency, prices)
292 }
293}
294
295