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 ctp confirmation bug (#9050)
Sahkal Poddar44137517de31
diff --git a/crates/hyperswitch_connectors/src/connectors/unified_authentication_service/transformers.rs b/crates/hyperswitch_connectors/src/connectors/unified_authentication_service/transformers.rsindex 2eeebbeade..a57271d860 100644--- a/crates/hyperswitch_connectors/src/connectors/unified_authentication_service/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/unified_authentication_service/transformers.rs@@ -66,7 +66,7 @@ pub struct UnifiedAuthenticationServiceAuthenticateConfirmationRequest {pub checkout_event_status: Option<String>,pub confirmation_status: Option<String>,pub confirmation_reason: Option<String>,- pub confirmation_timestamp: Option<PrimitiveDateTime>,+ pub confirmation_timestamp: Option<String>,pub network_authorization_code: Option<String>,pub network_transaction_identifier: Option<String>,pub correlation_id: Option<String>,@@ -526,7 +526,7 @@ impl TryFrom<&UnifiedAuthenticationServiceRouterData<&UasAuthenticationConfirmatcheckout_event_status: item.router_data.request.checkout_event_status.clone(),confirmation_status: item.router_data.request.confirmation_status.clone(),confirmation_reason: item.router_data.request.confirmation_reason.clone(),- confirmation_timestamp: item.router_data.request.confirmation_timestamp,+ confirmation_timestamp: item.router_data.request.confirmation_timestamp.clone(),network_authorization_code: item.router_data.request.network_authorization_code.clone(),network_transaction_identifier: item.router_datadiff --git a/crates/hyperswitch_domain_models/src/router_request_types/unified_authentication_service.rs b/crates/hyperswitch_domain_models/src/router_request_types/unified_authentication_service.rsindex 4edcdb7962..e71e369309 100644--- a/crates/hyperswitch_domain_models/src/router_request_types/unified_authentication_service.rs+++ b/crates/hyperswitch_domain_models/src/router_request_types/unified_authentication_service.rs@@ -3,7 +3,6 @@ use common_enums::MerchantCategoryCode;use common_types::payments::MerchantCountryCode;use common_utils::types::MinorUnit;use masking::Secret;-use time::PrimitiveDateTime;use crate::address::Address;@@ -169,7 +168,7 @@ pub struct UasConfirmationRequestData {pub checkout_event_status: Option<String>,pub confirmation_status: Option<String>,pub confirmation_reason: Option<String>,- pub confirmation_timestamp: Option<PrimitiveDateTime>,+ pub confirmation_timestamp: Option<String>,// Authorisation code associated with an approved transaction.pub network_authorization_code: Option<String>,// The unique authorisation related tracing value assigned by a Payment Network and provided in an authorisation response. Required only when checkoutEventType=01. If checkoutEventType=01 and the value of networkTransactionIdentifier is unknown, please pass UNAVLBdiff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 77deaae2dc..a87d22191b 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -115,6 +115,7 @@ use crate::{payment_methods::{cards, network_tokenization},payouts,routing::{self as core_routing},+ unified_authentication_service::types::{ClickToPay, UnifiedAuthenticationService},utils::{self as core_utils},},db::StorageInterface,@@ -712,7 +713,6 @@ where.await?;if is_eligible_for_uas {- let should_do_uas_confirmation_call = false;operation.to_domain()?.call_unified_authentication_service_if_eligible(@@ -723,7 +723,6 @@ where&business_profile,merchant_context.get_merchant_key_store(),mandate_type,- &should_do_uas_confirmation_call,).await?;} else {@@ -843,23 +842,6 @@ where).await?;- if is_eligible_for_uas {- let should_do_uas_confirmation_call = true;- operation- .to_domain()?- .call_unified_authentication_service_if_eligible(- state,- &mut payment_data,- &mut should_continue_transaction,- &connector_details,- &business_profile,- merchant_context.get_merchant_key_store(),- mandate_type,- &should_do_uas_confirmation_call,- )- .await?;- }-let op_ref = &operation;let should_trigger_post_processing_flows = is_operation_confirm(&operation);@@ -911,6 +893,15 @@ where.await?;}+ if is_eligible_for_uas {+ complete_confirmation_for_click_to_pay_if_required(+ state,+ merchant_context,+ &payment_data,+ )+ .await?;+ }+payment_data}@@ -1022,23 +1013,6 @@ wherelet op_ref = &operation;let should_trigger_post_processing_flows = is_operation_confirm(&operation);- if is_eligible_for_uas {- let should_do_uas_confirmation_call = true;- operation- .to_domain()?- .call_unified_authentication_service_if_eligible(- state,- &mut payment_data,- &mut should_continue_transaction,- &connector_details,- &business_profile,- merchant_context.get_merchant_key_store(),- mandate_type,- &should_do_uas_confirmation_call,- )- .await?;- }-let operation = Box::new(PaymentResponse);connector_http_status_code = router_data.connector_http_status_code;external_latency = router_data.external_latency;@@ -1086,6 +1060,15 @@ where.await?;}+ if is_eligible_for_uas {+ complete_confirmation_for_click_to_pay_if_required(+ state,+ merchant_context,+ &payment_data,+ )+ .await?;+ }+payment_data}@@ -6720,6 +6703,78 @@ whereOk(router_data_and_should_continue_payment)}+#[cfg(feature = "v1")]+async fn complete_confirmation_for_click_to_pay_if_required<F, D>(+ state: &SessionState,+ merchant_context: &domain::MerchantContext,+ payment_data: &D,+) -> RouterResult<()>+where+ F: Send + Clone + Sync,+ D: OperationSessionGetters<F> + OperationSessionSetters<F> + Send + Sync + Clone,+{+ let payment_attempt = payment_data.get_payment_attempt();+ let payment_intent = payment_data.get_payment_intent();+ let service_details = payment_data.get_click_to_pay_service_details();+ let authentication = payment_data.get_authentication();++ let should_do_uas_confirmation_call = service_details+ .as_ref()+ .map(|details| details.is_network_confirmation_call_required())+ .unwrap_or(true);+ if should_do_uas_confirmation_call+ && (payment_intent.status == storage_enums::IntentStatus::Succeeded+ || payment_intent.status == storage_enums::IntentStatus::Failed)+ {+ let authentication_connector_id = authentication+ .as_ref()+ .and_then(|auth| auth.authentication.merchant_connector_id.clone())+ .ok_or(errors::ApiErrorResponse::InternalServerError)+ .attach_printable(+ "Failed to get authentication connector id from authentication table",+ )?;+ let key_manager_state = &(state).into();+ let key_store = merchant_context.get_merchant_key_store();+ let merchant_id = merchant_context.get_merchant_account().get_id();++ let connector_mca = state+ .store+ .find_by_merchant_connector_account_merchant_id_merchant_connector_id(+ key_manager_state,+ merchant_id,+ &authentication_connector_id,+ key_store,+ )+ .await+ .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {+ id: authentication_connector_id.get_string_repr().to_string(),+ })?;++ let payment_method = payment_attempt+ .payment_method+ .ok_or(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to get payment method from payment attempt")?;++ ClickToPay::confirmation(+ state,+ payment_attempt.authentication_id.as_ref(),+ payment_intent.currency,+ payment_attempt.status,+ service_details.cloned(),+ &helpers::MerchantConnectorAccountType::DbVal(Box::new(connector_mca.clone())),+ &connector_mca.connector_name,+ payment_method,+ payment_attempt.net_amount.get_order_amount(),+ Some(&payment_intent.payment_id),+ merchant_id,+ )+ .await?;+ Ok(())+ } else {+ Ok(())+ }+}+#[cfg(feature = "v1")]#[allow(clippy::too_many_arguments)]async fn complete_postprocessing_steps_if_required<F, Q, RouterDReq, D>(@@ -10324,6 +10379,8 @@ pub trait OperationSessionGetters<F> {#[cfg(feature = "v2")]fn get_optional_external_vault_session_details(&self) -> Option<api::VaultSessionDetails>;+ #[cfg(feature = "v1")]+ fn get_click_to_pay_service_details(&self) -> Option<&api_models::payments::CtpServiceDetails>;}pub trait OperationSessionSetters<F> {@@ -10560,6 +10617,10 @@ impl<F: Clone> OperationSessionGetters<F> for PaymentData<F> {self.connector_customer_id.clone()}+ fn get_click_to_pay_service_details(&self) -> Option<&api_models::payments::CtpServiceDetails> {+ self.service_details.as_ref()+ }+// #[cfg(feature = "v2")]// fn get_capture_method(&self) -> Option<enums::CaptureMethod> {// Some(self.payment_intent.capture_method)diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 2de5d00ba5..d4bf2c455d 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -6942,7 +6942,6 @@ pub enum UnifiedAuthenticationServiceFlow {ExternalAuthenticationPostAuthenticate {authentication_id: id_type::AuthenticationId,},- ClickToPayConfirmation,}#[cfg(feature = "v1")]@@ -6953,7 +6952,6 @@ pub async fn decide_action_for_unified_authentication_service<F: Clone>(payment_data: &mut PaymentData<F>,connector_call_type: &api::ConnectorCallType,mandate_type: Option<api_models::payments::MandateTransactionType>,- do_authorisation_confirmation: &bool,) -> RouterResult<Option<UnifiedAuthenticationServiceFlow>> {let external_authentication_flow = get_payment_external_authentication_flow_during_confirm(state,@@ -6989,17 +6987,7 @@ pub async fn decide_action_for_unified_authentication_service<F: Clone>(&& business_profile.is_click_to_pay_enabled&& payment_data.service_details.is_some(){- let should_do_uas_confirmation_call = payment_data- .service_details- .as_ref()- .map(|details| details.is_network_confirmation_call_required())- .unwrap_or(true);-- if *do_authorisation_confirmation && should_do_uas_confirmation_call {- Some(UnifiedAuthenticationServiceFlow::ClickToPayConfirmation)- } else {- Some(UnifiedAuthenticationServiceFlow::ClickToPayInitiate)- }+ Some(UnifiedAuthenticationServiceFlow::ClickToPayInitiate)} else {None}diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rsindex b9c36a1f79..2d8488ab6c 100644--- a/crates/router/src/core/payments/operations.rs+++ b/crates/router/src/core/payments/operations.rs@@ -355,7 +355,6 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {_business_profile: &domain::Profile,_key_store: &domain::MerchantKeyStore,_mandate_type: Option<api_models::payments::MandateTransactionType>,- _do_authorization_confirmation: &bool,) -> CustomResult<(), errors::ApiErrorResponse> {Ok(())}diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex dca5c726a5..0e343a437b 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -1227,7 +1227,6 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forbusiness_profile: &domain::Profile,key_store: &domain::MerchantKeyStore,mandate_type: Option<api_models::payments::MandateTransactionType>,- do_authorisation_confirmation: &bool,) -> CustomResult<(), errors::ApiErrorResponse> {let unified_authentication_service_flow =helpers::decide_action_for_unified_authentication_service(@@ -1237,7 +1236,6 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forpayment_data,connector_call_type,mandate_type,- do_authorisation_confirmation,).await?;@@ -1378,60 +1376,6 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for};payment_data.authentication = Some(authentication_store);},- helpers::UnifiedAuthenticationServiceFlow::ClickToPayConfirmation => {- let authentication_product_ids = business_profile- .authentication_product_ids- .clone()- .ok_or(errors::ApiErrorResponse::PreconditionFailed {- message: "authentication_product_ids is not configured in business profile"- .to_string(),- })?;- let click_to_pay_mca_id = authentication_product_ids- .get_click_to_pay_connector_account_id()- .change_context(errors::ApiErrorResponse::MissingRequiredField {- field_name: "click_to_pay_mca_id",- })?;- let key_manager_state = &(state).into();- let merchant_id = &business_profile.merchant_id;-- let connector_mca = state- .store- .find_by_merchant_connector_account_merchant_id_merchant_connector_id(- key_manager_state,- merchant_id,- &click_to_pay_mca_id,- key_store,- )- .await- .to_not_found_response(- errors::ApiErrorResponse::MerchantConnectorAccountNotFound {- id: click_to_pay_mca_id.get_string_repr().to_string(),- },- )?;-- let payment_method = payment_data.payment_attempt.payment_method.ok_or(- errors::ApiErrorResponse::MissingRequiredField {- field_name: "payment_method",- },- )?;-- ClickToPay::confirmation(- state,- key_store,- business_profile,- payment_data.payment_attempt.authentication_id.as_ref(),- payment_data.payment_intent.currency,- payment_data.payment_attempt.status,- payment_data.service_details.clone(),- &helpers::MerchantConnectorAccountType::DbVal(Box::new(connector_mca.clone())),- &connector_mca.connector_name,- payment_method,- payment_data.payment_attempt.net_amount.get_order_amount(),- Some(&payment_data.payment_intent.payment_id),- merchant_id,- )- .await?- },helpers::UnifiedAuthenticationServiceFlow::ExternalAuthenticationInitiate {acquirer_details,token,diff --git a/crates/router/src/core/unified_authentication_service.rs b/crates/router/src/core/unified_authentication_service.rsindex 6ea77d3fdc..b9e209bc9b 100644--- a/crates/router/src/core/unified_authentication_service.rs+++ b/crates/router/src/core/unified_authentication_service.rs@@ -203,8 +203,6 @@ impl UnifiedAuthenticationService for ClickToPay {async fn confirmation(state: &SessionState,- _key_store: &domain::MerchantKeyStore,- _business_profile: &domain::Profile,authentication_id: Option<&common_utils::id_type::AuthenticationId>,currency: Option<common_enums::Currency>,status: common_enums::AttemptStatus,@@ -224,7 +222,9 @@ impl UnifiedAuthenticationService for ClickToPay {field_name: "currency",})?;- let current_time = common_utils::date_time::now();+ let current_time = common_utils::date_time::date_as_yyyymmddthhmmssmmmz()+ .change_context(ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to get current time")?;let payment_attempt_status = status;@@ -245,7 +245,7 @@ impl UnifiedAuthenticationService for ClickToPay {confirmation_reason,confirmation_timestamp: Some(current_time),network_authorization_code: Some("01".to_string()), // hardcoded to '01' since only authorise flow is implemented- network_transaction_identifier: Some("01".to_string()), // hardcoded to '01' since only authorise flow is implemented+ network_transaction_identifier: Some("mastercard".to_string()), // hardcoded to 'mastercard' since only mastercard has confirmation flow requirementcorrelation_id: click_to_pay_details.clone().and_then(|details| details.correlation_id),diff --git a/crates/router/src/core/unified_authentication_service/types.rs b/crates/router/src/core/unified_authentication_service/types.rsindex fca63ee4cc..49a24ce022 100644--- a/crates/router/src/core/unified_authentication_service/types.rs+++ b/crates/router/src/core/unified_authentication_service/types.rs@@ -154,8 +154,6 @@ pub trait UnifiedAuthenticationService {#[allow(clippy::too_many_arguments)]async fn confirmation(_state: &SessionState,- _key_store: &domain::MerchantKeyStore,- _business_profile: &domain::Profile,_authentication_id: Option<&common_utils::id_type::AuthenticationId>,_currency: Option<common_enums::Currency>,_status: common_enums::AttemptStatus,diff --git a/crates/router/src/core/unified_authentication_service/utils.rs b/crates/router/src/core/unified_authentication_service/utils.rsindex 8d6e27e065..387e642953 100644--- a/crates/router/src/core/unified_authentication_service/utils.rs+++ b/crates/router/src/core/unified_authentication_service/utils.rs@@ -317,12 +317,12 @@ pub fn get_checkout_event_status_and_reason() -> (Option<String>, Option<String>) {match attempt_status {common_enums::AttemptStatus::Charged | common_enums::AttemptStatus::Authorized => (- Some("02".to_string()),- Some("Approval Code received".to_string()),+ Some("01".to_string()),+ Some("The payment was successful".to_string()),),_ => (Some("03".to_string()),- Some("No Approval Code received".to_string()),+ Some("The payment was not successful".to_string()),),}}