1use bigdecimal::BigDecimal;
2use log::debug;
3
4use crate::client::HttpClient;
5use crate::model::payment::PaymentItem;
6use crate::model::Address;
7use crate::options::Options;
8use crate::requests::CreateIyziupFormInitializeRequest;
9use crate::requests::PKISerialize;
10use crate::requests::RequestStringBuilder;
11use crate::requests::RetrieveIyziupFormRequest;
12use crate::resource::IyzipayResource;
13use crate::types::Result;
14
15#[derive(Debug, Default, Serialize, Deserialize, Clone)]
16#[serde(rename_all = "camelCase")]
17#[serde(default)]
18pub struct InitialConsumer {
19 name: Option<String>,
20
21 surname: Option<String>,
22
23 email: Option<String>,
24
25 gsm_number: Option<String>,
26
27 address_list: Option<Vec<IyziupAddress>>,
28}
29
30impl InitialConsumer {
31 pub fn new() -> Self {
32 Self::default()
33 }
34
35 pub fn set_name<T: Into<String>>(&mut self, name: T) {
36 self.name = Some(name.into());
37 }
38
39 pub fn set_surname<T: Into<String>>(&mut self, surname: T) {
40 self.surname = Some(surname.into());
41 }
42
43 pub fn set_email<T: Into<String>>(&mut self, email: T) {
44 self.email = Some(email.into());
45 }
46
47 pub fn set_gsm_number<T: Into<String>>(&mut self, gsm_number: T) {
48 self.gsm_number = Some(gsm_number.into());
49 }
50
51 pub fn set_address_list<T: Into<Vec<IyziupAddress>>>(&mut self, address_list: T) {
52 self.address_list = Some(address_list.into());
53 }
54
55 pub fn name(&self) -> Option<&String> {
56 self.name.as_ref()
57 }
58 pub fn surname(&self) -> Option<&String> {
59 self.surname.as_ref()
60 }
61 pub fn email(&self) -> Option<&String> {
62 self.email.as_ref()
63 }
64 pub fn gsm_number(&self) -> Option<&String> {
65 self.gsm_number.as_ref()
66 }
67 pub fn address_list(&self) -> Option<&Vec<IyziupAddress>> {
68 self.address_list.as_ref()
69 }
70}
71
72impl PKISerialize for InitialConsumer {
73 fn serialize(&self) -> Option<String> {
74 let mut ser = RequestStringBuilder::new();
75 ser.append_option("name", self.name.as_ref());
76 ser.append_option("surname", self.surname.as_ref());
77 ser.append_option("email", self.email.as_ref());
78 ser.append_option("gsmNumber", self.gsm_number.as_ref());
79 ser.append_option("addressList", self.address_list.serialize());
80 Option::from(ser.build(true))
81 }
82}
83
84#[derive(Debug, Default, Serialize, Deserialize, Clone)]
85#[serde(rename_all = "camelCase")]
86#[serde(default)]
87pub struct IyziupAddress {
88 alias: Option<String>,
89
90 address_line1: Option<String>,
91
92 address_line2: Option<String>,
93
94 zip_code: Option<String>,
95
96 contact_name: Option<String>,
97
98 city: Option<String>,
99
100 country: Option<String>,
101}
102
103impl IyziupAddress {
104 pub fn new() -> Self {
105 Self::default()
106 }
107
108 pub fn set_alias<T: Into<String>>(&mut self, alias: T) {
109 self.alias = Some(alias.into());
110 }
111
112 pub fn set_address_line1<T: Into<String>>(&mut self, address_line1: T) {
113 self.address_line1 = Some(address_line1.into());
114 }
115
116 pub fn set_address_line2<T: Into<String>>(&mut self, address_line2: T) {
117 self.address_line2 = Some(address_line2.into());
118 }
119
120 pub fn set_zip_code<T: Into<String>>(&mut self, zip_code: T) {
121 self.zip_code = Some(zip_code.into());
122 }
123
124 pub fn set_contact_name<T: Into<String>>(&mut self, contact_name: T) {
125 self.contact_name = Some(contact_name.into());
126 }
127
128 pub fn set_city<T: Into<String>>(&mut self, city: T) {
129 self.city = Some(city.into());
130 }
131
132 pub fn set_country<T: Into<String>>(&mut self, country: T) {
133 self.country = Some(country.into());
134 }
135
136 pub fn alias(&self) -> Option<&String> {
137 self.alias.as_ref()
138 }
139 pub fn address_line1(&self) -> Option<&String> {
140 self.address_line1.as_ref()
141 }
142 pub fn address_line2(&self) -> Option<&String> {
143 self.address_line2.as_ref()
144 }
145 pub fn zip_code(&self) -> Option<&String> {
146 self.zip_code.as_ref()
147 }
148 pub fn contact_name(&self) -> Option<&String> {
149 self.contact_name.as_ref()
150 }
151 pub fn city(&self) -> Option<&String> {
152 self.city.as_ref()
153 }
154 pub fn country(&self) -> Option<&String> {
155 self.country.as_ref()
156 }
157}
158
159impl PKISerialize for IyziupAddress {
160 fn serialize(&self) -> Option<String> {
161 let mut ser = RequestStringBuilder::new();
162 ser.append_option("alias", self.alias.as_ref());
163 ser.append_option("addressLine1", self.address_line1.as_ref());
164 ser.append_option("addressLine2", self.address_line2.as_ref());
165 ser.append_option("zipCode", self.zip_code.as_ref());
166 ser.append_option("contactName", self.contact_name.as_ref());
167 ser.append_option("city", self.city.as_ref());
168 ser.append_option("country", self.country.as_ref());
169 Option::from(ser.build(true))
170 }
171}
172
173#[derive(Debug, Default, Serialize, Deserialize, Clone)]
174#[serde(rename_all = "camelCase")]
175#[serde(default)]
176pub struct OrderItem {
177 id: Option<String>,
178
179 price: Option<BigDecimal>,
180
181 name: Option<String>,
182
183 category1: Option<String>,
184
185 category2: Option<String>,
186
187 item_type: Option<String>,
188
189 item_url: Option<String>,
190
191 item_description: Option<String>,
192}
193
194impl OrderItem {
195 pub fn new() -> OrderItem {
196 OrderItem::default()
197 }
198
199 pub fn set_id<T: Into<String>>(&mut self, id: T) {
200 self.id = Some(id.into());
201 }
202
203 pub fn set_price<T: Into<BigDecimal>>(&mut self, price: T) {
204 self.price = Some(price.into());
205 }
206
207 pub fn set_name<T: Into<String>>(&mut self, name: T) {
208 self.name = Some(name.into());
209 }
210
211 pub fn set_category1<T: Into<String>>(&mut self, category1: T) {
212 self.category1 = Some(category1.into());
213 }
214
215 pub fn set_category2<T: Into<String>>(&mut self, category2: T) {
216 self.category2 = Some(category2.into());
217 }
218
219 pub fn set_item_type<T: Into<String>>(&mut self, item_type: T) {
220 self.item_type = Some(item_type.into());
221 }
222
223 pub fn set_item_url<T: Into<String>>(&mut self, item_url: T) {
224 self.item_url = Some(item_url.into());
225 }
226
227 pub fn set_item_description<T: Into<String>>(&mut self, item_description: T) {
228 self.item_description = Some(item_description.into());
229 }
230
231 pub fn id(&self) -> Option<&String> {
232 self.id.as_ref()
233 }
234 pub fn price(&self) -> Option<&BigDecimal> {
235 self.price.as_ref()
236 }
237 pub fn name(&self) -> Option<&String> {
238 self.name.as_ref()
239 }
240 pub fn category1(&self) -> Option<&String> {
241 self.category1.as_ref()
242 }
243 pub fn category2(&self) -> Option<&String> {
244 self.category2.as_ref()
245 }
246 pub fn item_type(&self) -> Option<&String> {
247 self.item_type.as_ref()
248 }
249 pub fn item_url(&self) -> Option<&String> {
250 self.item_url.as_ref()
251 }
252 pub fn item_description(&self) -> Option<&String> {
253 self.item_description.as_ref()
254 }
255}
256
257impl PKISerialize for OrderItem {
258 fn serialize(&self) -> Option<String> {
259 let mut ser = RequestStringBuilder::new();
260 ser.append_option("id", self.id.as_ref());
261 ser.append_price_option("price", self.price.as_ref());
262 ser.append_option("name", self.name.as_ref());
263 ser.append_option("category1", self.category1.as_ref());
264 ser.append_option("category2", self.category2.as_ref());
265 ser.append_option("itemType", self.item_type.as_ref());
266 ser.append_option("itemUrl", self.item_url.as_ref());
267 ser.append_option("itemDescription", self.item_description.as_ref());
268 Option::from(ser.build(true))
269 }
270}
271
272pub enum OrderItemType {
273 Physical,
274 Virtual,
275}
276
277impl OrderItemType {
278 pub fn value(&self) -> &'static str {
279 match self {
280 OrderItemType::Physical => "PHYSICAL",
281 OrderItemType::Virtual => "VIRTUAL",
282 }
283 }
284}
285
286#[derive(Debug, Default, Serialize, Deserialize)]
287#[serde(rename_all = "camelCase")]
288#[serde(default)]
289pub struct IyziupFormInitialize {
290 #[serde(flatten)]
291 resource: IyziupFormInitializeResource,
292}
293
294impl IyziupFormInitialize {
295 pub fn create(
296 req: &CreateIyziupFormInitializeRequest,
297 options: &Options,
298 ) -> Result<IyziupFormInitialize> {
299 let request = serde_json::to_string(req)?;
300 debug!("RequestBody:{}", request);
301 let res = HttpClient::create().post(
302 format!("{}{}", options.base_url(), "/v1/iyziup/form/initialize").as_str(),
303 request,
304 IyzipayResource::get_http_headers(req.serialize().unwrap_or_default(), &options),
305 )?;
306 let response = res.json()?;
307 Ok(response)
308 }
309}
310
311impl std::ops::Deref for IyziupFormInitialize {
312 type Target = IyziupFormInitializeResource;
313 fn deref(&self) -> &Self::Target {
314 &self.resource
315 }
316}
317
318#[derive(Debug, Default, Serialize, Deserialize)]
319#[serde(rename_all = "camelCase")]
320#[serde(default)]
321pub struct IyziupFormInitializeResource {
322 #[serde(flatten)]
323 resource: IyzipayResource,
324
325 token: Option<String>,
326
327 content: Option<String>,
328
329 token_expire_time: Option<i64>,
330}
331
332impl IyziupFormInitializeResource {
333 pub fn set_token<T: Into<String>>(&mut self, token: T) {
334 self.token = Some(token.into());
335 }
336
337 pub fn set_content<T: Into<String>>(&mut self, content: T) {
338 self.content = Some(content.into());
339 }
340
341 pub fn set_token_expire_time<T: Into<i64>>(&mut self, token_expire_time: T) {
342 self.token_expire_time = Some(token_expire_time.into());
343 }
344
345 pub fn token(&self) -> Option<&String> {
346 self.token.as_ref()
347 }
348 pub fn content(&self) -> Option<&String> {
349 self.content.as_ref()
350 }
351 pub fn token_expire_time(&self) -> Option<&i64> {
352 self.token_expire_time.as_ref()
353 }
354}
355
356impl std::ops::Deref for IyziupFormInitializeResource {
357 type Target = IyzipayResource;
358 fn deref(&self) -> &Self::Target {
359 &self.resource
360 }
361}
362
363#[derive(Debug, Default, Serialize, Deserialize)]
364#[serde(rename_all = "camelCase")]
365#[serde(default)]
366pub struct IyziupForm {
367 #[serde(flatten)]
368 resource: IyzipayResource,
369
370 order_response_status: Option<String>,
371
372 token: Option<String>,
373
374 callback_url: Option<String>,
375
376 consumer: Option<Consumer>,
377
378 shipping_address: Option<Address>,
379
380 billing_address: Option<Address>,
381
382 payment_detail: Option<IyziupPayment>,
383}
384
385impl IyziupForm {
386 pub fn retrieve(req: &RetrieveIyziupFormRequest, options: &Options) -> Result<IyziupForm> {
387 let request = serde_json::to_string(req)?;
388 debug!("RequestBody:{}", request);
389 let res = HttpClient::create().post(
390 format!("{}{}", options.base_url(), "/v1/iyziup/form/order/retrieve").as_str(),
391 request,
392 IyzipayResource::get_http_headers(req.serialize().unwrap_or_default(), &options),
393 )?;
394 let response = res.json()?;
395 Ok(response)
396 }
397
398 pub fn set_order_response_status<T: Into<String>>(&mut self, order_response_status: T) {
399 self.order_response_status = Some(order_response_status.into());
400 }
401
402 pub fn set_token<T: Into<String>>(&mut self, token: T) {
403 self.token = Some(token.into());
404 }
405
406 pub fn set_callback_url<T: Into<String>>(&mut self, callback_url: T) {
407 self.callback_url = Some(callback_url.into());
408 }
409
410 pub fn set_consumer<T: Into<Consumer>>(&mut self, consumer: T) {
411 self.consumer = Some(consumer.into());
412 }
413
414 pub fn set_shipping_address<T: Into<Address>>(&mut self, shipping_address: T) {
415 self.shipping_address = Some(shipping_address.into());
416 }
417
418 pub fn set_billing_address<T: Into<Address>>(&mut self, billing_address: T) {
419 self.billing_address = Some(billing_address.into());
420 }
421
422 pub fn set_payment_detail<T: Into<IyziupPayment>>(&mut self, payment_detail: T) {
423 self.payment_detail = Some(payment_detail.into());
424 }
425
426 pub fn order_response_status(&self) -> Option<&String> {
427 self.order_response_status.as_ref()
428 }
429 pub fn token(&self) -> Option<&String> {
430 self.token.as_ref()
431 }
432 pub fn callback_url(&self) -> Option<&String> {
433 self.callback_url.as_ref()
434 }
435 pub fn consumer(&self) -> Option<&Consumer> {
436 self.consumer.as_ref()
437 }
438 pub fn shipping_address(&self) -> Option<&Address> {
439 self.shipping_address.as_ref()
440 }
441 pub fn billing_address(&self) -> Option<&Address> {
442 self.billing_address.as_ref()
443 }
444 pub fn payment_detail(&self) -> Option<&IyziupPayment> {
445 self.payment_detail.as_ref()
446 }
447}
448
449impl std::ops::Deref for IyziupForm {
450 type Target = IyzipayResource;
451 fn deref(&self) -> &Self::Target {
452 &self.resource
453 }
454}
455
456#[derive(Debug, Default, Serialize, Deserialize)]
457#[serde(rename_all = "camelCase")]
458#[serde(default)]
459pub struct Consumer {
460 name: Option<String>,
461
462 surname: Option<String>,
463
464 identity_number: Option<String>,
465
466 email: Option<String>,
467
468 gsm_number: Option<String>,
469}
470
471impl Consumer {
472 pub fn set_name<T: Into<String>>(&mut self, name: T) {
473 self.name = Some(name.into());
474 }
475
476 pub fn set_surname<T: Into<String>>(&mut self, surname: T) {
477 self.surname = Some(surname.into());
478 }
479
480 pub fn set_identity_number<T: Into<String>>(&mut self, identity_number: T) {
481 self.identity_number = Some(identity_number.into());
482 }
483
484 pub fn set_email<T: Into<String>>(&mut self, email: T) {
485 self.email = Some(email.into());
486 }
487
488 pub fn set_gsm_number<T: Into<String>>(&mut self, gsm_number: T) {
489 self.gsm_number = Some(gsm_number.into());
490 }
491
492 pub fn name(&self) -> Option<&String> {
493 self.name.as_ref()
494 }
495 pub fn surname(&self) -> Option<&String> {
496 self.surname.as_ref()
497 }
498 pub fn identity_number(&self) -> Option<&String> {
499 self.identity_number.as_ref()
500 }
501 pub fn email(&self) -> Option<&String> {
502 self.email.as_ref()
503 }
504 pub fn gsm_number(&self) -> Option<&String> {
505 self.gsm_number.as_ref()
506 }
507}
508
509#[derive(Debug, Default, Serialize, Deserialize)]
510#[serde(rename_all = "camelCase")]
511#[serde(default)]
512pub struct IyziupPayment {
513 price: Option<BigDecimal>,
514
515 paid_price: Option<BigDecimal>,
516
517 currency: Option<String>,
518
519 installment: Option<i32>,
520
521 payment_id: Option<String>,
522
523 payment_status: Option<String>,
524
525 fraud_status: Option<i32>,
526
527 merchant_commission_rate: Option<BigDecimal>,
528
529 merchant_commission_rate_amount: Option<BigDecimal>,
530
531 iyzi_commission_rate_amount: Option<BigDecimal>,
532
533 iyzi_commission_fee: Option<BigDecimal>,
534
535 card_type: Option<String>,
536
537 card_association: Option<String>,
538
539 card_family: Option<String>,
540
541 bin_number: Option<String>,
542
543 basket_id: Option<String>,
544
545 #[serde(rename = "itemTransactions")]
546 payment_items: Option<Vec<PaymentItem>>,
547
548 connector_name: Option<String>,
549
550 auth_code: Option<String>,
551
552 phase: Option<String>,
553
554 last_four_digits: Option<String>,
555
556 pos_order_id: Option<String>,
557}
558
559impl IyziupPayment {
560 pub fn set_price<T: Into<BigDecimal>>(&mut self, price: T) {
561 self.price = Some(price.into());
562 }
563
564 pub fn set_paid_price<T: Into<BigDecimal>>(&mut self, paid_price: T) {
565 self.paid_price = Some(paid_price.into());
566 }
567
568 pub fn set_currency<T: Into<String>>(&mut self, currency: T) {
569 self.currency = Some(currency.into());
570 }
571
572 pub fn set_installment<T: Into<i32>>(&mut self, installment: T) {
573 self.installment = Some(installment.into());
574 }
575
576 pub fn set_payment_id<T: Into<String>>(&mut self, payment_id: T) {
577 self.payment_id = Some(payment_id.into());
578 }
579
580 pub fn set_payment_status<T: Into<String>>(&mut self, payment_status: T) {
581 self.payment_status = Some(payment_status.into());
582 }
583
584 pub fn set_fraud_status<T: Into<i32>>(&mut self, fraud_status: T) {
585 self.fraud_status = Some(fraud_status.into());
586 }
587
588 pub fn set_merchant_commission_rate<T: Into<BigDecimal>>(
589 &mut self,
590 merchant_commission_rate: T,
591 ) {
592 self.merchant_commission_rate = Some(merchant_commission_rate.into());
593 }
594
595 pub fn set_merchant_commission_rate_amount<T: Into<BigDecimal>>(
596 &mut self,
597 merchant_commission_rate_amount: T,
598 ) {
599 self.merchant_commission_rate_amount = Some(merchant_commission_rate_amount.into());
600 }
601
602 pub fn set_iyzi_commission_rate_amount<T: Into<BigDecimal>>(
603 &mut self,
604 iyzi_commission_rate_amount: T,
605 ) {
606 self.iyzi_commission_rate_amount = Some(iyzi_commission_rate_amount.into());
607 }
608
609 pub fn set_iyzi_commission_fee<T: Into<BigDecimal>>(&mut self, iyzi_commission_fee: T) {
610 self.iyzi_commission_fee = Some(iyzi_commission_fee.into());
611 }
612
613 pub fn set_card_type<T: Into<String>>(&mut self, card_type: T) {
614 self.card_type = Some(card_type.into());
615 }
616
617 pub fn set_card_association<T: Into<String>>(&mut self, card_association: T) {
618 self.card_association = Some(card_association.into());
619 }
620
621 pub fn set_card_family<T: Into<String>>(&mut self, card_family: T) {
622 self.card_family = Some(card_family.into());
623 }
624
625 pub fn set_bin_number<T: Into<String>>(&mut self, bin_number: T) {
626 self.bin_number = Some(bin_number.into());
627 }
628
629 pub fn set_basket_id<T: Into<String>>(&mut self, basket_id: T) {
630 self.basket_id = Some(basket_id.into());
631 }
632
633 pub fn set_payment_items<T: Into<Vec<PaymentItem>>>(&mut self, payment_items: T) {
634 self.payment_items = Some(payment_items.into());
635 }
636
637 pub fn set_connector_name<T: Into<String>>(&mut self, connector_name: T) {
638 self.connector_name = Some(connector_name.into());
639 }
640
641 pub fn set_auth_code<T: Into<String>>(&mut self, auth_code: T) {
642 self.auth_code = Some(auth_code.into());
643 }
644
645 pub fn set_phase<T: Into<String>>(&mut self, phase: T) {
646 self.phase = Some(phase.into());
647 }
648
649 pub fn set_last_four_digits<T: Into<String>>(&mut self, last_four_digits: T) {
650 self.last_four_digits = Some(last_four_digits.into());
651 }
652
653 pub fn set_pos_order_id<T: Into<String>>(&mut self, pos_order_id: T) {
654 self.pos_order_id = Some(pos_order_id.into());
655 }
656
657 pub fn price(&self) -> Option<&BigDecimal> {
658 self.price.as_ref()
659 }
660 pub fn paid_price(&self) -> Option<&BigDecimal> {
661 self.paid_price.as_ref()
662 }
663 pub fn currency(&self) -> Option<&String> {
664 self.currency.as_ref()
665 }
666 pub fn installment(&self) -> Option<&i32> {
667 self.installment.as_ref()
668 }
669 pub fn payment_id(&self) -> Option<&String> {
670 self.payment_id.as_ref()
671 }
672 pub fn payment_status(&self) -> Option<&String> {
673 self.payment_status.as_ref()
674 }
675 pub fn fraud_status(&self) -> Option<&i32> {
676 self.fraud_status.as_ref()
677 }
678 pub fn merchant_commission_rate(&self) -> Option<&BigDecimal> {
679 self.merchant_commission_rate.as_ref()
680 }
681 pub fn merchant_commission_rate_amount(&self) -> Option<&BigDecimal> {
682 self.merchant_commission_rate_amount.as_ref()
683 }
684 pub fn iyzi_commission_rate_amount(&self) -> Option<&BigDecimal> {
685 self.iyzi_commission_rate_amount.as_ref()
686 }
687 pub fn iyzi_commission_fee(&self) -> Option<&BigDecimal> {
688 self.iyzi_commission_fee.as_ref()
689 }
690 pub fn card_type(&self) -> Option<&String> {
691 self.card_type.as_ref()
692 }
693 pub fn card_association(&self) -> Option<&String> {
694 self.card_association.as_ref()
695 }
696 pub fn card_family(&self) -> Option<&String> {
697 self.card_family.as_ref()
698 }
699 pub fn bin_number(&self) -> Option<&String> {
700 self.bin_number.as_ref()
701 }
702 pub fn basket_id(&self) -> Option<&String> {
703 self.basket_id.as_ref()
704 }
705 pub fn payment_items(&self) -> Option<&Vec<PaymentItem>> {
706 self.payment_items.as_ref()
707 }
708 pub fn connector_name(&self) -> Option<&String> {
709 self.connector_name.as_ref()
710 }
711 pub fn auth_code(&self) -> Option<&String> {
712 self.auth_code.as_ref()
713 }
714 pub fn phase(&self) -> Option<&String> {
715 self.phase.as_ref()
716 }
717 pub fn last_four_digits(&self) -> Option<&String> {
718 self.last_four_digits.as_ref()
719 }
720 pub fn pos_order_id(&self) -> Option<&String> {
721 self.pos_order_id.as_ref()
722 }
723}