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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(router): generate payment fingerprint regardless of blocklist guard (#14510)
Ayush Anandda3f271b93a5
diff --git a/crates/router/src/core/blocklist/utils.rs b/crates/router/src/core/blocklist/utils.rsindex 28c8b3f414..61cbfb41fc 100644--- a/crates/router/src/core/blocklist/utils.rs+++ b/crates/router/src/core/blocklist/utils.rs@@ -740,14 +740,7 @@ where}.into())} else {- let (fingerprint_id, fingerprint_type) = generate_payment_fingerprint(- state,- processor.get_account(),- payment_data.payment_method_data.clone(),- )- .await?;- payment_data.payment_attempt.fingerprint_id = fingerprint_id;- payment_data.payment_attempt.fingerprint_type = fingerprint_type;+ populate_payment_fingerprint(state, processor.get_account(), payment_data).await;Ok(false)}}@@ -931,9 +924,6 @@ pub async fn generate_payment_fingerprint(payment_method_data: Option<domain::PaymentMethodData>,) -> CustomResult<(Option<String>, Option<common_enums::FingerprintType>), errors::ApiErrorResponse>{- let merchant_fingerprint_secret =- get_merchant_fingerprint_secret(state, merchant_account).await?;-let fingerprint_source = payment_method_data.as_ref().and_then(|payment_method_data| match payment_method_data {@@ -968,29 +958,56 @@ pub async fn generate_payment_fingerprint(_ => None,});- let (fingerprint_id, fingerprint_type) = match fingerprint_source {+ match fingerprint_source {Some((pan, fingerprint_type)) => {+ let merchant_fingerprint_secret =+ get_merchant_fingerprint_secret(state, merchant_account).await?;+let fingerprint_id = generate_fingerprint_and_get_id(state,StrongSecret::new(pan.get_card_no()),StrongSecret::new(merchant_fingerprint_secret),).await- .attach_printable("error in pm fingerprint creation")- .inspect_err(|error| logger::error!(?error))- .ok()- .map(|payload| payload.fingerprint_id);+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("error in pm fingerprint creation")?+ .fingerprint_id;- let fingerprint_type = fingerprint_id.is_some().then_some(fingerprint_type);- (fingerprint_id, fingerprint_type)+ Ok((Some(fingerprint_id), Some(fingerprint_type)))}None => {logger::debug!("payment method does not contain a PAN that can be fingerprinted");- (None, None)+ Ok((None, None))}- };+ }+}- Ok((fingerprint_id, fingerprint_type))+/// Best-effort fingerprinting: a failure is logged and the payment proceeds without a fingerprint.+pub async fn populate_payment_fingerprint<F>(+ state: &SessionState,+ merchant_account: &domain::MerchantAccount,+ payment_data: &mut PaymentData<F>,+) where+ F: Send + Clone,+{+ match generate_payment_fingerprint(+ state,+ merchant_account,+ payment_data.payment_method_data.clone(),+ )+ .await+ {+ Ok((fingerprint_id, fingerprint_type)) => {+ payment_data.payment_attempt.fingerprint_id = fingerprint_id;+ payment_data.payment_attempt.fingerprint_type = fingerprint_type;+ }+ Err(error) => {+ logger::warn!(+ ?error,+ "failed to generate payment fingerprint, proceeding without it"+ );+ }+ }}#[cfg(test)]diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex e9b5b73001..9db2241eec 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -8417,6 +8417,10 @@ where).await?)} else {+ operation+ .to_domain()?+ .populate_payment_fingerprint(state, processor, payment_data)+ .await;Ok(false)}}diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rsindex 0e71991451..3f8e8af906 100644--- a/crates/router/src/core/payments/operations.rs+++ b/crates/router/src/core/payments/operations.rs@@ -494,6 +494,15 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {Ok(false)}+ #[instrument(skip_all)]+ async fn populate_payment_fingerprint<'a>(+ &'a self,+ _state: &SessionState,+ _processor: &domain::Processor,+ _payment_data: &mut D,+ ) {+ }+async fn store_extended_card_info_temporarily<'a>(&'a self,_state: &SessionState,diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex 7ba0b135dd..8594b6675b 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -2425,6 +2425,17 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for.await}+ #[instrument(skip_all)]+ async fn populate_payment_fingerprint<'a>(+ &'a self,+ state: &SessionState,+ processor: &domain::Processor,+ payment_data: &mut PaymentData<F>,+ ) {+ blocklist_utils::populate_payment_fingerprint(state, processor.get_account(), payment_data)+ .await+ }+#[instrument(skip_all)]async fn store_extended_card_info_temporarily<'a>(&'a self,