mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	feat(router): add an api to enable connector_agnostic_mit feature (#4480)
				
					
				
			Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
		| @ -1100,6 +1100,13 @@ pub struct ExtendedCardInfoChoice { | |||||||
|  |  | ||||||
| impl common_utils::events::ApiEventMetric for ExtendedCardInfoChoice {} | impl common_utils::events::ApiEventMetric for ExtendedCardInfoChoice {} | ||||||
|  |  | ||||||
|  | #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)] | ||||||
|  | pub struct ConnectorAgnosticMitChoice { | ||||||
|  |     pub enabled: bool, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl common_utils::events::ApiEventMetric for ConnectorAgnosticMitChoice {} | ||||||
|  |  | ||||||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)] | #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)] | ||||||
| pub struct ExtendedCardInfoConfig { | pub struct ExtendedCardInfoConfig { | ||||||
|     /// Merchant public key |     /// Merchant public key | ||||||
|  | |||||||
| @ -37,6 +37,7 @@ pub struct BusinessProfile { | |||||||
|     pub authentication_connector_details: Option<serde_json::Value>, |     pub authentication_connector_details: Option<serde_json::Value>, | ||||||
|     pub is_extended_card_info_enabled: Option<bool>, |     pub is_extended_card_info_enabled: Option<bool>, | ||||||
|     pub extended_card_info_config: Option<pii::SecretSerdeValue>, |     pub extended_card_info_config: Option<pii::SecretSerdeValue>, | ||||||
|  |     pub is_connector_agnostic_mit_enabled: Option<bool>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)] | #[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)] | ||||||
| @ -65,6 +66,7 @@ pub struct BusinessProfileNew { | |||||||
|     pub authentication_connector_details: Option<serde_json::Value>, |     pub authentication_connector_details: Option<serde_json::Value>, | ||||||
|     pub is_extended_card_info_enabled: Option<bool>, |     pub is_extended_card_info_enabled: Option<bool>, | ||||||
|     pub extended_card_info_config: Option<pii::SecretSerdeValue>, |     pub extended_card_info_config: Option<pii::SecretSerdeValue>, | ||||||
|  |     pub is_connector_agnostic_mit_enabled: Option<bool>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)] | #[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)] | ||||||
| @ -90,6 +92,7 @@ pub struct BusinessProfileUpdateInternal { | |||||||
|     pub authentication_connector_details: Option<serde_json::Value>, |     pub authentication_connector_details: Option<serde_json::Value>, | ||||||
|     pub is_extended_card_info_enabled: Option<bool>, |     pub is_extended_card_info_enabled: Option<bool>, | ||||||
|     pub extended_card_info_config: Option<pii::SecretSerdeValue>, |     pub extended_card_info_config: Option<pii::SecretSerdeValue>, | ||||||
|  |     pub is_connector_agnostic_mit_enabled: Option<bool>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||||||
| @ -117,6 +120,9 @@ pub enum BusinessProfileUpdate { | |||||||
|     ExtendedCardInfoUpdate { |     ExtendedCardInfoUpdate { | ||||||
|         is_extended_card_info_enabled: Option<bool>, |         is_extended_card_info_enabled: Option<bool>, | ||||||
|     }, |     }, | ||||||
|  |     ConnectorAgnosticMitUpdate { | ||||||
|  |         is_connector_agnostic_mit_enabled: Option<bool>, | ||||||
|  |     }, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal { | impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal { | ||||||
| @ -168,6 +174,12 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal { | |||||||
|                 is_extended_card_info_enabled, |                 is_extended_card_info_enabled, | ||||||
|                 ..Default::default() |                 ..Default::default() | ||||||
|             }, |             }, | ||||||
|  |             BusinessProfileUpdate::ConnectorAgnosticMitUpdate { | ||||||
|  |                 is_connector_agnostic_mit_enabled, | ||||||
|  |             } => Self { | ||||||
|  |                 is_connector_agnostic_mit_enabled, | ||||||
|  |                 ..Default::default() | ||||||
|  |             }, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -195,6 +207,7 @@ impl From<BusinessProfileNew> for BusinessProfile { | |||||||
|             payment_link_config: new.payment_link_config, |             payment_link_config: new.payment_link_config, | ||||||
|             session_expiry: new.session_expiry, |             session_expiry: new.session_expiry, | ||||||
|             authentication_connector_details: new.authentication_connector_details, |             authentication_connector_details: new.authentication_connector_details, | ||||||
|  |             is_connector_agnostic_mit_enabled: new.is_connector_agnostic_mit_enabled, | ||||||
|             is_extended_card_info_enabled: new.is_extended_card_info_enabled, |             is_extended_card_info_enabled: new.is_extended_card_info_enabled, | ||||||
|             extended_card_info_config: new.extended_card_info_config, |             extended_card_info_config: new.extended_card_info_config, | ||||||
|         } |         } | ||||||
| @ -223,6 +236,7 @@ impl BusinessProfileUpdate { | |||||||
|             authentication_connector_details, |             authentication_connector_details, | ||||||
|             is_extended_card_info_enabled, |             is_extended_card_info_enabled, | ||||||
|             extended_card_info_config, |             extended_card_info_config, | ||||||
|  |             is_connector_agnostic_mit_enabled, | ||||||
|         } = self.into(); |         } = self.into(); | ||||||
|         BusinessProfile { |         BusinessProfile { | ||||||
|             profile_name: profile_name.unwrap_or(source.profile_name), |             profile_name: profile_name.unwrap_or(source.profile_name), | ||||||
| @ -245,6 +259,7 @@ impl BusinessProfileUpdate { | |||||||
|             session_expiry, |             session_expiry, | ||||||
|             authentication_connector_details, |             authentication_connector_details, | ||||||
|             is_extended_card_info_enabled, |             is_extended_card_info_enabled, | ||||||
|  |             is_connector_agnostic_mit_enabled, | ||||||
|             extended_card_info_config, |             extended_card_info_config, | ||||||
|             ..source |             ..source | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -194,6 +194,7 @@ diesel::table! { | |||||||
|         authentication_connector_details -> Nullable<Jsonb>, |         authentication_connector_details -> Nullable<Jsonb>, | ||||||
|         is_extended_card_info_enabled -> Nullable<Bool>, |         is_extended_card_info_enabled -> Nullable<Bool>, | ||||||
|         extended_card_info_config -> Nullable<Jsonb>, |         extended_card_info_config -> Nullable<Jsonb>, | ||||||
|  |         is_connector_agnostic_mit_enabled -> Nullable<Bool>, | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
| @ -1739,6 +1739,47 @@ pub async fn extended_card_info_toggle( | |||||||
|     Ok(service_api::ApplicationResponse::Json(ext_card_info_choice)) |     Ok(service_api::ApplicationResponse::Json(ext_card_info_choice)) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | pub async fn connector_agnostic_mit_toggle( | ||||||
|  |     state: AppState, | ||||||
|  |     merchant_id: &str, | ||||||
|  |     profile_id: &str, | ||||||
|  |     connector_agnostic_mit_choice: admin_types::ConnectorAgnosticMitChoice, | ||||||
|  | ) -> RouterResponse<admin_types::ConnectorAgnosticMitChoice> { | ||||||
|  |     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.merchant_id != merchant_id { | ||||||
|  |         Err(errors::ApiErrorResponse::AccessForbidden { | ||||||
|  |             resource: profile_id.to_string(), | ||||||
|  |         })? | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if business_profile.is_connector_agnostic_mit_enabled | ||||||
|  |         != Some(connector_agnostic_mit_choice.enabled) | ||||||
|  |     { | ||||||
|  |         let business_profile_update = | ||||||
|  |             storage::business_profile::BusinessProfileUpdate::ConnectorAgnosticMitUpdate { | ||||||
|  |                 is_connector_agnostic_mit_enabled: Some(connector_agnostic_mit_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( | ||||||
|  |         connector_agnostic_mit_choice, | ||||||
|  |     )) | ||||||
|  | } | ||||||
|  |  | ||||||
| pub(crate) fn validate_auth_and_metadata_type( | pub(crate) fn validate_auth_and_metadata_type( | ||||||
|     connector_name: api_models::enums::Connector, |     connector_name: api_models::enums::Connector, | ||||||
|     val: &types::ConnectorAuthType, |     val: &types::ConnectorAuthType, | ||||||
|  | |||||||
| @ -589,6 +589,32 @@ pub async fn business_profiles_list( | |||||||
|     ) |     ) | ||||||
|     .await |     .await | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #[instrument(skip_all, fields(flow = ?Flow::ToggleConnectorAgnosticMit))] | ||||||
|  | pub async fn toggle_connector_agnostic_mit( | ||||||
|  |     state: web::Data<AppState>, | ||||||
|  |     req: HttpRequest, | ||||||
|  |     path: web::Path<(String, String)>, | ||||||
|  |     json_payload: web::Json<api_models::admin::ConnectorAgnosticMitChoice>, | ||||||
|  | ) -> HttpResponse { | ||||||
|  |     let flow = Flow::ToggleConnectorAgnosticMit; | ||||||
|  |     let (merchant_id, profile_id) = path.into_inner(); | ||||||
|  |  | ||||||
|  |     Box::pin(api::server_wrap( | ||||||
|  |         flow, | ||||||
|  |         state, | ||||||
|  |         &req, | ||||||
|  |         json_payload.into_inner(), | ||||||
|  |         |state, _, req, _| connector_agnostic_mit_toggle(state, &merchant_id, &profile_id, req), | ||||||
|  |         auth::auth_type( | ||||||
|  |             &auth::ApiKeyAuth, | ||||||
|  |             &auth::JWTAuth(Permission::RoutingWrite), | ||||||
|  |             req.headers(), | ||||||
|  |         ), | ||||||
|  |         api_locking::LockAction::NotApplicable, | ||||||
|  |     )) | ||||||
|  |     .await | ||||||
|  | } | ||||||
| /// Merchant Account - KV Status | /// Merchant Account - KV Status | ||||||
| /// | /// | ||||||
| /// Toggle KV mode for the Merchant Account | /// Toggle KV mode for the Merchant Account | ||||||
|  | |||||||
| @ -1131,6 +1131,10 @@ impl BusinessProfile { | |||||||
|                     .service( |                     .service( | ||||||
|                         web::resource("/toggle_extended_card_info") |                         web::resource("/toggle_extended_card_info") | ||||||
|                             .route(web::post().to(toggle_extended_card_info)), |                             .route(web::post().to(toggle_extended_card_info)), | ||||||
|  |                     ) | ||||||
|  |                     .service( | ||||||
|  |                         web::resource("/toggle_connector_agnostic_mit") | ||||||
|  |                             .route(web::post().to(toggle_connector_agnostic_mit)), | ||||||
|                     ), |                     ), | ||||||
|             ) |             ) | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -168,7 +168,8 @@ impl From<Flow> for ApiIdentifier { | |||||||
|             | Flow::BusinessProfileRetrieve |             | Flow::BusinessProfileRetrieve | ||||||
|             | Flow::BusinessProfileDelete |             | Flow::BusinessProfileDelete | ||||||
|             | Flow::BusinessProfileList |             | Flow::BusinessProfileList | ||||||
|             | Flow::ToggleExtendedCardInfo => Self::Business, |             | Flow::ToggleExtendedCardInfo | ||||||
|  |             | Flow::ToggleConnectorAgnosticMit => Self::Business, | ||||||
|  |  | ||||||
|             Flow::PaymentLinkRetrieve |             Flow::PaymentLinkRetrieve | ||||||
|             | Flow::PaymentLinkInitiate |             | Flow::PaymentLinkInitiate | ||||||
|  | |||||||
| @ -175,6 +175,7 @@ impl ForeignTryFrom<(domain::MerchantAccount, BusinessProfileCreate)> | |||||||
|                 .change_context(errors::ApiErrorResponse::InvalidDataValue { |                 .change_context(errors::ApiErrorResponse::InvalidDataValue { | ||||||
|                     field_name: "authentication_connector_details", |                     field_name: "authentication_connector_details", | ||||||
|                 })?, |                 })?, | ||||||
|  |             is_connector_agnostic_mit_enabled: None, | ||||||
|             is_extended_card_info_enabled: None, |             is_extended_card_info_enabled: None, | ||||||
|             extended_card_info_config: None, |             extended_card_info_config: None, | ||||||
|         }) |         }) | ||||||
|  | |||||||
| @ -406,6 +406,8 @@ pub enum Flow { | |||||||
|     RetrievePollStatus, |     RetrievePollStatus, | ||||||
|     /// Toggles the extended card info feature in profile level |     /// Toggles the extended card info feature in profile level | ||||||
|     ToggleExtendedCardInfo, |     ToggleExtendedCardInfo, | ||||||
|  |     /// Toggles the extended card info feature in profile level | ||||||
|  |     ToggleConnectorAgnosticMit, | ||||||
|     /// Get the extended card info associated to a payment_id |     /// Get the extended card info associated to a payment_id | ||||||
|     GetExtendedCardInfo, |     GetExtendedCardInfo, | ||||||
| } | } | ||||||
|  | |||||||
| @ -0,0 +1,3 @@ | |||||||
|  | -- This file should undo anything in `up.sql` | ||||||
|  |  | ||||||
|  | ALTER TABLE business_profile DROP COLUMN IF EXISTS is_connector_agnostic_mit_enabled; | ||||||
| @ -0,0 +1,3 @@ | |||||||
|  | -- Your SQL goes here | ||||||
|  |  | ||||||
|  | ALTER TABLE business_profile ADD COLUMN IF NOT EXISTS is_connector_agnostic_mit_enabled BOOLEAN DEFAULT FALSE; | ||||||
		Reference in New Issue
	
	Block a user
	 Shankar Singh C
					Shankar Singh C