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

fix(router): Fix redacted customer behaviour in payment flows (#11047)

Anurag Thakur074549ecf4ae
diff --git a/Cargo.lock b/Cargo.lock
index 8ee06476be..248352424c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5844,9 +5844,9 @@ checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e"
[[package]]
name = "openssl-src"
-version = "300.5.5+3.5.5"
+version = "300.5.4+3.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3f1787d533e03597a7934fd0a765f0d28e94ecc5fb7789f8053b1e699a56f709"
+checksum = "a507b3792995dae9b0df8a1c1e3771e8418b7c2d9f0baeba32e6fe8b06c7cb72"
dependencies = [
"cc",
]
diff --git a/crates/hyperswitch_domain_models/src/customer.rs b/crates/hyperswitch_domain_models/src/customer.rs
index 8b1025c107..e7e25b5d39 100644
--- a/crates/hyperswitch_domain_models/src/customer.rs
+++ b/crates/hyperswitch_domain_models/src/customer.rs
@@ -695,6 +695,8 @@ where
storage_scheme: MerchantStorageScheme,
) -> CustomResult<Option<Customer>, Self::Error>;
+ /// This function is to retrieve customer details. If the customer is deleted, it returns
+ /// customer details that contains the fields as Redacted
#[cfg(feature = "v1")]
async fn find_customer_optional_with_redacted_customer_details_by_customer_id_merchant_id(
&self,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 2cf70132f6..10c9d25421 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -8031,7 +8031,6 @@ where
pub attempts: Option<Vec<storage::PaymentAttempt>>,
pub sessions_token: Vec<api::SessionToken>,
pub card_cvc: Option<Secret<String>>,
- pub email: Option<pii::Email>,
pub creds_identifier: Option<String>,
pub pm_token: Option<String>,
pub connector_customer_id: Option<String>,
@@ -11672,7 +11671,6 @@ pub trait OperationSessionSetters<F> {
fn set_payment_method_data(&mut self, payment_method_data: Option<domain::PaymentMethodData>);
fn set_payment_method_token(&mut self, payment_method_token: Option<PaymentMethodToken>);
fn set_payment_method_info(&mut self, payment_method_info: Option<domain::PaymentMethod>);
- fn set_email_if_not_present(&mut self, email: pii::Email);
fn set_payment_method_id_in_attempt(&mut self, payment_method_id: Option<String>);
fn set_pm_token(&mut self, token: String);
fn set_connector_customer_id(&mut self, customer_id: Option<String>);
@@ -11942,10 +11940,6 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentData<F> {
self.payment_attempt.payment_method_id = payment_method_id;
}
- fn set_email_if_not_present(&mut self, email: pii::Email) {
- self.email = self.email.clone().or(Some(email));
- }
-
fn set_pm_token(&mut self, token: String) {
self.pm_token = Some(token);
}
@@ -12300,10 +12294,6 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentIntentData<F> {
todo!()
}
- fn set_email_if_not_present(&mut self, _email: pii::Email) {
- todo!()
- }
-
fn set_pm_token(&mut self, _token: String) {
todo!()
}
@@ -12599,10 +12589,6 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentConfirmData<F> {
todo!()
}
- fn set_email_if_not_present(&mut self, _email: pii::Email) {
- todo!()
- }
-
fn set_pm_token(&mut self, _token: String) {
todo!()
}
@@ -12906,10 +12892,6 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentStatusData<F> {
todo!()
}
- fn set_email_if_not_present(&mut self, _email: pii::Email) {
- todo!()
- }
-
fn set_card_network(&mut self, card_network: enums::CardNetwork) {
todo!()
}
@@ -13225,10 +13207,6 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentCaptureData<F> {
todo!()
}
- fn set_email_if_not_present(&mut self, _email: pii::Email) {
- todo!()
- }
-
fn set_pm_token(&mut self, _token: String) {
todo!()
}
@@ -13674,10 +13652,6 @@ impl<F: Clone> OperationSessionSetters<F> for PaymentCancelData<F> {
todo!()
}
- fn set_email_if_not_present(&mut self, _email: pii::Email) {
- todo!()
- }
-
fn set_payment_method_id_in_attempt(&mut self, _payment_method_id: Option<String>) {
todo!()
}
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index a726fc92f4..1fc2a17f85 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -2128,12 +2128,6 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R, D>(
);
payment_data.payment_intent.customer_id = Some(customer.customer_id.clone());
- payment_data.email = payment_data.email.clone().or_else(|| {
- customer
- .email
- .clone()
- .map(|encrypted_value| encrypted_value.into())
- });
Some(customer)
}
diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rs
index f37f08e801..e5f125efbc 100644
--- a/crates/router/src/core/payments/operations.rs
+++ b/crates/router/src/core/payments/operations.rs
@@ -656,10 +656,10 @@ where
#[cfg(feature = "v1")]
async fn get_or_create_customer_details<'a>(
&'a self,
- state: &SessionState,
- payment_data: &mut D,
+ _state: &SessionState,
+ _payment_data: &mut D,
_request: Option<CustomerDetails>,
- provider: &domain::Provider,
+ _provider: &domain::Provider,
) -> CustomResult<
(
BoxedOperation<'a, F, api::PaymentsRetrieveRequest, D>,
@@ -667,29 +667,11 @@ where
),
errors::StorageError,
> {
- let db = &*state.store;
- let merchant_key_store = provider.get_key_store();
- let storage_scheme = provider.get_account().storage_scheme;
- let customer = match payment_data.get_payment_intent().customer_id.as_ref() {
- None => None,
- Some(customer_id) => {
- // This function is to retrieve customer details. If the customer is deleted, it returns
- // customer details that contains the fields as Redacted
- db.find_customer_optional_with_redacted_customer_details_by_customer_id_merchant_id(
- customer_id,
- &merchant_key_store.merchant_id,
- merchant_key_store,
- storage_scheme,
- )
- .await?
- }
- };
-
- if let Some(email) = customer.as_ref().and_then(|inner| inner.email.clone()) {
- payment_data.set_email_if_not_present(email.into());
- }
-
- Ok((Box::new(self), customer))
+ // We don't need to fetch customer here.
+ // Customer details have already been populated in the payment_intent during Confirm
+ // The customer returned from this method is only used for updating connector_customer_id
+ // which does not happen in case of Retrieve
+ Ok((Box::new(self), None))
}
async fn get_connector<'a>(
@@ -742,10 +724,10 @@ where
#[cfg(feature = "v1")]
async fn get_or_create_customer_details<'a>(
&'a self,
- state: &SessionState,
- payment_data: &mut D,
+ _state: &SessionState,
+ _payment_data: &mut D,
_request: Option<CustomerDetails>,
- provider: &domain::Provider,
+ _provider: &domain::Provider,
) -> CustomResult<
(
BoxedOperation<'a, F, api::PaymentsCaptureRequest, D>,
@@ -753,28 +735,11 @@ where
),
errors::StorageError,
> {
- let db = &*state.store;
- let merchant_key_store = provider.get_key_store();
- let storage_scheme = provider.get_account().storage_scheme;
-
- let customer = match payment_data.get_payment_intent().customer_id.as_ref() {
- None => None,
- Some(customer_id) => {
- db.find_customer_optional_by_customer_id_merchant_id(
- customer_id,
- &merchant_key_store.merchant_id,
- merchant_key_store,
- storage_scheme,
- )
- .await?
- }
- };
-
- if let Some(email) = customer.as_ref().and_then(|inner| inner.email.clone()) {
- payment_data.set_email_if_not_present(email.into());
- }
-
- Ok((Box::new(self), customer))
+ // We don't need to fetch customer here.
+ // Customer details have already been populated in the payment_intent during Confirm
+ // The customer returned from this method is only used for updating connector_customer_id
+ // which does not happen in case of Capture
+ Ok((Box::new(self), None))
}
#[instrument(skip_all)]
@@ -845,10 +810,10 @@ where
#[cfg(feature = "v1")]
async fn get_or_create_customer_details<'a>(
&'a self,
- state: &SessionState,
- payment_data: &mut D,
+ _state: &SessionState,
+ _payment_data: &mut D,
_request: Option<CustomerDetails>,
- provider: &domain::Provider,
+ _provider: &domain::Provider,
) -> CustomResult<
(
BoxedOperation<'a, F, api::PaymentsCancelRequest, D>,
@@ -856,28 +821,12 @@ where
),
errors::StorageError,
> {
- let db = &*state.store;
- let merchant_key_store = provider.get_key_store();
- let storage_scheme = provider.get_account().storage_scheme;
-
- let customer = match payment_data.get_payment_intent().customer_id.as_ref() {
- None => None,
- Some(customer_id) => {
- db.find_customer_optional_by_customer_id_merchant_id(
- customer_id,
- &merchant_key_store.merchant_id,
- merchant_key_store,
- storage_scheme,
- )
- .await?
- }
- };
-
- if let Some(email) = customer.as_ref().and_then(|inner| inner.email.clone()) {
- payment_data.set_email_if_not_present(email.into());
- }
-
- Ok((Box::new(self), customer))
+ // We don't need to fetch customer here.
+ // Customer details have already been populated in the payment_intent during Confirm
+ // The customer returned from this method is only used for updating connector_customer_id
+ // which does not happen in case of Cancel
+
+ Ok((Box::new(self), None))
}
#[instrument(skip_all)]
diff --git a/crates/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rs
index 50f7959135..8883de47f0 100644
--- a/crates/router/src/core/payments/operations/payment_approve.rs
+++ b/crates/router/src/core/payments/operations/payment_approve.rs
@@ -155,7 +155,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCaptureR
payment_attempt,
currency,
amount,
- email: None,
mandate_id: None,
mandate_connector: None,
setup_mandate: None,
diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rs
index b6a245a8a0..92ea14e8fe 100644
--- a/crates/router/src/core/payments/operations/payment_cancel.rs
+++ b/crates/router/src/core/payments/operations/payment_cancel.rs
@@ -167,7 +167,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCancelRe
payment_attempt,
currency,
amount,
- email: None,
mandate_id: None,
mandate_connector: None,
setup_mandate: None,
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 61f8b95653..5755c05183 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
@@ -150,7 +150,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCancelPo
payment_attempt,
currency,
amount,
- email: None,
mandate_id: None,
mandate_connector: None,
setup_mandate: None,
diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs
index e871c78329..1ed7967acd 100644
--- a/crates/router/src/core/payments/operations/payment_capture.rs
+++ b/crates/router/src/core/payments/operations/payment_capture.rs
@@ -225,7 +225,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, payments::PaymentData<F>, api::Paymen
force_sync: None,
all_keys_required: None,
amount,
- email: None,
mandate_id: None,
mandate_connector: None,
setup_mandate: None,
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 12d9a119dc..50a5de732c 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -2,6 +2,7 @@ use std::marker::PhantomData;
use api_models::enums::FrmSuggestion;
use async_trait::async_trait;
+use common_utils::ext_traits::AsyncExt;
use error_stack::{report, ResultExt};
use router_derive::PaymentOperation;
use router_env::{instrument, tracing};
@@ -11,7 +12,10 @@ use crate::{
core::{
errors::{self, CustomResult, RouterResult, StorageErrorExt},
mandate::helpers as m_helpers,
- payments::{self, helpers, operations, CustomerDetails, PaymentAddress, PaymentData},
+ payments::{
+ self, helpers, operations, CustomerDetails, OperationSessionGetters, PaymentAddress,
+ PaymentData,
+ },
},
events::audit_events::{AuditEvent, AuditEventType},
routes::{app::ReqState, SessionState},
@@ -321,7 +325,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
payment_attempt,
currency,
amount,
- email: request.email.clone(),
mandate_id: None,
mandate_connector,
setup_mandate,
@@ -403,47 +406,37 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
&'a self,
state: &SessionState,
payment_data: &mut PaymentData<F>,
- request: Option<CustomerDetails>,
+ _request: Option<CustomerDetails>,
provider: &domain::Provider,
) -> CustomResult<
(CompleteAuthorizeOperation<'a, F>, Option<domain::Customer>),
errors::StorageError,
> {
- match provider.get_account().merchant_account_type {
- common_enums::MerchantAccountType::Standard => {
- helpers::create_customer_if_not_exist(
- state,
- Box::new(self),
- payment_data,
- request,
- provider,
+ // We only fetch customer here because `connector_customer_id` could be created in CompleteAuthorize
+ // and we need the customer object in order to update that in the DB
+
+ let db = &*state.store;
+ let merchant_key_store = provider.get_key_store();
+ let storage_scheme = provider.get_account().storage_scheme;
+ let customer = payment_data
+ .get_payment_intent()
+ .customer_id
+ .as_ref()
+ .async_map(|customer_id| async {
+ // We allow CompleteAuthorize even if customer has been redacted
+ db.find_customer_optional_with_redacted_customer_details_by_customer_id_merchant_id(
+ customer_id,
+ &merchant_key_store.merchant_id,
+ merchant_key_store,
+ storage_scheme,
)
.await
- }
- common_enums::MerchantAccountType::Platform => {
- let customer = helpers::get_customer_if_exists(
- state,
- request.as_ref().and_then(|r| r.customer_id.as_ref()),
- payment_data.payment_intent.customer_id.as_ref(),
- provider,
- )
- .await?
- .inspect(|cust| {
- payment_data.email = payment_data
- .email
- .clone()
- .or_else(|| cust.email.clone().map(Into::into));
- });
+ })
+ .await
+ .transpose()?
+ .flatten();
- Ok((Box::new(self), customer))
- }
- common_enums::MerchantAccountType::Connected => {
- Err(errors::StorageError::ValueNotFound(
- "Connected merchant cannot be a provider".to_string(),
- )
- .into())
- }
- }
+ Ok((Box::new(self), customer))
}
#[instrument(skip_all)]
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 6d25623294..d763cf8087 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -865,7 +865,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
payment_attempt,
currency,
amount,
- email: request.email.clone(),
mandate_id: mandate_id.clone(),
mandate_connector,
setup_mandate,
@@ -997,10 +996,6 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
"Customer id mismatch between payment intent and request".to_string(),
))
.map_or(Ok(()), Err)?;
- payment_data.email = payment_data
- .email
- .clone()
- .or_else(|| cust.email.clone().map(Into::into));
Ok(cust)
})
.transpose()
@@ -1846,7 +1841,21 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
.parse_value("BrowserInfo")
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to parse browser_info")?;
- let email = payment_data.email.clone();
+
+ let email = payment_data.payment_intent.customer_details
+ .clone()
+ .map(|customer_details_encrypted| {
+ customer_details_encrypted
+ .into_inner()
+ .expose()
+ .parse_value::<hyperswitch_domain_models::payments::payment_intent::CustomerData>("CustomerData")
+ })
+ .transpose()
+ .change_context(errors::StorageError::DeserializationFailed)
+ .attach_printable("Failed to parse customer data from payment intent")
+ .change_context(errors::ApiErrorResponse::InternalServerError)?.and_then(|cust| cust.email);
+
+
let routing_region = uas_utils::utils::fetch_routing_region_for_uas(
state,
payment_data.payment_attempt.merchant_id.clone(),
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index 2c850d629e..7015be1d8d 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -605,7 +605,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
payment_attempt,
currency,
amount,
- email: request.email.clone(),
mandate_id: mandate_id.clone(),
mandate_connector,
setup_mandate,
@@ -694,10 +693,6 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
.await?
.inspect(|cust| {
payment_data.payment_intent.customer_id = Some(cust.customer_id.clone());
- payment_data.email = payment_data
- .email
- .clone()
- .or_else(|| cust.email.clone().map(Into::into));
});
Ok((Box::new(self), customer))
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 5a8ae3e404..77d8f87a97 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
@@ -128,7 +128,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsPostSess
payment_attempt,
currency,
amount,
- email: None,
mandate_id: None,
mandate_connector: None,
customer_acceptance: None,
diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs
index ea9e917957..24040bb27d 100644
--- a/crates/router/src/core/payments/operations/payment_reject.rs
+++ b/crates/router/src/core/payments/operations/payment_reject.rs
@@ -154,7 +154,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, PaymentsCancelRequest
payment_attempt,
currency,
amount,
- email: None,
mandate_id: None,
mandate_connector: None,
setup_mandate: None,
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index 6958aafb52..82bc79ffe6 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -179,7 +179,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsSessionR
payment_attempt,
currency,
amount,
- email: None,
mandate_id: None,
mandate_connector: None,
customer_acceptance: None,
@@ -350,14 +349,7 @@ where
payment_data.payment_intent.customer_id.as_ref(),
provider,
)
- .await?
- .inspect(|cust| {
- payment_data.email = payment_data
- .email
- .clone()
- .or_else(|| cust.email.clone().map(Into::into));
- });
-
+ .await?;
Ok((Box::new(self), customer))
}
common_enums::MerchantAccountType::Connected => {
diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rs
index 27ebc1cba1..26c9280692 100644
--- a/crates/router/src/core/payments/operations/payment_start.rs
+++ b/crates/router/src/core/payments/operations/payment_start.rs
@@ -164,7 +164,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsStartReq
payment_intent,
currency,
amount,
- email: None,
mandate_id: None,
mandate_connector: None,
setup_mandate: None,
@@ -287,49 +286,19 @@ where
#[instrument(skip_all)]
async fn get_or_create_customer_details<'a>(
&'a self,
- state: &SessionState,
- payment_data: &mut PaymentData<F>,
- request: Option<CustomerDetails>,
- provider: &domain::Provider,
+ _state: &SessionState,
+ _payment_data: &mut PaymentData<F>,
+ _request: Option<CustomerDetails>,
+ _provider: &domain::Provider,
) -> CustomResult<
(PaymentSessionOperation<'a, F>, Option<domain::Customer>),
errors::StorageError,
> {
- match provider.get_account().merchant_account_type {
- common_enums::MerchantAccountType::Standard => {
- helpers::create_customer_if_not_exist(
- state,
- Box::new(self),
- payment_data,
- request,
- provider,
- )
- .await
- }
- common_enums::MerchantAccountType::Platform => {
- let customer = helpers::get_customer_if_exists(
- state,
- request.as_ref().and_then(|r| r.customer_id.as_ref()),
- payment_data.payment_intent.customer_id.as_ref(),
- provider,
- )
- .await?
- .inspect(|cust| {
- payment_data.email = payment_data
- .email
- .clone()
- .or_else(|| cust.email.clone().map(Into::into));
- });
-
- Ok((Box::new(self), customer))
- }
- common_enums::MerchantAccountType::Connected => {
- Err(errors::StorageError::ValueNotFound(
- "Connected merchant cannot be a provider".to_string(),
- )
- .into())
- }
- }
+ // We don't need to fetch customer here.
+ // Customer details have already been populated in the payment_intent during Confirm
+ // The customer returned from this method is only used for updating connector_customer_id
+ // which does not happen in case of PaymentStart
+ Ok((Box::new(self), None))
}
#[instrument(skip_all)]
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index d2f57acb6f..f6e792fb4d 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -91,13 +91,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
payment_data.payment_intent.customer_id.as_ref(),
provider,
)
- .await?
- .inspect(|cust| {
- payment_data.email = payment_data
- .email
- .clone()
- .or_else(|| cust.email.clone().map(Into::into));
- });
+ .await?;
Ok((Box::new(self), customer))
}
@@ -509,7 +503,6 @@ async fn get_tracker_for_sync<
payment_intent,
currency,
amount,
- email: None,
mandate_id: payment_attempt
.mandate_id
.clone()
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index fe915f682f..2c2830881e 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -508,7 +508,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
payment_attempt,
currency,
amount,
- email: request.email.clone(),
mandate_id,
mandate_connector,
token,
@@ -613,10 +612,6 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
"Customer id mismatch between payment intent and request".to_string(),
))
.map_or(Ok(()), Err)?;
- payment_data.email = payment_data
- .email
- .clone()
- .or_else(|| cust.email.clone().map(Into::into));
Ok(cust)
})
.transpose()
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 591f8733b2..78a077c2fd 100644
--- a/crates/router/src/core/payments/operations/payment_update_metadata.rs
+++ b/crates/router/src/core/payments/operations/payment_update_metadata.rs
@@ -145,7 +145,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsUpdateMe
payment_attempt,
currency,
amount,
- email: None,
mandate_id: None,
mandate_connector: None,
customer_acceptance: None,
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 bead031b8a..ace766fc68 100644
--- a/crates/router/src/core/payments/operations/payments_extend_authorization.rs
+++ b/crates/router/src/core/payments/operations/payments_extend_authorization.rs
@@ -155,7 +155,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsExtendAu
payment_attempt,
currency,
amount,
- email: None,
mandate_id: None,
mandate_connector: None,
setup_mandate: None,
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 328774d660..8b15f66ca3 100644
--- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
+++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
@@ -134,7 +134,6 @@ impl<F: Send + Clone + Sync>
payment_attempt,
currency,
amount: amount.into(),
- email: None,
mandate_id: None,
mandate_connector: None,
setup_mandate: None,
@@ -322,10 +321,10 @@ impl<F: Clone + Send + Sync>
#[instrument(skip_all)]
async fn get_or_create_customer_details<'a>(
&'a self,
- _state: &SessionState,
- _payment_data: &mut payments::PaymentData<F>,
- _request: Option<CustomerDetails>,
- _provider: &domain::Provider,
+ state: &SessionState,
+ payment_data: &mut payments::PaymentData<F>,
+ request: Option<CustomerDetails>,
+ provider: &domain::Provider,
) -> CustomResult<
(
BoxedOperation<
@@ -338,7 +337,18 @@ impl<F: Clone + Send + Sync>
),
errors::StorageError,
> {
- Ok((Box::new(self), None))
+ // Fetching customer here to ensure customer has not been redacted
+ // We do not allow incremental authorization in case the customer has been redacted as it
+ // would be starting new money movement
+ let customer = helpers::get_customer_if_exists(
+ state,
+ request.as_ref().and_then(|r| r.customer_id.as_ref()),
+ payment_data.payment_intent.customer_id.as_ref(),
+ provider,
+ )
+ .await?;
+
+ Ok((Box::new(self), customer))
}
#[instrument(skip_all)]
diff --git a/crates/router/src/core/payments/operations/tax_calculation.rs b/crates/router/src/core/payments/operations/tax_calculation.rs
index 67b1e3fae0..f7496d3d91 100644
--- a/crates/router/src/core/payments/operations/tax_calculation.rs
+++ b/crates/router/src/core/payments/operations/tax_calculation.rs
@@ -144,7 +144,6 @@ impl<F: Send + Clone + Sync>
payment_attempt,
currency,
amount,
- email: None,
mandate_id: None,
mandate_connector: None,
customer_acceptance: None,
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 8f2e46bf0b..ab631301be 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -4945,6 +4945,11 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
.as_ref()
.and_then(|customer_data| customer_data.name.clone());
+ let customer_email = additional_data
+ .customer_data
+ .as_ref()
+ .and_then(|customer_data| customer_data.email.clone());
+
let customer_id = additional_data.customer_id.clone();
let split_payments = payment_data.payment_intent.split_payments.clone();
@@ -5004,7 +5009,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
minor_amount: amount,
currency: payment_data.currency,
browser_info,
- email: payment_data.email,
+ email: customer_email,
customer_name,
payment_experience: payment_data.payment_attempt.payment_experience,
order_details,
@@ -5769,7 +5774,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSessionD
),
order_details,
surcharge_details: payment_data.surcharge_details,
- email: payment_data.email,
+ email: additional_data.customer_data.and_then(|cust| cust.email),
apple_pay_recurring_details,
customer_name: None,
metadata: payment_data.payment_intent.metadata,
@@ -5874,7 +5879,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSessionD
},
),
order_details,
- email: payment_data.email,
+ email: additional_data.customer_data.and_then(|cust| cust.email),
surcharge_details: payment_data.surcharge_details,
apple_pay_recurring_details,
customer_name: None,
@@ -6092,7 +6097,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ
setup_mandate_details: payment_data.setup_mandate,
customer_acceptance: payment_data.customer_acceptance,
router_return_url,
- email: payment_data.email,
+ email: additional_data.customer_data.and_then(|cust| cust.email),
customer_name,
return_url: payment_data.payment_intent.return_url,
browser_info,
@@ -6265,7 +6270,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthoriz
.request_incremental_authorization,
Some(RequestIncrementalAuthorization::True)
),
- email: payment_data.email,
+ email: additional_data.customer_data.and_then(|cust| cust.email),
payment_method_data: payment_data.payment_method_data,
connector_transaction_id: payment_data
.payment_attempt
@@ -6374,7 +6379,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsPreProce
let amount = payment_data.payment_attempt.get_total_amount();
Ok(Self {
payment_method_data,
- email: payment_data.email,
+ email: additional_data.customer_data.and_then(|cust| cust.email),
currency: Some(payment_data.currency),
amount: amount.get_amount_as_i64(), // need to change this once we move to connector module
minor_amount: amount,