diff --git a/crates/data_models/src/payments/payment_attempt.rs b/crates/data_models/src/payments/payment_attempt.rs index 8984c1caeeb0..6c236729de44 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, connector_transaction_id: Option, authentication_type: Option, - payment_method_id: Option>, + payment_method_id: Option, mandate_id: Option, connector_metadata: Option, payment_token: Option, @@ -367,7 +367,7 @@ pub enum PaymentAttemptUpdate { status: storage_enums::AttemptStatus, connector: Option, connector_transaction_id: Option, - payment_method_id: Option>, + payment_method_id: Option, error_code: Option>, error_message: Option>, error_reason: Option>, @@ -403,7 +403,7 @@ pub enum PaymentAttemptUpdate { }, PreprocessingUpdate { status: storage_enums::AttemptStatus, - payment_method_id: Option>, + payment_method_id: Option, connector_metadata: Option, preprocessing_step_id: Option, connector_transaction_id: Option, diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 77fd21165d7a..6ad21eab12bc 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, connector_transaction_id: Option, authentication_type: Option, - payment_method_id: Option>, + payment_method_id: Option, mandate_id: Option, connector_metadata: Option, payment_token: Option, @@ -274,7 +274,7 @@ pub enum PaymentAttemptUpdate { status: storage_enums::AttemptStatus, connector: Option, connector_transaction_id: Option, - payment_method_id: Option>, + payment_method_id: Option, error_code: Option>, error_message: Option>, error_reason: Option>, @@ -310,7 +310,7 @@ pub enum PaymentAttemptUpdate { }, PreprocessingUpdate { status: storage_enums::AttemptStatus, - payment_method_id: Option>, + payment_method_id: Option, connector_metadata: Option, preprocessing_step_id: Option, connector_transaction_id: Option, @@ -350,7 +350,7 @@ pub struct PaymentAttemptUpdateInternal { authentication_type: Option, payment_method: Option, error_message: Option>, - payment_method_id: Option>, + payment_method_id: Option, cancellation_reason: Option, modified_at: Option, mandate_id: Option, @@ -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 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 87c93af6635a..e7ec99f61b62 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 bc43839fdcb2..a5132e4a3464 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 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 6cb19a29a1d5..66f35e63b2cb 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( 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( 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( 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 09400bb750b1..3eeecdba3a89 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()