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(api_keys): fix API key being created for non-existent merchant account (#1712)

Sangamesh Kulkarnic9e20dcd30be
diff --git a/crates/router/src/core/api_keys.rs b/crates/router/src/core/api_keys.rs
index d26879b116..b26a67d9fe 100644
--- a/crates/router/src/core/api_keys.rs
+++ b/crates/router/src/core/api_keys.rs
@@ -135,6 +135,18 @@ pub async fn create_api_key(
merchant_id: String,
) -> RouterResponse<api::CreateApiKeyResponse> {
let store = &*state.store;
+ // We are not fetching merchant account as the merchant key store is needed to search for a
+ // merchant account.
+ // Instead, we're only fetching merchant key store, as it is sufficient to identify
+ // non-existence of a merchant account.
+ store
+ .get_merchant_key_store_by_merchant_id(
+ merchant_id.as_str(),
+ &store.get_master_key().to_vec().into(),
+ )
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
+
let hash_key = get_hash_key(
api_key_config,
#[cfg(feature = "kms")]