Skip to content

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

feat(sdk): added sdk authorisation auth changes to sdk config api (#12845)

Sahkal Poddar51e91f26867c
diff --git a/crates/router/src/core/superposition_sdk_config.rs b/crates/router/src/core/superposition_sdk_config.rs
index c457855f64..b49de5f6f7 100644
--- a/crates/router/src/core/superposition_sdk_config.rs
+++ b/crates/router/src/core/superposition_sdk_config.rs
@@ -19,6 +19,7 @@ use crate::{
},
payments::helpers,
},
+ pii::ExposeInterface,
routes::SessionState,
types::domain,
};
@@ -127,6 +128,215 @@ async fn get_payment_context(
})
}
+pub async fn get_profile_superposition_sdk_config(
+ state: SessionState,
+ platform: domain::Platform,
+ profile_id: String,
+) -> RouterResponse<SuperPositionConfigResponse> {
+ let merchant_account = platform.get_processor().get_account();
+ let db = &*state.store;
+
+ let profile_id_typed =
+ common_utils::id_type::ProfileId::try_from(std::borrow::Cow::from(profile_id.clone()))
+ .change_context(errors::ApiErrorResponse::InvalidDataValue {
+ field_name: "profile_id",
+ })?;
+
+ let business_profile = db
+ .find_business_profile_by_profile_id(
+ platform.get_processor().get_key_store(),
+ &profile_id_typed,
+ )
+ .await
+ .change_context(errors::ApiErrorResponse::ProfileNotFound {
+ id: profile_id.to_owned(),
+ })?;
+
+ let all_mcas = db
+ .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ platform.get_processor().get_account().get_id(),
+ false,
+ platform.get_processor().get_key_store(),
+ )
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
+
+ let filtered_mcas: Vec<_> = all_mcas
+ .into_iter()
+ .filter(|mca| mca.profile_id == profile_id_typed)
+ .collect();
+
+ let mut payment_experiences_consolidated_hm: std::collections::HashMap<
+ api_enums::PaymentMethod,
+ std::collections::HashMap<
+ api_enums::PaymentMethodType,
+ std::collections::HashMap<api_enums::PaymentExperience, Vec<String>>,
+ >,
+ > = std::collections::HashMap::new();
+
+ let mut card_networks_consolidated_hm: std::collections::HashMap<
+ api_enums::PaymentMethod,
+ std::collections::HashMap<
+ api_enums::PaymentMethodType,
+ std::collections::HashMap<api_enums::CardNetwork, Vec<String>>,
+ >,
+ > = std::collections::HashMap::new();
+
+ let mut banks_consolidated_hm: std::collections::HashMap<
+ api_enums::PaymentMethodType,
+ Vec<String>,
+ > = std::collections::HashMap::new();
+ let mut bank_debits_consolidated_hm: std::collections::HashMap<
+ api_enums::PaymentMethodType,
+ Vec<String>,
+ > = std::collections::HashMap::new();
+ let mut bank_transfer_consolidated_hm: std::collections::HashMap<
+ api_enums::PaymentMethodType,
+ Vec<String>,
+ > = std::collections::HashMap::new();
+
+ for mca in &filtered_mcas {
+ if let Some(payment_methods_enabled_list) = &mca.payment_methods_enabled {
+ for pm_value in payment_methods_enabled_list {
+ if let Ok(pm_enabled) = serde_json::from_value::<
+ api_models::admin::PaymentMethodsEnabled,
+ >(pm_value.clone().expose())
+ {
+ let payment_method = pm_enabled.payment_method;
+ for pmt_info in pm_enabled.payment_method_types.unwrap_or_default() {
+ let payment_method_type = pmt_info.payment_method_type;
+ let connector = mca.connector_name.clone();
+
+ if let Some(payment_experience) = pmt_info.payment_experience {
+ let payment_method_hm = payment_experiences_consolidated_hm
+ .entry(payment_method)
+ .or_default();
+ let payment_method_type_hm =
+ payment_method_hm.entry(payment_method_type).or_default();
+ let vector_of_connectors = payment_method_type_hm
+ .entry(payment_experience)
+ .or_default();
+ if !vector_of_connectors.contains(&connector) {
+ vector_of_connectors.push(connector.clone());
+ }
+ }
+
+ if let Some(card_networks) = pmt_info.card_networks {
+ let payment_method_hm = card_networks_consolidated_hm
+ .entry(payment_method)
+ .or_default();
+ let payment_method_type_hm =
+ payment_method_hm.entry(payment_method_type).or_default();
+ for card_network in card_networks {
+ let vector_of_connectors =
+ payment_method_type_hm.entry(card_network).or_default();
+ if !vector_of_connectors.contains(&connector) {
+ vector_of_connectors.push(connector.clone());
+ }
+ }
+ }
+
+ if payment_method == api_enums::PaymentMethod::BankRedirect {
+ let vector_of_connectors = banks_consolidated_hm
+ .entry(payment_method_type)
+ .or_default();
+ if !vector_of_connectors.contains(&connector) {
+ vector_of_connectors.push(connector.clone());
+ }
+ }
+
+ if payment_method == api_enums::PaymentMethod::BankDebit {
+ let vector_of_connectors = bank_debits_consolidated_hm
+ .entry(payment_method_type)
+ .or_default();
+ if !vector_of_connectors.contains(&connector) {
+ vector_of_connectors.push(connector.clone());
+ }
+ }
+
+ if payment_method == api_enums::PaymentMethod::BankTransfer {
+ let vector_of_connectors = bank_transfer_consolidated_hm
+ .entry(payment_method_type)
+ .or_default();
+ if !vector_of_connectors.contains(&connector) {
+ vector_of_connectors.push(connector.clone());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ let merchant_enabled_context = MerchantEnabledPmsContext {
+ payment_experiences_consolidated_hm,
+ card_networks_consolidated_hm,
+ banks_consolidated_hm,
+ bank_debits_consolidated_hm,
+ bank_transfer_consolidated_hm,
+ required_fields_hm: std::collections::HashMap::new(),
+ pmt_to_auth_connector: std::collections::HashMap::new(),
+ connector_supports_installments: false,
+ collect_shipping_details_from_wallets: None,
+ collect_billing_details_from_wallets: None,
+ sdk_next_action: api_models::payments::SdkNextAction {
+ next_action: api_models::payments::NextActionCall::Confirm,
+ should_block_confirm: None,
+ },
+ };
+
+ let mut dimension_filter = Map::new();
+ dimension_filter.insert(
+ "profile_id".to_string(),
+ serde_json::Value::String(profile_id.to_string()),
+ );
+ dimension_filter.insert(
+ "merchant_id".to_string(),
+ serde_json::Value::String(merchant_account.get_id().get_string_repr().to_string()),
+ );
+ dimension_filter.insert(
+ "organization_id".to_string(),
+ serde_json::Value::String(merchant_account.get_org_id().get_string_repr().to_string()),
+ );
+ dimension_filter.insert(
+ "connector".to_string(),
+ serde_json::Value::Array(
+ filtered_mcas
+ .iter()
+ .map(|mca| serde_json::Value::String(mca.connector_name.clone()))
+ .collect(),
+ ),
+ );
+
+ let raw_configs = state
+ .superposition_service
+ .get_cached_config(
+ Some(vec![DYNAMIC_FIELDS.to_string()]),
+ Some(dimension_filter.clone()),
+ )
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable_lazy(|| {
+ format!(
+ "Failed to fetch superposition config for dimension filter: {dimension_filter:?}"
+ )
+ })?;
+
+ let payment_methods = translate_to_sdk_payment_methods(&state, &merchant_enabled_context)?;
+
+ let account_config = build_account_config(&state, &platform, &business_profile).await;
+
+ Ok(hyperswitch_domain_models::api::ApplicationResponse::Json(
+ SuperPositionConfigResponse {
+ raw_configs,
+ resolved_configs: None,
+ context_used: dimension_filter,
+ payment_methods: Some(payment_methods),
+ account_config,
+ },
+ ))
+}
+
pub async fn get_superposition_sdk_config(
state: SessionState,
platform: domain::Platform,
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index 235eb5ea73..acaacdd666 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -3395,5 +3395,9 @@ impl SdkConfig {
web::resource("{platform}/sdk_config.json")
.route(web::get().to(super::superposition_sdk_config::get_sdk_config)),
)
+ .service(
+ web::resource("{platform}/{profile_id}/sdk_config.json")
+ .route(web::get().to(super::superposition_sdk_config::get_profile_sdk_config)),
+ )
}
}
diff --git a/crates/router/src/routes/superposition_sdk_config.rs b/crates/router/src/routes/superposition_sdk_config.rs
index ed50af3136..2a7283745d 100644
--- a/crates/router/src/routes/superposition_sdk_config.rs
+++ b/crates/router/src/routes/superposition_sdk_config.rs
@@ -93,3 +93,34 @@ pub async fn get_sdk_config(
))
.await
}
+
+#[cfg(feature = "v1")]
+#[instrument(skip_all, fields(flow = ?Flow::GetSuperpositionSdkConfig))]
+pub async fn get_profile_sdk_config(
+ state: web::Data<AppState>,
+ req: HttpRequest,
+ path: web::Path<(String, String)>,
+) -> HttpResponse {
+ let flow = Flow::GetSuperpositionSdkConfig;
+ let (_platform, profile_id) = path.into_inner();
+
+ Box::pin(api::server_wrap(
+ flow,
+ state,
+ &req,
+ (),
+ |state: super::SessionState, auth_data, _req, _| {
+ superposition_sdk_config::get_profile_superposition_sdk_config(
+ state,
+ auth_data.platform,
+ profile_id.clone(),
+ )
+ },
+ &auth::HeaderAuth(auth::PublishableKeyAuth {
+ allow_connected_scope_operation: true,
+ allow_platform_self_operation: true,
+ }),
+ api_locking::LockAction::NotApplicable,
+ ))
+ .await
+}