mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
feat: add an api for toggling extended card info feature (#4444)
This commit is contained in:
@ -1648,7 +1648,7 @@ pub async fn update_business_profile(
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let business_profile_update = storage::business_profile::BusinessProfileUpdateInternal {
|
||||
let business_profile_update = storage::business_profile::BusinessProfileUpdate::Update {
|
||||
profile_name: request.profile_name,
|
||||
modified_at: Some(date_time::now()),
|
||||
return_url: request.return_url.map(|return_url| return_url.to_string()),
|
||||
@ -1691,6 +1691,39 @@ pub async fn update_business_profile(
|
||||
))
|
||||
}
|
||||
|
||||
pub async fn extended_card_info_toggle(
|
||||
state: AppState,
|
||||
profile_id: &str,
|
||||
ext_card_info_choice: admin_types::ExtendedCardInfoChoice,
|
||||
) -> RouterResponse<admin_types::ExtendedCardInfoChoice> {
|
||||
let db = state.store.as_ref();
|
||||
let business_profile = db
|
||||
.find_business_profile_by_profile_id(profile_id)
|
||||
.await
|
||||
.to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound {
|
||||
id: profile_id.to_string(),
|
||||
})?;
|
||||
|
||||
if business_profile.is_extended_card_info_enabled.is_none()
|
||||
|| business_profile
|
||||
.is_extended_card_info_enabled
|
||||
.is_some_and(|existing_config| existing_config != ext_card_info_choice.enabled)
|
||||
{
|
||||
let business_profile_update =
|
||||
storage::business_profile::BusinessProfileUpdate::ExtendedCardInfoUpdate {
|
||||
is_extended_card_info_enabled: Some(ext_card_info_choice.enabled),
|
||||
};
|
||||
|
||||
db.update_business_profile_by_profile_id(business_profile, business_profile_update)
|
||||
.await
|
||||
.to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound {
|
||||
id: profile_id.to_owned(),
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(service_api::ApplicationResponse::Json(ext_card_info_choice))
|
||||
}
|
||||
|
||||
pub(crate) fn validate_auth_and_metadata_type(
|
||||
connector_name: api_models::enums::Connector,
|
||||
val: &types::ConnectorAuthType,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
use api_models::routing as routing_types;
|
||||
use common_utils::ext_traits::Encode;
|
||||
use diesel_models::{
|
||||
business_profile::{BusinessProfile, BusinessProfileUpdateInternal},
|
||||
business_profile::{BusinessProfile, BusinessProfileUpdate},
|
||||
configs,
|
||||
};
|
||||
use error_stack::ResultExt;
|
||||
@ -245,7 +245,7 @@ pub async fn update_business_profile_active_algorithm_ref(
|
||||
storage::enums::TransactionType::Payout => (None, Some(ref_val)),
|
||||
};
|
||||
|
||||
let business_profile_update = BusinessProfileUpdateInternal {
|
||||
let business_profile_update = BusinessProfileUpdate::Update {
|
||||
profile_name: None,
|
||||
return_url: None,
|
||||
enable_payment_response_hash: None,
|
||||
|
||||
@ -30,7 +30,7 @@ pub trait BusinessProfileInterface {
|
||||
async fn update_business_profile_by_profile_id(
|
||||
&self,
|
||||
current_state: business_profile::BusinessProfile,
|
||||
business_profile_update: business_profile::BusinessProfileUpdateInternal,
|
||||
business_profile_update: business_profile::BusinessProfileUpdate,
|
||||
) -> CustomResult<business_profile::BusinessProfile, errors::StorageError>;
|
||||
|
||||
async fn delete_business_profile_by_profile_id_merchant_id(
|
||||
@ -90,7 +90,7 @@ impl BusinessProfileInterface for Store {
|
||||
async fn update_business_profile_by_profile_id(
|
||||
&self,
|
||||
current_state: business_profile::BusinessProfile,
|
||||
business_profile_update: business_profile::BusinessProfileUpdateInternal,
|
||||
business_profile_update: business_profile::BusinessProfileUpdate,
|
||||
) -> CustomResult<business_profile::BusinessProfile, errors::StorageError> {
|
||||
let conn = connection::pg_connection_write(self).await?;
|
||||
storage::business_profile::BusinessProfile::update_by_profile_id(
|
||||
@ -169,7 +169,7 @@ impl BusinessProfileInterface for MockDb {
|
||||
async fn update_business_profile_by_profile_id(
|
||||
&self,
|
||||
current_state: business_profile::BusinessProfile,
|
||||
business_profile_update: business_profile::BusinessProfileUpdateInternal,
|
||||
business_profile_update: business_profile::BusinessProfileUpdate,
|
||||
) -> CustomResult<business_profile::BusinessProfile, errors::StorageError> {
|
||||
self.business_profiles
|
||||
.lock()
|
||||
|
||||
@ -2039,7 +2039,7 @@ impl BusinessProfileInterface for KafkaStore {
|
||||
async fn update_business_profile_by_profile_id(
|
||||
&self,
|
||||
current_state: business_profile::BusinessProfile,
|
||||
business_profile_update: business_profile::BusinessProfileUpdateInternal,
|
||||
business_profile_update: business_profile::BusinessProfileUpdate,
|
||||
) -> CustomResult<business_profile::BusinessProfile, errors::StorageError> {
|
||||
self.diesel_store
|
||||
.update_business_profile_by_profile_id(current_state, business_profile_update)
|
||||
|
||||
@ -612,3 +612,25 @@ pub async fn merchant_account_kv_status(
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[instrument(skip_all, fields(flow = ?Flow::ToggleExtendedCardInfo))]
|
||||
pub async fn toggle_extended_card_info(
|
||||
state: web::Data<AppState>,
|
||||
req: HttpRequest,
|
||||
path: web::Path<(String, String)>,
|
||||
json_payload: web::Json<api_models::admin::ExtendedCardInfoChoice>,
|
||||
) -> HttpResponse {
|
||||
let flow = Flow::ToggleExtendedCardInfo;
|
||||
let (_, profile_id) = path.into_inner();
|
||||
|
||||
Box::pin(api::server_wrap(
|
||||
flow,
|
||||
state,
|
||||
&req,
|
||||
json_payload.into_inner(),
|
||||
|state, _, req, _| extended_card_info_toggle(state, &profile_id, req),
|
||||
&auth::AdminApiAuth,
|
||||
api_locking::LockAction::NotApplicable,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
@ -1104,10 +1104,17 @@ impl BusinessProfile {
|
||||
.route(web::get().to(business_profiles_list)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/{profile_id}")
|
||||
.route(web::get().to(business_profile_retrieve))
|
||||
.route(web::post().to(business_profile_update))
|
||||
.route(web::delete().to(business_profile_delete)),
|
||||
web::scope("/{profile_id}")
|
||||
.service(
|
||||
web::resource("")
|
||||
.route(web::get().to(business_profile_retrieve))
|
||||
.route(web::post().to(business_profile_update))
|
||||
.route(web::delete().to(business_profile_delete)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/toggle_extended_card_info")
|
||||
.route(web::post().to(toggle_extended_card_info)),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,7 +166,8 @@ impl From<Flow> for ApiIdentifier {
|
||||
| Flow::BusinessProfileUpdate
|
||||
| Flow::BusinessProfileRetrieve
|
||||
| Flow::BusinessProfileDelete
|
||||
| Flow::BusinessProfileList => Self::Business,
|
||||
| Flow::BusinessProfileList
|
||||
| Flow::ToggleExtendedCardInfo => Self::Business,
|
||||
|
||||
Flow::PaymentLinkRetrieve
|
||||
| Flow::PaymentLinkInitiate
|
||||
|
||||
@ -175,6 +175,7 @@ impl ForeignTryFrom<(domain::MerchantAccount, BusinessProfileCreate)>
|
||||
.change_context(errors::ApiErrorResponse::InvalidDataValue {
|
||||
field_name: "authentication_connector_details",
|
||||
})?,
|
||||
is_extended_card_info_enabled: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
pub use diesel_models::business_profile::{
|
||||
BusinessProfile, BusinessProfileNew, BusinessProfileUpdateInternal,
|
||||
BusinessProfile, BusinessProfileNew, BusinessProfileUpdate, BusinessProfileUpdateInternal,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user