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(router): add external vault sdk token support in sessions flow (#11781)

Prasunna Soppa5e1bb1c6814c
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 63fc4a0fee..50759b9e02 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -22047,6 +22047,33 @@
"revenue_growth_management_platform"
]
},
+ "HyperswitchVaultSessionDetails": {
+ "type": "object",
+ "required": [
+ "payment_method_session_id",
+ "client_secret",
+ "publishable_key",
+ "profile_id"
+ ],
+ "properties": {
+ "payment_method_session_id": {
+ "type": "string",
+ "description": "Session ID for Hyperswitch Vault"
+ },
+ "client_secret": {
+ "type": "string",
+ "description": "Client secret for Hyperswitch Vault"
+ },
+ "publishable_key": {
+ "type": "string",
+ "description": "Publishable key for Hyperswitch Vault"
+ },
+ "profile_id": {
+ "type": "string",
+ "description": "Profile ID for Hyperswitch Vault"
+ }
+ }
+ },
"IfStatement": {
"type": "object",
"description": "Represents an IF statement with conditions and optional nested IF statements\n\n```text\npayment.method = card {\npayment.method.cardtype = (credit, debit) {\npayment.method.network = (amex, rupay, diners)\n}\n}\n```",
@@ -33180,6 +33207,14 @@
"$ref": "#/components/schemas/SessionToken"
},
"description": "The list of session token object"
+ },
+ "vault_details": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/VaultSessionDetails"
+ }
+ ],
+ "nullable": true
}
}
},
@@ -42081,6 +42116,32 @@
"hyperswitch_sdk"
]
},
+ "VaultSessionDetails": {
+ "oneOf": [
+ {
+ "type": "object",
+ "required": [
+ "vgs"
+ ],
+ "properties": {
+ "vgs": {
+ "$ref": "#/components/schemas/VgsSessionDetails"
+ }
+ }
+ },
+ {
+ "type": "object",
+ "required": [
+ "hyperswitch_vault"
+ ],
+ "properties": {
+ "hyperswitch_vault": {
+ "$ref": "#/components/schemas/HyperswitchVaultSessionDetails"
+ }
+ }
+ }
+ ]
+ },
"VaultTokenField": {
"type": "object",
"properties": {
@@ -42133,6 +42194,23 @@
}
}
},
+ "VgsSessionDetails": {
+ "type": "object",
+ "required": [
+ "external_vault_id",
+ "sdk_env"
+ ],
+ "properties": {
+ "external_vault_id": {
+ "type": "string",
+ "description": "The identifier of the external vault"
+ },
+ "sdk_env": {
+ "type": "string",
+ "description": "The environment for the external vault initiation"
+ }
+ }
+ },
"VisaEligibilityCheckData": {
"type": "object",
"required": [
diff --git a/config/development.toml b/config/development.toml
index 8121198ade..423bae26d1 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -289,7 +289,7 @@ gpayments.base_url = "https://{{merchant_endpoint_prefix}}-test.api.as1.gpayment
helcim.base_url = "https://api.helcim.com/"
hipay.base_url = "https://stage-secure-gateway.hipay-tpp.com/rest/"
hyperpg.base_url = "https://sandbox.hyperpg.in"
-hyperswitch_vault.base_url = "http://localhost:8080"
+hyperswitch_vault.base_url = "https://app.hyperswitch.io/api/v1"
hyperwallet.base_url = "https://uat-api.paylution.com"
hipay.secondary_base_url = "https://stage-secure2-vault.hipay-tpp.com/rest/"
hipay.third_base_url = "https://stage-api-gateway.hipay.com/"
diff --git a/crates/api_models/src/enums.rs b/crates/api_models/src/enums.rs
index e27612baad..86f044d906 100644
--- a/crates/api_models/src/enums.rs
+++ b/crates/api_models/src/enums.rs
@@ -239,6 +239,25 @@ impl From<VaultConnectors> for Connector {
}
}
+impl TryFrom<String> for VaultConnectors {
+ type Error = String;
+ fn try_from(value: String) -> Result<Self, Self::Error> {
+ use std::str::FromStr;
+ Self::from_str(&value).map_err(|_| format!("'{value}' is not a valid vault connector name"))
+ }
+}
+
+impl VaultConnectors {
+ /// Parse a `VaultConnectors` from a connector name string, going through
+ /// the `Connector` enum to validate it is a known connector first.
+ pub fn from_connector_name(connector_name: &str) -> Result<Self, String> {
+ use std::str::FromStr;
+ let connector_enum = Connector::from_str(connector_name)
+ .map_err(|_| format!("Failed to parse connector name to enum: {connector_name}"))?;
+ Self::try_from(connector_enum)
+ }
+}
+
impl TryFrom<Connector> for VaultConnectors {
type Error = String;
fn try_from(value: Connector) -> Result<Self, Self::Error> {
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 13b3d25269..88307152cf 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -11074,6 +11074,8 @@ pub struct PaymentsSessionResponse {
pub client_secret: Secret<String, pii::ClientSecret>,
/// The list of session token object
pub session_token: Vec<SessionToken>,
+ /// External vault session details
+ pub vault_details: Option<VaultSessionDetails>,
}
#[cfg(feature = "v2")]
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs
index e053c169ea..f6a9e11c85 100644
--- a/crates/common_enums/src/enums.rs
+++ b/crates/common_enums/src/enums.rs
@@ -11316,3 +11316,20 @@ impl PostCaptureVoidStatus {
}
}
}
+
+#[derive(
+ Clone,
+ Copy,
+ Debug,
+ Eq,
+ PartialEq,
+ serde::Serialize,
+ strum::Display,
+ serde::Deserialize,
+ ToSchema,
+)]
+#[serde(rename_all = "snake_case")]
+pub enum VaultEnv {
+ Sandbox,
+ Live,
+}
diff --git a/crates/hyperswitch_connectors/src/connectors/hyperswitch_vault/transformers.rs b/crates/hyperswitch_connectors/src/connectors/hyperswitch_vault/transformers.rs
index 430b47f0c1..39e2eae64a 100644
--- a/crates/hyperswitch_connectors/src/connectors/hyperswitch_vault/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/hyperswitch_vault/transformers.rs
@@ -1,4 +1,5 @@
-use common_utils::pii::Email;
+use common_utils::{ext_traits::OptionExt, pii::Email};
+use error_stack::ResultExt;
use hyperswitch_domain_models::{
router_data::{ConnectorAuthType, RouterData},
router_flow_types::vault::ExternalVaultCreateFlow,
@@ -82,7 +83,7 @@ impl<F, T> TryFrom<ResponseRouterData<F, HyperswitchVaultCreateResponse, T, Vaul
#[derive(Default, Debug, Serialize)]
pub struct HyperswitchVaultCustomerCreateRequest {
- name: Option<Secret<String>>,
+ name: Secret<String>,
email: Option<Email>,
}
@@ -90,7 +91,14 @@ impl TryFrom<&ConnectorCustomerRouterData> for HyperswitchVaultCustomerCreateReq
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &ConnectorCustomerRouterData) -> Result<Self, Self::Error> {
Ok(Self {
- name: item.request.name.clone(),
+ name: item
+ .request
+ .name
+ .clone()
+ .get_required_value("customer name")
+ .change_context(errors::ConnectorError::MissingRequiredField {
+ field_name: "customer name",
+ })?,
email: item.request.email.clone(),
})
}
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index 6fbe30957a..64fef49850 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -613,6 +613,9 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::PaymentsSessionResponse,
api_models::payments::PazeWalletData,
api_models::payments::SessionToken,
+ api_models::payments::VaultSessionDetails,
+ api_models::payments::VgsSessionDetails,
+ api_models::payments::HyperswitchVaultSessionDetails,
api_models::payments::ApplePaySessionResponse,
api_models::payments::NullObject,
api_models::payments::ThirdPartySdkSessionResponse,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 5688c20905..b94df8588e 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -16,7 +16,6 @@ pub mod session_operation;
pub mod tokenization;
pub mod transformers;
pub mod types;
-#[cfg(feature = "v2")]
pub mod vault_session;
#[cfg(feature = "olap")]
use std::collections::HashMap;
@@ -1384,6 +1383,19 @@ where
&connectors,
)
.await?;
+
+ vault_session::populate_vault_session_details(
+ state,
+ req_state.clone(),
+ &customer,
+ platform,
+ &operation,
+ &business_profile,
+ &mut payment_data,
+ header_payload.clone(),
+ )
+ .await?;
+
Box::pin(call_multiple_connectors_service(
state,
platform.get_processor(),
@@ -7448,7 +7460,8 @@ where
dyn api::Connector:
services::api::ConnectorIntegration<F, Req, router_types::PaymentsResponseData>,
{
- let connector_name = payment_data.get_payment_attempt().connector.clone();
+ let connector_name = merchant_connector_account.get_connector_name();
+
match connector_name {
Some(connector_name) => {
let connector = api::ConnectorData::get_connector_by_name(
@@ -8722,6 +8735,7 @@ where
pub card_testing_guard_data:
Option<hyperswitch_domain_models::card_testing_guard_data::CardTestingGuardData>,
pub vault_operation: Option<domain_payments::VaultOperation>,
+ pub vault_session_details: Option<api::VaultSessionDetails>,
pub threeds_method_comp_ind: Option<api_models::payments::ThreeDsCompletionIndicator>,
pub whole_connector_response: Option<Secret<String>>,
pub is_manual_retry_enabled: Option<bool>,
@@ -12271,7 +12285,6 @@ pub trait OperationSessionGetters<F> {
&self,
) -> Option<HashMap<enums::PaymentMethodType, domain::PreRoutingConnectorChoice>>;
- #[cfg(feature = "v2")]
fn get_optional_external_vault_session_details(&self) -> Option<api::VaultSessionDetails>;
#[cfg(feature = "v1")]
fn get_click_to_pay_service_details(&self) -> Option<&api_models::payments::CtpServiceDetails>;
@@ -12355,7 +12368,6 @@ pub trait OperationSessionSetters<F> {
fn set_connector_response_reference_id(&mut self, reference_id: Option<String>);
- #[cfg(feature = "v2")]
fn set_vault_session_details(
&mut self,
external_vault_session_details: Option<api::VaultSessionDetails>,
@@ -12540,6 +12552,10 @@ impl<F: Clone> OperationSessionGetters<F> for PaymentData<F> {
self.client_session_id.clone()
}
+ fn get_optional_external_vault_session_details(&self) -> Option<api::VaultSessionDetails> {
+ self.vault_session_details.clone()
+ }
+
// #[cfg(feature = "v2")]
// fn get_capture_method(&self) -> Option<enums::CaptureMethod> {
// Some(self.payment_intent.capture_method)
@@ -12715,6 +12731,13 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentData<F> {
self.vault_operation = Some(vault_operation);
}
+ fn set_vault_session_details(
+ &mut self,
+ vault_session_details: Option<api::VaultSessionDetails>,
+ ) {
+ self.vault_session_details = vault_session_details;
+ }
+
fn set_routing_approach_in_attempt(
&mut self,
routing_approach: Option<enums::RoutingApproach>,
diff --git a/crates/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rs
index f4bb339ab5..a0b57d78d0 100644
--- a/crates/router/src/core/payments/operations/payment_approve.rs
+++ b/crates/router/src/core/payments/operations/payment_approve.rs
@@ -207,6 +207,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCaptureR
is_l2_l3_enabled: false,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rs
index 71f200133e..4e39d5b4cc 100644
--- a/crates/router/src/core/payments/operations/payment_cancel.rs
+++ b/crates/router/src/core/payments/operations/payment_cancel.rs
@@ -219,6 +219,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCancelRe
is_l2_l3_enabled: false,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs b/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs
index 53f2037ee7..194ab7e03d 100644
--- a/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs
+++ b/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs
@@ -201,6 +201,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCancelPo
is_l2_l3_enabled: false,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs
index aef129c6a7..4fdf75f9f0 100644
--- a/crates/router/src/core/payments/operations/payment_capture.rs
+++ b/crates/router/src/core/payments/operations/payment_capture.rs
@@ -275,6 +275,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, payments::PaymentData<F>, api::Paymen
is_l2_l3_enabled: false,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
index 6887c3f9ce..c2587be411 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -381,6 +381,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
is_l2_l3_enabled: business_profile.is_l2_l3_enabled,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let customer_details = Some(CustomerDetails {
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index a6703cf1cd..a289baa5af 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -1024,6 +1024,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
is_l2_l3_enabled: business_profile.is_l2_l3_enabled,
external_authentication_data: request.three_ds_data.clone(),
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index c177c72db1..7c31d2a802 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -751,6 +751,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
is_l2_l3_enabled: business_profile.is_l2_l3_enabled,
external_authentication_data: request.three_ds_data.clone(),
client_session_id,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/payment_post_session_tokens.rs b/crates/router/src/core/payments/operations/payment_post_session_tokens.rs
index dfafa1cfd5..b517eafe65 100644
--- a/crates/router/src/core/payments/operations/payment_post_session_tokens.rs
+++ b/crates/router/src/core/payments/operations/payment_post_session_tokens.rs
@@ -186,6 +186,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsPostSess
is_l2_l3_enabled: false,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
operation: Box::new(self),
diff --git a/crates/router/src/core/payments/operations/payment_recurrence.rs b/crates/router/src/core/payments/operations/payment_recurrence.rs
index 5baf7359ab..610f508867 100644
--- a/crates/router/src/core/payments/operations/payment_recurrence.rs
+++ b/crates/router/src/core/payments/operations/payment_recurrence.rs
@@ -305,6 +305,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
is_l2_l3_enabled: business_profile.is_l2_l3_enabled,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs
index 90dc4f33f9..07e9c79536 100644
--- a/crates/router/src/core/payments/operations/payment_reject.rs
+++ b/crates/router/src/core/payments/operations/payment_reject.rs
@@ -206,6 +206,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, PaymentsCancelRequest
is_l2_l3_enabled: false,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index bba2fd27d8..cbcad58707 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -227,6 +227,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsSessionR
service_details: None,
card_testing_guard_data: None,
vault_operation: None,
+ vault_session_details: None,
threeds_method_comp_ind: None,
whole_connector_response: None,
is_manual_retry_enabled: None,
diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rs
index fd58d9be0d..4ac583b6e3 100644
--- a/crates/router/src/core/payments/operations/payment_start.rs
+++ b/crates/router/src/core/payments/operations/payment_start.rs
@@ -251,6 +251,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsStartReq
is_l2_l3_enabled: false,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index e4ade6ad73..9d7b6c2aae 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -623,6 +623,7 @@ async fn get_tracker_for_sync<
is_l2_l3_enabled: business_profile.is_l2_l3_enabled,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index e0ddaff090..f971858b49 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -573,6 +573,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
is_l2_l3_enabled: business_profile.is_l2_l3_enabled,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/payment_update_metadata.rs b/crates/router/src/core/payments/operations/payment_update_metadata.rs
index 9dc1d06806..6a707ddb46 100644
--- a/crates/router/src/core/payments/operations/payment_update_metadata.rs
+++ b/crates/router/src/core/payments/operations/payment_update_metadata.rs
@@ -192,6 +192,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsUpdateMe
is_l2_l3_enabled: false,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
operation: Box::new(self),
diff --git a/crates/router/src/core/payments/operations/payments_extend_authorization.rs b/crates/router/src/core/payments/operations/payments_extend_authorization.rs
index 4961f61ca4..06ac4001b7 100644
--- a/crates/router/src/core/payments/operations/payments_extend_authorization.rs
+++ b/crates/router/src/core/payments/operations/payments_extend_authorization.rs
@@ -207,6 +207,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsExtendAu
is_l2_l3_enabled: false,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
index 1f7153a918..f3abe6b0af 100644
--- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
+++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
@@ -189,6 +189,7 @@ impl<F: Send + Clone + Sync>
is_l2_l3_enabled: false,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
diff --git a/crates/router/src/core/payments/operations/tax_calculation.rs b/crates/router/src/core/payments/operations/tax_calculation.rs
index 3cd9e00514..d9841e7f8f 100644
--- a/crates/router/src/core/payments/operations/tax_calculation.rs
+++ b/crates/router/src/core/payments/operations/tax_calculation.rs
@@ -201,6 +201,7 @@ impl<F: Send + Clone + Sync>
is_l2_l3_enabled: false,
external_authentication_data: None,
client_session_id: None,
+ vault_session_details: None,
};
let get_trackers_response = operations::GetTrackerResponse {
operation: Box::new(self),
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 75cad8e23e..ca3e9da7fd 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -2538,6 +2538,7 @@ where
.clone()
.get_required_value("client_secret")?
.into(),
+ vault_details: payment_data.get_optional_external_vault_session_details(),
},
vec![],
)))
@@ -5981,10 +5982,13 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSessionD
},
),
order_details,
- email: additional_data.customer_data.and_then(|cust| cust.email),
+ email: additional_data
+ .customer_data
+ .as_ref()
+ .and_then(|cust| cust.email.clone()),
surcharge_details: payment_data.surcharge_details,
apple_pay_recurring_details,
- customer_name: None,
+ customer_name: additional_data.customer_data.and_then(|cust| cust.name),
order_tax_amount,
shipping_cost,
metadata,
diff --git a/crates/router/src/core/payments/vault_session.rs b/crates/router/src/core/payments/vault_session.rs
index 6140cf3afc..d4f94818b3 100644
--- a/crates/router/src/core/payments/vault_session.rs
+++ b/crates/router/src/core/payments/vault_session.rs
@@ -1,48 +1,51 @@
-use std::{fmt::Debug, str::FromStr};
-
pub use common_enums::enums::CallConnectorAction;
-use common_utils::id_type;
use error_stack::{report, ResultExt};
+#[cfg(feature = "v2")]
+pub use hyperswitch_domain_models::payments::PaymentIntentData;
pub use hyperswitch_domain_models::{
mandates::MandateData,
payment_address::PaymentAddress,
- payments::{HeaderPayload, PaymentIntentData},
+ payments::HeaderPayload,
router_data::{PaymentMethodToken, RouterData},
router_data_v2::{flow_common_types::VaultConnectorFlowData, RouterDataV2},
router_flow_types::ExternalVaultCreateFlow,
router_request_types::CustomerDetails,
types::{VaultRouterData, VaultRouterDataV2},
};
-use hyperswitch_interfaces::{
- api::Connector as ConnectorTrait,
- connector_integration_v2::{ConnectorIntegrationV2, ConnectorV2},
-};
-use hyperswitch_masking::ExposeInterface;
-use router_env::{env::Env, instrument, tracing};
+use hyperswitch_interfaces::api::Connector as ConnectorTrait;
+#[cfg(feature = "v2")]
+use hyperswitch_interfaces::connector_integration_v2::{ConnectorIntegrationV2, ConnectorV2};
+use router_env::env::Env;
+#[cfg(feature = "v1")]
+use crate::core::payments::call_create_connector_customer_if_required;
+#[cfg(feature = "v2")]
+use crate::core::payments::customers;
use crate::{
core::{
- errors::{self, utils::StorageErrorExt, RouterResult},
+ errors::{self, RouterResult},
payments::{
- self as payments_core, call_multiple_connectors_service, customers,
flows::{ConstructFlowSpecificData, Feature},
gateway::context as gateway_context,
- helpers, helpers as payment_helpers, operations,
- operations::{BoxedOperation, Operation},
- transformers, OperationSessionGetters, OperationSessionSetters,
+ helpers,
+ operations::BoxedOperation,
+ OperationSessionGetters, OperationSessionSetters,
},
utils as core_utils,
},
db::errors::ConnectorErrorExt,
- errors::RouterResponse,
routes::{app::ReqState, SessionState},
services::{self, connector_integration_interface::RouterDataConversion},
types::{
self as router_types,
- api::{self, enums as api_enums, ConnectorCommon},
- domain, storage,
+ api::{self, enums as api_enums},
+ domain,
},
- utils::{OptionExt, ValueExt},
+};
+#[cfg(feature = "v2")]
+use crate::{
+ errors::RouterResponse,
+ types::{api::ConnectorCommon, storage},
};
#[cfg(feature = "v2")]
@@ -128,6 +131,114 @@ where
Ok(())
}
+#[cfg(feature = "v1")]
+#[allow(clippy::too_many_arguments)]
+pub async fn populate_vault_session_details<F, RouterDReq, ApiRequest, D>(
+ state: &SessionState,
+ _req_state: ReqState,
+ customer: &Option<domain::Customer>,
+ platform: &domain::Platform,
+ _operation: &BoxedOperation<'_, F, ApiRequest, D>,
+ profile: &domain::Profile,
+ payment_data: &mut D,
+ _header_payload: HeaderPayload,
+) -> RouterResult<()>
+where
+ F: Send + Clone + Sync,
+ RouterDReq: Send + Sync,
+ D: OperationSessionGetters<F> + OperationSessionSetters<F> + Send + Sync + Clone,
+ D: ConstructFlowSpecificData<F, RouterDReq, router_types::PaymentsResponseData>,
+ RouterData<F, RouterDReq, router_types::PaymentsResponseData>: Feature<F, RouterDReq> + Send,
+ 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 {
+ // Extract the vault connector id from the profile
+ let vault_connector_id = match &profile.external_vault_details {
+ domain::ExternalVaultDetails::ExternalVaultEnabled(details) => {
+ Some(&details.vault_connector_id)
+ }
+ domain::ExternalVaultDetails::Skip => None,
+ };
+
+ // Fetch the vault MCA using the vault_connector_id from profile
+ let vault_mca_type = helpers::get_merchant_connector_account(
+ state,
+ platform.get_processor(),
+ None,
+ profile.get_id(),
+ "",
+ vault_connector_id,
+ )
+ .await?;
+
+ let vault_mca = match vault_mca_type {
+ helpers::MerchantConnectorAccountType::DbVal(ref mca) => mca.clone(),
+ helpers::MerchantConnectorAccountType::CacheVal(_) => {
+ return Err(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Vault MCA must be a DB-backed account")
+ }
+ };
+ let connector_customer_map = customer
+ .as_ref()
+ .and_then(|customer| customer.connector_customer.as_ref());
+
+ let default_gateway_context = gateway_context::RouterGatewayContext::direct(
+ platform.get_processor().clone(),
+ vault_mca_type.clone(),
+ payment_data.get_payment_intent().merchant_id.clone(),
+ profile.get_id().clone(),
+ payment_data.get_creds_identifier().map(|id| id.to_string()),
+ );
+
+ let updated_customer = call_create_connector_customer_if_required(
+ state,
+ connector_customer_map,
+ platform.get_processor(),
+ platform.get_initiator(),
+ &vault_mca_type,
+ payment_data,
+ None,
+ &default_gateway_context,
+ )
+ .await?;
+
+ if let Some((customer, updated_customer)) = customer.clone().zip(updated_customer) {
+ let db = &*state.store;
+ let customer_id = customer.get_id().clone();
+ let customer_merchant_id = customer.merchant_id.clone();
+
+ let _updated_customer = db
+ .update_customer_by_customer_id_merchant_id(
+ customer_id,
+ customer_merchant_id,
+ customer,
+ updated_customer,
+ platform.get_provider().get_key_store(),
+ platform.get_provider().get_account().storage_scheme,
+ )
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to update customer during Vault session")?;
+ };
+
+ let connector_customer_id = payment_data.get_connector_customer_id();
+
+ let vault_session_details = generate_vault_session_details_v1(
+ state,
+ platform.get_processor(),
+ &vault_mca,
+ connector_customer_id,
+ )
+ .await?;
+
+ payment_data.set_vault_session_details(vault_session_details);
+ }
+ Ok(())
+}
+
#[cfg(feature = "v2")]
pub async fn call_create_connector_customer_if_required<F, Req, D>(
state: &SessionState,
@@ -295,6 +406,149 @@ pub async fn generate_vault_session_details(
}
}
+#[cfg(feature = "v1")]
+pub async fn generate_vault_session_details_v1(
+ state: &SessionState,
+ processor: &domain::Processor,
+ vault_mca: &domain::MerchantConnectorAccount,
+ connector_customer_id: Option<String>,
+) -> RouterResult<Option<api::VaultSessionDetails>> {
+ let connector_name_str = vault_mca.get_connector_name_as_string();
+ let connector =
+ api_enums::VaultConnectors::from_connector_name(&connector_name_str).map_err(|error| {
+ report!(errors::ApiErrorResponse::InternalServerError).attach_printable(error)
+ })?;
+
+ let connector_auth_type: router_types::ConnectorAuthType = vault_mca
+ .get_connector_account_details()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to parse connector auth type")?;
+
+ match (connector, connector_auth_type) {
+ // create session for vgs vault
+ (
+ api_enums::VaultConnectors::Vgs,
+ router_types::ConnectorAuthType::SignatureKey { api_secret, .. },
+ ) => {
+ let sdk_env = match state.conf.env {
+ Env::Sandbox | Env::Development | Env::Integ => {
+ common_enums::enums::VaultEnv::Sandbox.to_string()
+ }
+ Env::Production => common_enums::enums::VaultEnv::Live.to_string(),
+ };
+ Ok(Some(api::VaultSessionDetails::Vgs(
+ api::VgsSessionDetails {
+ external_vault_id: api_secret,
+ sdk_env,
+ },
+ )))
+ }
+ // create session for hyperswitch vault
+ (
+ api_enums::VaultConnectors::HyperswitchVault,
+ router_types::ConnectorAuthType::SignatureKey {
+ key1, api_secret, ..
+ },
+ ) => {
+ let connector_response = call_external_vault_create_v1(
+ state,
+ processor,
+ connector_name_str,
+ vault_mca,
+ connector_customer_id,
+ )
+ .await?;
+
+ match connector_response.response {
+ Ok(router_types::VaultResponseData::ExternalVaultCreateResponse {
+ session_id,
+ client_secret,
+ }) => Ok(Some(api::VaultSessionDetails::HyperswitchVault(
+ api::HyperswitchVaultSessionDetails {
+ payment_method_session_id: session_id,
+ client_secret,
+ publishable_key: key1,
+ profile_id: api_secret,
+ },
+ ))),
+ Ok(_) => {
+ router_env::logger::warn!("Unexpected response from external vault create API");
+ Err(errors::ApiErrorResponse::InternalServerError.into())
+ }
+ Err(err) => {
+ router_env::logger::error!(error_response_from_external_vault_create=?err);
+ Err(errors::ApiErrorResponse::InternalServerError.into())
+ }
+ }
+ }
+ _ => {
+ router_env::logger::warn!(
+ "External vault session creation is not supported for connector: {:?}",
+ connector
+ );
+ Ok(None)
+ }
+ }
+}
+
+#[cfg(feature = "v1")]
+async fn call_external_vault_create_v1(
+ state: &SessionState,
+ processor: &domain::Processor,
+ connector_name: String,
+ vault_mca: &domain::MerchantConnectorAccount,
+ connector_customer_id: Option<String>,
+) -> RouterResult<VaultRouterData<ExternalVaultCreateFlow>>
+where
+ dyn ConnectorTrait + Sync: services::api::ConnectorIntegration<
+ ExternalVaultCreateFlow,
+ router_types::VaultRequestData,
+ router_types::VaultResponseData,
+ >,
+{
+ let mca_id = vault_mca.get_id();
+ let connector_data: api::ConnectorData = api::ConnectorData::get_connector_by_name(
+ &state.conf.connectors,
+ &connector_name,
+ api::GetToken::Connector,
+ Some(mca_id),
+ )?;
+
+ let router_data = core_utils::construct_vault_router_data(
+ state,
+ processor.get_account().get_id(),
+ vault_mca,
+ None,
+ None,
+ connector_customer_id,
+ None,
+ )
+ .await?;
+
+ let old_router_data = VaultConnectorFlowData::to_old_router_data(router_data)
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable(
+ "Cannot construct router data for making the external vault create api call",
+ )?;
+
+ let connector_integration: services::BoxedVaultConnectorIntegrationInterface<
+ ExternalVaultCreateFlow,
+ router_types::VaultRequestData,
+ router_types::VaultResponseData,
+ > = connector_data.connector.get_connector_integration();
+ services::execute_connector_processing_step(
+ state,
+ connector_integration,
+ &old_router_data,
+ CallConnectorAction::Trigger,
+ None,
+ None,
+ )
+ .await
+ .to_vault_failed_response()
+}
+
+#[cfg(feature = "v2")]
async fn generate_hyperswitch_vault_session_details(
state: &SessionState,
platform: &domain::Platform,