mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 17:47:54 +08:00
chore(merchant_account): remove api_key field (#713)
This commit is contained in:
@ -18,9 +18,9 @@ use crate::{
|
||||
};
|
||||
|
||||
#[inline]
|
||||
pub fn create_merchant_api_key() -> String {
|
||||
pub fn create_merchant_publishable_key() -> String {
|
||||
format!(
|
||||
"{}_{}",
|
||||
"pk_{}_{}",
|
||||
router_env::env::prefix_for_env(),
|
||||
Uuid::new_v4().simple()
|
||||
)
|
||||
@ -30,9 +30,7 @@ pub async fn create_merchant_account(
|
||||
db: &dyn StorageInterface,
|
||||
req: api::MerchantAccountCreate,
|
||||
) -> RouterResponse<api::MerchantAccountResponse> {
|
||||
let publishable_key = Some(format!("pk_{}", create_merchant_api_key()));
|
||||
|
||||
let api_key = Some(create_merchant_api_key().into());
|
||||
let publishable_key = Some(create_merchant_publishable_key());
|
||||
|
||||
let merchant_details = Some(
|
||||
utils::Encode::<api::MerchantDetails>::encode_to_value(&req.merchant_details)
|
||||
@ -61,7 +59,6 @@ pub async fn create_merchant_account(
|
||||
let merchant_account = storage::MerchantAccountNew {
|
||||
merchant_id: req.merchant_id,
|
||||
merchant_name: req.merchant_name,
|
||||
api_key,
|
||||
merchant_details,
|
||||
return_url: req.return_url.map(|a| a.to_string()),
|
||||
webhook_details,
|
||||
@ -169,7 +166,6 @@ pub async fn merchant_account_update(
|
||||
redirect_to_merchant_with_http_post: req.redirect_to_merchant_with_http_post,
|
||||
locker_id: req.locker_id,
|
||||
metadata: req.metadata,
|
||||
api_key: None,
|
||||
publishable_key: None,
|
||||
};
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use error_stack::{IntoReport, Report};
|
||||
use masking::PeekInterface;
|
||||
use error_stack::IntoReport;
|
||||
|
||||
use super::{MockDb, Store};
|
||||
use crate::{
|
||||
@ -32,11 +31,6 @@ pub trait MerchantAccountInterface {
|
||||
merchant_account: storage::MerchantAccountUpdate,
|
||||
) -> CustomResult<storage::MerchantAccount, errors::StorageError>;
|
||||
|
||||
async fn find_merchant_account_by_api_key(
|
||||
&self,
|
||||
api_key: &str,
|
||||
) -> CustomResult<storage::MerchantAccount, errors::StorageError>;
|
||||
|
||||
async fn find_merchant_account_by_publishable_key(
|
||||
&self,
|
||||
publishable_key: &str,
|
||||
@ -138,17 +132,6 @@ impl MerchantAccountInterface for Store {
|
||||
}
|
||||
}
|
||||
|
||||
async fn find_merchant_account_by_api_key(
|
||||
&self,
|
||||
api_key: &str,
|
||||
) -> CustomResult<storage::MerchantAccount, errors::StorageError> {
|
||||
let conn = pg_connection(&self.master_pool).await?;
|
||||
storage::MerchantAccount::find_by_api_key(&conn, api_key)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()
|
||||
}
|
||||
|
||||
async fn find_merchant_account_by_publishable_key(
|
||||
&self,
|
||||
publishable_key: &str,
|
||||
@ -196,7 +179,6 @@ impl MerchantAccountInterface for MockDb {
|
||||
#[allow(clippy::as_conversions)]
|
||||
id: accounts.len() as i32,
|
||||
merchant_id: merchant_account.merchant_id,
|
||||
api_key: merchant_account.api_key,
|
||||
return_url: merchant_account.return_url,
|
||||
enable_payment_response_hash: merchant_account
|
||||
.enable_payment_response_hash
|
||||
@ -255,21 +237,6 @@ impl MerchantAccountInterface for MockDb {
|
||||
Err(errors::StorageError::MockDbError)?
|
||||
}
|
||||
|
||||
#[allow(clippy::panic)]
|
||||
async fn find_merchant_account_by_api_key(
|
||||
&self,
|
||||
api_key: &str,
|
||||
) -> CustomResult<storage::MerchantAccount, errors::StorageError> {
|
||||
let accounts = self.merchant_accounts.lock().await;
|
||||
|
||||
accounts
|
||||
.iter()
|
||||
.find(|account| account.api_key.as_ref().map(|s| s.peek()) == Some(&api_key.into()))
|
||||
.cloned()
|
||||
.ok_or_else(|| Report::from(storage_models::errors::DatabaseError::NotFound).into())
|
||||
.into_report()
|
||||
}
|
||||
|
||||
async fn find_merchant_account_by_publishable_key(
|
||||
&self,
|
||||
_publishable_key: &str,
|
||||
|
||||
@ -22,10 +22,9 @@ use crate::{
|
||||
configs::settings::Connectors,
|
||||
consts,
|
||||
core::{
|
||||
errors::{self, CustomResult, RouterResult},
|
||||
errors::{self, CustomResult},
|
||||
payments,
|
||||
},
|
||||
db::StorageInterface,
|
||||
logger,
|
||||
routes::{app::AppStateInfo, AppState},
|
||||
services::authentication as auth,
|
||||
@ -524,17 +523,6 @@ where
|
||||
HttpResponse::from_error(error.current_context().clone())
|
||||
}
|
||||
|
||||
pub async fn authenticate_by_api_key(
|
||||
store: &dyn StorageInterface,
|
||||
api_key: &str,
|
||||
) -> RouterResult<storage::MerchantAccount> {
|
||||
store
|
||||
.find_merchant_account_by_api_key(api_key)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::Unauthorized)
|
||||
.attach_printable("Merchant not authenticated")
|
||||
}
|
||||
|
||||
pub fn http_response_json<T: body::MessageBody + 'static>(response: T) -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
|
||||
@ -13,7 +13,6 @@ impl ForeignFrom<storage::MerchantAccount> for MerchantAccountResponse {
|
||||
Self {
|
||||
merchant_id: item.merchant_id,
|
||||
merchant_name: item.merchant_name,
|
||||
api_key: item.api_key,
|
||||
return_url: item.return_url,
|
||||
enable_payment_response_hash: item.enable_payment_response_hash,
|
||||
payment_response_hash_key: item.payment_response_hash_key,
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
use masking::Secret;
|
||||
use router::types::{
|
||||
self,
|
||||
api::{self},
|
||||
storage::enums,
|
||||
};
|
||||
use router::types::{self, api, storage::enums};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{
|
||||
|
||||
@ -276,7 +276,9 @@ async fn payments_create_core() {
|
||||
|
||||
let state = routes::AppState::with_storage(conf, StorageImpl::PostgresqlTest).await;
|
||||
|
||||
let merchant_account = services::authenticate_by_api_key(&*state.store, "MySecretApiKey")
|
||||
let merchant_account = state
|
||||
.store
|
||||
.find_merchant_account_by_merchant_id("juspay_merchant")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@ -426,7 +428,9 @@ async fn payments_create_core_adyen_no_redirect() {
|
||||
let merchant_id = "arunraj".to_string();
|
||||
let payment_id = "pay_mbabizu24mvu3mela5njyhpit10".to_string();
|
||||
|
||||
let merchant_account = services::authenticate_by_api_key(&*state.store, "321")
|
||||
let merchant_account = state
|
||||
.store
|
||||
.find_merchant_account_by_merchant_id("juspay_merchant")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@ use router::{
|
||||
};
|
||||
use time::macros::datetime;
|
||||
use uuid::Uuid;
|
||||
// use router;
|
||||
|
||||
#[test]
|
||||
fn connector_list() {
|
||||
@ -37,7 +36,9 @@ async fn payments_create_core() {
|
||||
|
||||
let state = routes::AppState::with_storage(conf, StorageImpl::PostgresqlTest).await;
|
||||
|
||||
let merchant_account = services::authenticate_by_api_key(&*state.store, "MySecretApiKey")
|
||||
let merchant_account = state
|
||||
.store
|
||||
.find_merchant_account_by_merchant_id("juspay_merchant")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@ -192,7 +193,9 @@ async fn payments_create_core_adyen_no_redirect() {
|
||||
let merchant_id = "arunraj".to_string();
|
||||
let payment_id = "pay_mbabizu24mvu3mela5njyhpit10".to_string();
|
||||
|
||||
let merchant_account = services::authenticate_by_api_key(&*state.store, "321")
|
||||
let merchant_account = state
|
||||
.store
|
||||
.find_merchant_account_by_merchant_id("juspay_merchant")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user