Skip to content

Commit

Permalink
revert: refactor(merchant_account): add back api_key field for back…
Browse files Browse the repository at this point in the history
…ward compatibility (#761) (#1062)
  • Loading branch information
SanchithHegde authored May 10, 2023
1 parent 5214e22 commit f481abb
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 52 deletions.
10 changes: 1 addition & 9 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use common_utils::pii;
use masking::{Secret, StrongSecret};
use masking::Secret;
use serde::{Deserialize, Serialize};
use url;
use utoipa::ToSchema;
Expand All @@ -18,10 +18,6 @@ pub struct MerchantAccountCreate {
#[schema(example = "NewAge Retailer")]
pub merchant_name: Option<String>,

/// API key that will be used for server side API access
#[schema(value_type = Option<String>, example = "Ah2354543543523")]
pub api_key: Option<StrongSecret<String>>,

/// Merchant related details
pub merchant_details: Option<MerchantDetails>,

Expand Down Expand Up @@ -155,10 +151,6 @@ pub struct MerchantAccountResponse {
#[schema(example = "NewAge Retailer")]
pub merchant_name: Option<String>,

/// API key that will be used for server side API access
#[schema(value_type = Option<String>, example = "Ah2354543543523")]
pub api_key: Option<StrongSecret<String>>,

/// The URL to redirect after the completion of the operation
#[schema(max_length = 255, example = "https://www.example.com/success")]
pub return_url: Option<String>,
Expand Down
36 changes: 3 additions & 33 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use api_models::admin::PrimaryBusinessDetails;
use common_utils::ext_traits::ValueExt;
use error_stack::{report, FutureExt, IntoReport, ResultExt};
use masking::Secret; //PeekInterface
use error_stack::{report, FutureExt, ResultExt};
use masking::Secret;
use storage_models::{enums, merchant_account};
use uuid::Uuid;

use crate::{
consts,
core::{
api_keys,
errors::{self, RouterResponse, RouterResult, StorageErrorExt},
payments::helpers,
},
db::StorageInterface,
routes::AppState,
services::api as service_api,
types::{
self, api,
Expand Down Expand Up @@ -58,38 +56,11 @@ fn get_primary_business_details(
}

pub async fn create_merchant_account(
state: &AppState,
db: &dyn StorageInterface,
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 primary_business_details = utils::Encode::<Vec<PrimaryBusinessDetails>>::encode_to_value(
&get_primary_business_details(&req),
)
Expand Down Expand Up @@ -132,7 +103,6 @@ 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,
Expand Down
1 change: 0 additions & 1 deletion crates/router/src/db/merchant_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,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
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/routes/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub async fn merchant_account_create(
state.get_ref(),
&req,
json_payload.into_inner(),
|state, _, req| create_merchant_account(state, req),
|state, _, req| create_merchant_account(&*state.store, req),
&auth::AdminApiAuth,
)
.await
Expand Down
1 change: 0 additions & 1 deletion crates/router/src/types/api/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ impl ForeignTryFrom<storage::MerchantAccount> for MerchantAccountResponse {
Ok(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,
Expand Down
3 changes: 0 additions & 3 deletions crates/storage_models/src/merchant_account.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use common_utils::pii;
use diesel::{AsChangeset, Identifiable, Insertable, Queryable};
use masking::StrongSecret;

use crate::{enums as storage_enums, schema::merchant_account};

Expand Down Expand Up @@ -34,7 +33,6 @@ pub struct MerchantAccount {
pub metadata: Option<pii::SecretSerdeValue>,
pub routing_algorithm: Option<serde_json::Value>,
pub primary_business_details: serde_json::Value,
pub api_key: Option<StrongSecret<String>>,
pub intent_fulfillment_time: Option<i64>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
Expand All @@ -58,7 +56,6 @@ pub struct MerchantAccountNew {
pub metadata: Option<pii::SecretSerdeValue>,
pub routing_algorithm: Option<serde_json::Value>,
pub primary_business_details: serde_json::Value,
pub api_key: Option<StrongSecret<String>>,
pub intent_fulfillment_time: Option<i64>,
}

Expand Down
1 change: 0 additions & 1 deletion crates/storage_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ diesel::table! {
metadata -> Nullable<Jsonb>,
routing_algorithm -> Nullable<Json>,
primary_business_details -> Json,
api_key -> Nullable<Varchar>,
intent_fulfillment_time -> Nullable<Int8>,
created_at -> Timestamp,
modified_at -> Timestamp,
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit f481abb

Please sign in to comment.