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(core): add support for Guest Customer in v2 tunnel (#10973)

Aishwariyaa Anandb2d115873c29
diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rs
index fcf178fd8f..ae59d8b3d9 100644
--- a/crates/hyperswitch_connectors/src/utils.rs
+++ b/crates/hyperswitch_connectors/src/utils.rs
@@ -7324,6 +7324,7 @@ pub(crate) fn convert_setup_mandate_router_data_to_authorize_router_data(
authentication_data: None,
customer_acceptance: data.request.customer_acceptance.clone(),
split_payments: None, // TODO: allow charges on mandates?
+ guest_customer: None,
merchant_order_reference_id: None,
integrity_object: None,
additional_payment_method_data: None,
diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs
index 118e0347e0..077a952c88 100644
--- a/crates/hyperswitch_domain_models/src/payments.rs
+++ b/crates/hyperswitch_domain_models/src/payments.rs
@@ -1457,3 +1457,9 @@ impl VaultData {
}
}
}
+
+/// Guest customer details for connectors
+#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq)]
+pub struct GuestCustomer {
+ pub customer_id: String,
+}
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index a97058d985..28323ddb9d 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -72,6 +72,9 @@ pub struct PaymentsAuthorizeData {
Option<common_types::primitive_wrappers::RequestExtendedAuthorizationBool>,
pub split_payments: Option<common_types::payments::SplitPaymentsRequest>,
+ // Guest customer fields
+ pub guest_customer: Option<payments::GuestCustomer>,
+
// New amount for amount frame work
pub minor_amount: MinorUnit,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index f9061a7259..b9bca39022 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -544,6 +544,19 @@ where
)
.await?;
+ let guest_customer = payment_data
+ .get_payment_intent()
+ .metadata
+ .as_ref()
+ .and_then(|metadata| metadata.peek().as_object())
+ .and_then(|metadata_map| metadata_map.get("guest_customer"))
+ .and_then(|guest_value| {
+ guest_value
+ .clone()
+ .parse_value::<hyperswitch_domain_models::payments::GuestCustomer>("guest_customer")
+ .ok()
+ });
+
let router_data = connector_service_decider(
state,
req_state.clone(),
@@ -556,6 +569,7 @@ where
profile,
req.should_return_raw_response(),
merchant_connector_account,
+ guest_customer,
)
.await?;
@@ -5192,6 +5206,7 @@ pub async fn connector_service_decider<F, RouterDReq, ApiRequest, D>(
business_profile: &domain::Profile,
return_raw_connector_response: Option<bool>,
merchant_connector_account_type_details: domain::MerchantConnectorAccountTypeDetails,
+ guest_customer: Option<hyperswitch_domain_models::payments::GuestCustomer>,
) -> RouterResult<RouterData<F, RouterDReq, router_types::PaymentsResponseData>>
where
F: Send + Clone + Sync,
@@ -5217,6 +5232,8 @@ where
)
.await?;
+ payment_data.add_guest_customer(&mut router_data, &guest_customer)?;
+
// Extract previous gateway from payment data
let previous_gateway = extract_gateway_system_from_payment_intent(payment_data);
diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs
index d797c3e2c9..84587176cf 100644
--- a/crates/router/src/core/payments/flows.rs
+++ b/crates/router/src/core/payments/flows.rs
@@ -78,6 +78,15 @@ pub trait ConstructFlowSpecificData<F, Req, Res> {
) -> RouterResult<Option<types::MerchantRecipientData>> {
Ok(None)
}
+
+ #[cfg(feature = "v2")]
+ fn add_guest_customer(
+ &self,
+ _router_data: &mut types::RouterData<F, Req, Res>,
+ _guest_customer: &Option<hyperswitch_domain_models::payments::GuestCustomer>,
+ ) -> RouterResult<()> {
+ Ok(())
+ }
}
#[allow(clippy::too_many_arguments)]
diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs
index 7d629e5b6d..83aebe2c9c 100644
--- a/crates/router/src/core/payments/flows/authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/authorize_flow.rs
@@ -117,6 +117,21 @@ impl
Ok(None)
}
}
+
+ fn add_guest_customer(
+ &self,
+ router_data: &mut types::RouterData<
+ api::Authorize,
+ types::PaymentsAuthorizeData,
+ types::PaymentsResponseData,
+ >,
+ guest_customer: &Option<hyperswitch_domain_models::payments::GuestCustomer>,
+ ) -> RouterResult<()> {
+ if let Some(guest_customer_data) = guest_customer {
+ router_data.request.guest_customer = Some(guest_customer_data.clone());
+ }
+ Ok(())
+ }
}
#[cfg(feature = "v1")]
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index e787b96c3a..b1c4e257eb 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -442,6 +442,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
authentication_data: None,
customer_acceptance: None,
split_payments: None,
+ guest_customer: None,
merchant_order_reference_id: payment_data
.payment_intent
.merchant_reference_id
@@ -4699,6 +4700,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
authentication_data: None,
request_extended_authorization: None,
split_payments: None,
+ guest_customer: None,
minor_amount: payment_data.payment_attempt.get_total_amount(),
merchant_order_reference_id,
integrity_object: None,
@@ -4947,6 +4949,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
customer_acceptance: payment_data.customer_acceptance,
request_extended_authorization: attempt.request_extended_authorization,
split_payments,
+ guest_customer: None,
merchant_order_reference_id,
integrity_object: None,
additional_payment_method_data,
diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rs
index 5d6a475fcb..93be67239a 100644
--- a/crates/router/src/core/unified_connector_service/transformers.rs
+++ b/crates/router/src/core/unified_connector_service/transformers.rs
@@ -311,9 +311,16 @@ impl
}),
customer_id: router_data
.request
- .customer_id
+ .guest_customer
.as_ref()
- .map(|id| id.get_string_repr().to_string()),
+ .map(|guest| guest.customer_id.clone())
+ .or_else(|| {
+ router_data
+ .request
+ .customer_id
+ .as_ref()
+ .map(|id| id.get_string_repr().to_string())
+ }),
metadata,
test_mode: router_data.test_mode,
connector_customer_id: router_data.connector_customer.clone(),
@@ -1389,9 +1396,16 @@ impl
}),
customer_id: router_data
.request
- .customer_id
+ .guest_customer
.as_ref()
- .map(|id| id.get_string_repr().to_string()),
+ .map(|guest| guest.customer_id.clone())
+ .or_else(|| {
+ router_data
+ .request
+ .customer_id
+ .as_ref()
+ .map(|id| id.get_string_repr().to_string())
+ }),
metadata,
test_mode: router_data.test_mode,
connector_customer_id: router_data.connector_customer.clone(),
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index e835d98b4a..3b9384eafd 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -1317,6 +1317,7 @@ impl ForeignFrom<&SetupMandateRouterData> for PaymentsAuthorizeData {
authentication_data: None,
customer_acceptance: data.request.customer_acceptance.clone(),
split_payments: None, // TODO: allow charges on mandates?
+ guest_customer: None,
merchant_order_reference_id: None,
integrity_object: None,
additional_payment_method_data: None,
diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs
index 8e12ea6c26..c75b3b5aae 100644
--- a/crates/router/src/types/api/verify_connector.rs
+++ b/crates/router/src/types/api/verify_connector.rs
@@ -55,6 +55,7 @@ impl VerifyConnectorData {
authentication_data: None,
customer_acceptance: None,
split_payments: None,
+ guest_customer: None,
merchant_order_reference_id: None,
integrity_object: None,
additional_payment_method_data: None,
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index f91acc516a..bfa23f4d57 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -1000,6 +1000,7 @@ impl Default for PaymentAuthorizeType {
authentication_data: None,
customer_acceptance: None,
split_payments: None,
+ guest_customer: None,
integrity_object: None,
merchant_order_reference_id: None,
additional_payment_method_data: None,