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(connector): [Peachpayments] Add 3DS Passthrough Flow (#12662)
Anurag661c8ef8c0c1
diff --git a/crates/hyperswitch_connectors/src/connectors/peachpayments.rs b/crates/hyperswitch_connectors/src/connectors/peachpayments.rsindex 14ccd6ca32..574d1c11a1 100644--- a/crates/hyperswitch_connectors/src/connectors/peachpayments.rs+++ b/crates/hyperswitch_connectors/src/connectors/peachpayments.rs@@ -463,6 +463,34 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo) -> CustomResult<ErrorResponse, errors::ConnectorError> {self.build_error_response(res, event_builder)}++ fn get_5xx_error_response(+ &self,+ res: Response,+ event_builder: Option<&mut ConnectorEvent>,+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {+ let response: peachpayments::PeachpaymentsErrorResponse = res+ .response+ .parse_struct("PeachpaymentsErrorResponse")+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;++ event_builder.map(|i| i.set_response_body(&response));+ router_env::logger::info!(connector_response=?response);++ Ok(ErrorResponse {+ status_code: res.status_code,+ code: response.error_ref.clone(),+ message: response.message.clone(),+ reason: Some(response.message.clone()),+ attempt_status: Some(enums::AttemptStatus::Authorized),+ connector_transaction_id: None,+ connector_response_reference_id: None,+ network_advice_code: None,+ network_decline_code: None,+ network_error_message: None,+ connector_metadata: None,+ })+ }}impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Peachpayments {@@ -562,6 +590,34 @@ impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Pe) -> CustomResult<ErrorResponse, errors::ConnectorError> {self.build_error_response(res, event_builder)}++ fn get_5xx_error_response(+ &self,+ res: Response,+ event_builder: Option<&mut ConnectorEvent>,+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {+ let response: peachpayments::PeachpaymentsErrorResponse = res+ .response+ .parse_struct("PeachpaymentsErrorResponse")+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;++ event_builder.map(|i| i.set_response_body(&response));+ router_env::logger::info!(connector_response=?response);++ Ok(ErrorResponse {+ status_code: res.status_code,+ code: response.error_ref.clone(),+ message: response.message.clone(),+ reason: Some(response.message.clone()),+ attempt_status: Some(enums::AttemptStatus::Authorized),+ connector_transaction_id: None,+ connector_response_reference_id: None,+ network_advice_code: None,+ network_decline_code: None,+ network_error_message: None,+ connector_metadata: None,+ })+ }}impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Peachpayments {diff --git a/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs b/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rsindex ee227a7358..140d9169c9 100644--- a/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs@@ -112,6 +112,8 @@ pub struct EcommerceCardPaymentOnlyTransactionData {pub trace_id: Option<String>,#[serde(skip_serializing_if = "Option::is_none")]pub transaction_link_id: Option<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub three_d_s_data: Option<PeachpaymentsThreeDSData>,}#[derive(Debug, Serialize, PartialEq)]@@ -152,6 +154,8 @@ pub struct EcommerceNetworkTokenPaymentOnlyTransactionData {pub trace_id: Option<String>,#[serde(skip_serializing_if = "Option::is_none")]pub transaction_link_id: Option<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub three_d_s_data: Option<PeachpaymentsThreeDSData>,}#[derive(Debug, Serialize, PartialEq)]@@ -170,6 +174,21 @@ pub enum DccMode {OptOutDcc,}+#[derive(Debug, Serialize, PartialEq)]+#[serde(rename_all = "camelCase")]+pub struct PeachpaymentsThreeDSData {+ #[serde(skip_serializing_if = "Option::is_none")]+ cavv: Option<Secret<String>>,+ #[serde(skip_serializing_if = "Option::is_none")]+ ds_trans_id: Option<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ three_d_s_version: Option<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ eci: Option<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ authentication_status: Option<common_enums::TransactionStatus>,+}+#[derive(Debug, Serialize, PartialEq)]#[serde(untagged)]pub enum EcommercePaymentOnlyTransactionData {@@ -201,8 +220,7 @@ pub struct RoutingReference {#[serde(rename_all = "camelCase")]pub struct CardDetails {pub pan: CardNumber,- #[serde(skip_serializing_if = "Option::is_none")]- pub cardholder_name: Option<Secret<String>>,+ pub cardholder_name: Secret<String>,#[serde(skip_serializing_if = "Option::is_none")]pub expiry_year: Option<Secret<String>>,#[serde(skip_serializing_if = "Option::is_none")]@@ -439,6 +457,25 @@ impl TryFrom<&PeachpaymentsRouterData<&PaymentsAuthorizeRouterData>>}}+fn get_three_ds_data(+ item: &PeachpaymentsRouterData<&PaymentsAuthorizeRouterData>,+) -> Option<PeachpaymentsThreeDSData> {+ item.router_data+ .request+ .authentication_data+ .as_ref()+ .map(|authentication_data| PeachpaymentsThreeDSData {+ cavv: Some(authentication_data.cavv.clone()),+ ds_trans_id: authentication_data.ds_trans_id.clone(),+ three_d_s_version: authentication_data+ .message_version+ .clone()+ .map(|version| format!("{}.{}", version.get_major(), version.get_minor(),)),+ eci: authentication_data.eci.clone(),+ authentication_status: authentication_data.transaction_status.clone(),+ })+}+implTryFrom<(&PeachpaymentsRouterData<&PaymentsAuthorizeRouterData>,@@ -452,6 +489,15 @@ implNetworkTokenData,),) -> Result<Self, Self::Error> {+ if item.router_data.is_three_ds() && item.router_data.request.authentication_data.is_none()+ {+ return Err(errors::ConnectorError::NotSupported {+ message: "3DS flow".to_string(),+ connector: "Peachpayments",+ }+ .into());+ }+let amount_in_cents = item.amount;let connector_merchant_config =@@ -514,6 +560,7 @@ implpre_auth_inc_ext_capture_flow,trace_id: None,transaction_link_id: None,+ three_d_s_data: get_three_ds_data(item),},);@@ -538,13 +585,15 @@ impl TryFrom<(&PeachpaymentsRouterData<&PaymentsAuthorizeRouterData>, Card)>fn try_from((item, req_card): (&PeachpaymentsRouterData<&PaymentsAuthorizeRouterData>, Card),) -> Result<Self, Self::Error> {- if item.router_data.is_three_ds() {+ if item.router_data.is_three_ds() && item.router_data.request.authentication_data.is_none()+ {return Err(errors::ConnectorError::NotSupported {message: "3DS flow".to_string(),connector: "Peachpayments",}.into());}+let amount_in_cents = item.amount;let connector_merchant_config =@@ -561,7 +610,11 @@ impl TryFrom<(&PeachpaymentsRouterData<&PaymentsAuthorizeRouterData>, Card)>let card = CardDetails {pan: req_card.card_number.clone(),- cardholder_name: req_card.card_holder_name.clone(),+ cardholder_name: req_card.card_holder_name.clone().ok_or_else(|| {+ errors::ConnectorError::MissingRequiredField {+ field_name: "card_holder_name",+ }+ })?,expiry_year: Some(req_card.get_card_expiry_year_2_digit()?),expiry_month: Some(req_card.card_exp_month.clone()),cvv: Some(req_card.card_cvc.clone()),@@ -607,6 +660,7 @@ impl TryFrom<(&PeachpaymentsRouterData<&PaymentsAuthorizeRouterData>, Card)>cof_data,trace_id: None,transaction_link_id: None,+ three_d_s_data: get_three_ds_data(item),});// Generate current timestamp for sendDateTime (ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ)@@ -653,7 +707,12 @@ impllet card = CardDetails {pan: card_with_limited_details.card_number.clone(),- cardholder_name: card_with_limited_details.card_holder_name.clone(),+ cardholder_name: card_with_limited_details+ .card_holder_name+ .clone()+ .ok_or_else(|| errors::ConnectorError::MissingRequiredField {+ field_name: "card_holder_name",+ })?,expiry_year: card_with_limited_details.get_card_expiry_year_2_digit()?,expiry_month: card_with_limited_details.card_exp_month.clone(),cvv: None,@@ -699,6 +758,7 @@ implcof_data,trace_id: None,transaction_link_id: None,+ three_d_s_data: get_three_ds_data(item),});// Generate current timestamp for sendDateTime (ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ)diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex f90be4a74f..39f74495c6 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -2601,7 +2601,22 @@ pub async fn should_execute_based_on_rollout(.unwrap_or_default())}Err(err) => {- logger::error!(error = ?err, "Failed to fetch rollout config from DB. Defaulting to not execute and setting should_execute to false.");+ // ValueNotFound may be an expected outcome when a rollout configuration has not+ // been provisioned. Treat it as a warning to avoid generating misleading errors.+ match err.current_context() {+ errors::StorageError::ValueNotFound(_) => {+ logger::warn!(+ error = ?err,+ "Failed to fetch rollout config from DB. Defaulting to not execute and setting should_execute to false."+ );+ }+ _ => {+ logger::error!(+ error = ?err,+ "Failed to fetch rollout config from DB. Defaulting to not execute and setting should_execute to false."+ );+ }+ }Ok(RolloutExecutionResult::default())}}