mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
refactor(core): authenticate client secret with fulfilment time (#2026)
This commit is contained in:
@ -24,7 +24,6 @@ pub use self::operations::{
|
|||||||
};
|
};
|
||||||
use self::{
|
use self::{
|
||||||
flows::{ConstructFlowSpecificData, Feature},
|
flows::{ConstructFlowSpecificData, Feature},
|
||||||
helpers::authenticate_client_secret,
|
|
||||||
operations::{payment_complete_authorize, BoxedOperation, Operation},
|
operations::{payment_complete_authorize, BoxedOperation, Operation},
|
||||||
};
|
};
|
||||||
use super::errors::StorageErrorExt;
|
use super::errors::StorageErrorExt;
|
||||||
@ -91,12 +90,6 @@ where
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
authenticate_client_secret(
|
|
||||||
req.get_client_secret(),
|
|
||||||
&payment_data.payment_intent,
|
|
||||||
merchant_account.intent_fulfillment_time,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let (operation, customer) = operation
|
let (operation, customer) = operation
|
||||||
.to_domain()?
|
.to_domain()?
|
||||||
.get_or_create_customer_details(
|
.get_or_create_customer_details(
|
||||||
|
|||||||
@ -75,6 +75,11 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
|||||||
"confirm",
|
"confirm",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
helpers::authenticate_client_secret(
|
||||||
|
request.client_secret.as_ref(),
|
||||||
|
&payment_intent,
|
||||||
|
merchant_account.intent_fulfillment_time,
|
||||||
|
)?;
|
||||||
payment_attempt = db
|
payment_attempt = db
|
||||||
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
|
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
|
||||||
payment_intent.payment_id.as_str(),
|
payment_intent.payment_id.as_str(),
|
||||||
|
|||||||
@ -69,6 +69,11 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsSessionRequest>
|
|||||||
"create a session token for",
|
"create a session token for",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
helpers::authenticate_client_secret(
|
||||||
|
Some(&request.client_secret),
|
||||||
|
&payment_intent,
|
||||||
|
merchant_account.intent_fulfillment_time,
|
||||||
|
)?;
|
||||||
let mut payment_attempt = db
|
let mut payment_attempt = db
|
||||||
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
|
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
|
||||||
payment_intent.payment_id.as_str(),
|
payment_intent.payment_id.as_str(),
|
||||||
|
|||||||
@ -67,6 +67,11 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsStartRequest> f
|
|||||||
"update",
|
"update",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
helpers::authenticate_client_secret(
|
||||||
|
payment_intent.client_secret.as_ref(),
|
||||||
|
&payment_intent,
|
||||||
|
merchant_account.intent_fulfillment_time,
|
||||||
|
)?;
|
||||||
payment_attempt = db
|
payment_attempt = db
|
||||||
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
|
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
|
||||||
payment_intent.payment_id.as_str(),
|
payment_intent.payment_id.as_str(),
|
||||||
|
|||||||
@ -175,7 +175,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRetrieveRequest
|
|||||||
)> {
|
)> {
|
||||||
get_tracker_for_sync(
|
get_tracker_for_sync(
|
||||||
payment_id,
|
payment_id,
|
||||||
&merchant_account.merchant_id,
|
merchant_account,
|
||||||
key_store,
|
key_store,
|
||||||
&*state.store,
|
&*state.store,
|
||||||
request,
|
request,
|
||||||
@ -192,7 +192,7 @@ async fn get_tracker_for_sync<
|
|||||||
Op: Operation<F, api::PaymentsRetrieveRequest> + 'a + Send + Sync,
|
Op: Operation<F, api::PaymentsRetrieveRequest> + 'a + Send + Sync,
|
||||||
>(
|
>(
|
||||||
payment_id: &api::PaymentIdType,
|
payment_id: &api::PaymentIdType,
|
||||||
merchant_id: &str,
|
merchant_account: &domain::MerchantAccount,
|
||||||
mechant_key_store: &domain::MerchantKeyStore,
|
mechant_key_store: &domain::MerchantKeyStore,
|
||||||
db: &dyn StorageInterface,
|
db: &dyn StorageInterface,
|
||||||
request: &api::PaymentsRetrieveRequest,
|
request: &api::PaymentsRetrieveRequest,
|
||||||
@ -205,9 +205,19 @@ async fn get_tracker_for_sync<
|
|||||||
)> {
|
)> {
|
||||||
let (payment_intent, payment_attempt, currency, amount);
|
let (payment_intent, payment_attempt, currency, amount);
|
||||||
|
|
||||||
(payment_intent, payment_attempt) =
|
(payment_intent, payment_attempt) = get_payment_intent_payment_attempt(
|
||||||
get_payment_intent_payment_attempt(db, payment_id, merchant_id, storage_scheme).await?;
|
db,
|
||||||
|
payment_id,
|
||||||
|
&merchant_account.merchant_id,
|
||||||
|
storage_scheme,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
helpers::authenticate_client_secret(
|
||||||
|
request.client_secret.as_ref(),
|
||||||
|
&payment_intent,
|
||||||
|
merchant_account.intent_fulfillment_time,
|
||||||
|
)?;
|
||||||
let payment_id_str = payment_attempt.payment_id.clone();
|
let payment_id_str = payment_attempt.payment_id.clone();
|
||||||
|
|
||||||
let mut connector_response = db
|
let mut connector_response = db
|
||||||
@ -241,11 +251,11 @@ async fn get_tracker_for_sync<
|
|||||||
let attempts = match request.expand_attempts {
|
let attempts = match request.expand_attempts {
|
||||||
Some(true) => {
|
Some(true) => {
|
||||||
Some(db
|
Some(db
|
||||||
.find_attempts_by_merchant_id_payment_id(merchant_id, &payment_id_str, storage_scheme)
|
.find_attempts_by_merchant_id_payment_id(&merchant_account.merchant_id, &payment_id_str, storage_scheme)
|
||||||
.await
|
.await
|
||||||
.change_context(errors::ApiErrorResponse::PaymentNotFound)
|
.change_context(errors::ApiErrorResponse::PaymentNotFound)
|
||||||
.attach_printable_lazy(|| {
|
.attach_printable_lazy(|| {
|
||||||
format!("Error while retrieving attempt list for, merchant_id: {merchant_id}, payment_id: {payment_id_str}")
|
format!("Error while retrieving attempt list for, merchant_id: {}, payment_id: {payment_id_str}",&merchant_account.merchant_id)
|
||||||
})?)
|
})?)
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
@ -262,7 +272,7 @@ async fn get_tracker_for_sync<
|
|||||||
.await
|
.await
|
||||||
.change_context(errors::ApiErrorResponse::PaymentNotFound)
|
.change_context(errors::ApiErrorResponse::PaymentNotFound)
|
||||||
.attach_printable_lazy(|| {
|
.attach_printable_lazy(|| {
|
||||||
format!("Error while retrieving capture list for, merchant_id: {merchant_id}, payment_id: {payment_id_str}")
|
format!("Error while retrieving capture list for, merchant_id: {}, payment_id: {payment_id_str}", merchant_account.merchant_id)
|
||||||
})?;
|
})?;
|
||||||
Some(types::MultipleCaptureData::new_for_sync(captures)?)
|
Some(types::MultipleCaptureData::new_for_sync(captures)?)
|
||||||
} else {
|
} else {
|
||||||
@ -270,30 +280,34 @@ async fn get_tracker_for_sync<
|
|||||||
};
|
};
|
||||||
|
|
||||||
let refunds = db
|
let refunds = db
|
||||||
.find_refund_by_payment_id_merchant_id(&payment_id_str, merchant_id, storage_scheme)
|
.find_refund_by_payment_id_merchant_id(
|
||||||
|
&payment_id_str,
|
||||||
|
&merchant_account.merchant_id,
|
||||||
|
storage_scheme,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.change_context(errors::ApiErrorResponse::PaymentNotFound)
|
.change_context(errors::ApiErrorResponse::PaymentNotFound)
|
||||||
.attach_printable_lazy(|| {
|
.attach_printable_lazy(|| {
|
||||||
format!(
|
format!(
|
||||||
"Failed while getting refund list for, payment_id: {}, merchant_id: {}",
|
"Failed while getting refund list for, payment_id: {}, merchant_id: {}",
|
||||||
&payment_id_str, merchant_id
|
&payment_id_str, merchant_account.merchant_id
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let disputes = db
|
let disputes = db
|
||||||
.find_disputes_by_merchant_id_payment_id(merchant_id, &payment_id_str)
|
.find_disputes_by_merchant_id_payment_id(&merchant_account.merchant_id, &payment_id_str)
|
||||||
.await
|
.await
|
||||||
.change_context(errors::ApiErrorResponse::PaymentNotFound)
|
.change_context(errors::ApiErrorResponse::PaymentNotFound)
|
||||||
.attach_printable_lazy(|| {
|
.attach_printable_lazy(|| {
|
||||||
format!("Error while retrieving dispute list for, merchant_id: {merchant_id}, payment_id: {payment_id_str}")
|
format!("Error while retrieving dispute list for, merchant_id: {}, payment_id: {payment_id_str}", &merchant_account.merchant_id)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let frm_response = db
|
let frm_response = db
|
||||||
.find_fraud_check_by_payment_id(payment_id_str.to_string(), merchant_id.to_string())
|
.find_fraud_check_by_payment_id(payment_id_str.to_string(), merchant_account.merchant_id.clone())
|
||||||
.await
|
.await
|
||||||
.change_context(errors::ApiErrorResponse::PaymentNotFound)
|
.change_context(errors::ApiErrorResponse::PaymentNotFound)
|
||||||
.attach_printable_lazy(|| {
|
.attach_printable_lazy(|| {
|
||||||
format!("Error while retrieving frm_response, merchant_id: {merchant_id}, payment_id: {payment_id_str}")
|
format!("Error while retrieving frm_response, merchant_id: {}, payment_id: {payment_id_str}", &merchant_account.merchant_id)
|
||||||
});
|
});
|
||||||
|
|
||||||
let frm_message = match frm_response.ok() {
|
let frm_message = match frm_response.ok() {
|
||||||
@ -325,7 +339,12 @@ async fn get_tracker_for_sync<
|
|||||||
.merchant_connector_details
|
.merchant_connector_details
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.async_map(|mcd| async {
|
.async_map(|mcd| async {
|
||||||
helpers::insert_merchant_connector_creds_to_config(db, merchant_id, mcd).await
|
helpers::insert_merchant_connector_creds_to_config(
|
||||||
|
db,
|
||||||
|
&merchant_account.merchant_id,
|
||||||
|
mcd,
|
||||||
|
)
|
||||||
|
.await
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|||||||
@ -80,6 +80,11 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
|||||||
"update",
|
"update",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
helpers::authenticate_client_secret(
|
||||||
|
request.client_secret.as_ref(),
|
||||||
|
&payment_intent,
|
||||||
|
merchant_account.intent_fulfillment_time,
|
||||||
|
)?;
|
||||||
let (
|
let (
|
||||||
token,
|
token,
|
||||||
payment_method,
|
payment_method,
|
||||||
|
|||||||
Reference in New Issue
Block a user