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
fix(rouer): fix billing address fetch in payments create and confirm flow (#11174)
Prasunna Soppa05317647bbb8
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex ef43b4893b..dfdcd80289 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -7741,13 +7741,12 @@ async fn decide_payment_method_tokenize_action(payment_method,connector_name);- //this will throw error, in repeat cit, since pm token generate wont be of this key+let connector_token_option = redis_conn.get_key::<Option<String>>(&key.into()).await.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to fetch the token from redis")?;- //new merchant,dont throw error??match connector_token_option {Some(connector_token) => {diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex 203f593ab9..6d25623294 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -5,7 +5,7 @@ use api_models::payment_methods::PaymentMethodsData;use api_models::{admin::ExtendedCardInfoConfig,enums::FrmSuggestion,- payments::{ConnectorMandateReferenceId, ExtendedCardInfo},+ payments::{ConnectorMandateReferenceId, ExtendedCardInfo, GetAddressFromPaymentMethodData},};use async_trait::async_trait;use common_utils::ext_traits::{AsyncExt, Encode, StringExt, ValueExt};@@ -764,22 +764,30 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>let payment_method_data_billing = request.payment_method_data.as_ref()- .and_then(|pmd| pmd.billing.clone())- .or(payment_method_with_raw_data.as_ref().and_then(|pm| {- pm.payment_method- .0- .payment_method_billing_address- .clone()- .map(|decrypted_data| decrypted_data.into_inner().expose())- .and_then(|decrypted_value| {- decrypted_value- .parse_value("payment method billing address")- .ok()- })- }));+ .and_then(|pmd| pmd.payment_method_data.as_ref())+ .and_then(|payment_method_data_billing| {+ payment_method_data_billing.get_billing_address()+ })+ .map(From::from);+ let pm_pmd_billing = payment_method_with_raw_data.as_ref().and_then(|pm| {+ pm.payment_method+ .0+ .payment_method_billing_address+ .clone()+ .map(|decrypted_data| decrypted_data.into_inner().expose())+ .and_then(|decrypted_value| {+ decrypted_value+ .parse_value::<hyperswitch_domain_models::address::Address>(+ "payment method billing address",+ )+ .ok()+ })+ });++ // billing address from request body has the highest priority followed by billing address from raw pm data and then billing address from payment_attempt+ let pmd_address = payment_method_data_billing.or(pm_pmd_billing);- let unified_address = address- .unify_with_payment_method_data_billing(payment_method_data_billing.map(From::from));+ let unified_address = address.unify_with_payment_method_data_billing(pmd_address);// If processor_payment_token is passed in request then populating the same in PaymentDatalet mandate_id = requestdiff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex 41def68dc7..2c850d629e 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -2,6 +2,7 @@ use std::marker::PhantomData;use api_models::{enums::FrmSuggestion, mandates::RecurringDetails, payment_methods::PaymentMethodsData,+ payments::GetAddressFromPaymentMethodData,};use async_trait::async_trait;use common_types::payments as common_payments_types;@@ -574,22 +575,29 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>let payment_method_data_billing = request.payment_method_data.as_ref()- .and_then(|pmd| pmd.billing.clone())- .or(payment_method_with_raw_data.as_ref().and_then(|pm| {- pm.payment_method- .0- .payment_method_billing_address- .clone()- .map(|decrypted_data| decrypted_data.into_inner().expose())- .and_then(|decrypted_value| {- decrypted_value- .parse_value("payment method billing address")- .ok()- })- }));+ .and_then(|pmd| pmd.payment_method_data.as_ref())+ .and_then(|payment_method_data_billing| {+ payment_method_data_billing.get_billing_address()+ })+ .map(From::from);+ let pm_pmd_billing = payment_method_with_raw_data.as_ref().and_then(|pm| {+ pm.payment_method+ .0+ .payment_method_billing_address+ .clone()+ .map(|decrypted_data| decrypted_data.into_inner().expose())+ .and_then(|decrypted_value| {+ decrypted_value+ .parse_value::<hyperswitch_domain_models::address::Address>(+ "payment method billing address",+ )+ .ok()+ })+ });++ let add = payment_method_data_billing.or(pm_pmd_billing);- let unified_address = address- .unify_with_payment_method_data_billing(payment_method_data_billing.map(From::from));+ let unified_address = address.unify_with_payment_method_data_billing(add);let payment_data = PaymentData {flow: PhantomData,