mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
refactor(core): locker call made synchronous for updation of pm_id (#4289)
Co-authored-by: Narayan Bhat <narayan.bhat@juspay.in>
This commit is contained in:
@ -347,7 +347,7 @@ pub enum PaymentAttemptUpdate {
|
|||||||
connector: Option<String>,
|
connector: Option<String>,
|
||||||
connector_transaction_id: Option<String>,
|
connector_transaction_id: Option<String>,
|
||||||
authentication_type: Option<storage_enums::AuthenticationType>,
|
authentication_type: Option<storage_enums::AuthenticationType>,
|
||||||
payment_method_id: Option<Option<String>>,
|
payment_method_id: Option<String>,
|
||||||
mandate_id: Option<String>,
|
mandate_id: Option<String>,
|
||||||
connector_metadata: Option<serde_json::Value>,
|
connector_metadata: Option<serde_json::Value>,
|
||||||
payment_token: Option<String>,
|
payment_token: Option<String>,
|
||||||
@ -367,7 +367,7 @@ pub enum PaymentAttemptUpdate {
|
|||||||
status: storage_enums::AttemptStatus,
|
status: storage_enums::AttemptStatus,
|
||||||
connector: Option<String>,
|
connector: Option<String>,
|
||||||
connector_transaction_id: Option<String>,
|
connector_transaction_id: Option<String>,
|
||||||
payment_method_id: Option<Option<String>>,
|
payment_method_id: Option<String>,
|
||||||
error_code: Option<Option<String>>,
|
error_code: Option<Option<String>>,
|
||||||
error_message: Option<Option<String>>,
|
error_message: Option<Option<String>>,
|
||||||
error_reason: Option<Option<String>>,
|
error_reason: Option<Option<String>>,
|
||||||
@ -403,7 +403,7 @@ pub enum PaymentAttemptUpdate {
|
|||||||
},
|
},
|
||||||
PreprocessingUpdate {
|
PreprocessingUpdate {
|
||||||
status: storage_enums::AttemptStatus,
|
status: storage_enums::AttemptStatus,
|
||||||
payment_method_id: Option<Option<String>>,
|
payment_method_id: Option<String>,
|
||||||
connector_metadata: Option<serde_json::Value>,
|
connector_metadata: Option<serde_json::Value>,
|
||||||
preprocessing_step_id: Option<String>,
|
preprocessing_step_id: Option<String>,
|
||||||
connector_transaction_id: Option<String>,
|
connector_transaction_id: Option<String>,
|
||||||
|
|||||||
@ -254,7 +254,7 @@ pub enum PaymentAttemptUpdate {
|
|||||||
connector: Option<String>,
|
connector: Option<String>,
|
||||||
connector_transaction_id: Option<String>,
|
connector_transaction_id: Option<String>,
|
||||||
authentication_type: Option<storage_enums::AuthenticationType>,
|
authentication_type: Option<storage_enums::AuthenticationType>,
|
||||||
payment_method_id: Option<Option<String>>,
|
payment_method_id: Option<String>,
|
||||||
mandate_id: Option<String>,
|
mandate_id: Option<String>,
|
||||||
connector_metadata: Option<serde_json::Value>,
|
connector_metadata: Option<serde_json::Value>,
|
||||||
payment_token: Option<String>,
|
payment_token: Option<String>,
|
||||||
@ -274,7 +274,7 @@ pub enum PaymentAttemptUpdate {
|
|||||||
status: storage_enums::AttemptStatus,
|
status: storage_enums::AttemptStatus,
|
||||||
connector: Option<String>,
|
connector: Option<String>,
|
||||||
connector_transaction_id: Option<String>,
|
connector_transaction_id: Option<String>,
|
||||||
payment_method_id: Option<Option<String>>,
|
payment_method_id: Option<String>,
|
||||||
error_code: Option<Option<String>>,
|
error_code: Option<Option<String>>,
|
||||||
error_message: Option<Option<String>>,
|
error_message: Option<Option<String>>,
|
||||||
error_reason: Option<Option<String>>,
|
error_reason: Option<Option<String>>,
|
||||||
@ -310,7 +310,7 @@ pub enum PaymentAttemptUpdate {
|
|||||||
},
|
},
|
||||||
PreprocessingUpdate {
|
PreprocessingUpdate {
|
||||||
status: storage_enums::AttemptStatus,
|
status: storage_enums::AttemptStatus,
|
||||||
payment_method_id: Option<Option<String>>,
|
payment_method_id: Option<String>,
|
||||||
connector_metadata: Option<serde_json::Value>,
|
connector_metadata: Option<serde_json::Value>,
|
||||||
preprocessing_step_id: Option<String>,
|
preprocessing_step_id: Option<String>,
|
||||||
connector_transaction_id: Option<String>,
|
connector_transaction_id: Option<String>,
|
||||||
@ -350,7 +350,7 @@ pub struct PaymentAttemptUpdateInternal {
|
|||||||
authentication_type: Option<storage_enums::AuthenticationType>,
|
authentication_type: Option<storage_enums::AuthenticationType>,
|
||||||
payment_method: Option<storage_enums::PaymentMethod>,
|
payment_method: Option<storage_enums::PaymentMethod>,
|
||||||
error_message: Option<Option<String>>,
|
error_message: Option<Option<String>>,
|
||||||
payment_method_id: Option<Option<String>>,
|
payment_method_id: Option<String>,
|
||||||
cancellation_reason: Option<String>,
|
cancellation_reason: Option<String>,
|
||||||
modified_at: Option<PrimitiveDateTime>,
|
modified_at: Option<PrimitiveDateTime>,
|
||||||
mandate_id: Option<String>,
|
mandate_id: Option<String>,
|
||||||
@ -459,7 +459,7 @@ impl PaymentAttemptUpdate {
|
|||||||
authentication_type: authentication_type.or(source.authentication_type),
|
authentication_type: authentication_type.or(source.authentication_type),
|
||||||
payment_method: payment_method.or(source.payment_method),
|
payment_method: payment_method.or(source.payment_method),
|
||||||
error_message: error_message.unwrap_or(source.error_message),
|
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),
|
cancellation_reason: cancellation_reason.or(source.cancellation_reason),
|
||||||
modified_at: common_utils::date_time::now(),
|
modified_at: common_utils::date_time::now(),
|
||||||
mandate_id: mandate_id.or(source.mandate_id),
|
mandate_id: mandate_id.or(source.mandate_id),
|
||||||
@ -605,7 +605,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
|
|||||||
authentication_id,
|
authentication_id,
|
||||||
payment_method_billing_address_id,
|
payment_method_billing_address_id,
|
||||||
fingerprint_id,
|
fingerprint_id,
|
||||||
payment_method_id: payment_method_id.map(Some),
|
payment_method_id,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
PaymentAttemptUpdate::VoidUpdate {
|
PaymentAttemptUpdate::VoidUpdate {
|
||||||
|
|||||||
@ -2136,7 +2136,9 @@ where
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
payment_data.payment_method_data = payment_method_data;
|
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
|
payment_data
|
||||||
} else {
|
} else {
|
||||||
payment_data
|
payment_data
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use error_stack;
|
use error_stack;
|
||||||
use router_env::tracing::Instrument;
|
|
||||||
|
|
||||||
|
// use router_env::tracing::Instrument;
|
||||||
use super::{ConstructFlowSpecificData, Feature};
|
use super::{ConstructFlowSpecificData, Feature};
|
||||||
use crate::{
|
use crate::{
|
||||||
core::{
|
core::{
|
||||||
@ -118,43 +118,65 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
|
|||||||
)
|
)
|
||||||
.await?)
|
.await?)
|
||||||
} else {
|
} else {
|
||||||
let connector = connector.clone();
|
|
||||||
let response = resp.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");
|
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(
|
let pm = Box::pin(tokenization::save_payment_method(
|
||||||
&state,
|
state,
|
||||||
&connector,
|
connector,
|
||||||
response,
|
response,
|
||||||
&maybe_customer,
|
maybe_customer,
|
||||||
&merchant_account,
|
merchant_account,
|
||||||
self.request.payment_method_type,
|
self.request.payment_method_type,
|
||||||
&key_store,
|
key_store,
|
||||||
Some(resp.request.amount),
|
Some(resp.request.amount),
|
||||||
Some(resp.request.currency),
|
Some(resp.request.currency),
|
||||||
))
|
))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Err(err) = result {
|
match pm {
|
||||||
logger::error!(
|
Ok((payment_method_id, payment_method_status)) => {
|
||||||
"Asynchronously saving card in locker failed : {:?}",
|
resp.payment_method_id = payment_method_id.clone();
|
||||||
err
|
resp.payment_method_status = payment_method_status;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
Err(_) => logger::error!("Save pm to locker failed"),
|
||||||
}
|
}
|
||||||
.in_current_span(),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(resp)
|
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 {
|
} else {
|
||||||
Ok(self.clone())
|
Ok(self.clone())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -587,7 +587,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
|
|||||||
let payment_attempt_update =
|
let payment_attempt_update =
|
||||||
storage::PaymentAttemptUpdate::PreprocessingUpdate {
|
storage::PaymentAttemptUpdate::PreprocessingUpdate {
|
||||||
status: updated_attempt_status,
|
status: updated_attempt_status,
|
||||||
payment_method_id: Some(router_data.payment_method_id),
|
payment_method_id: router_data.payment_method_id,
|
||||||
connector_metadata,
|
connector_metadata,
|
||||||
preprocessing_step_id,
|
preprocessing_step_id,
|
||||||
connector_transaction_id,
|
connector_transaction_id,
|
||||||
@ -676,7 +676,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
|
|||||||
amount_capturable: router_data
|
amount_capturable: router_data
|
||||||
.request
|
.request
|
||||||
.get_amount_capturable(&payment_data, updated_attempt_status),
|
.get_amount_capturable(&payment_data, updated_attempt_status),
|
||||||
payment_method_id: Some(payment_method_id),
|
payment_method_id,
|
||||||
mandate_id: payment_data
|
mandate_id: payment_data
|
||||||
.mandate_id
|
.mandate_id
|
||||||
.clone()
|
.clone()
|
||||||
@ -715,7 +715,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
|
|||||||
status: updated_attempt_status,
|
status: updated_attempt_status,
|
||||||
connector: None,
|
connector: None,
|
||||||
connector_transaction_id,
|
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_code: Some(reason.clone().map(|cd| cd.code)),
|
||||||
error_message: Some(reason.clone().map(|cd| cd.message)),
|
error_message: Some(reason.clone().map(|cd| cd.message)),
|
||||||
error_reason: Some(reason.map(|cd| cd.message)),
|
error_reason: Some(reason.map(|cd| cd.message)),
|
||||||
|
|||||||
@ -376,7 +376,7 @@ where
|
|||||||
.connector_response_reference_id
|
.connector_response_reference_id
|
||||||
.clone(),
|
.clone(),
|
||||||
authentication_type: None,
|
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: payment_data
|
||||||
.mandate_id
|
.mandate_id
|
||||||
.clone()
|
.clone()
|
||||||
|
|||||||
Reference in New Issue
Block a user