From 5b34b38961ffdc9a4fafd15ff432455b2b022aae Mon Sep 17 00:00:00 2001 From: Naian <126972030+nain-F49FF806@users.noreply.github.com> Date: Wed, 15 Nov 2023 11:59:32 +0100 Subject: [PATCH 1/2] refactor(connector): [Square] change error message from NotSupported to NotImplemented Resolves #2861 --- .../src/connector/square/transformers.rs | 73 +++++++++---------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/crates/router/src/connector/square/transformers.rs b/crates/router/src/connector/square/transformers.rs index 7343ef58bb08..c6f88bdfe5d3 100644 --- a/crates/router/src/connector/square/transformers.rs +++ b/crates/router/src/connector/square/transformers.rs @@ -4,7 +4,7 @@ use masking::{ExposeInterface, PeekInterface, Secret}; use serde::{Deserialize, Serialize}; use crate::{ - connector::utils::{CardData, PaymentsAuthorizeRequestData, RouterData}, + connector::utils::{self, CardData, PaymentsAuthorizeRequestData, RouterData}, core::errors, types::{ self, api, @@ -17,19 +17,18 @@ impl TryFrom<(&types::TokenizationRouterData, BankDebitData)> for SquareTokenReq fn try_from( value: (&types::TokenizationRouterData, BankDebitData), ) -> Result { - let (item, bank_debit_data) = value; + let (_item, bank_debit_data) = value; match bank_debit_data { BankDebitData::AchBankDebit { .. } => Err(errors::ConnectorError::NotImplemented( - "Payment Method".to_string(), + utils::get_unimplemented_payment_method_error_message("Square"), )) .into_report(), BankDebitData::SepaBankDebit { .. } | BankDebitData::BecsBankDebit { .. } - | BankDebitData::BacsBankDebit { .. } => Err(errors::ConnectorError::NotSupported { - message: format!("{:?}", item.request.payment_method_data), - connector: "Square", - })?, + | BankDebitData::BacsBankDebit { .. } => Err(errors::ConnectorError::NotImplemented( + utils::get_unimplemented_payment_method_error_message("Square"), + ))?, } } } @@ -82,12 +81,14 @@ impl TryFrom<(&types::TokenizationRouterData, PayLaterData)> for SquareTokenRequ fn try_from( value: (&types::TokenizationRouterData, PayLaterData), ) -> Result { - let (item, pay_later_data) = value; + let (_item, pay_later_data) = value; match pay_later_data { - PayLaterData::AfterpayClearpayRedirect { .. } => Err( - errors::ConnectorError::NotImplemented("Payment Method".to_string()), - ) - .into_report(), + PayLaterData::AfterpayClearpayRedirect { .. } => { + Err(errors::ConnectorError::NotImplemented( + utils::get_unimplemented_payment_method_error_message("Square"), + )) + .into_report() + } PayLaterData::KlarnaRedirect { .. } | PayLaterData::KlarnaSdk { .. } @@ -95,10 +96,9 @@ impl TryFrom<(&types::TokenizationRouterData, PayLaterData)> for SquareTokenRequ | PayLaterData::PayBrightRedirect { .. } | PayLaterData::WalleyRedirect { .. } | PayLaterData::AlmaRedirect { .. } - | PayLaterData::AtomeRedirect { .. } => Err(errors::ConnectorError::NotSupported { - message: format!("{:?}", item.request.payment_method_data), - connector: "Square", - })?, + | PayLaterData::AtomeRedirect { .. } => Err(errors::ConnectorError::NotImplemented( + utils::get_unimplemented_payment_method_error_message("Square"), + ))?, } } } @@ -106,16 +106,14 @@ impl TryFrom<(&types::TokenizationRouterData, PayLaterData)> for SquareTokenRequ impl TryFrom<(&types::TokenizationRouterData, WalletData)> for SquareTokenRequest { type Error = error_stack::Report; fn try_from(value: (&types::TokenizationRouterData, WalletData)) -> Result { - let (item, wallet_data) = value; + let (_item, wallet_data) = value; match wallet_data { - WalletData::ApplePay(_) => Err(errors::ConnectorError::NotImplemented( - "Payment Method".to_string(), - )) - .into_report(), - WalletData::GooglePay(_) => Err(errors::ConnectorError::NotImplemented( - "Payment Method".to_string(), - )) - .into_report(), + WalletData::ApplePay(_) | WalletData::GooglePay(_) => { + Err(errors::ConnectorError::NotImplemented( + utils::get_unimplemented_payment_method_error_message("Square"), + )) + .into_report() + } WalletData::AliPayQr(_) | WalletData::AliPayRedirect(_) @@ -140,10 +138,9 @@ impl TryFrom<(&types::TokenizationRouterData, WalletData)> for SquareTokenReques | WalletData::WeChatPayRedirect(_) | WalletData::WeChatPayQr(_) | WalletData::CashappQr(_) - | WalletData::SwishQr(_) => Err(errors::ConnectorError::NotSupported { - message: format!("{:?}", item.request.payment_method_data), - connector: "Square", - })?, + | WalletData::SwishQr(_) => Err(errors::ConnectorError::NotImplemented( + utils::get_unimplemented_payment_method_error_message("Square"), + ))?, } } } @@ -181,7 +178,7 @@ impl TryFrom<&types::TokenizationRouterData> for SquareTokenRequest { Self::try_from((item, pay_later_data)) } api::PaymentMethodData::GiftCard(_) => Err(errors::ConnectorError::NotImplemented( - "Payment Method".to_string(), + utils::get_unimplemented_payment_method_error_message("Square"), )) .into_report(), api::PaymentMethodData::BankRedirect(_) @@ -192,10 +189,9 @@ impl TryFrom<&types::TokenizationRouterData> for SquareTokenRequest { | api::PaymentMethodData::Reward | api::PaymentMethodData::Upi(_) | api::PaymentMethodData::Voucher(_) - | api::PaymentMethodData::CardToken(_) => Err(errors::ConnectorError::NotSupported { - message: format!("{:?}", item.request.payment_method_data), - connector: "Square", - })?, + | api::PaymentMethodData::CardToken(_) => Err(errors::ConnectorError::NotImplemented( + utils::get_unimplemented_payment_method_error_message("Square"), + ))?, } } } @@ -298,7 +294,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for SquarePaymentsRequest { | api::PaymentMethodData::GiftCard(_) | api::PaymentMethodData::PayLater(_) | api::PaymentMethodData::Wallet(_) => Err(errors::ConnectorError::NotImplemented( - "Payment Method".to_string(), + utils::get_unimplemented_payment_method_error_message("Square"), )) .into_report(), api::PaymentMethodData::BankRedirect(_) @@ -309,10 +305,9 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for SquarePaymentsRequest { | api::PaymentMethodData::Reward | api::PaymentMethodData::Upi(_) | api::PaymentMethodData::Voucher(_) - | api::PaymentMethodData::CardToken(_) => Err(errors::ConnectorError::NotSupported { - message: format!("{:?}", item.request.payment_method_data), - connector: "Square", - })?, + | api::PaymentMethodData::CardToken(_) => Err(errors::ConnectorError::NotImplemented( + utils::get_unimplemented_payment_method_error_message("Square"), + ))?, } } } From 50d566a71741fb796b7c1faad35f46f733ca94cd Mon Sep 17 00:00:00 2001 From: Naian <126972030+nain-F49FF806@users.noreply.github.com> Date: Thu, 1 Feb 2024 12:26:20 +0100 Subject: [PATCH 2/2] refactor(connector): [Square] club together NotImplemented error return arms --- .../src/connector/square/transformers.rs | 43 +++++-------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/crates/router/src/connector/square/transformers.rs b/crates/router/src/connector/square/transformers.rs index c6f88bdfe5d3..af0acf83ae64 100644 --- a/crates/router/src/connector/square/transformers.rs +++ b/crates/router/src/connector/square/transformers.rs @@ -19,12 +19,8 @@ impl TryFrom<(&types::TokenizationRouterData, BankDebitData)> for SquareTokenReq ) -> Result { let (_item, bank_debit_data) = value; match bank_debit_data { - BankDebitData::AchBankDebit { .. } => Err(errors::ConnectorError::NotImplemented( - utils::get_unimplemented_payment_method_error_message("Square"), - )) - .into_report(), - - BankDebitData::SepaBankDebit { .. } + BankDebitData::AchBankDebit { .. } + | BankDebitData::SepaBankDebit { .. } | BankDebitData::BecsBankDebit { .. } | BankDebitData::BacsBankDebit { .. } => Err(errors::ConnectorError::NotImplemented( utils::get_unimplemented_payment_method_error_message("Square"), @@ -83,14 +79,8 @@ impl TryFrom<(&types::TokenizationRouterData, PayLaterData)> for SquareTokenRequ ) -> Result { let (_item, pay_later_data) = value; match pay_later_data { - PayLaterData::AfterpayClearpayRedirect { .. } => { - Err(errors::ConnectorError::NotImplemented( - utils::get_unimplemented_payment_method_error_message("Square"), - )) - .into_report() - } - - PayLaterData::KlarnaRedirect { .. } + PayLaterData::AfterpayClearpayRedirect { .. } + | PayLaterData::KlarnaRedirect { .. } | PayLaterData::KlarnaSdk { .. } | PayLaterData::AffirmRedirect { .. } | PayLaterData::PayBrightRedirect { .. } @@ -108,14 +98,9 @@ impl TryFrom<(&types::TokenizationRouterData, WalletData)> for SquareTokenReques fn try_from(value: (&types::TokenizationRouterData, WalletData)) -> Result { let (_item, wallet_data) = value; match wallet_data { - WalletData::ApplePay(_) | WalletData::GooglePay(_) => { - Err(errors::ConnectorError::NotImplemented( - utils::get_unimplemented_payment_method_error_message("Square"), - )) - .into_report() - } - - WalletData::AliPayQr(_) + WalletData::ApplePay(_) + | WalletData::GooglePay(_) + | WalletData::AliPayQr(_) | WalletData::AliPayRedirect(_) | WalletData::AliPayHkRedirect(_) | WalletData::MomoRedirect(_) @@ -177,11 +162,8 @@ impl TryFrom<&types::TokenizationRouterData> for SquareTokenRequest { api::PaymentMethodData::PayLater(pay_later_data) => { Self::try_from((item, pay_later_data)) } - api::PaymentMethodData::GiftCard(_) => Err(errors::ConnectorError::NotImplemented( - utils::get_unimplemented_payment_method_error_message("Square"), - )) - .into_report(), - api::PaymentMethodData::BankRedirect(_) + api::PaymentMethodData::GiftCard(_) + | api::PaymentMethodData::BankRedirect(_) | api::PaymentMethodData::BankTransfer(_) | api::PaymentMethodData::CardRedirect(_) | api::PaymentMethodData::Crypto(_) @@ -293,11 +275,8 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for SquarePaymentsRequest { api::PaymentMethodData::BankDebit(_) | api::PaymentMethodData::GiftCard(_) | api::PaymentMethodData::PayLater(_) - | api::PaymentMethodData::Wallet(_) => Err(errors::ConnectorError::NotImplemented( - utils::get_unimplemented_payment_method_error_message("Square"), - )) - .into_report(), - api::PaymentMethodData::BankRedirect(_) + | api::PaymentMethodData::Wallet(_) + | api::PaymentMethodData::BankRedirect(_) | api::PaymentMethodData::BankTransfer(_) | api::PaymentMethodData::CardRedirect(_) | api::PaymentMethodData::Crypto(_)