-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathpayment_methods.rs
2863 lines (2445 loc) · 108 KB
/
payment_methods.rs
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use std::collections::{HashMap, HashSet};
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
use std::str::FromStr;
use cards::CardNumber;
use common_utils::{
consts::SURCHARGE_PERCENTAGE_PRECISION_LENGTH,
crypto::OptionalEncryptableName,
errors,
ext_traits::OptionExt,
id_type, link_utils, pii,
types::{MinorUnit, Percentage, Surcharge},
};
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
use masking::PeekInterface;
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
use masking::{ExposeInterface, PeekInterface};
use serde::de;
use utoipa::{schema, ToSchema};
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
use crate::customers;
#[cfg(feature = "payouts")]
use crate::payouts;
use crate::{
admin, enums as api_enums,
payments::{self, BankCodeResponse},
};
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodCreate {
/// The type of payment method use for the payment.
#[schema(value_type = PaymentMethod,example = "card")]
pub payment_method: Option<api_enums::PaymentMethod>,
/// This is a sub-category of payment method.
#[schema(value_type = Option<PaymentMethodType>,example = "credit")]
pub payment_method_type: Option<api_enums::PaymentMethodType>,
/// The name of the bank/ provider issuing the payment method to the end user
#[schema(example = "Citibank")]
pub payment_method_issuer: Option<String>,
/// A standard code representing the issuer of payment method
#[schema(value_type = Option<PaymentMethodIssuerCode>,example = "jp_applepay")]
pub payment_method_issuer_code: Option<api_enums::PaymentMethodIssuerCode>,
/// Card Details
#[schema(example = json!({
"card_number": "4111111145551142",
"card_exp_month": "10",
"card_exp_year": "25",
"card_holder_name": "John Doe"}))]
pub card: Option<CardDetail>,
/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
#[schema(value_type = Option<Object>,example = json!({ "city": "NY", "unit": "245" }))]
pub metadata: Option<pii::SecretSerdeValue>,
/// The unique identifier of the customer.
#[schema(value_type = Option<String>, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
pub customer_id: Option<id_type::CustomerId>,
/// The card network
#[schema(example = "Visa")]
pub card_network: Option<String>,
/// Payment method details from locker
#[cfg(feature = "payouts")]
#[schema(value_type = Option<Bank>)]
pub bank_transfer: Option<payouts::Bank>,
/// Payment method details from locker
#[cfg(feature = "payouts")]
#[schema(value_type = Option<Wallet>)]
pub wallet: Option<payouts::Wallet>,
/// For Client based calls, SDK will use the client_secret
/// in order to call /payment_methods
/// Client secret will be generated whenever a new
/// payment method is created
pub client_secret: Option<String>,
/// Payment method data to be passed in case of client
/// based flow
pub payment_method_data: Option<PaymentMethodCreateData>,
/// The billing details of the payment method
#[schema(value_type = Option<Address>)]
pub billing: Option<payments::Address>,
#[serde(skip_deserializing)]
/// The connector mandate details of the payment method, this is added only for cards migration
/// api and is skipped during deserialization of the payment method create request as this
/// it should not be passed in the request
pub connector_mandate_details: Option<PaymentsMandateReference>,
#[serde(skip_deserializing)]
/// The transaction id of a CIT (customer initiated transaction) associated with the payment method,
/// this is added only for cards migration api and is skipped during deserialization of the
/// payment method create request as it should not be passed in the request
pub network_transaction_id: Option<String>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodCreate {
/// The type of payment method use for the payment.
#[schema(value_type = PaymentMethod,example = "card")]
pub payment_method_type: api_enums::PaymentMethod,
/// This is a sub-category of payment method.
#[schema(value_type = Option<PaymentMethodType>,example = "credit")]
pub payment_method_subtype: Option<api_enums::PaymentMethodType>,
/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
#[schema(value_type = Option<Object>,example = json!({ "city": "NY", "unit": "245" }))]
pub metadata: Option<pii::SecretSerdeValue>,
/// The unique identifier of the customer.
#[schema(
min_length = 32,
max_length = 64,
example = "12345_cus_01926c58bc6e77c09e809964e72af8c8",
value_type = String
)]
pub customer_id: id_type::GlobalCustomerId,
/// Payment method data to be passed
pub payment_method_data: PaymentMethodCreateData,
/// The billing details of the payment method
#[schema(value_type = Option<Address>)]
pub billing: Option<payments::Address>,
/// The tokenization type to be applied
#[schema(value_type = Option<PspTokenization>)]
pub psp_tokenization: Option<common_types::payment_methods::PspTokenization>,
/// The network tokenization configuration if applicable
#[schema(value_type = Option<NetworkTokenization>)]
pub network_tokenization: Option<common_types::payment_methods::NetworkTokenization>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodIntentCreate {
/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
#[schema(value_type = Option<Object>,example = json!({ "city": "NY", "unit": "245" }))]
pub metadata: Option<pii::SecretSerdeValue>,
/// The billing details of the payment method
#[schema(value_type = Option<Address>)]
pub billing: Option<payments::Address>,
/// The unique identifier of the customer.
#[schema(
min_length = 32,
max_length = 64,
example = "12345_cus_01926c58bc6e77c09e809964e72af8c8",
value_type = String
)]
pub customer_id: id_type::GlobalCustomerId,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodIntentConfirm {
/// The unique identifier of the customer.
#[schema(value_type = Option<String>, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
pub customer_id: Option<id_type::CustomerId>,
/// Payment method data to be passed
pub payment_method_data: PaymentMethodCreateData,
/// The type of payment method use for the payment.
#[schema(value_type = PaymentMethod,example = "card")]
pub payment_method_type: api_enums::PaymentMethod,
/// This is a sub-category of payment method.
#[schema(value_type = PaymentMethodType,example = "credit")]
pub payment_method_subtype: api_enums::PaymentMethodType,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
impl PaymentMethodIntentConfirm {
pub fn validate_payment_method_data_against_payment_method(
payment_method_type: api_enums::PaymentMethod,
payment_method_data: PaymentMethodCreateData,
) -> bool {
match payment_method_type {
api_enums::PaymentMethod::Card => {
matches!(payment_method_data, PaymentMethodCreateData::Card(_))
}
_ => false,
}
}
}
/// This struct is used internally only
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct PaymentMethodIntentConfirmInternal {
pub id: id_type::GlobalPaymentMethodId,
pub request: PaymentMethodIntentConfirm,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
impl From<PaymentMethodIntentConfirmInternal> for PaymentMethodIntentConfirm {
fn from(item: PaymentMethodIntentConfirmInternal) -> Self {
item.request
}
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
/// This struct is only used by and internal api to migrate payment method
pub struct PaymentMethodMigrate {
/// Merchant id
pub merchant_id: id_type::MerchantId,
/// The type of payment method use for the payment.
pub payment_method: Option<api_enums::PaymentMethod>,
/// This is a sub-category of payment method.
pub payment_method_type: Option<api_enums::PaymentMethodType>,
/// The name of the bank/ provider issuing the payment method to the end user
pub payment_method_issuer: Option<String>,
/// A standard code representing the issuer of payment method
pub payment_method_issuer_code: Option<api_enums::PaymentMethodIssuerCode>,
/// Card Details
pub card: Option<MigrateCardDetail>,
/// Network token details
pub network_token: Option<MigrateNetworkTokenDetail>,
/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
pub metadata: Option<pii::SecretSerdeValue>,
/// The unique identifier of the customer.
pub customer_id: Option<id_type::CustomerId>,
/// The card network
pub card_network: Option<String>,
/// Payment method details from locker
#[cfg(feature = "payouts")]
pub bank_transfer: Option<payouts::Bank>,
/// Payment method details from locker
#[cfg(feature = "payouts")]
pub wallet: Option<payouts::Wallet>,
/// Payment method data to be passed in case of client
/// based flow
pub payment_method_data: Option<PaymentMethodCreateData>,
/// The billing details of the payment method
pub billing: Option<payments::Address>,
/// The connector mandate details of the payment method
#[serde(deserialize_with = "deserialize_connector_mandate_details")]
pub connector_mandate_details: Option<CommonMandateReference>,
// The CIT (customer initiated transaction) transaction id associated with the payment method
pub network_transaction_id: Option<String>,
}
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct PaymentMethodMigrateResponse {
//payment method response when payment method entry is created
pub payment_method_response: PaymentMethodResponse,
//card data migration status
pub card_migrated: Option<bool>,
//network token data migration status
pub network_token_migrated: Option<bool>,
//connector mandate details migration status
pub connector_mandate_details_migrated: Option<bool>,
//network transaction id migration status
pub network_transaction_id_migrated: Option<bool>,
}
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
pub struct PaymentsMandateReference(
pub HashMap<id_type::MerchantConnectorAccountId, PaymentsMandateReferenceRecord>,
);
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct PayoutsMandateReference(
pub HashMap<id_type::MerchantConnectorAccountId, PayoutsMandateReferenceRecord>,
);
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct PayoutsMandateReferenceRecord {
pub transfer_method_id: Option<String>,
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct PaymentsMandateReferenceRecord {
pub connector_mandate_id: String,
pub payment_method_type: Option<common_enums::PaymentMethodType>,
pub original_payment_authorized_amount: Option<i64>,
pub original_payment_authorized_currency: Option<common_enums::Currency>,
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct CommonMandateReference {
pub payments: Option<PaymentsMandateReference>,
pub payouts: Option<PayoutsMandateReference>,
}
impl From<CommonMandateReference> for PaymentsMandateReference {
fn from(common_mandate: CommonMandateReference) -> Self {
common_mandate.payments.unwrap_or_default()
}
}
impl From<PaymentsMandateReference> for CommonMandateReference {
fn from(payments_reference: PaymentsMandateReference) -> Self {
Self {
payments: Some(payments_reference),
payouts: None,
}
}
}
fn deserialize_connector_mandate_details<'de, D>(
deserializer: D,
) -> Result<Option<CommonMandateReference>, D::Error>
where
D: serde::Deserializer<'de>,
{
let value: Option<serde_json::Value> =
<Option<serde_json::Value> as de::Deserialize>::deserialize(deserializer)?;
let payments_data = value
.clone()
.map(|mut mandate_details| {
mandate_details
.as_object_mut()
.map(|obj| obj.remove("payouts"));
serde_json::from_value::<PaymentsMandateReference>(mandate_details)
})
.transpose()
.map_err(|err| {
let err_msg = format!("{err:?}");
de::Error::custom(format_args!(
"Failed to deserialize PaymentsMandateReference `{}`",
err_msg
))
})?;
let payouts_data = value
.clone()
.map(|mandate_details| {
serde_json::from_value::<Option<CommonMandateReference>>(mandate_details).map(
|optional_common_mandate_details| {
optional_common_mandate_details
.and_then(|common_mandate_details| common_mandate_details.payouts)
},
)
})
.transpose()
.map_err(|err| {
let err_msg = format!("{err:?}");
de::Error::custom(format_args!(
"Failed to deserialize CommonMandateReference `{}`",
err_msg
))
})?
.flatten();
Ok(Some(CommonMandateReference {
payments: payments_data,
payouts: payouts_data,
}))
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
impl PaymentMethodCreate {
pub fn get_payment_method_create_from_payment_method_migrate(
card_number: CardNumber,
payment_method_migrate: &PaymentMethodMigrate,
) -> Self {
let card_details =
payment_method_migrate
.card
.as_ref()
.map(|payment_method_migrate_card| CardDetail {
card_number,
card_exp_month: payment_method_migrate_card.card_exp_month.clone(),
card_exp_year: payment_method_migrate_card.card_exp_year.clone(),
card_holder_name: payment_method_migrate_card.card_holder_name.clone(),
nick_name: payment_method_migrate_card.nick_name.clone(),
card_issuing_country: payment_method_migrate_card.card_issuing_country.clone(),
card_network: payment_method_migrate_card.card_network.clone(),
card_issuer: payment_method_migrate_card.card_issuer.clone(),
card_type: payment_method_migrate_card.card_type.clone(),
});
Self {
customer_id: payment_method_migrate.customer_id.clone(),
payment_method: payment_method_migrate.payment_method,
payment_method_type: payment_method_migrate.payment_method_type,
payment_method_issuer: payment_method_migrate.payment_method_issuer.clone(),
payment_method_issuer_code: payment_method_migrate.payment_method_issuer_code,
metadata: payment_method_migrate.metadata.clone(),
payment_method_data: payment_method_migrate.payment_method_data.clone(),
connector_mandate_details: payment_method_migrate
.connector_mandate_details
.clone()
.map(|common_mandate_reference| {
PaymentsMandateReference::from(common_mandate_reference)
}),
client_secret: None,
billing: payment_method_migrate.billing.clone(),
card: card_details,
card_network: payment_method_migrate.card_network.clone(),
#[cfg(feature = "payouts")]
bank_transfer: payment_method_migrate.bank_transfer.clone(),
#[cfg(feature = "payouts")]
wallet: payment_method_migrate.wallet.clone(),
network_transaction_id: payment_method_migrate.network_transaction_id.clone(),
}
}
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
impl PaymentMethodCreate {
pub fn validate_payment_method_data_against_payment_method(
payment_method_type: api_enums::PaymentMethod,
payment_method_data: PaymentMethodCreateData,
) -> bool {
match payment_method_type {
api_enums::PaymentMethod::Card => {
matches!(payment_method_data, PaymentMethodCreateData::Card(_))
}
_ => false,
}
}
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodUpdate {
/// Card Details
#[schema(example = json!({
"card_number": "4111111145551142",
"card_exp_month": "10",
"card_exp_year": "25",
"card_holder_name": "John Doe"}))]
pub card: Option<CardDetailUpdate>,
/// This is a 15 minute expiry token which shall be used from the client to authenticate and perform sessions from the SDK
#[schema(max_length = 30, min_length = 30, example = "secret_k2uj3he2893eiu2d")]
pub client_secret: Option<String>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodUpdate {
/// Payment method details to be updated for the payment_method
pub payment_method_data: Option<PaymentMethodUpdateData>,
/// The connector token details to be updated for the payment_method
pub connector_token_details: Option<ConnectorTokenDetails>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "snake_case")]
#[serde(rename = "payment_method_data")]
pub enum PaymentMethodUpdateData {
Card(CardDetailUpdate),
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "snake_case")]
#[serde(rename = "payment_method_data")]
pub enum PaymentMethodCreateData {
Card(CardDetail),
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "snake_case")]
#[serde(rename = "payment_method_data")]
pub enum PaymentMethodCreateData {
Card(CardDetail),
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct CardDetail {
/// Card Number
#[schema(value_type = String,example = "4111111145551142")]
pub card_number: CardNumber,
/// Card Expiry Month
#[schema(value_type = String,example = "10")]
pub card_exp_month: masking::Secret<String>,
/// Card Expiry Year
#[schema(value_type = String,example = "25")]
pub card_exp_year: masking::Secret<String>,
/// Card Holder Name
#[schema(value_type = String,example = "John Doe")]
pub card_holder_name: Option<masking::Secret<String>>,
/// Card Holder's Nick Name
#[schema(value_type = Option<String>,example = "John Doe")]
pub nick_name: Option<masking::Secret<String>>,
/// Card Issuing Country
pub card_issuing_country: Option<String>,
/// Card's Network
#[schema(value_type = Option<CardNetwork>)]
pub card_network: Option<api_enums::CardNetwork>,
/// Issuer Bank for Card
pub card_issuer: Option<String>,
/// Card Type
pub card_type: Option<String>,
}
#[derive(
Debug,
serde::Deserialize,
serde::Serialize,
Clone,
ToSchema,
strum::EnumString,
strum::Display,
Eq,
PartialEq,
)]
#[serde(rename_all = "snake_case")]
pub enum CardType {
Credit,
Debit,
}
// We cannot use the card struct that we have for payments for the following reason
// The card struct used for payments has card_cvc as mandatory
// but when vaulting the card, we do not need cvc to be collected from the user
// This is because, the vaulted payment method can be used for future transactions in the presence of the customer
// when the customer is on_session again, the cvc can be collected from the customer
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct CardDetail {
/// Card Number
#[schema(value_type = String,example = "4111111145551142")]
pub card_number: CardNumber,
/// Card Expiry Month
#[schema(value_type = String,example = "10")]
pub card_exp_month: masking::Secret<String>,
/// Card Expiry Year
#[schema(value_type = String,example = "25")]
pub card_exp_year: masking::Secret<String>,
/// Card Holder Name
#[schema(value_type = String,example = "John Doe")]
pub card_holder_name: Option<masking::Secret<String>>,
/// Card Holder's Nick Name
#[schema(value_type = Option<String>,example = "John Doe")]
pub nick_name: Option<masking::Secret<String>>,
/// Card Issuing Country
#[schema(value_type = CountryAlpha2)]
pub card_issuing_country: Option<api_enums::CountryAlpha2>,
/// Card's Network
#[schema(value_type = Option<CardNetwork>)]
pub card_network: Option<api_enums::CardNetwork>,
/// Issuer Bank for Card
pub card_issuer: Option<String>,
/// Card Type
pub card_type: Option<CardType>,
/// The CVC number for the card
/// This is optional in case the card needs to be vaulted
#[schema(value_type = String, example = "242")]
pub card_cvc: Option<masking::Secret<String>>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct MigrateCardDetail {
/// Card Number
#[schema(value_type = String,example = "4111111145551142")]
pub card_number: masking::Secret<String>,
/// Card Expiry Month
#[schema(value_type = String,example = "10")]
pub card_exp_month: masking::Secret<String>,
/// Card Expiry Year
#[schema(value_type = String,example = "25")]
pub card_exp_year: masking::Secret<String>,
/// Card Holder Name
#[schema(value_type = String,example = "John Doe")]
pub card_holder_name: Option<masking::Secret<String>>,
/// Card Holder's Nick Name
#[schema(value_type = Option<String>,example = "John Doe")]
pub nick_name: Option<masking::Secret<String>>,
/// Card Issuing Country
pub card_issuing_country: Option<String>,
/// Card's Network
#[schema(value_type = Option<CardNetwork>)]
pub card_network: Option<api_enums::CardNetwork>,
/// Issuer Bank for Card
pub card_issuer: Option<String>,
/// Card Type
pub card_type: Option<String>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct MigrateNetworkTokenData {
/// Network Token Number
#[schema(value_type = String,example = "4111111145551142")]
pub network_token_number: CardNumber,
/// Network Token Expiry Month
#[schema(value_type = String,example = "10")]
pub network_token_exp_month: masking::Secret<String>,
/// Network Token Expiry Year
#[schema(value_type = String,example = "25")]
pub network_token_exp_year: masking::Secret<String>,
/// Card Holder Name
#[schema(value_type = String,example = "John Doe")]
pub card_holder_name: Option<masking::Secret<String>>,
/// Card Holder's Nick Name
#[schema(value_type = Option<String>,example = "John Doe")]
pub nick_name: Option<masking::Secret<String>>,
/// Card Issuing Country
pub card_issuing_country: Option<String>,
/// Card's Network
#[schema(value_type = Option<CardNetwork>)]
pub card_network: Option<api_enums::CardNetwork>,
/// Issuer Bank for Card
pub card_issuer: Option<String>,
/// Card Type
pub card_type: Option<String>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct MigrateNetworkTokenDetail {
/// Network token details
pub network_token_data: MigrateNetworkTokenData,
/// Network token requestor reference id
pub network_token_requestor_ref_id: String,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct CardDetailUpdate {
/// Card Expiry Month
#[schema(value_type = String,example = "10")]
pub card_exp_month: Option<masking::Secret<String>>,
/// Card Expiry Year
#[schema(value_type = String,example = "25")]
pub card_exp_year: Option<masking::Secret<String>>,
/// Card Holder Name
#[schema(value_type = String,example = "John Doe")]
pub card_holder_name: Option<masking::Secret<String>>,
/// Card Holder's Nick Name
#[schema(value_type = Option<String>,example = "John Doe")]
pub nick_name: Option<masking::Secret<String>>,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
impl CardDetailUpdate {
pub fn apply(&self, card_data_from_locker: Card) -> CardDetail {
CardDetail {
card_number: card_data_from_locker.card_number,
card_exp_month: self
.card_exp_month
.clone()
.unwrap_or(card_data_from_locker.card_exp_month),
card_exp_year: self
.card_exp_year
.clone()
.unwrap_or(card_data_from_locker.card_exp_year),
card_holder_name: self
.card_holder_name
.clone()
.or(card_data_from_locker.name_on_card),
nick_name: self
.nick_name
.clone()
.or(card_data_from_locker.nick_name.map(masking::Secret::new)),
card_issuing_country: None,
card_network: None,
card_issuer: None,
card_type: None,
}
}
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct CardDetailUpdate {
/// Card Holder Name
#[schema(value_type = String,example = "John Doe")]
pub card_holder_name: Option<masking::Secret<String>>,
/// Card Holder's Nick Name
#[schema(value_type = Option<String>,example = "John Doe")]
pub nick_name: Option<masking::Secret<String>>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
impl CardDetailUpdate {
pub fn apply(&self, card_data_from_locker: Card) -> CardDetail {
CardDetail {
card_number: card_data_from_locker.card_number,
card_exp_month: card_data_from_locker.card_exp_month,
card_exp_year: card_data_from_locker.card_exp_year,
card_holder_name: self
.card_holder_name
.clone()
.or(card_data_from_locker.name_on_card),
nick_name: self
.nick_name
.clone()
.or(card_data_from_locker.nick_name.map(masking::Secret::new)),
card_issuing_country: None,
card_network: None,
card_issuer: None,
card_type: None,
card_cvc: None,
}
}
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "snake_case")]
#[serde(rename = "payment_method_data")]
pub enum PaymentMethodResponseData {
Card(CardDetailFromLocker),
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct PaymentMethodResponse {
/// Unique identifier for a merchant
#[schema(example = "merchant_1671528864", value_type = String)]
pub merchant_id: id_type::MerchantId,
/// The unique identifier of the customer.
#[schema(value_type = Option<String>, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
pub customer_id: Option<id_type::CustomerId>,
/// The unique identifier of the Payment method
#[schema(example = "card_rGK4Vi5iSW70MY7J2mIg")]
pub payment_method_id: String,
/// The type of payment method use for the payment.
#[schema(value_type = PaymentMethod, example = "card")]
pub payment_method: Option<api_enums::PaymentMethod>,
/// This is a sub-category of payment method.
#[schema(value_type = Option<PaymentMethodType>, example = "credit")]
pub payment_method_type: Option<api_enums::PaymentMethodType>,
/// Card details from card locker
#[schema(example = json!({"last4": "1142","exp_month": "03","exp_year": "2030"}))]
pub card: Option<CardDetailFromLocker>,
/// Indicates whether the payment method is eligible for recurring payments
#[schema(example = true)]
pub recurring_enabled: bool,
/// Indicates whether the payment method is eligible for installment payments
#[schema(example = true)]
pub installment_payment_enabled: bool,
/// Type of payment experience enabled with the connector
#[schema(value_type = Option<Vec<PaymentExperience>>, example = json!(["redirect_to_url"]))]
pub payment_experience: Option<Vec<api_enums::PaymentExperience>>,
/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
#[schema(value_type = Option<Object>, example = json!({ "city": "NY", "unit": "245" }))]
pub metadata: Option<pii::SecretSerdeValue>,
/// A timestamp (ISO 8601 code) that determines when the payment method was created
#[schema(value_type = Option<PrimitiveDateTime>, example = "2023-01-18T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub created: Option<time::PrimitiveDateTime>,
/// Payment method details from locker
#[cfg(feature = "payouts")]
#[schema(value_type = Option<Bank>)]
#[serde(skip_serializing_if = "Option::is_none")]
pub bank_transfer: Option<payouts::Bank>,
#[schema(value_type = Option<PrimitiveDateTime>, example = "2024-02-24T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub last_used_at: Option<time::PrimitiveDateTime>,
/// For Client based calls
pub client_secret: Option<String>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema, Clone)]
pub struct ConnectorTokenDetails {
/// The unique identifier of the connector account through which the token was generated
#[schema(value_type = String, example = "mca_")]
pub connector_id: id_type::MerchantConnectorAccountId,
#[schema(value_type = TokenizationType)]
pub token_type: common_enums::TokenizationType,
/// The status of connector token if it is active or inactive
#[schema(value_type = ConnectorTokenStatus)]
pub status: common_enums::ConnectorTokenStatus,
/// The reference id of the connector token
/// This is the reference that was passed to connector when creating the token
pub connector_token_request_reference_id: Option<String>,
pub original_payment_authorized_amount: Option<MinorUnit>,
/// The currency of the original payment authorized amount
#[schema(value_type = Currency)]
pub original_payment_authorized_currency: Option<common_enums::Currency>,
/// Metadata associated with the connector token
pub metadata: Option<pii::SecretSerdeValue>,
/// The value of the connector token. This token can be used to make merchant initiated payments ( MIT ), directly with the connector.
pub token: masking::Secret<String>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Serialize, serde::Deserialize, ToSchema, Clone)]
pub struct PaymentMethodResponse {
/// The unique identifier of the Payment method
#[schema(value_type = String, example = "12345_pm_01926c58bc6e77c09e809964e72af8c8")]
pub id: id_type::GlobalPaymentMethodId,
/// Unique identifier for a merchant
#[schema(value_type = String, example = "merchant_1671528864")]
pub merchant_id: id_type::MerchantId,
/// The unique identifier of the customer.
#[schema(
min_length = 32,
max_length = 64,
example = "12345_cus_01926c58bc6e77c09e809964e72af8c8",
value_type = String
)]
pub customer_id: id_type::GlobalCustomerId,
/// The type of payment method use for the payment.
#[schema(value_type = PaymentMethod, example = "card")]
pub payment_method_type: Option<api_enums::PaymentMethod>,
/// This is a sub-category of payment method.
#[schema(value_type = Option<PaymentMethodType>, example = "credit")]
pub payment_method_subtype: Option<api_enums::PaymentMethodType>,
/// Indicates whether the payment method is eligible for recurring payments
#[schema(example = true)]
pub recurring_enabled: bool,
/// A timestamp (ISO 8601 code) that determines when the payment method was created
#[schema(value_type = Option<PrimitiveDateTime>, example = "2023-01-18T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub created: Option<time::PrimitiveDateTime>,
/// A timestamp (ISO 8601 code) that determines when the payment method was last used
#[schema(value_type = Option<PrimitiveDateTime>, example = "2024-02-24T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub last_used_at: Option<time::PrimitiveDateTime>,
/// The payment method details related to the payment method
pub payment_method_data: Option<PaymentMethodResponseData>,
/// The connector token details if available
pub connector_tokens: Option<Vec<ConnectorTokenDetails>>,
pub network_token: Option<NetworkTokenResponse>,
}
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub enum PaymentMethodsData {
Card(CardDetailsPaymentMethod),
BankDetails(PaymentMethodDataBankCreds),
WalletDetails(PaymentMethodDataWalletInfo),
}
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct CardDetailsPaymentMethod {
pub last4_digits: Option<String>,
pub issuer_country: Option<String>,
pub expiry_month: Option<masking::Secret<String>>,
pub expiry_year: Option<masking::Secret<String>>,
pub nick_name: Option<masking::Secret<String>>,
pub card_holder_name: Option<masking::Secret<String>>,
pub card_isin: Option<String>,
pub card_issuer: Option<String>,
pub card_network: Option<api_enums::CardNetwork>,
pub card_type: Option<String>,
#[serde(default = "saved_in_locker_default")]
pub saved_to_locker: bool,
}
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct NetworkTokenDetailsPaymentMethod {
pub last4_digits: Option<String>,
pub issuer_country: Option<String>,
#[schema(value_type = Option<String>)]
pub network_token_expiry_month: Option<masking::Secret<String>>,
#[schema(value_type = Option<String>)]
pub network_token_expiry_year: Option<masking::Secret<String>>,
#[schema(value_type = Option<String>)]
pub nick_name: Option<masking::Secret<String>>,
#[schema(value_type = Option<String>)]
pub card_holder_name: Option<masking::Secret<String>>,
pub card_isin: Option<String>,
pub card_issuer: Option<String>,
#[schema(value_type = Option<CardNetwork>)]
pub card_network: Option<api_enums::CardNetwork>,
pub card_type: Option<String>,
#[serde(default = "saved_in_locker_default")]