Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,3 +1095,10 @@ 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 {}
15 changes: 15 additions & 0 deletions crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct BusinessProfile {
pub session_expiry: Option<i64>,
pub authentication_connector_details: Option<serde_json::Value>,
pub is_extended_card_info_enabled: Option<bool>,
pub is_connector_agnostic_mit_enabled: Option<bool>,
}

#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
Expand Down Expand Up @@ -63,6 +64,7 @@ pub struct BusinessProfileNew {
pub session_expiry: Option<i64>,
pub authentication_connector_details: Option<serde_json::Value>,
pub is_extended_card_info_enabled: Option<bool>,
pub is_connector_agnostic_mit_enabled: Option<bool>,
}

#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
Expand All @@ -87,6 +89,7 @@ pub struct BusinessProfileUpdateInternal {
pub session_expiry: Option<i64>,
pub authentication_connector_details: Option<serde_json::Value>,
pub is_extended_card_info_enabled: Option<bool>,
pub is_connector_agnostic_mit_enabled: Option<bool>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
Expand All @@ -113,6 +116,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 {
Expand Down Expand Up @@ -162,6 +168,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()
},
}
}
}
Expand Down Expand Up @@ -189,6 +201,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,
}
}
Expand All @@ -215,6 +228,7 @@ impl BusinessProfileUpdate {
session_expiry,
authentication_connector_details,
is_extended_card_info_enabled,
is_connector_agnostic_mit_enabled,
} = self.into();
BusinessProfile {
profile_name: profile_name.unwrap_or(source.profile_name),
Expand All @@ -237,6 +251,7 @@ impl BusinessProfileUpdate {
session_expiry,
authentication_connector_details,
is_extended_card_info_enabled,
is_connector_agnostic_mit_enabled,
..source
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ diesel::table! {
session_expiry -> Nullable<Int8>,
authentication_connector_details -> Nullable<Jsonb>,
is_extended_card_info_enabled -> Nullable<Bool>,
is_connector_agnostic_mit_enabled -> Nullable<Bool>,
}
}

Expand Down
34 changes: 34 additions & 0 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,40 @@ 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,
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.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,
Expand Down
26 changes: 26 additions & 0 deletions crates/router/src/routes/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (_, profile_id) = path.into_inner();

Box::pin(api::server_wrap(
flow,
state,
&req,
json_payload.into_inner(),
|state, _, req, _| connector_agnostic_mit_toggle(state, &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 Account
Expand Down
4 changes: 4 additions & 0 deletions crates/router/src/routes/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,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)),
),
)
}
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/routes/lock_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,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::PaymentLinkInitiate
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/types/api/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
Expand Down
2 changes: 2 additions & 0 deletions crates/router_env/src/logger/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ pub enum Flow {
RetrievePollStatus,
/// Toggles the extended card info feature in profile level
ToggleExtendedCardInfo,
/// Toggles the extended card info feature in profile level
ToggleConnectorAgnosticMit,
}

///
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;