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(authentication): fixed race condition for authentication cavv update and authentication status update (#13386)
Sahkal Poddar5c26e7f0f016
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex 5815b9b884..64d142cbef 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -2222,13 +2222,29 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for).update_storage_scheme(platform.get_processor().get_account().storage_scheme);- let cryptogram = sync_response.authentication_details.and_then(|authentication_details| authentication_details.three_ds_data.and_then(|data| data.authentication_cryptogram)).ok_or(errors::ApiErrorResponse::MissingRequiredField{field_name:"authentication_cryptogram"})?;+ let cavv = if updated_authentication_status+ == api_models::enums::AuthenticationStatus::Success+ {+ let cryptogram = sync_response+ .authentication_details+ .and_then(|authentication_details| authentication_details.three_ds_data)+ .and_then(|data| data.authentication_cryptogram)+ .ok_or(errors::ApiErrorResponse::MissingRequiredField {+ field_name: "authentication_cryptogram",+ })?;++ match cryptogram {+ api_models::authentication::Cryptogram::Cavv {+ authentication_cryptogram,+ } => Some(authentication_cryptogram),+ }+ } else {+ None+ };let authentication_store =hyperswitch_domain_models::router_request_types::authentication::AuthenticationStore {- cavv: match cryptogram {- api_models::authentication::Cryptogram::Cavv { authentication_cryptogram } => Some(authentication_cryptogram),- },+ cavv,authentication:authentication_domain_model};diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rsindex 323b55c9cf..17d1b8f7aa 100644--- a/crates/router/src/core/webhooks/incoming.rs+++ b/crates/router/src/core/webhooks/incoming.rs@@ -1938,19 +1938,10 @@ async fn external_authentication_incoming_webhook_flow("received a non-external-authentication id for retrieving authentication",)}?;- let updated_authentication = state- .store- .update_authentication_by_processor_merchant_id_authentication_id(- authentication,- authentication_update,- platform.get_processor().get_key_store(),- &key_manager_state,- platform.get_processor().get_account().storage_scheme,- )- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Error while updating authentication")?;+ // Store the authentication value before publishing the successful authentication state.+ // Otherwise, the browser callback can observe `Success` and attempt authorization before+ // the CAVV is available in Redis.authentication_details.authentication_value.async_map(|auth_val| {@@ -1958,7 +1949,7 @@ async fn external_authentication_incoming_webhook_flow(&state,auth_val.expose(),None,- updated_authentication+ authentication.authentication_id.clone().get_string_repr()@@ -1968,6 +1959,20 @@ async fn external_authentication_incoming_webhook_flow(}).await.transpose()?;++ let updated_authentication = state+ .store+ .update_authentication_by_processor_merchant_id_authentication_id(+ authentication,+ authentication_update,+ platform.get_processor().get_key_store(),+ &key_manager_state,+ platform.get_processor().get_account().storage_scheme,+ )+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Error while updating authentication")?;+// Check if it's a payment authentication flow, payment_id would be there only for payment authentication flowsif let Some(payment_id) = updated_authentication.payment_id {let is_pull_mechanism_enabled = helper_utils::check_if_pull_mechanism_for_external_3ds_enabled_from_connector_metadata(merchant_connector_account.metadata.map(|metadata| metadata.expose()));