fix(api_keys): fix API key being created for non-existent merchant account (#1712)

This commit is contained in:
Sangamesh Kulkarni
2023-07-14 17:15:10 +05:30
committed by GitHub
parent 8c5703df54
commit c9e20dcd30

View File

@ -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")]