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(payment_methods): surface customer email in client PML intent_data (#13146)

Ayush Anand838dbcf52813
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 7aa22e7d7f..2acf47a1b0 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -30548,6 +30548,11 @@
],
"nullable": true
},
+ "email": {
+ "type": "string",
+ "description": "The email associated with the payment",
+ "nullable": true
+ },
"metadata": {
"type": "object",
"description": "Additional metadata",
diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs
index 618918442e..79fb18b792 100644
--- a/crates/api_models/src/payment_methods.rs
+++ b/crates/api_models/src/payment_methods.rs
@@ -2891,6 +2891,10 @@ pub struct PaymentMethodListIntentData {
#[schema(value_type = Option<Address>)]
pub shipping: Option<payments::Address>,
+ /// The email associated with the payment
+ #[schema(value_type = Option<String>)]
+ pub email: Option<pii::Email>,
+
/// Additional metadata
#[schema(value_type = Option<Object>)]
pub metadata: Option<pii::SecretSerdeValue>,
diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs
index f343b22937..c295f2296f 100644
--- a/crates/hyperswitch_domain_models/src/payments.rs
+++ b/crates/hyperswitch_domain_models/src/payments.rs
@@ -537,13 +537,21 @@ impl PaymentIntent {
show_installments: bool,
extra: PaymentMethodListIntentDataInput,
business_profile: &crate::business_profile::Profile,
+ customer: Option<&crate::customer::Customer>,
) -> CustomResult<PaymentMethodListIntentData, errors::api_error_response::ApiErrorResponse>
{
let request_ext_3ds = self.get_request_external_three_ds_authentication();
let is_guest = self.is_guest_customer();
let is_tax = business_profile.get_is_tax_calculation_enabled(&self);
- let billing: Option<Address> = self
+ // Populating the email directly, for the cases where we have customer details stored in
+ // Payment Intent
+ let customer_details_from_pi = self
+ .get_intent_customer_details()
+ .change_context(errors::api_error_response::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to parse customer_details")?;
+
+ let mut billing: Option<Address> = self
.billing_details
.map(|b| b.deserialize_inner_value(|value| value.parse_value("Address")))
.transpose()
@@ -559,6 +567,46 @@ impl PaymentIntent {
.attach_printable("Failed to parse shipping address")?
.map(|enc| enc.into_inner());
+ if let Some(billing_address) = billing.as_mut() {
+ billing_address.email = billing_address.email.clone().or_else(|| {
+ customer_details_from_pi
+ .as_ref()
+ .and_then(|customer_details| customer_details.email.clone())
+ .or_else(|| {
+ customer.and_then(|cust| {
+ cust.email
+ .as_ref()
+ .map(|email| pii::Email::from(email.clone()))
+ })
+ })
+ });
+ } else {
+ billing = Some(Address {
+ email: customer_details_from_pi
+ .as_ref()
+ .and_then(|customer_details| customer_details.email.clone())
+ .or_else(|| {
+ customer.and_then(|cust| {
+ cust.email
+ .as_ref()
+ .map(|email| pii::Email::from(email.clone()))
+ })
+ }),
+ ..Default::default()
+ });
+ }
+
+ let email = customer_details_from_pi
+ .as_ref()
+ .and_then(|customer_details| customer_details.email.clone())
+ .or_else(|| {
+ customer.and_then(|cust| {
+ cust.email
+ .as_ref()
+ .map(|email| pii::Email::from(email.clone()))
+ })
+ });
+
let installment_options = match show_installments {
false => None,
true => self
@@ -597,6 +645,7 @@ impl PaymentIntent {
setup_future_usage: self.setup_future_usage,
billing,
shipping,
+ email,
metadata: self.metadata.map(Secret::new),
order_details: self.order_details,
created: Some(self.created_at),
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 8ed4a20e70..f5f5c39aae 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -4974,6 +4974,7 @@ pub async fn list_payment_methods(
pms_ctx.connector_supports_installments,
extra,
&business_profile,
+ customer.as_ref(),
)
})
.transpose()
diff --git a/crates/router/src/core/payment_methods/client.rs b/crates/router/src/core/payment_methods/client.rs
index 329691d767..6d3ab0c66c 100644
--- a/crates/router/src/core/payment_methods/client.rs
+++ b/crates/router/src/core/payment_methods/client.rs
@@ -614,6 +614,7 @@ pub async fn list_payment_methods_client(
connector_supports_installments,
intent_data_input,
&payment_intent_context.business_profile,
+ payment_intent_context.customer.as_ref(),
)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to build intent_data")?;