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

feat(core): support external authentication for platform merchants (#13126)

Apoorv Dixit230b2b4a251d
diff --git a/crates/diesel_models/src/query/authentication.rs b/crates/diesel_models/src/query/authentication.rs
index 6c3e9342df..6af586aba2 100644
--- a/crates/diesel_models/src/query/authentication.rs
+++ b/crates/diesel_models/src/query/authentication.rs
@@ -22,6 +22,45 @@ impl AuthenticationNew {
}
impl Authentication {
+ pub async fn update_by_processor_merchant_id_authentication_id(
+ conn: &PgPooledConn,
+ processor_merchant_id: &common_utils::id_type::MerchantId,
+ authentication_id: &common_utils::id_type::AuthenticationId,
+ authentication_update: AuthenticationUpdateInternal,
+ ) -> StorageResult<Self> {
+ match generics::generic_update_with_unique_predicate_get_result::<
+ <Self as HasTable>::Table,
+ _,
+ _,
+ _,
+ >(
+ conn,
+ dsl::processor_merchant_id
+ .eq(processor_merchant_id.to_owned())
+ .and(dsl::authentication_id.eq(authentication_id.to_owned())),
+ authentication_update,
+ )
+ .await
+ {
+ Err(error) => match error.current_context() {
+ errors::DatabaseError::NotFound => Err(error.attach_printable(
+ "Authentication with the given Authentication ID does not exist",
+ )),
+ errors::DatabaseError::NoFieldsToUpdate => {
+ generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
+ conn,
+ dsl::processor_merchant_id
+ .eq(processor_merchant_id.to_owned())
+ .and(dsl::authentication_id.eq(authentication_id.to_owned())),
+ )
+ .await
+ }
+ _ => Err(error),
+ },
+ result => result,
+ }
+ }
+
pub async fn update_by_merchant_id_authentication_id(
conn: &PgPooledConn,
merchant_id: &common_utils::id_type::MerchantId,
@@ -61,6 +100,20 @@ impl Authentication {
}
}
+ pub async fn find_by_processor_merchant_id_authentication_id(
+ conn: &PgPooledConn,
+ processor_merchant_id: &common_utils::id_type::MerchantId,
+ authentication_id: &common_utils::id_type::AuthenticationId,
+ ) -> StorageResult<Self> {
+ generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
+ conn,
+ dsl::processor_merchant_id
+ .eq(processor_merchant_id.to_owned())
+ .and(dsl::authentication_id.eq(authentication_id.to_owned())),
+ )
+ .await
+ }
+
pub async fn find_by_merchant_id_authentication_id(
conn: &PgPooledConn,
merchant_id: &common_utils::id_type::MerchantId,
@@ -75,6 +128,20 @@ impl Authentication {
.await
}
+ pub async fn find_authentication_by_processor_merchant_id_connector_authentication_id(
+ conn: &PgPooledConn,
+ processor_merchant_id: &common_utils::id_type::MerchantId,
+ connector_authentication_id: &str,
+ ) -> StorageResult<Self> {
+ generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
+ conn,
+ dsl::processor_merchant_id
+ .eq(processor_merchant_id.to_owned())
+ .and(dsl::connector_authentication_id.eq(connector_authentication_id.to_owned())),
+ )
+ .await
+ }
+
pub async fn find_authentication_by_merchant_id_connector_authentication_id(
conn: &PgPooledConn,
merchant_id: &common_utils::id_type::MerchantId,
@@ -94,14 +161,18 @@ impl AuthenticationUpdateInternal {
pub async fn generate_drainer_update_query(
self,
conn: &mut PgPooledConn,
- merchant_id: common_utils::id_type::MerchantId,
+ processor_merchant_id: common_utils::id_type::MerchantId,
authentication_id: common_utils::id_type::AuthenticationId,
) -> StorageResult<kv::SerializableQuery> {
+ // Stagger release: match on processor_merchant_id, falling back to merchant_id for legacy
+ // rows where processor_merchant_id is NULL (the value passed is unwrap_or(merchant_id)).
kv::generate_update_query_with_predicate::<<Authentication as HasTable>::Table, _, _>(
conn,
- dsl::merchant_id
- .eq(merchant_id)
- .and(dsl::authentication_id.eq(authentication_id)),
+ dsl::authentication_id.eq(authentication_id).and(
+ dsl::processor_merchant_id
+ .eq(processor_merchant_id.clone())
+ .or(dsl::merchant_id.eq(processor_merchant_id)),
+ ),
self,
)
.await
diff --git a/crates/hyperswitch_domain_models/src/authentication.rs b/crates/hyperswitch_domain_models/src/authentication.rs
index 1089e4571c..8473fd5f60 100644
--- a/crates/hyperswitch_domain_models/src/authentication.rs
+++ b/crates/hyperswitch_domain_models/src/authentication.rs
@@ -772,25 +772,25 @@ pub trait AuthenticationInterface {
storage_scheme: common_enums::MerchantStorageScheme,
) -> CustomResult<Authentication, Self::Error>;
- async fn find_authentication_by_merchant_id_authentication_id(
+ async fn find_authentication_by_processor_merchant_id_authentication_id(
&self,
- merchant_id: &common_utils::id_type::MerchantId,
+ processor_merchant_id: &common_utils::id_type::MerchantId,
authentication_id: &common_utils::id_type::AuthenticationId,
merchant_key_store: &crate::merchant_key_store::MerchantKeyStore,
state: &KeyManagerState,
storage_scheme: common_enums::MerchantStorageScheme,
) -> CustomResult<Authentication, Self::Error>;
- async fn find_authentication_by_merchant_id_connector_authentication_id(
+ async fn find_authentication_by_processor_merchant_id_connector_authentication_id(
&self,
- merchant_id: common_utils::id_type::MerchantId,
+ processor_merchant_id: common_utils::id_type::MerchantId,
connector_authentication_id: String,
merchant_key_store: &crate::merchant_key_store::MerchantKeyStore,
state: &KeyManagerState,
storage_scheme: common_enums::MerchantStorageScheme,
) -> CustomResult<Authentication, Self::Error>;
- async fn update_authentication_by_merchant_id_authentication_id(
+ async fn update_authentication_by_processor_merchant_id_authentication_id(
&self,
previous_state: Authentication,
authentication_update: AuthenticationUpdate,
diff --git a/crates/router/src/core/authentication.rs b/crates/router/src/core/authentication.rs
index 034f4fd151..f6ab00a5f0 100644
--- a/crates/router/src/core/authentication.rs
+++ b/crates/router/src/core/authentication.rs
@@ -135,7 +135,7 @@ pub async fn perform_post_authentication(
);
let authentication = state
.store
- .find_authentication_by_merchant_id_authentication_id(
+ .find_authentication_by_processor_merchant_id_authentication_id(
&business_profile.merchant_id,
&authentication_id,
processor.get_key_store(),
@@ -221,6 +221,7 @@ pub async fn perform_post_authentication(
pub async fn perform_pre_authentication(
state: &SessionState,
processor: &domain::Processor,
+ provider_merchant_id: common_utils::id_type::MerchantId,
card: hyperswitch_domain_models::payment_method_data::Card,
token: String,
business_profile: &domain::Profile,
@@ -241,7 +242,7 @@ pub async fn perform_pre_authentication(
let authentication_connector_name = authentication_connector.to_string();
let authentication = utils::create_new_authentication(
state,
- business_profile.merchant_id.clone(),
+ provider_merchant_id,
authentication_connector_name.clone(),
token,
business_profile.get_id().to_owned(),
diff --git a/crates/router/src/core/authentication/utils.rs b/crates/router/src/core/authentication/utils.rs
index 1078d2a35e..28cfd8017c 100644
--- a/crates/router/src/core/authentication/utils.rs
+++ b/crates/router/src/core/authentication/utils.rs
@@ -346,7 +346,7 @@ pub async fn update_trackers<F: Clone, Req>(
};
state
.store
- .update_authentication_by_merchant_id_authentication_id(
+ .update_authentication_by_processor_merchant_id_authentication_id(
authentication,
authentication_update,
merchant_key_store,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 71e62628e5..0f081f40da 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -5133,7 +5133,7 @@ impl PaymentRedirectFlow for PaymentAuthenticateCompleteAuthorize {
let key_manager_state = &(state).into();
let authentication = state
.store
- .find_authentication_by_merchant_id_authentication_id(
+ .find_authentication_by_processor_merchant_id_authentication_id(
platform.get_processor().get_account().get_id(),
&authentication_id,
platform.get_processor().get_key_store(),
@@ -12643,9 +12643,9 @@ pub async fn payment_external_authentication<F: Clone + Sync>(
.store
.find_customer_by_customer_id_merchant_id(
customer_id,
- platform.get_processor().get_account().get_id(),
- platform.get_processor().get_key_store(),
- storage_scheme,
+ platform.get_provider().get_account().get_id(),
+ platform.get_provider().get_key_store(),
+ platform.get_provider().get_account().storage_scheme,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
@@ -12857,7 +12857,7 @@ pub async fn payment_external_authentication<F: Clone + Sync>(
}
} else {
let authentication = db
- .find_authentication_by_merchant_id_authentication_id(
+ .find_authentication_by_processor_merchant_id_authentication_id(
processor_merchant_id,
&payment_attempt
.authentication_id
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 7994c0c910..35c5685b08 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -1497,6 +1497,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
let authentication_store = Box::pin(authentication::perform_pre_authentication(
state,
processor,
+ payment_data.payment_attempt.merchant_id.clone(),
*card,
token,
business_profile,
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 051294b929..bff1d87043 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -2896,7 +2896,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
};
let updated_authentication = state
.store
- .update_authentication_by_merchant_id_authentication_id(
+ .update_authentication_by_processor_merchant_id_authentication_id(
authentication_store.authentication,
authentication_update,
processor.get_key_store(),
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index 7aa808f66b..38b9a5f9c0 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -478,14 +478,13 @@ async fn get_tracker_for_sync<
None
};
- let merchant_id = payment_intent.merchant_id.clone();
let key_manager_state = &(state).into();
let authentication_store =
if let Some(ref authentication_id) = payment_attempt.authentication_id {
let authentication = db
- .find_authentication_by_merchant_id_authentication_id(
- &merchant_id,
+ .find_authentication_by_processor_merchant_id_authentication_id(
+ platform.get_processor().get_account().get_id(),
authentication_id,
platform.get_processor().get_key_store(),
key_manager_state,
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index be6392e892..9823b5e57e 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -377,7 +377,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
merchant_connector_account,
) => Some(helpers::create_webhook_url(
router_base_url,
- &attempt.merchant_id,
+ &attempt.processor_merchant_id,
merchant_connector_account.get_id().get_string_repr(),
)),
domain::MerchantConnectorAccountTypeDetails::MerchantConnectorDetails(_) => {
@@ -641,7 +641,7 @@ pub async fn construct_external_vault_proxy_payment_router_data<'a>(
merchant_connector_account,
) => Some(helpers::create_webhook_url(
router_base_url,
- &attempt.merchant_id,
+ &attempt.processor_merchant_id,
merchant_connector_account.get_id().get_string_repr(),
)),
domain::MerchantConnectorAccountTypeDetails::MerchantConnectorDetails(_) => {
@@ -805,7 +805,7 @@ pub async fn construct_external_vault_proxy_payment_router_data_v1<'a>(
let webhook_url = Some(helpers::create_webhook_url(
&state.base_url,
- &attempt.merchant_id,
+ &attempt.processor_merchant_id,
&merchant_connector_account_id_or_connector_name,
));
@@ -1716,7 +1716,7 @@ pub async fn construct_payment_router_data_for_setup_mandate<'a>(
merchant_connector_account,
) => Some(helpers::create_webhook_url(
router_base_url,
- &attempt.merchant_id,
+ &attempt.processor_merchant_id,
merchant_connector_account.get_id().get_string_repr(),
)),
domain::MerchantConnectorAccountTypeDetails::MerchantConnectorDetails(_) => {
@@ -5034,7 +5034,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
let webhook_url = Some(helpers::create_webhook_url(
router_base_url,
- &attempt.merchant_id,
+ &attempt.processor_merchant_id,
merchant_connector_account_id_or_connector_name,
));
let router_return_url = Some(helpers::create_redirect_url(
@@ -5241,7 +5241,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
let webhook_url = Some(helpers::create_webhook_url(
router_base_url,
- &attempt.merchant_id,
+ &attempt.processor_merchant_id,
merchant_connector_account_id_or_connector_name,
));
let router_return_url = Some(helpers::create_redirect_url(
@@ -5671,7 +5671,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsCaptureD
.ok_or(errors::ApiErrorResponse::MerchantAccountNotFound)?;
let webhook_url: Option<_> = Some(helpers::create_webhook_url(
router_base_url,
- &attempt.merchant_id,
+ &attempt.processor_merchant_id,
merchant_connector_account_id,
));
Ok(Self {
@@ -5737,7 +5737,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsCancelDa
.ok_or(errors::ApiErrorResponse::MerchantAccountNotFound)?;
let webhook_url: Option<_> = Some(helpers::create_webhook_url(
router_base_url,
- &attempt.merchant_id,
+ &attempt.processor_merchant_id,
merchant_connector_account_id,
));
let capture_method = payment_data.payment_intent.capture_method;
@@ -5806,7 +5806,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsCancelDa
.ok_or(errors::ApiErrorResponse::MerchantAccountNotFound)?;
let webhook_url: Option<_> = Some(helpers::create_webhook_url(
router_base_url,
- &attempt.merchant_id,
+ &attempt.processor_merchant_id,
merchant_connector_account_id,
));
let capture_method = payment_data.payment_attempt.capture_method;
@@ -6437,7 +6437,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ
.unwrap_or(connector_name);
let webhook_url = Some(helpers::create_webhook_url(
router_base_url,
- &attempt.merchant_id,
+ &attempt.processor_merchant_id,
merchant_connector_account_id_or_connector_name,
));
let complete_authorize_url = Some(helpers::create_complete_authorize_url(
@@ -6799,7 +6799,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsPreProce
.unwrap_or(connector_name);
let webhook_url = Some(helpers::create_webhook_url(
router_base_url,
- &attempt.merchant_id,
+ &attempt.processor_merchant_id,
merchant_connector_account_id_or_connector_name,
));
let router_return_url = Some(helpers::create_redirect_url(
diff --git a/crates/router/src/core/unified_authentication_service.rs b/crates/router/src/core/unified_authentication_service.rs
index 224ecfa943..40c1164f69 100644
--- a/crates/router/src/core/unified_authentication_service.rs
+++ b/crates/router/src/core/unified_authentication_service.rs
@@ -715,8 +715,8 @@ pub async fn authentication_create_core(
req: AuthenticationCreateRequest,
) -> RouterResponse<AuthenticationResponse> {
let db = &*state.store;
- let merchant_account = platform.get_processor().get_account();
- let merchant_id = merchant_account.get_id();
+ let processor_merchant_account = platform.get_processor().get_account();
+ let processor_merchant_id = processor_merchant_account.get_id();
let key_manager_state = (&state).into();
let profile_id = core_utils::get_profile_id_from_business_details(
None,
@@ -734,7 +734,7 @@ pub async fn authentication_create_core(
.to_not_found_response(ApiErrorResponse::ProfileNotFound {
id: profile_id.get_string_repr().to_owned(),
})?;
- let organization_id = merchant_account.organization_id.clone();
+ let organization_id = processor_merchant_account.organization_id.clone();
let authentication_id = common_utils::id_type::AuthenticationId::generate_authentication_id(
consts::AUTHENTICATION_ID_PREFIX,
);
@@ -793,7 +793,7 @@ pub async fn authentication_create_core(
let new_authentication = create_new_authentication(
&state,
- merchant_id.clone(),
+ processor_merchant_id.clone(),
req.authentication_connector
.map(|connector| connector.to_string()),
profile_id.clone(),
@@ -1040,22 +1040,22 @@ pub async fn authentication_eligibility_core(
req: AuthenticationEligibilityRequest,
authentication_id: common_utils::id_type::AuthenticationId,
) -> RouterResponse<AuthenticationEligibilityResponse> {
- let merchant_account = platform.get_processor().get_account();
+ let processor_merchant_account = platform.get_processor().get_account();
let key_manager_state = (&state).into();
- let merchant_id = merchant_account.get_id();
+ let processor_merchant_id = processor_merchant_account.get_id();
let db = &*state.store;
let dimensions = dimension_state::Dimensions::new()
.with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())
.with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())
- .with_organization_id(merchant_account.organization_id.clone());
+ .with_organization_id(processor_merchant_account.organization_id.clone());
let authentication = db
- .find_authentication_by_merchant_id_authentication_id(
- merchant_id,
+ .find_authentication_by_processor_merchant_id_authentication_id(
+ processor_merchant_id,
&authentication_id,
platform.get_processor().get_key_store(),
&key_manager_state,
- merchant_account.storage_scheme,
+ processor_merchant_account.storage_scheme,
)
.await
.to_not_found_response(ApiErrorResponse::AuthenticationNotFound {
@@ -1109,7 +1109,7 @@ pub async fn authentication_eligibility_core(
None => Some(url::Url::parse(&format!(
"{base_url}/authentication/{merchant_id}/{authentication_id}/redirect",
base_url = state.base_url,
- merchant_id = merchant_id.get_string_repr(),
+ merchant_id = processor_merchant_id.get_string_repr(),
authentication_id = authentication_id.get_string_repr()
)))
.transpose()
@@ -1201,17 +1201,17 @@ pub async fn authentication_eligibility_core(
// If we resolved acquirer details from a bucket, persist them to the authentication record.
let key_manager_state_ref = &key_manager_state;
- db.update_authentication_by_merchant_id_authentication_id(
+ db.update_authentication_by_processor_merchant_id_authentication_id(
authentication.clone(),
hyperswitch_domain_models::authentication::AuthenticationUpdate::AcquirerDetailsUpdate {
acquirer_bin: acquirer_details.as_ref().and_then(|d| d.acquirer_bin.clone()),
acquirer_merchant_id: acquirer_details.as_ref().and_then(|d| d.acquirer_assigned_merchant_id.clone()),
acquirer_country_code: acquirer_details.as_ref().and_then(|d| d.acquirer_country_code.clone()),
- updated_by: merchant_account.storage_scheme.to_string(),
+ updated_by: processor_merchant_account.storage_scheme.to_string(),
},
platform.get_processor().get_key_store(),
key_manager_state_ref,
- merchant_account.storage_scheme,
+ processor_merchant_account.storage_scheme,
)
.await
.change_context(ApiErrorResponse::InternalServerError)
@@ -1282,7 +1282,7 @@ pub async fn authentication_eligibility_core(
let pre_auth_response =
<ExternalAuthentication as UnifiedAuthenticationService>::pre_authentication(
&state,
- merchant_id,
+ processor_merchant_id,
None,
Some(&payment_method_data),
req.payment_method_type,
@@ -1324,7 +1324,7 @@ pub async fn authentication_eligibility_core(
None,
merchant_category_code,
merchant_country_code.clone(),
- merchant_account.storage_scheme,
+ processor_merchant_account.storage_scheme,
))
.await?;
@@ -1356,17 +1356,17 @@ pub async fn authentication_authenticate_core(
auth_flow: AuthFlow,
) -> RouterResponse<AuthenticationAuthenticateResponse> {
let authentication_id = req.authentication_id.clone();
- let merchant_account = platform.get_processor().get_account();
- let merchant_id = merchant_account.get_id();
+ let processor_merchant_account = platform.get_processor().get_account();
+ let processor_merchant_id = processor_merchant_account.get_id();
let db = &*state.store;
let key_manager_state = (&state).into();
let authentication = db
- .find_authentication_by_merchant_id_authentication_id(
- merchant_id,
+ .find_authentication_by_processor_merchant_id_authentication_id(
+ processor_merchant_id,
&authentication_id,
platform.get_processor().get_key_store(),
&key_manager_state,
- merchant_account.storage_scheme,
+ processor_merchant_account.storage_scheme,
)
.await
.to_not_found_response(ApiErrorResponse::AuthenticationNotFound {
@@ -1385,7 +1385,7 @@ pub async fn authentication_authenticate_core(
let dimensions = dimension_state::Dimensions::new()
.with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())
.with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())
- .with_organization_id(merchant_account.organization_id.clone());
+ .with_organization_id(processor_merchant_account.organization_id.clone());
let profile_id = authentication.profile_id.clone();
@@ -1428,7 +1428,7 @@ pub async fn authentication_authenticate_core(
let webhook_url = helpers::create_webhook_url(
&state.base_url,
- merchant_id,
+ processor_merchant_id,
merchant_connector_account_id_or_connector_name,
);
@@ -1475,7 +1475,7 @@ pub async fn authentication_authenticate_core(
.and_then(|sdk_information| sdk_information.device_details),
None,
None,
- merchant_account.storage_scheme,
+ processor_merchant_account.storage_scheme,
))
.await?;
@@ -1687,20 +1687,20 @@ pub async fn authentication_eligibility_check_core(
) -> RouterResponse<AuthenticationEligibilityCheckResponse> {
let authentication_id = req.authentication_id.clone();
let db = &*state.store;
- let merchant_account = platform.get_processor().get_account();
- let merchant_id = merchant_account.get_id();
+ let processor_merchant_account = platform.get_processor().get_account();
+ let processor_merchant_id = processor_merchant_account.get_id();
let key_manager_state = (&state).into();
let dimensions = dimension_state::Dimensions::new()
.with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())
.with_provider_merchant_id(platform.get_provider().get_provider_merchant_id());
let authentication = db
- .find_authentication_by_merchant_id_authentication_id(
- merchant_id,
+ .find_authentication_by_processor_merchant_id_authentication_id(
+ processor_merchant_id,
&authentication_id,
platform.get_processor().get_key_store(),
&key_manager_state,
- merchant_account.storage_scheme,
+ processor_merchant_account.storage_scheme,
)
.await
.to_not_found_response(ApiErrorResponse::AuthenticationNotFound {
@@ -2071,17 +2071,17 @@ pub async fn authentication_sync_core(
req: AuthenticationSyncRequest,
) -> RouterResponse<AuthenticationSyncResponse> {
let authentication_id = req.authentication_id;
- let merchant_account = platform.get_processor().get_account();
- let merchant_id = merchant_account.get_id();
+ let processor_merchant_account = platform.get_processor().get_account();
+ let processor_merchant_id = processor_merchant_account.get_id();
let db = &*state.store;
let key_manager_state = (&state).into();
let authentication = db
- .find_authentication_by_merchant_id_authentication_id(
- merchant_id,
+ .find_authentication_by_processor_merchant_id_authentication_id(
+ processor_merchant_id,
&authentication_id,
platform.get_processor().get_key_store(),
&key_manager_state,
- merchant_account.storage_scheme,
+ processor_merchant_account.storage_scheme,
)
.await
.to_not_found_response(ApiErrorResponse::AuthenticationNotFound {
@@ -2234,8 +2234,8 @@ pub async fn authentication_sync_core(
&authentication_connector,
&three_ds_connector_account,
&authentication_id,
- merchant_id,
- merchant_account,
+ processor_merchant_id,
+ processor_merchant_account,
should_disable_vault_tokenization,
))
.await?
@@ -2323,7 +2323,7 @@ pub async fn authentication_sync_core(
let response = AuthenticationSyncResponse {
authentication_id: authentication_id.clone(),
- merchant_id: merchant_id.clone(),
+ merchant_id: processor_merchant_id.clone(),
status: updated_authentication.authentication_status,
client_secret: updated_authentication
.authentication_client_secret
@@ -2382,21 +2382,21 @@ pub async fn authentication_post_sync_core(
req: AuthenticationSyncPostUpdateRequest,
) -> RouterResponse<()> {
let authentication_id = req.authentication_id;
- let merchant_account = platform.get_processor().get_account();
- let merchant_id = merchant_account.get_id();
+ let processor_merchant_account = platform.get_processor().get_account();
+ let processor_merchant_id = processor_merchant_account.get_id();
let db = &*state.store;
let key_manager_state = (&state).into();
let dimensions = dimension_state::Dimensions::new()
.with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())
.with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())
- .with_organization_id(merchant_account.organization_id.clone());
+ .with_organization_id(processor_merchant_account.organization_id.clone());
let authentication = db
- .find_authentication_by_merchant_id_authentication_id(
- merchant_id,
+ .find_authentication_by_processor_merchant_id_authentication_id(
+ processor_merchant_id,
&authentication_id,
platform.get_processor().get_key_store(),
&key_manager_state,
- merchant_account.storage_scheme,
+ processor_merchant_account.storage_scheme,
)
.await
.to_not_found_response(ApiErrorResponse::AuthenticationNotFound {
@@ -2434,7 +2434,7 @@ pub async fn authentication_post_sync_core(
&authentication_connector.to_string(),
&authentication_id,
common_enums::PaymentMethod::Card,
- merchant_id,
+ processor_merchant_id,
Some(&authentication),
Some(routing_region),
)
@@ -2453,7 +2453,7 @@ pub async fn authentication_post_sync_core(
None,
None,
None,
- merchant_account.storage_scheme,
+ processor_merchant_account.storage_scheme,
)
.await?;
@@ -2510,19 +2510,19 @@ pub async fn authentication_session_core(
platform: domain::Platform,
req: AuthenticationSessionTokenRequest,
) -> RouterResponse<api_models::authentication::AuthenticationSessionResponse> {
- let merchant_account = platform.get_processor().get_account();
- let merchant_id = merchant_account.get_id();
+ let processor_merchant_account = platform.get_processor().get_account();
+ let processor_merchant_id = processor_merchant_account.get_id();
let key_manager_state = (&state).into();
let authentication_id = req.authentication_id;
let authentication = state
.store
- .find_authentication_by_merchant_id_authentication_id(
- merchant_id,
+ .find_authentication_by_processor_merchant_id_authentication_id(
+ processor_merchant_id,
&authentication_id,
platform.get_processor().get_key_store(),
&key_manager_state,
- merchant_account.storage_scheme,
+ processor_merchant_account.storage_scheme,
)
.await
.to_not_found_response(ApiErrorResponse::AuthenticationNotFound {
diff --git a/crates/router/src/core/unified_authentication_service/utils.rs b/crates/router/src/core/unified_authentication_service/utils.rs
index d7254071bf..7aadbc5fcd 100644
--- a/crates/router/src/core/unified_authentication_service/utils.rs
+++ b/crates/router/src/core/unified_authentication_service/utils.rs
@@ -444,7 +444,7 @@ pub async fn external_authentication_update_trackers<F: Clone, Req>(
state
.store
- .update_authentication_by_merchant_id_authentication_id(
+ .update_authentication_by_processor_merchant_id_authentication_id(
authentication,
authentication_update,
merchant_key_store,
diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs
index 4cbd2cc5ab..b283b8f5f4 100644
--- a/crates/router/src/core/webhooks/incoming.rs
+++ b/crates/router/src/core/webhooks/incoming.rs
@@ -1933,7 +1933,7 @@ async fn external_authentication_incoming_webhook_flow(
match authentication_id_type {
webhooks::AuthenticationIdType::AuthenticationId(authentication_id) => state
.store
- .find_authentication_by_merchant_id_authentication_id(
+ .find_authentication_by_processor_merchant_id_authentication_id(
platform.get_processor().get_account().get_id(),
&authentication_id,
platform.get_processor().get_key_store(),
@@ -1949,7 +1949,7 @@ async fn external_authentication_incoming_webhook_flow(
connector_authentication_id,
) => state
.store
- .find_authentication_by_merchant_id_connector_authentication_id(
+ .find_authentication_by_processor_merchant_id_connector_authentication_id(
platform.get_processor().get_account().get_id().clone(),
connector_authentication_id.clone(),
platform.get_processor().get_key_store(),
@@ -1969,7 +1969,7 @@ async fn external_authentication_incoming_webhook_flow(
}?;
let updated_authentication = state
.store
- .update_authentication_by_merchant_id_authentication_id(
+ .update_authentication_by_processor_merchant_id_authentication_id(
authentication,
authentication_update,
platform.get_processor().get_key_store(),
diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs
index 20d4b26f32..7aa95465d9 100644
--- a/crates/router/src/db/kafka_store.rs
+++ b/crates/router/src/db/kafka_store.rs
@@ -4183,9 +4183,9 @@ impl AuthenticationInterface for KafkaStore {
Ok(auth)
}
- async fn find_authentication_by_merchant_id_authentication_id(
+ async fn find_authentication_by_processor_merchant_id_authentication_id(
&self,
- merchant_id: &id_type::MerchantId,
+ processor_merchant_id: &id_type::MerchantId,
authentication_id: &id_type::AuthenticationId,
key_store: &domain::MerchantKeyStore,
state: &KeyManagerState,
@@ -4195,8 +4195,8 @@ impl AuthenticationInterface for KafkaStore {
errors::StorageError,
> {
self.diesel_store
- .find_authentication_by_merchant_id_authentication_id(
- merchant_id,
+ .find_authentication_by_processor_merchant_id_authentication_id(
+ processor_merchant_id,
authentication_id,
key_store,
state,
@@ -4205,9 +4205,9 @@ impl AuthenticationInterface for KafkaStore {
.await
}
- async fn find_authentication_by_merchant_id_connector_authentication_id(
+ async fn find_authentication_by_processor_merchant_id_connector_authentication_id(
&self,
- merchant_id: id_type::MerchantId,
+ processor_merchant_id: id_type::MerchantId,
connector_authentication_id: String,
key_store: &domain::MerchantKeyStore,
state: &KeyManagerState,
@@ -4217,8 +4217,8 @@ impl AuthenticationInterface for KafkaStore {
errors::StorageError,
> {
self.diesel_store
- .find_authentication_by_merchant_id_connector_authentication_id(
- merchant_id,
+ .find_authentication_by_processor_merchant_id_connector_authentication_id(
+ processor_merchant_id,
connector_authentication_id,
key_store,
state,
@@ -4227,7 +4227,7 @@ impl AuthenticationInterface for KafkaStore {
.await
}
- async fn update_authentication_by_merchant_id_authentication_id(
+ async fn update_authentication_by_processor_merchant_id_authentication_id(
&self,
previous_state: hyperswitch_domain_models::authentication::Authentication,
authentication_update: hyperswitch_domain_models::authentication::AuthenticationUpdate,
@@ -4240,7 +4240,7 @@ impl AuthenticationInterface for KafkaStore {
> {
let auth = self
.diesel_store
- .update_authentication_by_merchant_id_authentication_id(
+ .update_authentication_by_processor_merchant_id_authentication_id(
previous_state.clone(),
authentication_update,
key_store,
diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rs
index 59e0b41f9b..f9dc7464dd 100644
--- a/crates/router/src/utils.rs
+++ b/crates/router/src/utils.rs
@@ -324,7 +324,7 @@ pub async fn find_mca_from_authentication_id_type(
let db = &*state.store;
let authentication = match authentication_id_type {
webhooks::AuthenticationIdType::AuthenticationId(authentication_id) => db
- .find_authentication_by_merchant_id_authentication_id(
+ .find_authentication_by_processor_merchant_id_authentication_id(
platform.get_processor().get_account().get_id(),
&authentication_id,
platform.get_processor().get_key_store(),
@@ -334,7 +334,7 @@ pub async fn find_mca_from_authentication_id_type(
.await
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?,
webhooks::AuthenticationIdType::ConnectorAuthenticationId(connector_authentication_id) => {
- db.find_authentication_by_merchant_id_connector_authentication_id(
+ db.find_authentication_by_processor_merchant_id_connector_authentication_id(
platform.get_processor().get_account().get_id().clone(),
connector_authentication_id,
platform.get_processor().get_key_store(),
diff --git a/crates/storage_impl/src/authentication.rs b/crates/storage_impl/src/authentication.rs
index 65d6731f3b..4cffe956cc 100644
--- a/crates/storage_impl/src/authentication.rs
+++ b/crates/storage_impl/src/authentication.rs
@@ -88,73 +88,109 @@ impl<T: DatabaseStore> AuthenticationInterface for RouterStore<T> {
}
#[instrument(skip_all)]
- async fn find_authentication_by_merchant_id_authentication_id(
+ async fn find_authentication_by_processor_merchant_id_authentication_id(
&self,
- merchant_id: &common_utils::id_type::MerchantId,
+ processor_merchant_id: &common_utils::id_type::MerchantId,
authentication_id: &common_utils::id_type::AuthenticationId,
merchant_key_store: &MerchantKeyStore,
state: &common_utils::types::keymanager::KeyManagerState,
_storage_scheme: common_enums::MerchantStorageScheme,
) -> error_stack::Result<Authentication, errors::StorageError> {
let conn = pg_connection_read(self).await?;
- diesel_authentication::find_by_merchant_id_authentication_id(
+ // Stagger release: try processor_merchant_id, fall back to merchant_id for legacy NULL rows.
+ let result = diesel_authentication::find_by_processor_merchant_id_authentication_id(
&conn,
- merchant_id,
+ processor_merchant_id,
authentication_id,
)
- .await
- .map_err(|error| {
- let new_err = diesel_error_to_data_error(*error.current_context());
- error.change_context(new_err)
- })
- .async_and_then(|authentication| async {
- Authentication::convert_back(
- state,
- authentication,
- merchant_key_store.key.get_inner(),
- merchant_key_store.merchant_id.clone().into(),
- )
+ .await;
+ let result = match result {
+ Err(error)
+ if matches!(
+ error.current_context(),
+ diesel_models::errors::DatabaseError::NotFound
+ ) =>
+ {
+ diesel_authentication::find_by_merchant_id_authentication_id(
+ &conn,
+ processor_merchant_id,
+ authentication_id,
+ )
+ .await
+ }
+ other => other,
+ };
+ result
+ .map_err(|error| {
+ let new_err = diesel_error_to_data_error(*error.current_context());
+ error.change_context(new_err)
+ })
+ .async_and_then(|authentication| async {
+ Authentication::convert_back(
+ state,
+ authentication,
+ merchant_key_store.key.get_inner(),
+ merchant_key_store.merchant_id.clone().into(),
+ )
+ .await
+ .change_context(errors::StorageError::DecryptionError)
+ })
.await
- .change_context(errors::StorageError::DecryptionError)
- })
- .await
}
#[instrument(skip_all)]
- async fn find_authentication_by_merchant_id_connector_authentication_id(
+ async fn find_authentication_by_processor_merchant_id_connector_authentication_id(
&self,
- merchant_id: common_utils::id_type::MerchantId,
+ processor_merchant_id: common_utils::id_type::MerchantId,
connector_authentication_id: String,
merchant_key_store: &MerchantKeyStore,
state: &common_utils::types::keymanager::KeyManagerState,
_storage_scheme: common_enums::MerchantStorageScheme,
) -> error_stack::Result<Authentication, errors::StorageError> {
let conn = pg_connection_read(self).await?;
- diesel_authentication::find_authentication_by_merchant_id_connector_authentication_id(
+ // Stagger release: try processor_merchant_id, fall back to merchant_id for legacy NULL rows.
+ let result = diesel_authentication::find_authentication_by_processor_merchant_id_connector_authentication_id(
&conn,
- &merchant_id,
+ &processor_merchant_id,
&connector_authentication_id,
)
- .await
- .map_err(|error| {
- let new_err = diesel_error_to_data_error(*error.current_context());
- error.change_context(new_err)
- })
- .async_and_then(|authentication| async {
- Authentication::convert_back(
- state,
- authentication,
- merchant_key_store.key.get_inner(),
- merchant_key_store.merchant_id.clone().into(),
- )
+ .await;
+ let result = match result {
+ Err(error)
+ if matches!(
+ error.current_context(),
+ diesel_models::errors::DatabaseError::NotFound
+ ) =>
+ {
+ diesel_authentication::find_authentication_by_merchant_id_connector_authentication_id(
+ &conn,
+ &processor_merchant_id,
+ &connector_authentication_id,
+ )
+ .await
+ }
+ other => other,
+ };
+ result
+ .map_err(|error| {
+ let new_err = diesel_error_to_data_error(*error.current_context());
+ error.change_context(new_err)
+ })
+ .async_and_then(|authentication| async {
+ Authentication::convert_back(
+ state,
+ authentication,
+ merchant_key_store.key.get_inner(),
+ merchant_key_store.merchant_id.clone().into(),
+ )
+ .await
+ .change_context(errors::StorageError::DecryptionError)
+ })
.await
- .change_context(errors::StorageError::DecryptionError)
- })
- .await
}
#[instrument(skip_all)]
- async fn update_authentication_by_merchant_id_authentication_id(
+ async fn update_authentication_by_processor_merchant_id_authentication_id(
&self,
previous_state: Authentication,
authentication_update: AuthenticationUpdate,
@@ -163,30 +199,55 @@ impl<T: DatabaseStore> AuthenticationInterface for RouterStore<T> {
_storage_scheme: common_enums::MerchantStorageScheme,
) -> error_stack::Result<Authentication, errors::StorageError> {
let conn = pg_connection_write(self).await?;
- diesel_authentication::update_by_merchant_id_authentication_id(
- &conn,
- &previous_state.merchant_id,
- &previous_state.authentication_id,
+ let authentication_update_internal =
diesel_models::authentication::AuthenticationUpdateInternal::from(
diesel_models::authentication::AuthenticationUpdate::from(authentication_update),
- ),
+ );
+ // Stagger release: try processor_merchant_id, fall back to merchant_id for legacy NULL rows.
+ let processor_merchant_id = previous_state
+ .processor_merchant_id
+ .clone()
+ .unwrap_or_else(|| previous_state.merchant_id.clone());
+ let result = diesel_authentication::update_by_processor_merchant_id_authentication_id(
+ &conn,
+ &processor_merchant_id,
+ &previous_state.authentication_id,
+ authentication_update_internal.clone(),
)
- .await
- .map_err(|error| {
- let new_err = diesel_error_to_data_error(*error.current_context());
- error.change_context(new_err)
- })
- .async_and_then(|authentication| async {
- Authentication::convert_back(
- state,
- authentication,
- merchant_key_store.key.get_inner(),
- merchant_key_store.merchant_id.clone().into(),
- )
+ .await;
+ let result = match result {
+ Err(error)
+ if matches!(
+ error.current_context(),
+ diesel_models::errors::DatabaseError::NotFound
+ ) =>
+ {
+ diesel_authentication::update_by_merchant_id_authentication_id(
+ &conn,
+ &processor_merchant_id,
+ &previous_state.authentication_id,
+ authentication_update_internal,
+ )
+ .await
+ }
+ other => other,
+ };
+ result
+ .map_err(|error| {
+ let new_err = diesel_error_to_data_error(*error.current_context());
+ error.change_context(new_err)
+ })
+ .async_and_then(|authentication| async {
+ Authentication::convert_back(
+ state,
+ authentication,
+ merchant_key_store.key.get_inner(),
+ merchant_key_store.merchant_id.clone().into(),
+ )
+ .await
+ .change_context(errors::StorageError::DecryptionError)
+ })
.await
- .change_context(errors::StorageError::DecryptionError)
- })
- .await
}
}
@@ -224,7 +285,10 @@ impl<T: DatabaseStore> AuthenticationInterface for KVRouterStore<T> {
// Record which layer wrote this row; drives KV-vs-Postgres routing on later updates.
let authentication = authentication.update_storage_scheme(storage_scheme);
- let merchant_id = &authentication.merchant_id;
+ let merchant_id = authentication
+ .processor_merchant_id
+ .as_ref()
+ .unwrap_or(&authentication.merchant_id);
let authentication_id = &authentication.authentication_id;
let payment_id = &authentication.payment_id;
@@ -312,9 +376,9 @@ impl<T: DatabaseStore> AuthenticationInterface for KVRouterStore<T> {
}
#[instrument(skip_all)]
- async fn find_authentication_by_merchant_id_authentication_id(
+ async fn find_authentication_by_processor_merchant_id_authentication_id(
&self,
- merchant_id: &common_utils::id_type::MerchantId,
+ processor_merchant_id: &common_utils::id_type::MerchantId,
authentication_id: &common_utils::id_type::AuthenticationId,
merchant_key_store: &MerchantKeyStore,
state: &common_utils::types::keymanager::KeyManagerState,
@@ -322,13 +386,30 @@ impl<T: DatabaseStore> AuthenticationInterface for KVRouterStore<T> {
) -> error_stack::Result<Authentication, errors::StorageError> {
let database_call = || async {
let conn = pg_connection_read(self).await?;
- diesel_authentication::find_by_merchant_id_authentication_id(
+ // Stagger release: try processor_merchant_id, fall back to merchant_id for legacy NULL rows.
+ let result = diesel_authentication::find_by_processor_merchant_id_authentication_id(
&conn,
- merchant_id,
+ processor_merchant_id,
authentication_id,
)
- .await
- .map_err(|error| {
+ .await;
+ let result = match result {
+ Err(error)
+ if matches!(
+ error.current_context(),
+ diesel_models::errors::DatabaseError::NotFound
+ ) =>
+ {
+ diesel_authentication::find_by_merchant_id_authentication_id(
+ &conn,
+ processor_merchant_id,
+ authentication_id,
+ )
+ .await
+ }
+ other => other,
+ };
+ result.map_err(|error| {
let new_err = diesel_error_to_data_error(*error.current_context());
error.change_context(new_err)
})
@@ -346,7 +427,7 @@ impl<T: DatabaseStore> AuthenticationInterface for KVRouterStore<T> {
common_enums::MerchantStorageScheme::RedisKv => {
// Resolve partition/field via the authentication-id reverse lookup.
let lookup_id = diesel_authentication::get_authentication_id_lookup_id(
- merchant_id,
+ processor_merchant_id,
authentication_id,
);
let lookup = fallback_reverse_lookup_not_found!(
@@ -394,9 +475,9 @@ impl<T: DatabaseStore> AuthenticationInterface for KVRouterStore<T> {
}
#[instrument(skip_all)]
- async fn find_authentication_by_merchant_id_connector_authentication_id(
+ async fn find_authentication_by_processor_merchant_id_connector_authentication_id(
&self,
- merchant_id: common_utils::id_type::MerchantId,
+ processor_merchant_id: common_utils::id_type::MerchantId,
connector_authentication_id: String,
merchant_key_store: &MerchantKeyStore,
state: &common_utils::types::keymanager::KeyManagerState,
@@ -404,13 +485,31 @@ impl<T: DatabaseStore> AuthenticationInterface for KVRouterStore<T> {
) -> error_stack::Result<Authentication, errors::StorageError> {
let database_call = || async {
let conn = pg_connection_read(self).await?;
- diesel_authentication::find_authentication_by_merchant_id_connector_authentication_id(
- &conn,
- &merchant_id,
- &connector_authentication_id,
- )
- .await
- .map_err(|error| {
+ // Stagger release: try processor_merchant_id, fall back to merchant_id for legacy NULL rows.
+ let result =
+ diesel_authentication::find_authentication_by_processor_merchant_id_connector_authentication_id(
+ &conn,
+ &processor_merchant_id,
+ &connector_authentication_id,
+ )
+ .await;
+ let result = match result {
+ Err(error)
+ if matches!(
+ error.current_context(),
+ diesel_models::errors::DatabaseError::NotFound
+ ) =>
+ {
+ diesel_authentication::find_authentication_by_merchant_id_connector_authentication_id(
+ &conn,
+ &processor_merchant_id,
+ &connector_authentication_id,
+ )
+ .await
+ }
+ other => other,
+ };
+ result.map_err(|error| {
let new_err = diesel_error_to_data_error(*error.current_context());
error.change_context(new_err)
})
@@ -428,7 +527,7 @@ impl<T: DatabaseStore> AuthenticationInterface for KVRouterStore<T> {
common_enums::MerchantStorageScheme::RedisKv => {
// Resolve partition/field via the connector reverse lookup (webhook flow).
let lookup_id = diesel_authentication::get_connector_authentication_lookup_id(
- &merchant_id,
+ &processor_merchant_id,
&connector_authentication_id,
);
let lookup = fallback_reverse_lookup_not_found!(
@@ -476,7 +575,7 @@ impl<T: DatabaseStore> AuthenticationInterface for KVRouterStore<T> {
}
#[instrument(skip_all)]
- async fn update_authentication_by_merchant_id_authentication_id(
+ async fn update_authentication_by_processor_merchant_id_authentication_id(
&self,
previous_state: Authentication,
authentication_update: AuthenticationUpdate,
@@ -484,7 +583,10 @@ impl<T: DatabaseStore> AuthenticationInterface for KVRouterStore<T> {
state: &common_utils::types::keymanager::KeyManagerState,
storage_scheme: common_enums::MerchantStorageScheme,
) -> error_stack::Result<Authentication, errors::StorageError> {
- let merchant_id = previous_state.merchant_id.clone();
+ let merchant_id = previous_state
+ .processor_merchant_id
+ .clone()
+ .unwrap_or_else(|| previous_state.merchant_id.clone());
let authentication_id = previous_state.authentication_id.clone();
let payment_id = previous_state.payment_id.clone();
@@ -512,7 +614,7 @@ impl<T: DatabaseStore> AuthenticationInterface for KVRouterStore<T> {
match storage_scheme {
common_enums::MerchantStorageScheme::PostgresOnly => {
self.router_store
- .update_authentication_by_merchant_id_authentication_id(
+ .update_authentication_by_processor_merchant_id_authentication_id(
previous_state,
authentication_update,
merchant_key_store,
@@ -646,9 +748,9 @@ impl AuthenticationInterface for MockDb {
Ok(authentication)
}
- async fn find_authentication_by_merchant_id_authentication_id(
+ async fn find_authentication_by_processor_merchant_id_authentication_id(
&self,
- merchant_id: &common_utils::id_type::MerchantId,
+ processor_merchant_id: &common_utils::id_type::MerchantId,
authentication_id: &common_utils::id_type::AuthenticationId,
_merchant_key_store: &MerchantKeyStore,
_state: &common_utils::types::keymanager::KeyManagerState,
@@ -658,22 +760,22 @@ impl AuthenticationInterface for MockDb {
authentications
.iter()
.find(|auth| {
- auth.merchant_id == *merchant_id && auth.authentication_id == *authentication_id
+ auth.merchant_id == *processor_merchant_id && auth.authentication_id == *authentication_id
})
.cloned()
.ok_or(
errors::StorageError::ValueNotFound(format!(
- "Authentication not found for merchant_id: {} and authentication_id: {}",
- merchant_id.get_string_repr(),
+ "Authentication not found for processor_merchant_id: {} and authentication_id: {}",
+ processor_merchant_id.get_string_repr(),
authentication_id.get_string_repr()
))
.into(),
)
}
- async fn find_authentication_by_merchant_id_connector_authentication_id(
+ async fn find_authentication_by_processor_merchant_id_connector_authentication_id(
&self,
- merchant_id: common_utils::id_type::MerchantId,
+ processor_merchant_id: common_utils::id_type::MerchantId,
connector_authentication_id: String,
_merchant_key_store: &MerchantKeyStore,
_state: &common_utils::types::keymanager::KeyManagerState,
@@ -683,22 +785,22 @@ impl AuthenticationInterface for MockDb {
authentications
.iter()
.find(|auth| {
- auth.merchant_id == merchant_id
+ auth.merchant_id == processor_merchant_id
&& auth.connector_authentication_id.as_ref()
== Some(&connector_authentication_id)
})
.cloned()
.ok_or(
errors::StorageError::ValueNotFound(format!(
- "Authentication not found for merchant_id: {} and connector_authentication_id: {}",
- merchant_id.get_string_repr(),
+ "Authentication not found for processor_merchant_id: {} and connector_authentication_id: {}",
+ processor_merchant_id.get_string_repr(),
connector_authentication_id
))
.into(),
)
}
- async fn update_authentication_by_merchant_id_authentication_id(
+ async fn update_authentication_by_processor_merchant_id_authentication_id(
&self,
previous_state: Authentication,
authentication_update: AuthenticationUpdate,
diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs
index cfe09000e0..0348fe2587 100644
--- a/crates/storage_impl/src/payments/payment_attempt.rs
+++ b/crates/storage_impl/src/payments/payment_attempt.rs
@@ -712,10 +712,10 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
.await
}
MerchantStorageScheme::RedisKv => {
- let merchant_id = payment_attempt.merchant_id.clone();
+ let processor_merchant_id = payment_attempt.processor_merchant_id.clone();
let payment_id = payment_attempt.payment_id.clone();
let key = PartitionKey::MerchantIdPaymentId {
- merchant_id: &merchant_id,
+ merchant_id: &processor_merchant_id,
payment_id: &payment_id,
};
let key_str = key.to_string();
diff --git a/migrations/2026-07-02-000001_add_index_processor_merchant_id_connector_authentication_id_for_authentication/down.sql b/migrations/2026-07-02-000001_add_index_processor_merchant_id_connector_authentication_id_for_authentication/down.sql
new file mode 100644
index 0000000000..0795e52b38
--- /dev/null
+++ b/migrations/2026-07-02-000001_add_index_processor_merchant_id_connector_authentication_id_for_authentication/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+DROP INDEX CONCURRENTLY IF EXISTS authentication_processor_mid_connector_auth_id_index;
diff --git a/migrations/2026-07-02-000001_add_index_processor_merchant_id_connector_authentication_id_for_authentication/metadata.toml b/migrations/2026-07-02-000001_add_index_processor_merchant_id_connector_authentication_id_for_authentication/metadata.toml
new file mode 100644
index 0000000000..79e9221c1f
--- /dev/null
+++ b/migrations/2026-07-02-000001_add_index_processor_merchant_id_connector_authentication_id_for_authentication/metadata.toml
@@ -0,0 +1 @@
+run_in_transaction = false
diff --git a/migrations/2026-07-02-000001_add_index_processor_merchant_id_connector_authentication_id_for_authentication/up.sql b/migrations/2026-07-02-000001_add_index_processor_merchant_id_connector_authentication_id_for_authentication/up.sql
new file mode 100644
index 0000000000..dc83a945b9
--- /dev/null
+++ b/migrations/2026-07-02-000001_add_index_processor_merchant_id_connector_authentication_id_for_authentication/up.sql
@@ -0,0 +1,2 @@
+-- Your SQL goes here
+CREATE INDEX CONCURRENTLY IF NOT EXISTS authentication_processor_mid_connector_auth_id_index ON authentication (processor_merchant_id, connector_authentication_id);