Bug: [Patch]: make locker call sync to pupulate pm_id



Sample curl:
### `Payment Create` with confirm as true: 
```
curl --location 'http://127.0.0.1:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_vEXG9ROzIB0Mg0v43nHhIp7yA3zGl6XkiEKd5RekoXbUUiB9OIF4VRlBWYjdzToU' \
--data-raw '{
    "amount": 150,
    "currency": "USD",
    "confirm": true,
    "profile_id": "pro_QCRgQVCzV1nySudvYgIe",
    "capture_method": "automatic",
    "customer_id": "cus_1RzIEX1NgYo6fLeGjgtv",
    "amount_to_capture": 150,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "5555 5555 5555 4444",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "card_cvc": "737"
        }
    },
    "phone_country_code": "+65",
    "authentication_type": "three_ds",
    "description": "Its my first payment request",
    "return_url": "https://google.com",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "metadata": {
    },
            "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    },
    "setup_future_usage": "off_session"
}
'
``` 


Response should include pm_id
```
{
    "payment_id": "pay_yL8fXbw3pbRlJSRX4e7a",
    "merchant_id": "merchant_1711530541",
    "status": "requires_customer_action",
    "amount": 150,
    "net_amount": 150,
    "amount_capturable": 150,
    "amount_received": 0,
    "connector": "stripe",
    "client_secret": "pay_yL8fXbw3pbRlJSRX4e7a_secret_vwCOaRzAJMljn8SBDSm5",
    "created": "2024-04-03T12:33:58.442Z",
    "currency": "USD",
    "customer_id": "cus_1RzIEX1NgYo6fLeGjgtv",
    "customer": {
        "id": "cus_1RzIEX1NgYo6fLeGjgtv",
        "name": "John Doe",
        "email": "guest@example.com",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "off_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4444",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "555555",
            "card_extended_bin": "55555555",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": null,
    "order_details": null,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "three_ds",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "next_action": {
        "type": "redirect_to_url",
        "redirect_to_url": "http://localhost:8080/payments/redirect/pay_yL8fXbw3pbRlJSRX4e7a/merchant_1711530541/pay_yL8fXbw3pbRlJSRX4e7a_1"
    },
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": null,
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "cus_1RzIEX1NgYo6fLeGjgtv",
        "created_at": 1712147638,
        "expires": 1712151238,
        "secret": "epk_e4aed6ba27104cae922e7eca3abac9a1"
    },
    "manual_retry_allowed": null,
    "connector_transaction_id": "pi_3P1T0sCuXDMKrYZe0aiQy6I9",
    "frm_message": null,
    "metadata": {},
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3P1T0sCuXDMKrYZe0aiQy6I9",
    "payment_link": null,
    "profile_id": "pro_QCRgQVCzV1nySudvYgIe",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_fIdf9xGkZ1oFaetaZ3Gu",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-04-03T12:48:58.442Z",
    "fingerprint": null,
    "browser_info": null,
    **"payment_method_id": "pm_SCw1B5EgzNSOBf89mDd7",**
    "payment_method_status": null
}
```
diff --git a/crates/data_models/src/payments/payment_attempt.rs b/crates/data_models/src/payments/payment_attempt.rs
index 8984c1caeeb..6c236729de4 100644
--- a/crates/data_models/src/payments/payment_attempt.rs
+++ b/crates/data_models/src/payments/payment_attempt.rs
@@ -347,7 +347,7 @@ pub enum PaymentAttemptUpdate {
         connector: Option<String>,
         connector_transaction_id: Option<String>,
         authentication_type: Option<storage_enums::AuthenticationType>,
-        payment_method_id: Option<Option<String>>,
+        payment_method_id: Option<String>,
         mandate_id: Option<String>,
         connector_metadata: Option<serde_json::Value>,
         payment_token: Option<String>,
@@ -367,7 +367,7 @@ pub enum PaymentAttemptUpdate {
         status: storage_enums::AttemptStatus,
         connector: Option<String>,
         connector_transaction_id: Option<String>,
-        payment_method_id: Option<Option<String>>,
+        payment_method_id: Option<String>,
         error_code: Option<Option<String>>,
         error_message: Option<Option<String>>,
         error_reason: Option<Option<String>>,
@@ -403,7 +403,7 @@ pub enum PaymentAttemptUpdate {
     },
     PreprocessingUpdate {
         status: storage_enums::AttemptStatus,
-        payment_method_id: Option<Option<String>>,
+        payment_method_id: Option<String>,
         connector_metadata: Option<serde_json::Value>,
         preprocessing_step_id: Option<String>,
         connector_transaction_id: Option<String>,
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index 77fd21165d7..6ad21eab12b 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -254,7 +254,7 @@ pub enum PaymentAttemptUpdate {
         connector: Option<String>,
         connector_transaction_id: Option<String>,
         authentication_type: Option<storage_enums::AuthenticationType>,
-        payment_method_id: Option<Option<String>>,
+        payment_method_id: Option<String>,
         mandate_id: Option<String>,
         connector_metadata: Option<serde_json::Value>,
         payment_token: Option<String>,
@@ -274,7 +274,7 @@ pub enum PaymentAttemptUpdate {
         status: storage_enums::AttemptStatus,
         connector: Option<String>,
         connector_transaction_id: Option<String>,
-        payment_method_id: Option<Option<String>>,
+        payment_method_id: Option<String>,
         error_code: Option<Option<String>>,
         error_message: Option<Option<String>>,
         error_reason: Option<Option<String>>,
@@ -310,7 +310,7 @@ pub enum PaymentAttemptUpdate {
     },
     PreprocessingUpdate {
         status: storage_enums::AttemptStatus,
-        payment_method_id: Option<Option<String>>,
+        payment_method_id: Option<String>,
         connector_metadata: Option<serde_json::Value>,
         preprocessing_step_id: Option<String>,
         connector_transaction_id: Option<String>,
@@ -350,7 +350,7 @@ pub struct PaymentAttemptUpdateInternal {
     authentication_type: Option<storage_enums::AuthenticationType>,
     payment_method: Option<storage_enums::PaymentMethod>,
     error_message: Option<Option<String>>,
-    payment_method_id: Option<Option<String>>,
+    payment_method_id: Option<String>,
     cancellation_reason: Option<String>,
     modified_at: Option<PrimitiveDateTime>,
     mandate_id: Option<String>,
@@ -459,7 +459,7 @@ impl PaymentAttemptUpdate {
             authentication_type: authentication_type.or(source.authentication_type),
             payment_method: payment_method.or(source.payment_method),
             error_message: error_message.unwrap_or(source.error_message),
-            payment_method_id: payment_method_id.unwrap_or(source.payment_method_id),
+            payment_method_id: payment_method_id.or(source.payment_method_id),
             cancellation_reason: cancellation_reason.or(source.cancellation_reason),
             modified_at: common_utils::date_time::now(),
             mandate_id: mandate_id.or(source.mandate_id),
@@ -605,7 +605,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
                 authentication_id,
                 payment_method_billing_address_id,
                 fingerprint_id,
-                payment_method_id: payment_method_id.map(Some),
+                payment_method_id,
                 ..Default::default()
             },
             PaymentAttemptUpdate::VoidUpdate {
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 87c93af6635..e7ec99f61b6 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -2136,7 +2136,9 @@ where
                 )
                 .await?;
             payment_data.payment_method_data = payment_method_data;
-            payment_data.payment_attempt.payment_method_id = pm_id;
+            if let Some(payment_method_id) = pm_id {
+                payment_data.payment_attempt.payment_method_id = Some(payment_method_id);
+            }
             payment_data
         } else {
             payment_data
diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs
index bc43839fdcb..a5132e4a346 100644
--- a/crates/router/src/core/payments/flows/authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/authorize_flow.rs
@@ -1,7 +1,7 @@
 use async_trait::async_trait;
 use error_stack;
-use router_env::tracing::Instrument;
 
+// use router_env::tracing::Instrument;
 use super::{ConstructFlowSpecificData, Feature};
 use crate::{
     core::{
@@ -118,43 +118,65 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
                 )
                 .await?)
             } else {
-                let connector = connector.clone();
                 let response = resp.clone();
-                let maybe_customer = maybe_customer.clone();
-                let merchant_account = merchant_account.clone();
-                let key_store = key_store.clone();
-                let state = state.clone();
 
                 logger::info!("Call to save_payment_method in locker");
-                let _task_handle = tokio::spawn(
-                    async move {
-                        logger::info!("Starting async call to save_payment_method in locker");
-
-                        let result = Box::pin(tokenization::save_payment_method(
-                            &state,
-                            &connector,
-                            response,
-                            &maybe_customer,
-                            &merchant_account,
-                            self.request.payment_method_type,
-                            &key_store,
-                            Some(resp.request.amount),
-                            Some(resp.request.currency),
-                        ))
-                        .await;
-
-                        if let Err(err) = result {
-                            logger::error!(
-                                "Asynchronously saving card in locker failed : {:?}",
-                                err
-                            );
-                        }
+
+                let pm = Box::pin(tokenization::save_payment_method(
+                    state,
+                    connector,
+                    response,
+                    maybe_customer,
+                    merchant_account,
+                    self.request.payment_method_type,
+                    key_store,
+                    Some(resp.request.amount),
+                    Some(resp.request.currency),
+                ))
+                .await;
+
+                match pm {
+                    Ok((payment_method_id, payment_method_status)) => {
+                        resp.payment_method_id = payment_method_id.clone();
+                        resp.payment_method_status = payment_method_status;
                     }
-                    .in_current_span(),
-                );
+                    Err(_) => logger::error!("Save pm to locker failed"),
+                }
 
                 Ok(resp)
             }
+
+            // Async locker code (Commenting out the code for near future refactors)
+            //     logger::info!("Call to save_payment_method in locker");
+            //     let _task_handle = tokio::spawn(
+            //         async move {
+            //             logger::info!("Starting async call to save_payment_method in locker");
+            //
+            //             let result = Box::pin(tokenization::save_payment_method(
+            //                 &state,
+            //                 &connector,
+            //                 response,
+            //                 &maybe_customer,
+            //                 &merchant_account,
+            //                 self.request.payment_method_type,
+            //                 &key_store,
+            //                 Some(resp.request.amount),
+            //                 Some(resp.request.currency),
+            //             ))
+            //             .await;
+            //
+            //             if let Err(err) = result {
+            //                 logger::error!(
+            //                     "Asynchronously saving card in locker failed : {:?}",
+            //                     err
+            //                 );
+            //             }
+            //         }
+            //         .in_current_span(),
+            //     );
+            //
+            //     Ok(resp)
+            // }
         } else {
             Ok(self.clone())
         }
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 6cb19a29a1d..66f35e63b2c 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -587,7 +587,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
                     let payment_attempt_update =
                         storage::PaymentAttemptUpdate::PreprocessingUpdate {
                             status: updated_attempt_status,
-                            payment_method_id: Some(router_data.payment_method_id),
+                            payment_method_id: router_data.payment_method_id,
                             connector_metadata,
                             preprocessing_step_id,
                             connector_transaction_id,
@@ -676,7 +676,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
                                 amount_capturable: router_data
                                     .request
                                     .get_amount_capturable(&payment_data, updated_attempt_status),
-                                payment_method_id: Some(payment_method_id),
+                                payment_method_id,
                                 mandate_id: payment_data
                                     .mandate_id
                                     .clone()
@@ -715,7 +715,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
                             status: updated_attempt_status,
                             connector: None,
                             connector_transaction_id,
-                            payment_method_id: Some(router_data.payment_method_id),
+                            payment_method_id: router_data.payment_method_id,
                             error_code: Some(reason.clone().map(|cd| cd.code)),
                             error_message: Some(reason.clone().map(|cd| cd.message)),
                             error_reason: Some(reason.map(|cd| cd.message)),
diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs
index 09400bb750b..3eeecdba3a8 100644
--- a/crates/router/src/core/payments/retry.rs
+++ b/crates/router/src/core/payments/retry.rs
@@ -376,7 +376,7 @@ where
                         .connector_response_reference_id
                         .clone(),
                     authentication_type: None,
-                    payment_method_id: Some(router_data.payment_method_id),
+                    payment_method_id: router_data.payment_method_id,
                     mandate_id: payment_data
                         .mandate_id
                         .clone()

## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [ ] New feature
- [ ] Enhancement
- [x] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->
Making the locker call synchronous in order to update pm_id in payment response.

### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->


## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->
Sample curl:
### `Payment Create` with confirm as true: 
```
curl --location 'http://127.0.0.1:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_vEXG9ROzIB0Mg0v43nHhIp7yA3zGl6XkiEKd5RekoXbUUiB9OIF4VRlBWYjdzToU' \
--data-raw '{
    "amount": 150,
    "currency": "USD",
    "confirm": true,
    "profile_id": "pro_QCRgQVCzV1nySudvYgIe",
    "capture_method": "automatic",
    "customer_id": "cus_1RzIEX1NgYo6fLeGjgtv",
    "amount_to_capture": 150,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "5555 5555 5555 4444",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "card_cvc": "737"
        }
    },
    "phone_country_code": "+65",
    "authentication_type": "three_ds",
    "description": "Its my first payment request",
    "return_url": "https://google.com",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "metadata": {
    },
            "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    },
    "setup_future_usage": "off_session"
}
'
``` 


Response should include pm_id
```
{
    "payment_id": "pay_yL8fXbw3pbRlJSRX4e7a",
    "merchant_id": "merchant_1711530541",
    "status": "requires_customer_action",
    "amount": 150,
    "net_amount": 150,
    "amount_capturable": 150,
    "amount_received": 0,
    "connector": "stripe",
    "client_secret": "pay_yL8fXbw3pbRlJSRX4e7a_secret_vwCOaRzAJMljn8SBDSm5",
    "created": "2024-04-03T12:33:58.442Z",
    "currency": "USD",
    "customer_id": "cus_1RzIEX1NgYo6fLeGjgtv",
    "customer": {
        "id": "cus_1RzIEX1NgYo6fLeGjgtv",
        "name": "John Doe",
        "email": "guest@example.com",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "off_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4444",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "555555",
            "card_extended_bin": "55555555",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": null,
    "order_details": null,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "three_ds",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "next_action": {
        "type": "redirect_to_url",
        "redirect_to_url": "http://localhost:8080/payments/redirect/pay_yL8fXbw3pbRlJSRX4e7a/merchant_1711530541/pay_yL8fXbw3pbRlJSRX4e7a_1"
    },
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": null,
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "cus_1RzIEX1NgYo6fLeGjgtv",
        "created_at": 1712147638,
        "expires": 1712151238,
        "secret": "epk_e4aed6ba27104cae922e7eca3abac9a1"
    },
    "manual_retry_allowed": null,
    "connector_transaction_id": "pi_3P1T0sCuXDMKrYZe0aiQy6I9",
    "frm_message": null,
    "metadata": {},
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3P1T0sCuXDMKrYZe0aiQy6I9",
    "payment_link": null,
    "profile_id": "pro_QCRgQVCzV1nySudvYgIe",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_fIdf9xGkZ1oFaetaZ3Gu",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-04-03T12:48:58.442Z",
    "fingerprint": null,
    "browser_info": null,
    **"payment_method_id": "pm_SCw1B5EgzNSOBf89mDd7",**
    "payment_method_status": null
}
```

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [ ] I formatted the code `cargo +nightly fmt --all`
- [ ] I addressed lints thrown by `cargo clippy`
- [ ] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
- [ ] I added a [CHANGELOG](/CHANGELOG.md) entry if applicable
