@@ -221,8 +221,6 @@ pub async fn create_or_update_address_for_payment_by_request(
221
221
None => match req_address {
222
222
Some ( address) => {
223
223
// generate a new address here
224
- let customer_id = customer_id. get_required_value ( "customer_id" ) ?;
225
-
226
224
let address_details = address. address . clone ( ) . unwrap_or_default ( ) ;
227
225
Some (
228
226
db. insert_address_for_payments (
@@ -282,7 +280,6 @@ pub async fn create_or_find_address_for_payment_by_request(
282
280
None => match req_address {
283
281
Some ( address) => {
284
282
// generate a new address here
285
- let customer_id = customer_id. get_required_value ( "customer_id" ) ?;
286
283
287
284
let address_details = address. address . clone ( ) . unwrap_or_default ( ) ;
288
285
Some (
@@ -317,7 +314,7 @@ pub async fn get_domain_address_for_payments(
317
314
address_details : api_models:: payments:: AddressDetails ,
318
315
address : & api_models:: payments:: Address ,
319
316
merchant_id : & str ,
320
- customer_id : & str ,
317
+ customer_id : Option < & String > ,
321
318
payment_id : & str ,
322
319
key : & [ u8 ] ,
323
320
storage_scheme : enums:: MerchantStorageScheme ,
@@ -332,7 +329,7 @@ pub async fn get_domain_address_for_payments(
332
329
. async_lift ( |inner| types:: encrypt_optional ( inner, key) )
333
330
. await ?,
334
331
country_code : address. phone . as_ref ( ) . and_then ( |a| a. country_code . clone ( ) ) ,
335
- customer_id : customer_id. to_string ( ) ,
332
+ customer_id : customer_id. cloned ( ) ,
336
333
merchant_id : merchant_id. to_string ( ) ,
337
334
address_id : generate_id ( consts:: ID_LENGTH , "add" ) ,
338
335
city : address_details. city ,
@@ -763,25 +760,14 @@ fn validate_new_mandate_request(
763
760
}
764
761
765
762
pub fn validate_customer_id_mandatory_cases (
766
- has_shipping : bool ,
767
- has_billing : bool ,
768
763
has_setup_future_usage : bool ,
769
764
customer_id : & Option < String > ,
770
765
) -> RouterResult < ( ) > {
771
- match (
772
- has_shipping,
773
- has_billing,
774
- has_setup_future_usage,
775
- customer_id,
776
- ) {
777
- ( true , _, _, None ) | ( _, true , _, None ) | ( _, _, true , None ) => {
778
- Err ( errors:: ApiErrorResponse :: PreconditionFailed {
779
- message : "customer_id is mandatory when shipping or billing \
780
- address is given or when setup_future_usage is given"
781
- . to_string ( ) ,
782
- } )
783
- . into_report ( )
784
- }
766
+ match ( has_setup_future_usage, customer_id) {
767
+ ( true , None ) => Err ( errors:: ApiErrorResponse :: PreconditionFailed {
768
+ message : "customer_id is mandatory when setup_future_usage is given" . to_string ( ) ,
769
+ } )
770
+ . into_report ( ) ,
785
771
_ => Ok ( ( ) ) ,
786
772
}
787
773
}
0 commit comments