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(superposition): surface account config with SDK vault strategy (#12739)
Shankar Singh C76e91e3997b5
diff --git a/crates/api_models/src/superposition_sdk_config.rs b/crates/api_models/src/superposition_sdk_config.rsindex 860d2c4fca..a218795f63 100644--- a/crates/api_models/src/superposition_sdk_config.rs+++ b/crates/api_models/src/superposition_sdk_config.rs@@ -31,12 +31,40 @@ pub struct SdkPaymentMethod {pub payment_method_types: Vec<SdkPaymentMethodType>,}+/// Tells the SDK whether to tokenize payment method details before calling confirm.+#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq)]+#[serde(rename_all = "snake_case")]+pub enum VaultingAction {+ /// Tokenize payment method details through the modular vaulting flow.+ Tokenize,+ /// Skip tokenization and call confirm directly.+ Skip,+}++/// Profile level configuration surfaced to the SDK.+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]+pub struct ProfileAccountConfig {+ pub collect_shipping_details_from_wallet_connector: bool,+ pub collect_billing_details_from_wallet_connector: bool,+ pub always_collect_billing_details_from_wallet_connector: bool,+ pub always_collect_shipping_details_from_wallet_connector: bool,+ /// Whether the SDK should tokenize payment method details before calling confirm.+ pub vaulting_action: VaultingAction,+}++/// Account level configuration surfaced to the SDK.+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]+pub struct AccountConfig {+ pub profile: ProfileAccountConfig,+}+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]pub struct SuperPositionConfigResponse {pub raw_configs: Config,pub resolved_configs: Option<Map<String, Value>>,pub context_used: Map<String, Value>,pub payment_methods: Option<Vec<SdkPaymentMethod>>,+ pub account_config: AccountConfig,}impl ApiEventMetric for SuperPositionConfigResponse {}diff --git a/crates/router/src/core/superposition_sdk_config.rs b/crates/router/src/core/superposition_sdk_config.rsindex 8e7b6c032c..c457855f64 100644--- a/crates/router/src/core/superposition_sdk_config.rs+++ b/crates/router/src/core/superposition_sdk_config.rs@@ -1,8 +1,8 @@use api_models::{enums as api_enums,superposition_sdk_config::{- PaymentMethodCriteria, SdkCriteriaRule, SdkPaymentMethod, SdkPaymentMethodType,- SuperPositionConfigResponse,+ AccountConfig, PaymentMethodCriteria, ProfileAccountConfig, SdkCriteriaRule,+ SdkPaymentMethod, SdkPaymentMethodType, SuperPositionConfigResponse, VaultingAction,},};use common_utils::ext_traits::AsyncExt;@@ -12,6 +12,7 @@ use serde_json::Map;use crate::{consts::superposition::DYNAMIC_FIELDS,core::{+ configs::dimension_state::Dimensions,errors::{self, RouterResponse, StorageErrorExt},payment_methods::cards::{build_merchant_enabled_pms_context, get_banks, MerchantEnabledPmsContext,@@ -212,16 +213,72 @@ pub async fn get_superposition_sdk_config(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,},))}+/// Build the account level configuration surfaced to the SDK.+async fn build_account_config(+ state: &SessionState,+ platform: &domain::Platform,+ business_profile: &domain::Profile,+) -> AccountConfig {+ let dimensions = Dimensions::new()+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id());+ let feature_config = crate::core::utils::get_feature_config(state, platform, &dimensions).await;++ AccountConfig {+ profile: build_profile_account_config(+ business_profile,+ feature_config.is_payment_method_modular_allowed,+ ),+ }+}++/// Build the profile level configuration surfaced to the SDK.+fn build_profile_account_config(+ business_profile: &domain::Profile,+ is_payment_method_modular_allowed: bool,+) -> ProfileAccountConfig {+ ProfileAccountConfig {+ collect_shipping_details_from_wallet_connector: business_profile+ .collect_shipping_details_from_wallet_connector+ .unwrap_or(false),+ collect_billing_details_from_wallet_connector: business_profile+ .collect_billing_details_from_wallet_connector+ .unwrap_or(false),+ always_collect_billing_details_from_wallet_connector: business_profile+ .always_collect_billing_details_from_wallet_connector+ .unwrap_or(false),+ always_collect_shipping_details_from_wallet_connector: business_profile+ .always_collect_shipping_details_from_wallet_connector+ .unwrap_or(false),+ vaulting_action: resolve_vaulting_action(is_payment_method_modular_allowed),+ }+}++/// Determine whether the SDK should tokenize payment method details.+///+/// Driven solely by whether the modular vaulting flow should be invoked: `Tokenize` when it+/// should, `Skip` otherwise.+fn resolve_vaulting_action(should_call_modular: bool) -> VaultingAction {+ if should_call_modular {+ VaultingAction::Tokenize+ } else {+ VaultingAction::Skip+ }+}+fn format_criteria_value(card_network: Option<String>,bank_name: Option<String>,