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

feat(connector): [Adyen] add PMD validation in validate_capture_method method for all the implemented PM’s #3584

Merged
merged 11 commits into from
Feb 14, 2024
Merged
128 changes: 118 additions & 10 deletions crates/router/src/connector/adyen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod transformers;

use std::fmt::Debug;

use api_models::webhooks::IncomingWebhookEvent;
use api_models::{enums::PaymentMethodType, webhooks::IncomingWebhookEvent};
use base64::Engine;
use common_utils::request::RequestContent;
use diesel_models::{enums as storage_enums, enums};
Expand All @@ -11,12 +11,11 @@ use ring::hmac;
use router_env::{instrument, tracing};

use self::transformers as adyen;
use super::utils as connector_utils;
use crate::{
configs::settings,
consts,
core::errors::{self, CustomResult},
headers, logger,
headers, logger, not_supported,
services::{
self,
request::{self, Mask},
Expand Down Expand Up @@ -81,15 +80,124 @@ impl ConnectorValidation for Adyen {
fn validate_capture_method(
&self,
capture_method: Option<storage_enums::CaptureMethod>,
pmt: Option<PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
enums::CaptureMethod::Automatic
| enums::CaptureMethod::Manual
| enums::CaptureMethod::ManualMultiple => Ok(()),
enums::CaptureMethod::Scheduled => Err(
connector_utils::construct_not_implemented_error_report(capture_method, self.id()),
),
let connector = self.id();
match pmt {
Some(payment_method_type) => match payment_method_type {
PaymentMethodType::Affirm
| PaymentMethodType::AfterpayClearpay
| PaymentMethodType::ApplePay
| PaymentMethodType::Credit
| PaymentMethodType::Debit
| PaymentMethodType::GooglePay
| PaymentMethodType::MobilePay
| PaymentMethodType::PayBright
| PaymentMethodType::Sepa
| PaymentMethodType::Vipps
| PaymentMethodType::Paypal => match capture_method {
enums::CaptureMethod::Automatic
| enums::CaptureMethod::Manual
| enums::CaptureMethod::ManualMultiple => Ok(()),
enums::CaptureMethod::Scheduled => {
not_supported!(connector, capture_method, payment_method_type)
}
},
PaymentMethodType::Ach
| PaymentMethodType::Alma
| PaymentMethodType::Bacs
| PaymentMethodType::Givex
| PaymentMethodType::Klarna
| PaymentMethodType::Twint
| PaymentMethodType::Walley => match capture_method {
enums::CaptureMethod::Automatic | enums::CaptureMethod::Manual => Ok(()),
enums::CaptureMethod::ManualMultiple | enums::CaptureMethod::Scheduled => {
not_supported!(connector, capture_method, payment_method_type)
}
},

PaymentMethodType::AliPay
| PaymentMethodType::AliPayHk
| PaymentMethodType::Atome
| PaymentMethodType::BancontactCard
| PaymentMethodType::Benefit
| PaymentMethodType::Bizum
| PaymentMethodType::Blik
| PaymentMethodType::Boleto
| PaymentMethodType::Dana
| PaymentMethodType::Eps
| PaymentMethodType::OnlineBankingFpx
| PaymentMethodType::Gcash
| PaymentMethodType::GoPay
| PaymentMethodType::Ideal
| PaymentMethodType::KakaoPay
| PaymentMethodType::Knet
| PaymentMethodType::MbWay
| PaymentMethodType::Momo
| PaymentMethodType::MomoAtm
| PaymentMethodType::OnlineBankingFinland
| PaymentMethodType::OnlineBankingPoland
| PaymentMethodType::OnlineBankingSlovakia
| PaymentMethodType::OnlineBankingThailand
| PaymentMethodType::Oxxo
| PaymentMethodType::PaySafeCard
| PaymentMethodType::Pix
| PaymentMethodType::Swish
| PaymentMethodType::TouchNGo
| PaymentMethodType::Trustly
| PaymentMethodType::WeChatPay
| PaymentMethodType::DanamonVa
| PaymentMethodType::BcaBankTransfer
| PaymentMethodType::BriVa
| PaymentMethodType::BniVa
| PaymentMethodType::CimbVa
| PaymentMethodType::MandiriVa
| PaymentMethodType::Alfamart
| PaymentMethodType::Indomaret
| PaymentMethodType::FamilyMart
| PaymentMethodType::Sofort
| PaymentMethodType::Giropay
| PaymentMethodType::Seicomart
| PaymentMethodType::PayEasy
| PaymentMethodType::MiniStop
| PaymentMethodType::Lawson
| PaymentMethodType::SevenEleven
| PaymentMethodType::OpenBankingUk
| PaymentMethodType::OnlineBankingCzechRepublic
| PaymentMethodType::PermataBankTransfer => match capture_method {
enums::CaptureMethod::Automatic => Ok(()),
enums::CaptureMethod::Manual
| enums::CaptureMethod::ManualMultiple
| enums::CaptureMethod::Scheduled => {
not_supported!(connector, capture_method, payment_method_type)
}
},
PaymentMethodType::CardRedirect
| PaymentMethodType::Interac
| PaymentMethodType::Multibanco
| PaymentMethodType::Przelewy24
| PaymentMethodType::Becs
| PaymentMethodType::ClassicReward
| PaymentMethodType::Pse
| PaymentMethodType::Efecty
| PaymentMethodType::PagoEfectivo
| PaymentMethodType::RedCompra
| PaymentMethodType::RedPagos
| PaymentMethodType::CryptoCurrency
| PaymentMethodType::SamsungPay
| PaymentMethodType::Evoucher
| PaymentMethodType::Cashapp
| PaymentMethodType::UpiCollect => {
not_supported!(connector, capture_method, payment_method_type)
}
},
None => match capture_method {
enums::CaptureMethod::Automatic
| enums::CaptureMethod::Manual
| enums::CaptureMethod::ManualMultiple => Ok(()),
enums::CaptureMethod::Scheduled => not_supported!(connector, capture_method),
},
}
}
fn validate_psync_reference_id(
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/airwallex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl ConnectorValidation for Airwallex {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/authorizedotnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl ConnectorValidation for Authorizedotnet {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/bambora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl ConnectorValidation for Bambora {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/bankofamerica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ impl ConnectorValidation for Bankofamerica {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/bluesnap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ impl ConnectorValidation for Bluesnap {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/boku.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl ConnectorValidation for Boku {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/braintree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl ConnectorValidation for Braintree {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/cashtocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl ConnectorValidation for Cashtocode {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl ConnectorValidation for Checkout {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ impl ConnectorValidation for Coinbase {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/cybersource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ impl ConnectorValidation for Cybersource {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/dlocal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl ConnectorValidation for Dlocal {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/dummyconnector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ impl<const T: u8> ConnectorValidation for DummyConnector<T> {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/fiserv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl ConnectorValidation for Fiserv {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/forte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl ConnectorValidation for Forte {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/globalpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl ConnectorValidation for Globalpay {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/connector/gocardless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ impl
impl ConnectorValidation for Gocardless {
fn validate_capture_method(
&self,
capture_method: Option<api_models::enums::CaptureMethod>,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/helcim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl ConnectorValidation for Helcim {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/multisafepay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl ConnectorValidation for Multisafepay {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/nexinets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl ConnectorValidation for Nexinets {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/nmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl ConnectorValidation for Nmi {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/noon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl ConnectorValidation for Noon {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/nuvei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl ConnectorValidation for Nuvei {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/opayo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ impl ConnectorValidation for Opayo {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/payeezy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl ConnectorValidation for Payeezy {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/payme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl ConnectorValidation for Payme {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/paypal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ impl ConnectorValidation for Paypal {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/payu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl ConnectorValidation for Payu {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/placetopay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl ConnectorValidation for Placetopay {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/powertranz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl ConnectorValidation for Powertranz {
fn validate_capture_method(
&self,
capture_method: Option<enums::CaptureMethod>,
_pmt: Option<enums::PaymentMethodType>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
Expand Down
Loading
Loading