Skip to content

Commit

Permalink
refactor(connector): remove default cases for Authorizedotnet, Braint…
Browse files Browse the repository at this point in the history
…ree and Fiserv Connector (#2796)

Co-authored-by: chikke srujan <[email protected]>
  • Loading branch information
swangi-kumari and srujanchikke authored Mar 5, 2024
1 parent 19c5023 commit dbac556
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 34 deletions.
103 changes: 79 additions & 24 deletions crates/router/src/connector/authorizedotnet/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,23 @@ fn get_pm_and_subsequent_auth_detail(
});
Ok((payment_details, processing_options, subseuent_auth_info))
}
_ => Err(errors::ConnectorError::NotSupported {
message: format!("{:?}", item.router_data.request.payment_method_data),
connector: "AuthorizeDotNet",
})?,
api::PaymentMethodData::CardRedirect(_)
| api::PaymentMethodData::Wallet(_)
| api::PaymentMethodData::PayLater(_)
| api::PaymentMethodData::BankRedirect(_)
| api::PaymentMethodData::BankDebit(_)
| api::PaymentMethodData::BankTransfer(_)
| api::PaymentMethodData::Crypto(_)
| api::PaymentMethodData::MandatePayment
| api::PaymentMethodData::Reward
| api::PaymentMethodData::Upi(_)
| api::PaymentMethodData::Voucher(_)
| api::PaymentMethodData::GiftCard(_)
| api::PaymentMethodData::CardToken(_) => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("authorizedotnet"),
))?
}
}
}
_ => match item.router_data.request.payment_method_data {
Expand All @@ -193,10 +206,20 @@ fn get_pm_and_subsequent_auth_detail(
None,
None,
)),
_ => Err(errors::ConnectorError::NotSupported {
message: format!("{:?}", item.router_data.request.payment_method_data),
connector: "AuthorizeDotNet",
})?,
api::PaymentMethodData::CardRedirect(_)
| api::PaymentMethodData::PayLater(_)
| api::PaymentMethodData::BankRedirect(_)
| api::PaymentMethodData::BankDebit(_)
| api::PaymentMethodData::BankTransfer(_)
| api::PaymentMethodData::Crypto(_)
| api::PaymentMethodData::MandatePayment
| api::PaymentMethodData::Reward
| api::PaymentMethodData::Upi(_)
| api::PaymentMethodData::Voucher(_)
| api::PaymentMethodData::GiftCard(_)
| api::PaymentMethodData::CardToken(_) => Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("authorizedotnet"),
))?,
},
}
}
Expand Down Expand Up @@ -289,11 +312,16 @@ pub enum AuthorizationType {
Pre,
}

impl From<enums::CaptureMethod> for AuthorizationType {
fn from(item: enums::CaptureMethod) -> Self {
match item {
enums::CaptureMethod::Manual => Self::Pre,
_ => Self::Final,
impl TryFrom<enums::CaptureMethod> for AuthorizationType {
type Error = error_stack::Report<errors::ConnectorError>;

fn try_from(capture_method: enums::CaptureMethod) -> Result<Self, Self::Error> {
match capture_method {
enums::CaptureMethod::Manual => Ok(Self::Pre),
enums::CaptureMethod::Automatic => Ok(Self::Final),
enums::CaptureMethod::ManualMultiple | enums::CaptureMethod::Scheduled => Err(
utils::construct_not_supported_error_report(capture_method, "authorizedotnet"),
)?,
}
}
}
Expand All @@ -307,13 +335,13 @@ impl TryFrom<&AuthorizedotnetRouterData<&types::PaymentsAuthorizeRouterData>>
) -> Result<Self, Self::Error> {
let (payment_details, processing_options, subsequent_auth_information) =
get_pm_and_subsequent_auth_detail(item)?;
let authorization_indicator_type =
item.router_data
.request
.capture_method
.map(|c| AuthorizationIndicator {
authorization_indicator: c.into(),
});
let authorization_indicator_type = match item.router_data.request.capture_method {
Some(capture_method) => Some(AuthorizationIndicator {
authorization_indicator: capture_method.try_into()?,
}),
None => None,
};

let transaction_request = TransactionRequest {
transaction_type: TransactionType::from(item.router_data.request.capture_method),
amount: item.amount,
Expand Down Expand Up @@ -904,6 +932,7 @@ pub enum SyncStatus {
#[serde(rename = "FDSPendingReview")]
FDSPendingReview,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncTransactionResponse {
Expand Down Expand Up @@ -938,7 +967,9 @@ impl From<SyncStatus> for enums::AttemptStatus {
SyncStatus::Voided => Self::Voided,
SyncStatus::CouldNotVoid => Self::VoidFailed,
SyncStatus::GeneralError => Self::Failure,
_ => Self::Pending,
SyncStatus::RefundSettledSuccessfully
| SyncStatus::RefundPendingSettlement
| SyncStatus::FDSPendingReview => Self::Pending,
}
}
}
Expand Down Expand Up @@ -1190,9 +1221,33 @@ fn get_wallet_data(
cancel_url: return_url.to_owned(),
}))
}
_ => Err(errors::ConnectorError::NotImplemented(
"Payment method".to_string(),
))?,
api_models::payments::WalletData::AliPayQr(_)
| api_models::payments::WalletData::AliPayRedirect(_)
| api_models::payments::WalletData::AliPayHkRedirect(_)
| api_models::payments::WalletData::MomoRedirect(_)
| api_models::payments::WalletData::KakaoPayRedirect(_)
| api_models::payments::WalletData::GoPayRedirect(_)
| api_models::payments::WalletData::GcashRedirect(_)
| api_models::payments::WalletData::ApplePayRedirect(_)
| api_models::payments::WalletData::ApplePayThirdPartySdk(_)
| api_models::payments::WalletData::DanaRedirect {}
| api_models::payments::WalletData::GooglePayRedirect(_)
| api_models::payments::WalletData::GooglePayThirdPartySdk(_)
| api_models::payments::WalletData::MbWayRedirect(_)
| api_models::payments::WalletData::MobilePayRedirect(_)
| api_models::payments::WalletData::PaypalSdk(_)
| api_models::payments::WalletData::SamsungPay(_)
| api_models::payments::WalletData::TwintRedirect {}
| api_models::payments::WalletData::VippsRedirect {}
| api_models::payments::WalletData::TouchNGoRedirect(_)
| api_models::payments::WalletData::WeChatPayRedirect(_)
| api_models::payments::WalletData::WeChatPayQr(_)
| api_models::payments::WalletData::CashappQr(_)
| api_models::payments::WalletData::SwishQr(_) => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("authorizedotnet"),
))?
}
}
}

Expand Down
52 changes: 46 additions & 6 deletions crates/router/src/connector/braintree/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,53 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for BraintreePaymentsRequest {
api_models::payments::WalletData::PaypalSdk(wallet_data) => {
Ok(wallet_data.token.to_owned())
}
_ => Err(errors::ConnectorError::InvalidWallet),
api_models::payments::WalletData::ApplePay(_)
| api_models::payments::WalletData::GooglePay(_)
| api_models::payments::WalletData::SamsungPay(_)
| api_models::payments::WalletData::AliPayQr(_)
| api_models::payments::WalletData::AliPayRedirect(_)
| api_models::payments::WalletData::AliPayHkRedirect(_)
| api_models::payments::WalletData::MomoRedirect(_)
| api_models::payments::WalletData::KakaoPayRedirect(_)
| api_models::payments::WalletData::GoPayRedirect(_)
| api_models::payments::WalletData::GcashRedirect(_)
| api_models::payments::WalletData::ApplePayRedirect(_)
| api_models::payments::WalletData::ApplePayThirdPartySdk(_)
| api_models::payments::WalletData::DanaRedirect {}
| api_models::payments::WalletData::GooglePayRedirect(_)
| api_models::payments::WalletData::GooglePayThirdPartySdk(_)
| api_models::payments::WalletData::MbWayRedirect(_)
| api_models::payments::WalletData::MobilePayRedirect(_)
| api_models::payments::WalletData::PaypalRedirect(_)
| api_models::payments::WalletData::TwintRedirect {}
| api_models::payments::WalletData::VippsRedirect {}
| api_models::payments::WalletData::TouchNGoRedirect(_)
| api_models::payments::WalletData::WeChatPayRedirect(_)
| api_models::payments::WalletData::WeChatPayQr(_)
| api_models::payments::WalletData::CashappQr(_)
| api_models::payments::WalletData::SwishQr(_) => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("braintree"),
))
}
}?
.into(),
}))
}
_ => Err(errors::ConnectorError::NotImplemented(format!(
"Current Payment Method - {:?}",
item.request.payment_method_data
))),
api::PaymentMethodData::PayLater(_)
| api::PaymentMethodData::BankRedirect(_)
| api::PaymentMethodData::BankDebit(_)
| api::PaymentMethodData::BankTransfer(_)
| api::PaymentMethodData::Crypto(_)
| api::PaymentMethodData::CardRedirect(_)
| api::PaymentMethodData::MandatePayment
| api::PaymentMethodData::Reward
| api::PaymentMethodData::Upi(_)
| api::PaymentMethodData::Voucher(_)
| api::PaymentMethodData::GiftCard(_)
| api::PaymentMethodData::CardToken(_) => Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("braintree"),
)),
}?;
let braintree_transaction_body = TransactionBody {
amount,
Expand Down Expand Up @@ -211,7 +249,9 @@ impl From<BraintreePaymentStatus> for enums::AttemptStatus {
| BraintreePaymentStatus::SettlementDeclined => Self::Failure,
BraintreePaymentStatus::Authorized => Self::Authorized,
BraintreePaymentStatus::Voided => Self::Voided,
_ => Self::Pending,
BraintreePaymentStatus::SubmittedForSettlement
| BraintreePaymentStatus::SettlementPending
| BraintreePaymentStatus::SettlementConfirmed => Self::Pending,
}
}
}
Expand Down
22 changes: 18 additions & 4 deletions crates/router/src/connector/fiserv/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,23 @@ impl TryFrom<&FiservRouterData<&types::PaymentsAuthorizeRouterData>> for FiservP
};
Source::PaymentCard { card }
}
_ => Err(errors::ConnectorError::NotImplemented(
"Payment Methods".to_string(),
))?,
api::PaymentMethodData::Wallet(_)
| api::PaymentMethodData::PayLater(_)
| api::PaymentMethodData::BankRedirect(_)
| api::PaymentMethodData::BankDebit(_)
| api::PaymentMethodData::CardRedirect(_)
| api::PaymentMethodData::BankTransfer(_)
| api::PaymentMethodData::Crypto(_)
| api::PaymentMethodData::MandatePayment
| api::PaymentMethodData::Reward
| api::PaymentMethodData::Upi(_)
| api::PaymentMethodData::Voucher(_)
| api::PaymentMethodData::GiftCard(_)
| api::PaymentMethodData::CardToken(_) => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("fiserv"),
))
}?,
};
Ok(Self {
amount,
Expand Down Expand Up @@ -306,7 +320,7 @@ impl From<FiservPaymentStatus> for enums::RefundStatus {
| FiservPaymentStatus::Authorized
| FiservPaymentStatus::Captured => Self::Success,
FiservPaymentStatus::Declined | FiservPaymentStatus::Failed => Self::Failure,
_ => Self::Pending,
FiservPaymentStatus::Voided | FiservPaymentStatus::Processing => Self::Pending,
}
}
}
Expand Down

0 comments on commit dbac556

Please sign in to comment.