Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(router): add an api to enable `connector_agnostic_mit` feature (#4480)
Shankar Singh Ce769abe50147
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex fde693a370..75bd2a31d8 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -1100,6 +1100,13 @@ pub struct 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)]pub struct ExtendedCardInfoConfig {/// Merchant public keydiff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rsindex 90a9dcbb7d..1131e9ad67 100644--- a/crates/diesel_models/src/business_profile.rs+++ b/crates/diesel_models/src/business_profile.rs@@ -37,6 +37,7 @@ pub struct BusinessProfile {pub authentication_connector_details: Option<serde_json::Value>,pub is_extended_card_info_enabled: Option<bool>,pub extended_card_info_config: Option<pii::SecretSerdeValue>,+ pub is_connector_agnostic_mit_enabled: Option<bool>,}#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]@@ -65,6 +66,7 @@ pub struct BusinessProfileNew {pub authentication_connector_details: Option<serde_json::Value>,pub is_extended_card_info_enabled: Option<bool>,pub extended_card_info_config: Option<pii::SecretSerdeValue>,+ pub is_connector_agnostic_mit_enabled: Option<bool>,}#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]@@ -90,6 +92,7 @@ pub struct BusinessProfileUpdateInternal {pub authentication_connector_details: Option<serde_json::Value>,pub is_extended_card_info_enabled: Option<bool>,pub extended_card_info_config: Option<pii::SecretSerdeValue>,+ pub is_connector_agnostic_mit_enabled: Option<bool>,}#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]@@ -117,6 +120,9 @@ pub enum BusinessProfileUpdate {ExtendedCardInfoUpdate {is_extended_card_info_enabled: Option<bool>,},+ ConnectorAgnosticMitUpdate {+ is_connector_agnostic_mit_enabled: Option<bool>,+ },}impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {@@ -168,6 +174,12 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {is_extended_card_info_enabled,..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,session_expiry: new.session_expiry,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,extended_card_info_config: new.extended_card_info_config,}@@ -223,6 +236,7 @@ impl BusinessProfileUpdate {authentication_connector_details,is_extended_card_info_enabled,extended_card_info_config,+ is_connector_agnostic_mit_enabled,} = self.into();BusinessProfile {profile_name: profile_name.unwrap_or(source.profile_name),@@ -245,6 +259,7 @@ impl BusinessProfileUpdate {session_expiry,authentication_connector_details,is_extended_card_info_enabled,+ is_connector_agnostic_mit_enabled,extended_card_info_config,..source}diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex f5dc5abe1e..2e28bc5d30 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -194,6 +194,7 @@ diesel::table! {authentication_connector_details -> Nullable<Jsonb>,is_extended_card_info_enabled -> Nullable<Bool>,extended_card_info_config -> Nullable<Jsonb>,+ is_connector_agnostic_mit_enabled -> Nullable<Bool>,}}diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex 7d2fabc3f3..0b8d52332d 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -1739,6 +1739,47 @@ pub async fn extended_card_info_toggle(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(connector_name: api_models::enums::Connector,val: &types::ConnectorAuthType,diff --git a/crates/router/src/routes/admin.rs b/crates/router/src/routes/admin.rsindex 63d9f840a0..d9cadf002c 100644--- a/crates/router/src/routes/admin.rs+++ b/crates/router/src/routes/admin.rs@@ -589,6 +589,32 @@ pub async fn business_profiles_list().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////// Toggle KV mode for the Merchant Accountdiff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rsindex 0f3673ee20..6a8a4ee5e0 100644--- a/crates/router/src/routes/app.rs+++ b/crates/router/src/routes/app.rs@@ -1131,6 +1131,10 @@ impl BusinessProfile {.service(web::resource("/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)),),)}diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rsindex 4d1121a8ea..bf91f8055d 100644--- a/crates/router/src/routes/lock_utils.rs+++ b/crates/router/src/routes/lock_utils.rs@@ -168,7 +168,8 @@ impl From<Flow> for ApiIdentifier {| Flow::BusinessProfileRetrieve| Flow::BusinessProfileDelete| Flow::BusinessProfileList- | Flow::ToggleExtendedCardInfo => Self::Business,+ | Flow::ToggleExtendedCardInfo+ | Flow::ToggleConnectorAgnosticMit => Self::Business,Flow::PaymentLinkRetrieve| Flow::PaymentLinkInitiatediff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rsindex 77fe837181..793d042ea4 100644--- a/crates/router/src/types/api/admin.rs+++ b/crates/router/src/types/api/admin.rs@@ -175,6 +175,7 @@ impl ForeignTryFrom<(domain::MerchantAccount, BusinessProfileCreate)>.change_context(errors::ApiErrorResponse::InvalidDataValue {field_name: "authentication_connector_details",})?,+ is_connector_agnostic_mit_enabled: None,is_extended_card_info_enabled: None,extended_card_info_config: None,})diff --git a/crates/router_env/src/logger/types.rs b/crates/router_env/src/logger/types.rsindex 78f570f647..e8ffe0685b 100644--- a/crates/router_env/src/logger/types.rs+++ b/crates/router_env/src/logger/types.rs@@ -406,6 +406,8 @@ pub enum Flow {RetrievePollStatus,/// Toggles the extended card info feature in profile levelToggleExtendedCardInfo,+ /// Toggles the extended card info feature in profile level+ ToggleConnectorAgnosticMit,/// Get the extended card info associated to a payment_idGetExtendedCardInfo,}diff --git a/migrations/2024-04-24-111807_add-is-connector_agnostic_mit/down.sql b/migrations/2024-04-24-111807_add-is-connector_agnostic_mit/down.sqlnew file mode 100644index 0000000000..80672e85a2--- /dev/null+++ b/migrations/2024-04-24-111807_add-is-connector_agnostic_mit/down.sql@@ -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;\ No newline at end of filediff --git a/migrations/2024-04-24-111807_add-is-connector_agnostic_mit/up.sql b/migrations/2024-04-24-111807_add-is-connector_agnostic_mit/up.sqlnew file mode 100644index 0000000000..beee332561--- /dev/null+++ b/migrations/2024-04-24-111807_add-is-connector_agnostic_mit/up.sql@@ -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;\ No newline at end of file