Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(connector): [Square] change error message from NotSupported to NotImplemented #2875

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 34 additions & 39 deletions crates/router/src/connector/square/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,19 +17,18 @@ impl TryFrom<(&types::TokenizationRouterData, BankDebitData)> for SquareTokenReq
fn try_from(
value: (&types::TokenizationRouterData, BankDebitData),
) -> Result<Self, Self::Error> {
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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can club all the match arms and propagate the expected common error.
Please use | and throw the NotImplemented error in the end. No need for it to be done twice

Copy link
Contributor Author

@nain-F49FF806 nain-F49FF806 Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had assumed the two blocks were kept separate on purpose to have the AchBank arm generate a report, and the others not.

On second look, it seems the conversion happens automatically for the others anyway, to keep the return type identical.

I shall club them all and also remove the .into_report altogether. Let me know if that is not as intended.

))?,
}
}
}
Expand Down Expand Up @@ -82,40 +81,39 @@ impl TryFrom<(&types::TokenizationRouterData, PayLaterData)> for SquareTokenRequ
fn try_from(
value: (&types::TokenizationRouterData, PayLaterData),
) -> Result<Self, Self::Error> {
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 { .. }
| PayLaterData::AffirmRedirect { .. }
| 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"),
))?,
SamraatBansal marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

impl TryFrom<(&types::TokenizationRouterData, WalletData)> for SquareTokenRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(value: (&types::TokenizationRouterData, WalletData)) -> Result<Self, Self::Error> {
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(_)
Expand All @@ -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"),
))?,
SamraatBansal marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down Expand Up @@ -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"),
SamraatBansal marked this conversation as resolved.
Show resolved Hide resolved
))
.into_report(),
api::PaymentMethodData::BankRedirect(_)
Expand All @@ -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"),
))?,
}
}
}
Expand Down Expand Up @@ -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"),
SamraatBansal marked this conversation as resolved.
Show resolved Hide resolved
))
.into_report(),
api::PaymentMethodData::BankRedirect(_)
Expand All @@ -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"),
))?,
}
}
}
Expand Down
Loading