Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(core): locker call made synchronous for updation of pm_id (#4289)
Prajjwal Kumar6e94a5636462
diff --git a/crates/data_models/src/payments/payment_attempt.rs b/crates/data_models/src/payments/payment_attempt.rsindex 8984c1caee..6c236729de 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.rsindex 77fd21165d..6ad21eab12 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.rsindex 87c93af663..e7ec99f61b 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_datadiff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rsindex bc43839fdc..a5132e4a34 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.rsindex 6cb19a29a1..66f35e63b2 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.rsindex 09400bb750..3eeecdba3a 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()