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(payments): restructure v1 session_token vault_details contract (#12771)

Shankar Singh C914bf6e9b129
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index e244248f4d..b7cd7cf5ce 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -22905,6 +22905,18 @@
"revenue_growth_management_platform"
]
},
+ "HyperswitchVaultData": {
+ "type": "object",
+ "required": [
+ "sdk_authorization"
+ ],
+ "properties": {
+ "sdk_authorization": {
+ "type": "string",
+ "description": "Base64-encoded SDK authorization token for the Hyperswitch Vault session"
+ }
+ }
+ },
"HyperswitchVaultSessionDetails": {
"type": "object",
"required": [
@@ -34373,7 +34385,7 @@
"vault_details": {
"allOf": [
{
- "$ref": "#/components/schemas/VaultDetails"
+ "$ref": "#/components/schemas/VaultDetailsResponse"
}
],
"nullable": true
@@ -43766,6 +43778,50 @@
}
}
},
+ "VaultDetailsResponse": {
+ "oneOf": [
+ {
+ "type": "object",
+ "required": [
+ "vault_type",
+ "vault_data"
+ ],
+ "properties": {
+ "vault_type": {
+ "type": "string",
+ "enum": [
+ "hyperswitch"
+ ]
+ },
+ "vault_data": {
+ "$ref": "#/components/schemas/HyperswitchVaultData"
+ }
+ }
+ },
+ {
+ "type": "object",
+ "required": [
+ "vault_type",
+ "vault_data"
+ ],
+ "properties": {
+ "vault_type": {
+ "type": "string",
+ "enum": [
+ "vgs"
+ ]
+ },
+ "vault_data": {
+ "$ref": "#/components/schemas/VgsVaultData"
+ }
+ }
+ }
+ ],
+ "description": "V1-facing vault details for the session-tokens response, serialized as a tagged\n`{ \"vault_type\": ..., \"vault_data\": { ... } }` object. Exactly one variant is returned:\nexternal vault details when configured, otherwise the internal Hyperswitch vault session.",
+ "discriminator": {
+ "propertyName": "vault_type"
+ }
+ },
"VaultSdk": {
"type": "string",
"enum": [
@@ -43868,6 +43924,23 @@
}
}
},
+ "VgsVaultData": {
+ "type": "object",
+ "required": [
+ "vault_id",
+ "environment"
+ ],
+ "properties": {
+ "vault_id": {
+ "type": "string",
+ "description": "The identifier of the external vault"
+ },
+ "environment": {
+ "type": "string",
+ "description": "The environment for the external vault initiation"
+ }
+ }
+ },
"VisaEligibilityCheckData": {
"type": "object",
"required": [
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 7b64c4f29f..72e27a3332 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -10211,6 +10211,62 @@ pub struct HyperswitchVaultSessionDetails {
pub sdk_authorization: Secret<String>,
}
+/// V1-facing vault details for the session-tokens response, serialized as a tagged
+/// `{ "vault_type": ..., "vault_data": { ... } }` object. Exactly one variant is returned:
+/// external vault details when configured, otherwise the internal Hyperswitch vault session.
+#[cfg(feature = "v1")]
+#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, ToSchema)]
+#[serde(tag = "vault_type", content = "vault_data", rename_all = "snake_case")]
+pub enum VaultDetailsResponse {
+ /// Internal/default Hyperswitch vault session
+ Hyperswitch(HyperswitchVaultData),
+ /// External VGS vault session
+ Vgs(VgsVaultData),
+}
+
+#[cfg(feature = "v1")]
+#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, ToSchema)]
+pub struct HyperswitchVaultData {
+ /// Base64-encoded SDK authorization token for the Hyperswitch Vault session
+ #[schema(value_type = String)]
+ pub sdk_authorization: Secret<String>,
+}
+
+#[cfg(feature = "v1")]
+#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, ToSchema)]
+pub struct VgsVaultData {
+ /// The identifier of the external vault
+ #[schema(value_type = String)]
+ pub vault_id: Secret<String>,
+ /// The environment for the external vault initiation
+ pub environment: String,
+}
+
+#[cfg(feature = "v1")]
+impl From<VaultDetails> for Option<VaultDetailsResponse> {
+ fn from(details: VaultDetails) -> Self {
+ match details.external_vault_details {
+ // An external vault is configured: surface it as-is (VGS or Hyperswitch Vault).
+ Some(VaultSessionDetails::Vgs(vgs)) => Some(VaultDetailsResponse::Vgs(VgsVaultData {
+ vault_id: vgs.external_vault_id,
+ environment: vgs.sdk_env,
+ })),
+ Some(VaultSessionDetails::HyperswitchVault(hs)) => {
+ Some(VaultDetailsResponse::Hyperswitch(HyperswitchVaultData {
+ sdk_authorization: hs.sdk_authorization,
+ }))
+ }
+ // No external vault configured (the SaaS default): fall back to the internal
+ // Hyperswitch vault SDK authorization.
+ None => details.internal_vault.map(|internal| {
+ VaultDetailsResponse::Hyperswitch(HyperswitchVaultData {
+ sdk_authorization: Secret::new(internal.sdk_authorization),
+ })
+ }),
+ }
+ }
+}
+
#[derive(
Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema, SmithyModel,
)]
@@ -10939,8 +10995,8 @@ pub struct PaymentsSessionResponse {
pub client_secret: Secret<String, pii::ClientSecret>,
/// The list of session token object
pub session_token: Vec<SessionToken>,
- /// Vault details containing internal vault (SDK auth) and external vault info
- pub vault_details: Option<VaultDetails>,
+ /// Vault details for the session, returned as a tagged `{ vault_type, vault_data }` object
+ pub vault_details: Option<VaultDetailsResponse>,
}
#[cfg(feature = "v2")]
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index 9042647783..1592c6690f 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -771,6 +771,9 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::AmazonPayShippingMethod,
api_models::payments::VaultDetails,
api_models::payments::InternalVaultSessionDetails,
+ api_models::payments::VaultDetailsResponse,
+ api_models::payments::HyperswitchVaultData,
+ api_models::payments::VgsVaultData,
api_models::payments::ProxyCardData,
api_models::payment_methods::RequiredFieldInfo,
api_models::payment_methods::DefaultPaymentMethod,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 084d56d410..c7258ed3b3 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -1404,6 +1404,7 @@ where
&business_profile,
&mut payment_data,
header_payload.clone(),
+ feature_config.is_payment_method_modular_allowed,
)
.await?;
diff --git a/crates/router/src/core/payments/session_operation.rs b/crates/router/src/core/payments/session_operation.rs
index 8b8948b9c5..e21eba130e 100644
--- a/crates/router/src/core/payments/session_operation.rs
+++ b/crates/router/src/core/payments/session_operation.rs
@@ -175,6 +175,8 @@ where
&profile,
&mut payment_data,
header_payload.clone(),
+ // V2 gates internally on `profile.is_vault_sdk_enabled()`; this flag is ignored here.
+ false,
)
.await?;
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index d6b255cf11..0e111f8f59 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -2797,7 +2797,9 @@ where
.clone()
.get_required_value("client_secret")?
.into(),
- vault_details: payment_data.get_optional_external_vault_session_details(),
+ vault_details: payment_data
+ .get_optional_external_vault_session_details()
+ .and_then(Into::into),
},
vec![],
)))
diff --git a/crates/router/src/core/payments/vault_session.rs b/crates/router/src/core/payments/vault_session.rs
index feacfb2c6f..ecdbb5ae4f 100644
--- a/crates/router/src/core/payments/vault_session.rs
+++ b/crates/router/src/core/payments/vault_session.rs
@@ -63,6 +63,9 @@ pub async fn populate_vault_session_details<F, RouterDReq, ApiRequest, D>(
profile: &domain::Profile,
payment_data: &mut D,
header_payload: HeaderPayload,
+ // V2 gates on `profile.is_vault_sdk_enabled()`; the modular-service flag is V1-only and ignored
+ // here, but kept in the signature so the shared call site compiles under both feature flags.
+ _is_modular_service_enabled: bool,
) -> RouterResult<()>
where
F: Send + Clone + Sync,
@@ -197,6 +200,7 @@ pub async fn populate_vault_session_details<F, RouterDReq, ApiRequest, D>(
profile: &domain::Profile,
payment_data: &mut D,
_header_payload: HeaderPayload,
+ is_modular_service_enabled: bool,
) -> RouterResult<()>
where
F: Send + Clone + Sync,
@@ -207,9 +211,10 @@ where
dyn api::Connector:
services::api::ConnectorIntegration<F, RouterDReq, router_types::PaymentsResponseData>,
{
- let is_external_vault_sdk_enabled = profile.external_vault_details.is_external_vault_enabled();
-
- if is_external_vault_sdk_enabled {
+ // Always route vault session creation through the modular PM service when the org is eligible
+ // for it (not just when an external vault is configured). When no external vault is set up, the
+ // PM service returns the internal Hyperswitch vault SDK authorization, which is the SaaS default.
+ if is_modular_service_enabled {
let customer_id = customer.as_ref().map(|c| c.get_id());
let vault_details =