mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 12:15:40 +08:00
refactor(merchant_account): add back api_key field for backward compatibility (#761)
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
use common_utils::pii;
|
||||
use masking::Secret;
|
||||
use masking::{Secret, StrongSecret};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use url;
|
||||
use utoipa::ToSchema;
|
||||
@ -18,6 +18,10 @@ 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>,
|
||||
|
||||
@ -131,6 +135,10 @@ 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>,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)),
|
||||
);
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use common_utils::pii;
|
||||
use diesel::{AsChangeset, Identifiable, Insertable, Queryable};
|
||||
use masking::StrongSecret;
|
||||
|
||||
use crate::{enums as storage_enums, schema::merchant_account};
|
||||
|
||||
@ -32,6 +33,7 @@ pub struct MerchantAccount {
|
||||
pub locker_id: Option<String>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub routing_algorithm: Option<serde_json::Value>,
|
||||
pub api_key: Option<StrongSecret<String>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Insertable, router_derive::DebugAsDisplay)]
|
||||
@ -51,6 +53,7 @@ pub struct MerchantAccountNew {
|
||||
pub locker_id: Option<String>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub routing_algorithm: Option<serde_json::Value>,
|
||||
pub api_key: Option<StrongSecret<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@ -176,6 +176,7 @@ diesel::table! {
|
||||
locker_id -> Nullable<Varchar>,
|
||||
metadata -> Nullable<Jsonb>,
|
||||
routing_algorithm -> Nullable<Json>,
|
||||
api_key -> Nullable<Varchar>,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1 @@
|
||||
ALTER TABLE merchant_account DROP COLUMN api_key;
|
||||
@ -0,0 +1,2 @@
|
||||
ALTER TABLE merchant_account
|
||||
ADD COLUMN api_key VARCHAR(128);
|
||||
Reference in New Issue
Block a user