From afba7444f19eee763da3d5196da6cf396e93b20a Mon Sep 17 00:00:00 2001 From: Debarshi Gupta Date: Thu, 19 Dec 2024 15:39:27 +0530 Subject: [PATCH] chore: Resolved PR comments --- .../connectors/deutschebank/transformers.rs | 60 ++-- .../payment_connector_required_fields.rs | 264 ++++++++++++++++++ 2 files changed, 297 insertions(+), 27 deletions(-) diff --git a/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs b/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs index 246030898b81..b95251b0e68f 100644 --- a/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs @@ -167,7 +167,7 @@ pub struct DeutschebankThreeDSInitializeRequestCreditCardExpiry { #[serde(rename_all = "snake_case")] pub struct DeutschebankThreeDSInitializeRequestAmountTotal { amount: MinorUnit, - currency: String, + currency: api_models::enums::Currency, } #[derive(Debug, Serialize)] @@ -245,11 +245,6 @@ impl TryFrom<&DeutschebankRouterData<&PaymentsAuthorizeRouterData>> .into()) } else { let billing_address = item.router_data.get_billing_address()?; - let cardholder = ccard.clone().card_holder_name.ok_or_else(|| { - errors::ConnectorError::MissingRequiredField { - field_name: "card_holder_name", - } - })?; Ok(Self::CreditCard(Box::new(DeutschebankThreeDSInitializeRequest { means_of_payment: DeutschebankThreeDSInitializeRequestMeansOfPayment { credit_card: DeutschebankThreeDSInitializeRequestCreditCard { @@ -259,11 +254,11 @@ impl TryFrom<&DeutschebankRouterData<&PaymentsAuthorizeRouterData>> month: ccard.card_exp_month, }, code: ccard.card_cvc, - cardholder, + cardholder: item.router_data.get_billing_full_name()?, }}, amount_total: DeutschebankThreeDSInitializeRequestAmountTotal { amount: item.amount, - currency: item.router_data.request.currency.clone().to_string(), + currency: item.router_data.request.currency, }, tds_20_data: DeutschebankThreeDSInitializeRequestTds20Data { communication_data: DeutschebankThreeDSInitializeRequestCommunicationData { @@ -398,10 +393,15 @@ impl }), ..item.data }), - None => Err(errors::ConnectorError::UnexpectedResponseError( - bytes::Bytes::from("missing processed".to_owned()), - ) - .into()), + None => { + let response_string = format!("{:?}", item.response); + Err( + errors::ConnectorError::UnexpectedResponseError(bytes::Bytes::from( + response_string, + )) + .into(), + ) + } } } DeutschebankThreeDSInitializeResponseOutcome::ChallengeRequired => { @@ -425,16 +425,21 @@ impl }), ..item.data }), - None => Err(errors::ConnectorError::UnexpectedResponseError( - bytes::Bytes::from("missing challenge_required".to_owned()), - ) - .into()), + None => { + let response_string = format!("{:?}", item.response); + Err( + errors::ConnectorError::UnexpectedResponseError(bytes::Bytes::from( + response_string, + )) + .into(), + ) + } } } DeutschebankThreeDSInitializeResponseOutcome::MethodRequired => Ok(Self { status: common_enums::AttemptStatus::Failure, response: Err(ErrorResponse { - code: "500".to_owned(), + code: item.http_code.to_string(), message: "Method_Required Flow not supported".to_owned(), reason: Some("Method_Required Flow is not currently supported".to_owned()), status_code: 500, @@ -714,14 +719,11 @@ impl TryFrom<&DeutschebankRouterData<&PaymentsCompleteAuthorizeRouterData>> .get_redirect_response_payload()? .expose(); - let deserialized: HashMap = - serde_json::from_value(redirect_response_payload) - .map_err(|_| errors::ConnectorError::ResponseDeserializationFailed)?; - - let cres = deserialized + let cres = redirect_response_payload .get("cres") - .ok_or(errors::ConnectorError::MissingRequiredField { field_name: "cres" })? - .to_owned(); + .and_then(|v| v.as_str()) + .map(String::from) + .ok_or(errors::ConnectorError::MissingRequiredField { field_name: "cres" })?; Ok(Self::DeutschebankThreeDSCompleteAuthorizeRequest( DeutschebankThreeDSCompleteAuthorizeRequest { cres }, @@ -932,7 +934,9 @@ impl TryFrom<&DeutschebankRouterData<&PaymentsCaptureRouterData>> for Deutscheba ) -> Result { Ok(Self { changed_amount: item.amount, - kind: match item.router_data.is_three_ds() { + kind: match item.router_data.is_three_ds() + && matches!(item.router_data.payment_method, PaymentMethod::Card) + { true => DeutschebankTransactionKind::Creditcard3ds20, false => DeutschebankTransactionKind::Directdebit, }, @@ -1058,7 +1062,7 @@ impl TryFrom<&PaymentsCancelRouterData> for DeutschebankReversalRequest { type Error = error_stack::Report; fn try_from(item: &PaymentsCancelRouterData) -> Result { Ok(Self { - kind: match item.is_three_ds() { + kind: match item.is_three_ds() && matches!(item.payment_method, PaymentMethod::Card) { true => DeutschebankTransactionKind::Creditcard3ds20, false => DeutschebankTransactionKind::Directdebit, }, @@ -1104,7 +1108,9 @@ impl TryFrom<&DeutschebankRouterData<&RefundsRouterData>> for Deutschebank fn try_from(item: &DeutschebankRouterData<&RefundsRouterData>) -> Result { Ok(Self { changed_amount: item.amount.to_owned(), - kind: match item.router_data.is_three_ds() { + kind: match item.router_data.is_three_ds() + && matches!(item.router_data.payment_method, PaymentMethod::Card) + { true => DeutschebankTransactionKind::Creditcard3ds20, false => DeutschebankTransactionKind::Directdebit, }, diff --git a/crates/router/src/configs/defaults/payment_connector_required_fields.rs b/crates/router/src/configs/defaults/payment_connector_required_fields.rs index 0954ac51c7df..d3d2b83271e8 100644 --- a/crates/router/src/configs/defaults/payment_connector_required_fields.rs +++ b/crates/router/src/configs/defaults/payment_connector_required_fields.rs @@ -941,6 +941,138 @@ impl Default for settings::RequiredFields { ), } ), + ( + enums::Connector::Deutschebank, + RequiredFieldFinal { + mandate: HashMap::new(), + non_mandate : HashMap::from( + [ + ( + "payment_method_data.card.card_number".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.card.card_number".to_string(), + display_name: "card_number".to_string(), + field_type: enums::FieldType::UserCardNumber, + value: None, + } + ), + ( + "payment_method_data.card.card_exp_month".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.card.card_exp_month".to_string(), + display_name: "card_exp_month".to_string(), + field_type: enums::FieldType::UserCardExpiryMonth, + value: None, + } + ), + ( + "payment_method_data.card.card_exp_year".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.card.card_exp_year".to_string(), + display_name: "card_exp_year".to_string(), + field_type: enums::FieldType::UserCardExpiryYear, + value: None, + } + ), + ( + "payment_method_data.card.card_cvc".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.card.card_cvc".to_string(), + display_name: "card_cvc".to_string(), + field_type: enums::FieldType::UserCardCvc, + value: None, + } + ), + ( + "payment_method_data.card.card_holder_name".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.card.card_holder_name".to_string(), + display_name: "card_holder_name".to_string(), + field_type: enums::FieldType::UserBillingName, + value: None, + } + ), + ( + "email".to_string(), + RequiredFieldInfo { + required_field: "email".to_string(), + display_name: "email".to_string(), + field_type: enums::FieldType::UserEmailAddress, + value: None, + } + ), + ( + "billing.address.line1".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.line1".to_string(), + display_name: "line1".to_string(), + field_type: enums::FieldType::UserAddressLine1, + value: None, + } + ), + ( + "billing.address.city".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.city".to_string(), + display_name: "city".to_string(), + field_type: enums::FieldType::UserAddressCity, + value: None, + } + ), + ( + "billing.address.state".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.state".to_string(), + display_name: "state".to_string(), + field_type: enums::FieldType::UserAddressState, + value: None, + } + ), + ( + "billing.address.zip".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.zip".to_string(), + display_name: "zip".to_string(), + field_type: enums::FieldType::UserAddressPincode, + value: None, + } + ), + ( + "billing.address.country".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.country".to_string(), + display_name: "country".to_string(), + field_type: enums::FieldType::UserAddressCountry{ + options: vec![ + "ALL".to_string(), + ] + }, + value: None, + } + ), + ( + "billing.address.first_name".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.first_name".to_string(), + display_name: "first_name".to_string(), + field_type: enums::FieldType::UserFullName, + value: None, + } + ), + ( + "billing.address.last_name".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.last_name".to_string(), + display_name: "last_name".to_string(), + field_type: enums::FieldType::UserFullName, + value: None, + } + ) + ] + ), + common: HashMap::new(), + } + ), ( enums::Connector::Dlocal, RequiredFieldFinal { @@ -4138,6 +4270,138 @@ impl Default for settings::RequiredFields { ), } ), + ( + enums::Connector::Deutschebank, + RequiredFieldFinal { + mandate: HashMap::new(), + non_mandate : HashMap::from( + [ + ( + "payment_method_data.card.card_number".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.card.card_number".to_string(), + display_name: "card_number".to_string(), + field_type: enums::FieldType::UserCardNumber, + value: None, + } + ), + ( + "payment_method_data.card.card_exp_month".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.card.card_exp_month".to_string(), + display_name: "card_exp_month".to_string(), + field_type: enums::FieldType::UserCardExpiryMonth, + value: None, + } + ), + ( + "payment_method_data.card.card_exp_year".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.card.card_exp_year".to_string(), + display_name: "card_exp_year".to_string(), + field_type: enums::FieldType::UserCardExpiryYear, + value: None, + } + ), + ( + "payment_method_data.card.card_cvc".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.card.card_cvc".to_string(), + display_name: "card_cvc".to_string(), + field_type: enums::FieldType::UserCardCvc, + value: None, + } + ), + ( + "payment_method_data.card.card_holder_name".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.card.card_holder_name".to_string(), + display_name: "card_holder_name".to_string(), + field_type: enums::FieldType::UserBillingName, + value: None, + } + ), + ( + "email".to_string(), + RequiredFieldInfo { + required_field: "email".to_string(), + display_name: "email".to_string(), + field_type: enums::FieldType::UserEmailAddress, + value: None, + } + ), + ( + "billing.address.line1".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.line1".to_string(), + display_name: "line1".to_string(), + field_type: enums::FieldType::UserAddressLine1, + value: None, + } + ), + ( + "billing.address.city".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.city".to_string(), + display_name: "city".to_string(), + field_type: enums::FieldType::UserAddressCity, + value: None, + } + ), + ( + "billing.address.state".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.state".to_string(), + display_name: "state".to_string(), + field_type: enums::FieldType::UserAddressState, + value: None, + } + ), + ( + "billing.address.zip".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.zip".to_string(), + display_name: "zip".to_string(), + field_type: enums::FieldType::UserAddressPincode, + value: None, + } + ), + ( + "billing.address.country".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.country".to_string(), + display_name: "country".to_string(), + field_type: enums::FieldType::UserAddressCountry{ + options: vec![ + "ALL".to_string(), + ] + }, + value: None, + } + ), + ( + "billing.address.first_name".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.first_name".to_string(), + display_name: "first_name".to_string(), + field_type: enums::FieldType::UserFullName, + value: None, + } + ), + ( + "billing.address.last_name".to_string(), + RequiredFieldInfo { + required_field: "payment_method_data.billing.address.last_name".to_string(), + display_name: "last_name".to_string(), + field_type: enums::FieldType::UserFullName, + value: None, + } + ) + ] + ), + common: HashMap::new(), + } + ), ( enums::Connector::Dlocal, RequiredFieldFinal {