Skip to content

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

fix(redirection): complete authorize flow for modular integrations (#14636)

Kashife079b258747d
diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
index e616962e89..2a474177bb 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -14,10 +14,12 @@ use crate::{
configs::dimension_state,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
mandate::helpers as m_helpers,
+ payment_methods::transformers as pm_transformers,
payments::{
self, helpers, operations, CustomerDetails, OperationSessionGetters, PaymentAddress,
PaymentData,
},
+ utils as core_utils,
},
events::audit_events::{AuditEvent, AuditEventType},
routes::{app::ReqState, SessionState},
@@ -51,11 +53,16 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
_auth_flow: services::AuthFlow,
_flow_kind: operations::PaymentFlowKind,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
- _payment_method_fetch_data: operations::PaymentMethodFetchData,
+ payment_method_fetch_data: operations::PaymentMethodFetchData,
_dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
_payment_pre_fetched_info: Option<operations::PaymentPreFetchedInformation>,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRequest, PaymentData<F>>>
{
+ let operations::PaymentMethodFetchData {
+ payment_intent: prefetched_payment_intent,
+ payment_method_info: prefetched_payment_method_info,
+ ..
+ } = payment_method_fetch_data;
let db = &*state.store;
let processor_merchant_id = platform.get_processor().get_processor_merchant_id();
@@ -66,15 +73,18 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.get_payment_intent_id()
.change_context(errors::ApiErrorResponse::PaymentNotFound)?;
- payment_intent = db
- .find_payment_intent_by_payment_id_processor_merchant_id(
- &payment_id,
- &processor_merchant_id,
- platform.get_processor().get_key_store(),
- storage_scheme,
- )
- .await
- .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
+ payment_intent = match prefetched_payment_intent {
+ Some(payment_intent) => payment_intent,
+ None => db
+ .find_payment_intent_by_payment_id_processor_merchant_id(
+ &payment_id,
+ &processor_merchant_id,
+ platform.get_processor().get_key_store(),
+ storage_scheme,
+ )
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,
+ };
// TODO (#7195): Add platform merchant account validation once client_secret auth is solved
@@ -143,12 +153,13 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
platform,
payment_attempt.payment_method_id.clone(),
payment_intent.customer_id.as_ref(),
- None,
+ prefetched_payment_method_info.clone(),
))
.await?;
+ let payment_method_info = payment_method_info.or(prefetched_payment_method_info);
+
// Priority: request > payment_attempt > payment_method_info
- // If payment_method_info is present but customer_acceptance is missing/invalid, return an error
let customer_acceptance: Option<CustomerAcceptance> =
if let Some(ca) = request.customer_acceptance.clone() {
Some(ca)
@@ -160,10 +171,12 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
"Failed to deserialize customer_acceptance from payment_attempt",
)?,
)
- } else if let Some(pm) = payment_method_info.clone() {
+ } else if let Some(ca) = payment_method_info
+ .as_ref()
+ .and_then(|pm| pm.customer_acceptance.clone())
+ {
Some(
- pm.customer_acceptance
- .parse_value::<CustomerAcceptance>("CustomerAcceptance")
+ ca.parse_value::<CustomerAcceptance>("CustomerAcceptance")
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable(
"Failed to deserialize customer_acceptance from payment_method_info",
@@ -429,6 +442,82 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
#[async_trait]
impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for CompleteAuthorize {
+ #[instrument(skip_all)]
+ async fn fetch_payment_method(
+ &self,
+ state: &SessionState,
+ req: &api::PaymentsRequest,
+ platform: &domain::Platform,
+ feature_config: &core_utils::FeatureConfig,
+ ) -> RouterResult<operations::PaymentMethodFetchData> {
+ let payment_id = req.payment_id.as_ref().get_required_value("payment_id")?;
+ let (payment_intent, payment_attempt) =
+ Box::pin(super::payment_status::get_payment_intent_payment_attempt(
+ state,
+ payment_id,
+ &platform.get_processor().get_processor_merchant_id(),
+ platform.get_processor().get_key_store(),
+ platform.get_processor().get_storage_scheme(),
+ ))
+ .await?;
+
+ let payment_method_info = if let Some(pm_id) = payment_attempt.payment_method_id.as_ref() {
+ let payment_method_info = match state
+ .store
+ .find_payment_method(
+ platform.get_provider().get_key_store(),
+ pm_id,
+ platform.get_processor().get_account().storage_scheme,
+ )
+ .await
+ {
+ Ok(pm) => Ok(Some(pm)),
+ Err(error)
+ if error.current_context().is_db_not_found()
+ && feature_config.is_payment_method_modular_allowed =>
+ {
+ Ok(None)
+ }
+ Err(error) => Err(error)
+ .to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound),
+ }?;
+
+ // An existing V1 record must pass the freshness check even after rollout.
+ if payment_method_info.as_ref().map_or(
+ feature_config.is_payment_method_modular_allowed,
+ |pm| {
+ feature_config.should_use_modular_pm_path(
+ Some(pm.version),
+ pm.compatibility_updated_at,
+ Some(pm.last_modified),
+ )
+ },
+ ) {
+ let profile_id = payment_intent
+ .profile_id
+ .as_ref()
+ .get_required_value("profile_id")?;
+ Some(
+ Box::pin(pm_transformers::fetch_payment_method_from_modular_service(
+ state, platform, profile_id, pm_id, None, false, false,
+ ))
+ .await?
+ .payment_method,
+ )
+ } else {
+ payment_method_info
+ }
+ } else {
+ None
+ };
+
+ Ok(operations::PaymentMethodFetchData {
+ payment_intent: Some(payment_intent),
+ payment_method_info,
+ ..Default::default()
+ })
+ }
+
#[instrument(skip_all)]
async fn get_or_create_customer_details<'a>(
&'a self,
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index da3ea1c528..41aa016561 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -13,10 +13,12 @@ use crate::{
core::{
configs::dimension_state,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
+ payment_methods::transformers as pm_transformers,
payments::{
helpers, operations, types as payment_types, CustomerDetails, PaymentAddress,
PaymentData,
},
+ utils as core_utils,
},
events::audit_events::{AuditEvent, AuditEventType},
routes::{app::ReqState, SessionState},
@@ -236,7 +238,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRetrieve
_flow_kind: operations::PaymentFlowKind,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
_payment_method_fetch_data: operations::PaymentMethodFetchData,
- _dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
_payment_pre_fetched_info: Option<operations::PaymentPreFetchedInformation>,
) -> RouterResult<
operations::GetTrackerResponse<'a, F, api::PaymentsRetrieveRequest, PaymentData<F>>,
@@ -248,6 +250,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRetrieve
request,
self,
platform.get_processor().get_storage_scheme(),
+ dimensions,
))
.await
}
@@ -265,6 +268,7 @@ async fn get_tracker_for_sync<
_request: &api::PaymentsRetrieveRequest,
_operation: Op,
_storage_scheme: enums::MerchantStorageScheme,
+ _dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRetrieveRequest, PaymentData<F>>>
{
todo!()
@@ -283,6 +287,7 @@ async fn get_tracker_for_sync<
request: &api::PaymentsRetrieveRequest,
operation: Op,
storage_scheme: domain::ProcessorStorageScheme,
+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRetrieveRequest, PaymentData<F>>>
{
let (payment_intent, mut payment_attempt, currency, amount);
@@ -461,7 +466,8 @@ async fn get_tracker_for_sync<
let payment_method_info =
if let Some(ref payment_method_id) = payment_attempt.payment_method_id.clone() {
- match db
+ let feature_config = core_utils::get_feature_config(state, platform, dimensions).await;
+ let payment_method_info = match db
.find_payment_method(
platform.get_provider().get_key_store(),
payment_method_id,
@@ -469,17 +475,47 @@ async fn get_tracker_for_sync<
)
.await
{
- Ok(payment_method_info) => Some(payment_method_info),
- Err(error) => {
- if error.current_context().is_db_not_found() {
- logger::info!("Payment Method not found in db {:?}", error);
+ Ok(pm) => Some(pm),
+ Err(error) if error.current_context().is_db_not_found() => None,
+ Err(error) => Err(error)
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Error retrieving payment method from db")?,
+ };
+ let use_modular = payment_method_info.as_ref().map_or(
+ feature_config.is_payment_method_modular_allowed,
+ |pm| {
+ feature_config.should_use_modular_pm_path(
+ Some(pm.version),
+ pm.compatibility_updated_at,
+ Some(pm.last_modified),
+ )
+ },
+ );
+
+ if use_modular {
+ match Box::pin(pm_transformers::fetch_payment_method_from_modular_service(
+ state,
+ platform,
+ &profile_id,
+ payment_method_id,
+ None,
+ false,
+ false,
+ ))
+ .await
+ {
+ Ok(pm) => Some(pm.payment_method),
+ Err(error) => {
+ // Historical payments remain readable after PM deletion or an outage.
+ logger::warn!(
+ ?error,
+ "Modular PM metadata unavailable during payment sync"
+ );
None
- } else {
- Err(error)
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Error retrieving payment method from db")?
}
}
+ } else {
+ payment_method_info
}
} else {
None