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(core): Fix customer acceptance lookup and next action priority order in complete authorize (#12510)
Vani Gupta7e03c2e8bf87
diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rsindex 3001593eb8..67ddcb3652 100644--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs@@ -2,7 +2,7 @@ use std::marker::PhantomData;use api_models::enums::FrmSuggestion;use async_trait::async_trait;-use common_utils::ext_traits::AsyncExt;+use common_utils::ext_traits::{AsyncExt, ValueExt};use error_stack::{report, ResultExt};use hyperswitch_domain_models::mandates;use router_derive::PaymentOperation;@@ -144,16 +144,32 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>None,)).await?;++ // Priority: request > payment_attempt > payment_method_info+ // If payment_method_info is present but customer_acceptance is missing/invalid, return an errorlet customer_acceptance: Option<CustomerAcceptance> =- request.customer_acceptance.clone().or(payment_method_info- .clone()- .map(|pm| {+ if let Some(ca) = request.customer_acceptance.clone() {+ Some(ca)+ } else if let Some(ca) = payment_attempt.customer_acceptance.clone() {+ Some(+ ca.parse_value::<CustomerAcceptance>("CustomerAcceptance")+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable(+ "Failed to deserialize customer_acceptance from payment_attempt",+ )?,+ )+ } else if let Some(pm) = payment_method_info.clone() {+ Some(pm.customer_acceptance.parse_value::<CustomerAcceptance>("CustomerAcceptance")- })- .transpose()- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed to deserialize to CustomerAcceptance")?);+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable(+ "Failed to deserialize customer_acceptance from payment_method_info",+ )?,+ )+ } else {+ None+ };let token = token.or_else(|| payment_attempt.payment_token.clone());if let Some(payment_method) = payment_method {diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex 7a31702819..8119202180 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -3781,12 +3781,39 @@ where|| next_action_containing_fetch_qr_code_url.is_some()|| payment_data.get_authentication().is_some(){- next_action_response = bank_transfer_next_steps+ next_action_response = next_action_invoke_ddc_iframe.map(|ddc_iframe_data| {+ api_models::payments::NextActionData::InvokeDdc {+ ddc_data: api_models::payments::DDCData {+ iframe_url: ddc_iframe_data.iframe_url,+ timeout_ms: ddc_iframe_data.timeout_ms,+ }+ }+ }).or(+ payment_attempt.authentication_data.as_ref().map(|_| {+ // Check if iframe redirection is enabled in the business profile+ let redirect_url = helpers::create_startpay_url(+ base_url,+ &payment_attempt,+ &payment_intent,+ );+ // Check if redirection inside popup is enabled in the payment intent+ if payment_intent.is_iframe_redirection_enabled.unwrap_or(false) {+ api_models::payments::NextActionData::RedirectInsidePopup {+ popup_url: redirect_url,+ redirect_response_url:router_return_url+ }+ } else {+ api_models::payments::NextActionData::RedirectToUrl {+ redirect_to_url: redirect_url,+ }+ }+ }))+ .or(bank_transfer_next_steps.map(|bank_transfer| {api_models::payments::NextActionData::DisplayBankTransferInformation {bank_transfer_steps_and_charges_details: bank_transfer,}- })+ })).or(next_action_voucher.map(|voucher_data| {api_models::payments::NextActionData::DisplayVoucherInformation {voucher_details: voucher_data,@@ -3818,33 +3845,6 @@ wherepoll_config: wait_screen_data.poll_config,}}))- .or(next_action_invoke_ddc_iframe.map(|ddc_iframe_data| {- api_models::payments::NextActionData::InvokeDdc {- ddc_data: api_models::payments::DDCData {- iframe_url: ddc_iframe_data.iframe_url,- timeout_ms: ddc_iframe_data.timeout_ms,- }- }- }))- .or(payment_attempt.authentication_data.as_ref().map(|_| {- // Check if iframe redirection is enabled in the business profile- let redirect_url = helpers::create_startpay_url(- base_url,- &payment_attempt,- &payment_intent,- );- // Check if redirection inside popup is enabled in the payment intent- if payment_intent.is_iframe_redirection_enabled.unwrap_or(false) {- api_models::payments::NextActionData::RedirectInsidePopup {- popup_url: redirect_url,- redirect_response_url:router_return_url- }- } else {- api_models::payments::NextActionData::RedirectToUrl {- redirect_to_url: redirect_url,- }- }- })).or(match payment_data.get_authentication(){Some(authentication_store) => {let authentication = &authentication_store.authentication;