@@ -56,7 +56,7 @@ pub struct Customer {
56
56
pub description : Option < Description > ,
57
57
pub created_at : PrimitiveDateTime ,
58
58
pub metadata : Option < pii:: SecretSerdeValue > ,
59
- pub connector_customer : Option < pii :: SecretSerdeValue > ,
59
+ pub connector_customer : Option < diesel_models :: ConnectorCustomerMap > ,
60
60
pub modified_at : PrimitiveDateTime ,
61
61
pub default_payment_method_id : Option < id_type:: GlobalPaymentMethodId > ,
62
62
pub updated_by : Option < String > ,
@@ -80,6 +80,31 @@ impl Customer {
80
80
pub fn get_id ( & self ) -> & id_type:: GlobalCustomerId {
81
81
& self . id
82
82
}
83
+
84
+ /// Get the connector customer ID for the specified connector label, if present
85
+ #[ cfg( all( any( feature = "v1" , feature = "v2" ) , not( feature = "customer_v2" ) ) ) ]
86
+ pub fn get_connector_customer_id ( & self , connector_label : & str ) -> Option < & str > {
87
+ use masking:: PeekInterface ;
88
+
89
+ self . connector_customer
90
+ . as_ref ( )
91
+ . and_then ( |connector_customer_value| {
92
+ connector_customer_value. peek ( ) . get ( connector_label)
93
+ } )
94
+ . and_then ( |connector_customer| connector_customer. as_str ( ) )
95
+ }
96
+
97
+ /// Get the connector customer ID for the specified merchant connector account ID, if present
98
+ #[ cfg( all( feature = "v2" , feature = "customer_v2" ) ) ]
99
+ pub fn get_connector_customer_id (
100
+ & self ,
101
+ merchant_connector_id : & id_type:: MerchantConnectorAccountId ,
102
+ ) -> Option < & str > {
103
+ self . connector_customer
104
+ . as_ref ( )
105
+ . and_then ( |connector_customer_map| connector_customer_map. get ( merchant_connector_id) )
106
+ . map ( |connector_customer_id| connector_customer_id. as_str ( ) )
107
+ }
83
108
}
84
109
85
110
#[ cfg( all( any( feature = "v1" , feature = "v2" ) , not( feature = "customer_v2" ) ) ) ]
@@ -300,24 +325,28 @@ impl super::behaviour::Conversion for Customer {
300
325
}
301
326
}
302
327
328
+ #[ cfg( all( feature = "v2" , feature = "customer_v2" ) ) ]
329
+ #[ derive( Clone , Debug ) ]
330
+ pub struct CustomerGeneralUpdate {
331
+ pub name : crypto:: OptionalEncryptableName ,
332
+ pub email : Box < crypto:: OptionalEncryptableEmail > ,
333
+ pub phone : Box < crypto:: OptionalEncryptablePhone > ,
334
+ pub description : Option < Description > ,
335
+ pub phone_country_code : Option < String > ,
336
+ pub metadata : Option < pii:: SecretSerdeValue > ,
337
+ pub connector_customer : Box < Option < diesel_models:: ConnectorCustomerMap > > ,
338
+ pub default_billing_address : Option < Encryption > ,
339
+ pub default_shipping_address : Option < Encryption > ,
340
+ pub default_payment_method_id : Option < Option < id_type:: GlobalPaymentMethodId > > ,
341
+ pub status : Option < DeleteStatus > ,
342
+ }
343
+
303
344
#[ cfg( all( feature = "v2" , feature = "customer_v2" ) ) ]
304
345
#[ derive( Clone , Debug ) ]
305
346
pub enum CustomerUpdate {
306
- Update {
307
- name : crypto:: OptionalEncryptableName ,
308
- email : Box < crypto:: OptionalEncryptableEmail > ,
309
- phone : Box < crypto:: OptionalEncryptablePhone > ,
310
- description : Option < Description > ,
311
- phone_country_code : Option < String > ,
312
- metadata : Option < pii:: SecretSerdeValue > ,
313
- connector_customer : Box < Option < pii:: SecretSerdeValue > > ,
314
- default_billing_address : Option < Encryption > ,
315
- default_shipping_address : Option < Encryption > ,
316
- default_payment_method_id : Option < Option < id_type:: GlobalPaymentMethodId > > ,
317
- status : Option < DeleteStatus > ,
318
- } ,
347
+ Update ( Box < CustomerGeneralUpdate > ) ,
319
348
ConnectorCustomer {
320
- connector_customer : Option < pii :: SecretSerdeValue > ,
349
+ connector_customer : Option < diesel_models :: ConnectorCustomerMap > ,
321
350
} ,
322
351
UpdateDefaultPaymentMethod {
323
352
default_payment_method_id : Option < Option < id_type:: GlobalPaymentMethodId > > ,
@@ -328,33 +357,36 @@ pub enum CustomerUpdate {
328
357
impl From < CustomerUpdate > for CustomerUpdateInternal {
329
358
fn from ( customer_update : CustomerUpdate ) -> Self {
330
359
match customer_update {
331
- CustomerUpdate :: Update {
332
- name,
333
- email,
334
- phone,
335
- description,
336
- phone_country_code,
337
- metadata,
338
- connector_customer,
339
- default_billing_address,
340
- default_shipping_address,
341
- default_payment_method_id,
342
- status,
343
- } => Self {
344
- name : name. map ( Encryption :: from) ,
345
- email : email. map ( Encryption :: from) ,
346
- phone : phone. map ( Encryption :: from) ,
347
- description,
348
- phone_country_code,
349
- metadata,
350
- connector_customer : * connector_customer,
351
- modified_at : date_time:: now ( ) ,
352
- default_billing_address,
353
- default_shipping_address,
354
- default_payment_method_id,
355
- updated_by : None ,
356
- status,
357
- } ,
360
+ CustomerUpdate :: Update ( update) => {
361
+ let CustomerGeneralUpdate {
362
+ name,
363
+ email,
364
+ phone,
365
+ description,
366
+ phone_country_code,
367
+ metadata,
368
+ connector_customer,
369
+ default_billing_address,
370
+ default_shipping_address,
371
+ default_payment_method_id,
372
+ status,
373
+ } = * update;
374
+ Self {
375
+ name : name. map ( Encryption :: from) ,
376
+ email : email. map ( Encryption :: from) ,
377
+ phone : phone. map ( Encryption :: from) ,
378
+ description,
379
+ phone_country_code,
380
+ metadata,
381
+ connector_customer : * connector_customer,
382
+ modified_at : date_time:: now ( ) ,
383
+ default_billing_address,
384
+ default_shipping_address,
385
+ default_payment_method_id,
386
+ updated_by : None ,
387
+ status,
388
+ }
389
+ }
358
390
CustomerUpdate :: ConnectorCustomer { connector_customer } => Self {
359
391
connector_customer,
360
392
name : None ,
0 commit comments