refactor(merchant_account): add back api_key field for backward compatibility (#761)

This commit is contained in:
Sanchith Hegde
2023-03-17 15:30:20 +05:30
committed by GitHub
parent 20b93276fc
commit 661dd48ae5
11 changed files with 55 additions and 7 deletions

View File

@ -1,13 +1,17 @@
use common_utils::ext_traits::ValueExt;
use error_stack::{report, FutureExt, ResultExt};
use error_stack::{report, FutureExt, IntoReport, ResultExt};
use storage_models::{enums, merchant_account};
use uuid::Uuid;
use crate::{
consts,
core::errors::{self, RouterResponse, RouterResult, StorageErrorExt},
core::{
api_keys,
errors::{self, RouterResponse, RouterResult, StorageErrorExt},
},
db::StorageInterface,
pii::Secret,
routes::AppState,
services::api as service_api,
types::{
self, api,
@ -27,11 +31,38 @@ pub fn create_merchant_publishable_key() -> String {
}
pub async fn create_merchant_account(
db: &dyn StorageInterface,
state: &AppState,
req: api::MerchantAccountCreate,
) -> RouterResponse<api::MerchantAccountResponse> {
let db = &*state.store;
let publishable_key = Some(create_merchant_publishable_key());
let api_key_request = api::CreateApiKeyRequest {
name: "Default API key".into(),
description: Some(
"An API key created by default when a user signs up on the HyperSwitch dashboard"
.into(),
),
expiration: api::ApiKeyExpiration::Never,
};
let api_key = match api_keys::create_api_key(
db,
&state.conf.api_keys,
#[cfg(feature = "kms")]
&state.conf.kms,
api_key_request,
req.merchant_id.clone(),
)
.await?
{
service_api::ApplicationResponse::Json(api::CreateApiKeyResponse { api_key, .. }) => {
Ok(api_key)
}
_ => Err(errors::ApiErrorResponse::InternalServerError)
.into_report()
.attach_printable("Unexpected create API key response"),
}?;
let merchant_details = Some(
utils::Encode::<api::MerchantDetails>::encode_to_value(&req.merchant_details)
.change_context(errors::ApiErrorResponse::InvalidDataValue {
@ -59,6 +90,7 @@ pub async fn create_merchant_account(
let merchant_account = storage::MerchantAccountNew {
merchant_id: req.merchant_id,
merchant_name: req.merchant_name,
api_key: Some(api_key),
merchant_details,
return_url: req.return_url.map(|a| a.to_string()),
webhook_details,

View File

@ -167,7 +167,7 @@ where
payment_method_id,
mandate_reference,
) {
logger::error!("{:?}", new_mandate_data);
logger::debug!("{:?}", new_mandate_data);
resp.request
.set_mandate_id(api_models::payments::MandateIds {
mandate_id: new_mandate_data.mandate_id.clone(),

View File

@ -179,6 +179,7 @@ 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

View File

@ -33,7 +33,7 @@ pub async fn merchant_account_create(
state.get_ref(),
&req,
json_payload.into_inner(),
|state, _, req| create_merchant_account(&*state.store, req),
|state, _, req| create_merchant_account(state, req),
&auth::AdminApiAuth,
)
.await

View File

@ -113,7 +113,6 @@ impl Payments {
)
.service(
web::resource("/{payment_id}/{merchant_id}/complete/{connector}")
// .route(web::get().to(payments_redirect_response))
.route(web::post().to(payments_complete_authorize)),
);
}

View File

@ -13,6 +13,7 @@ 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,