feat(connector): [Adyen] Add support for card redirection (KNET, BENEFIT) (#1816)

Co-authored-by: Arjun Karthik <m.arjunkarthik@gmail.com>
This commit is contained in:
Sangamesh Kulkarni
2023-08-08 12:39:14 +05:30
committed by GitHub
parent 7b2c419ce5
commit 62461f1b38
17 changed files with 168 additions and 2 deletions

View File

@ -616,6 +616,13 @@ pub struct Card {
pub nick_name: Option<Secret<String>>,
}
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum CardRedirectData {
Knet {},
Benefit {},
}
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum PayLaterData {
@ -712,6 +719,7 @@ pub enum BankDebitData {
#[serde(rename_all = "snake_case")]
pub enum PaymentMethodData {
Card(Card),
CardRedirect(CardRedirectData),
Wallet(WalletData),
PayLater(PayLaterData),
BankRedirect(BankRedirectData),
@ -775,6 +783,7 @@ pub enum AdditionalPaymentData {
Upi {},
GiftCard {},
Voucher {},
CardRedirect {},
}
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
@ -1312,6 +1321,7 @@ pub enum PaymentMethodDataResponse {
Upi,
Voucher,
GiftCard,
CardRedirect,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema)]
@ -2037,6 +2047,7 @@ impl From<AdditionalPaymentData> for PaymentMethodDataResponse {
AdditionalPaymentData::BankTransfer {} => Self::BankTransfer,
AdditionalPaymentData::Voucher {} => Self::Voucher,
AdditionalPaymentData::GiftCard {} => Self::GiftCard,
AdditionalPaymentData::CardRedirect {} => Self::CardRedirect,
}
}
}

View File

@ -878,6 +878,7 @@ pub enum PaymentMethodType {
Bacs,
BancontactCard,
Becs,
Benefit,
Bizum,
Blik,
Boleto,
@ -907,6 +908,7 @@ pub enum PaymentMethodType {
Klarna,
KakaoPay,
MandiriVa,
Knet,
MbWay,
MobilePay,
Momo,
@ -963,6 +965,7 @@ pub enum PaymentMethodType {
pub enum PaymentMethod {
#[default]
Card,
CardRedirect,
PayLater,
Wallet,
BankRedirect,

View File

@ -1548,6 +1548,7 @@ impl From<PaymentMethodType> for PaymentMethod {
PaymentMethodType::Becs => Self::BankDebit,
PaymentMethodType::BniVa => Self::BankTransfer,
PaymentMethodType::BriVa => Self::BankTransfer,
PaymentMethodType::Benefit => Self::CardRedirect,
PaymentMethodType::Bizum => Self::BankRedirect,
PaymentMethodType::Blik => Self::BankRedirect,
PaymentMethodType::Alfamart => Self::Voucher,
@ -1567,6 +1568,7 @@ impl From<PaymentMethodType> for PaymentMethod {
PaymentMethodType::Ideal => Self::BankRedirect,
PaymentMethodType::Klarna => Self::PayLater,
PaymentMethodType::KakaoPay => Self::Wallet,
PaymentMethodType::Knet => Self::CardRedirect,
PaymentMethodType::MbWay => Self::Wallet,
PaymentMethodType::MobilePay => Self::Wallet,
PaymentMethodType::Momo => Self::Wallet,

View File

@ -371,6 +371,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for AciPaymentsRequest {
| api::PaymentMethodData::BankTransfer(_)
| api::PaymentMethodData::Reward(_)
| api::PaymentMethodData::GiftCard(_)
| api::PaymentMethodData::CardRedirect(_)
| api::PaymentMethodData::Upi(_)
| api::PaymentMethodData::Voucher(_) => Err(errors::ConnectorError::NotSupported {
message: format!("{:?}", item.payment_method),

View File

@ -453,6 +453,10 @@ pub enum AdyenPaymentMethod<'a> {
AdyenGiftCard(Box<GiftCardData>),
#[serde(rename = "swish")]
Swish,
#[serde(rename = "benefit")]
Benefit,
#[serde(rename = "knet")]
Knet,
}
#[derive(Debug, Clone, Serialize)]
@ -1003,6 +1007,8 @@ pub enum PaymentType {
Twint,
Vipps,
Giftcard,
Knet,
Benefit,
Swish,
#[serde(rename = "doku_permata_lite_atm")]
PermataBankTransfer,
@ -1181,6 +1187,9 @@ impl<'a> TryFrom<&types::PaymentsAuthorizeRouterData> for AdyenPaymentRequest<'a
api_models::payments::PaymentMethodData::BankTransfer(ref bank_transfer) => {
AdyenPaymentRequest::try_from((item, bank_transfer.as_ref()))
}
api_models::payments::PaymentMethodData::CardRedirect(ref card_redirect_data) => {
AdyenPaymentRequest::try_from((item, card_redirect_data))
}
api_models::payments::PaymentMethodData::Voucher(ref voucher_data) => {
AdyenPaymentRequest::try_from((item, voucher_data))
}
@ -1933,6 +1942,18 @@ impl<'a> TryFrom<&api_models::payments::BankTransferData> for AdyenPaymentMethod
}
}
impl<'a> TryFrom<&api_models::payments::CardRedirectData> for AdyenPaymentMethod<'a> {
type Error = Error;
fn try_from(
card_redirect_data: &api_models::payments::CardRedirectData,
) -> Result<Self, Self::Error> {
match card_redirect_data {
payments::CardRedirectData::Knet {} => Ok(AdyenPaymentMethod::Knet),
payments::CardRedirectData::Benefit {} => Ok(AdyenPaymentMethod::Benefit),
}
}
}
impl<'a>
TryFrom<(
&types::PaymentsAuthorizeRouterData,
@ -2445,6 +2466,60 @@ impl<'a> TryFrom<(&types::PaymentsAuthorizeRouterData, &api::PayLaterData)>
}
}
impl<'a>
TryFrom<(
&types::PaymentsAuthorizeRouterData,
&api_models::payments::CardRedirectData,
)> for AdyenPaymentRequest<'a>
{
type Error = Error;
fn try_from(
value: (
&types::PaymentsAuthorizeRouterData,
&api_models::payments::CardRedirectData,
),
) -> Result<Self, Self::Error> {
let (item, card_redirect_data) = value;
let amount = get_amount_data(item);
let auth_type = AdyenAuthType::try_from(&item.connector_auth_type)?;
let payment_method = AdyenPaymentMethod::try_from(card_redirect_data)?;
let shopper_interaction = AdyenShopperInteraction::from(item);
let return_url = item.request.get_return_url()?;
let shopper_name = get_shopper_name(item.address.billing.as_ref());
let shopper_email = item.request.email.clone();
let telephone_number = item
.get_billing_phone()
.change_context(errors::ConnectorError::MissingRequiredField {
field_name: "billing.phone",
})?
.number
.to_owned();
Ok(AdyenPaymentRequest {
amount,
merchant_account: auth_type.merchant_account,
payment_method,
reference: item.payment_id.to_string(),
return_url,
shopper_interaction,
recurring_processing_model: None,
browser_info: None,
additional_data: None,
telephone_number,
shopper_name,
shopper_email,
shopper_locale: None,
billing_address: None,
delivery_address: None,
country_code: None,
line_items: None,
shopper_reference: None,
store_payment_method: None,
channel: None,
social_security_number: None,
})
}
}
impl TryFrom<&types::PaymentsCancelRouterData> for AdyenCancelRequest {
type Error = Error;
fn try_from(item: &types::PaymentsCancelRouterData) -> Result<Self, Self::Error> {
@ -2845,6 +2920,8 @@ pub fn get_wait_screen_metadata(
| PaymentType::Twint
| PaymentType::Vipps
| PaymentType::Swish
| PaymentType::Knet
| PaymentType::Benefit
| PaymentType::PermataBankTransfer
| PaymentType::BcaBankTransfer
| PaymentType::BniVa
@ -2921,6 +2998,8 @@ pub fn get_present_to_shopper_metadata(
| PaymentType::Klarna
| PaymentType::Kakaopay
| PaymentType::Mbway
| PaymentType::Knet
| PaymentType::Benefit
| PaymentType::MobilePay
| PaymentType::Momo
| PaymentType::OnlineBankingCzechRepublic

View File

@ -300,6 +300,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for BluesnapPaymentsRequest {
| payments::PaymentMethodData::MandatePayment
| payments::PaymentMethodData::Reward(_)
| payments::PaymentMethodData::Upi(_)
| payments::PaymentMethodData::CardRedirect(_)
| payments::PaymentMethodData::Voucher(_)
| payments::PaymentMethodData::GiftCard(_) => {
Err(errors::ConnectorError::NotImplemented(

View File

@ -99,6 +99,7 @@ impl TryFrom<&types::TokenizationRouterData> for TokenRequest {
| api_models::payments::PaymentMethodData::Reward(_)
| api_models::payments::PaymentMethodData::Upi(_)
| api_models::payments::PaymentMethodData::Voucher(_)
| api_models::payments::PaymentMethodData::CardRedirect(_)
| api_models::payments::PaymentMethodData::GiftCard(_) => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("checkout"),
@ -274,6 +275,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentsRequest {
| api_models::payments::PaymentMethodData::Reward(_)
| api_models::payments::PaymentMethodData::Upi(_)
| api_models::payments::PaymentMethodData::Voucher(_)
| api_models::payments::PaymentMethodData::CardRedirect(_)
| api_models::payments::PaymentMethodData::GiftCard(_) => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("checkout"),

View File

@ -724,6 +724,7 @@ impl<F>
| payments::PaymentMethodData::Reward(_)
| payments::PaymentMethodData::Upi(_)
| payments::PaymentMethodData::Voucher(_)
| api_models::payments::PaymentMethodData::CardRedirect(_)
| payments::PaymentMethodData::GiftCard(_) => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("nuvei"),
@ -893,6 +894,7 @@ impl TryFrom<(&types::PaymentsCompleteAuthorizeRouterData, String)> for NuveiPay
| Some(api::PaymentMethodData::MandatePayment)
| Some(api::PaymentMethodData::GiftCard(..))
| Some(api::PaymentMethodData::Voucher(..))
| Some(api::PaymentMethodData::CardRedirect(..))
| Some(api::PaymentMethodData::Reward(..))
| Some(api::PaymentMethodData::Upi(..))
| None => Err(errors::ConnectorError::NotImplemented(

View File

@ -241,6 +241,7 @@ impl TryFrom<&PaymentMethodData> for SalePaymentMethod {
| PaymentMethodData::MandatePayment
| PaymentMethodData::Reward(_)
| PaymentMethodData::GiftCard(_)
| PaymentMethodData::CardRedirect(_)
| PaymentMethodData::Upi(_)
| api::PaymentMethodData::Voucher(_) => {
Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into())

View File

@ -148,6 +148,7 @@ impl TryFrom<&types::TokenizationRouterData> for StaxTokenRequest {
| api::PaymentMethodData::Reward(_)
| api::PaymentMethodData::Voucher(_)
| api::PaymentMethodData::GiftCard(_)
| api::PaymentMethodData::CardRedirect(_)
| api::PaymentMethodData::Upi(_) => Err(errors::ConnectorError::NotImplemented(
"Payment Method".to_string(),
))

View File

@ -612,6 +612,8 @@ impl TryFrom<enums::PaymentMethodType> for StripePaymentMethodType {
| enums::PaymentMethodType::PaySafeCard
| enums::PaymentMethodType::Givex
| enums::PaymentMethodType::Oxxo
| enums::PaymentMethodType::Benefit
| enums::PaymentMethodType::Knet
| enums::PaymentMethodType::Walley => Err(errors::ConnectorError::NotImplemented(
connector_util::get_unimplemented_payment_method_error_message("stripe"),
)
@ -907,6 +909,8 @@ fn infer_stripe_pay_later_type(
| enums::PaymentMethodType::DanamonVa
| enums::PaymentMethodType::Indomaret
| enums::PaymentMethodType::MandiriVa
| enums::PaymentMethodType::Benefit
| enums::PaymentMethodType::Knet
| enums::PaymentMethodType::PermataBankTransfer
| enums::PaymentMethodType::PaySafeCard
| enums::PaymentMethodType::Givex
@ -1417,6 +1421,7 @@ fn create_stripe_payment_method(
| payments::PaymentMethodData::MandatePayment
| payments::PaymentMethodData::Reward(_)
| payments::PaymentMethodData::Upi(_)
| payments::PaymentMethodData::CardRedirect(_)
| payments::PaymentMethodData::Voucher(_)
| payments::PaymentMethodData::GiftCard(_) => Err(errors::ConnectorError::NotImplemented(
connector_util::get_unimplemented_payment_method_error_message("stripe"),
@ -2706,6 +2711,7 @@ impl TryFrom<&types::PaymentsPreProcessingRouterData> for StripeCreditTransferSo
| Some(payments::PaymentMethodData::MandatePayment)
| Some(payments::PaymentMethodData::Upi(..))
| Some(payments::PaymentMethodData::GiftCard(..))
| Some(payments::PaymentMethodData::CardRedirect(..))
| Some(payments::PaymentMethodData::Voucher(..))
| None => Err(errors::ConnectorError::NotImplemented(
connector_util::get_unimplemented_payment_method_error_message("stripe"),
@ -3192,6 +3198,7 @@ impl
| api::PaymentMethodData::Reward(_)
| api::PaymentMethodData::GiftCard(_)
| api::PaymentMethodData::Upi(_)
| api::PaymentMethodData::CardRedirect(_)
| api::PaymentMethodData::Voucher(_) => Err(errors::ConnectorError::NotSupported {
message: format!("{pm_type:?}"),
connector: "Stripe",

View File

@ -90,6 +90,7 @@ fn fetch_payment_instrument(
| api_models::payments::PaymentMethodData::Reward(_)
| api_models::payments::PaymentMethodData::Upi(_)
| api_models::payments::PaymentMethodData::Voucher(_)
| api_models::payments::PaymentMethodData::CardRedirect(_)
| api_models::payments::PaymentMethodData::GiftCard(_) => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("worldpay"),

View File

@ -651,6 +651,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for ZenPaymentsRequest {
| api_models::payments::PaymentMethodData::MandatePayment
| api_models::payments::PaymentMethodData::Reward(_)
| api_models::payments::PaymentMethodData::Upi(_)
| api_models::payments::PaymentMethodData::CardRedirect(_)
| api_models::payments::PaymentMethodData::GiftCard(_) => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("zen"),

View File

@ -1290,6 +1290,7 @@ pub async fn make_pm_data<'a, F: Clone, R>(
(pm @ Some(api::PaymentMethodData::Upi(_)), _) => Ok(pm.to_owned()),
(pm @ Some(api::PaymentMethodData::Voucher(_)), _) => Ok(pm.to_owned()),
(pm @ Some(api::PaymentMethodData::Reward(_)), _) => Ok(pm.to_owned()),
(pm @ Some(api::PaymentMethodData::CardRedirect(_)), _) => Ok(pm.to_owned()),
(pm @ Some(api::PaymentMethodData::GiftCard(_)), _) => Ok(pm.to_owned()),
(pm_opt @ Some(pm @ api::PaymentMethodData::BankTransfer(_)), _) => {
let token = vault::Vault::store_payment_method_data_in_locker(
@ -1578,6 +1579,10 @@ pub fn validate_payment_method_type_against_payment_method(
api_enums::PaymentMethodType::Givex | api_enums::PaymentMethodType::PaySafeCard
)
}
api_enums::PaymentMethod::CardRedirect => matches!(
payment_method_type,
api_enums::PaymentMethodType::Knet | api_enums::PaymentMethodType::Benefit
),
}
}
@ -2839,6 +2844,9 @@ pub async fn get_additional_payment_data(
api_models::payments::PaymentMethodData::Upi(_) => {
api_models::payments::AdditionalPaymentData::Upi {}
}
api_models::payments::PaymentMethodData::CardRedirect(_) => {
api_models::payments::AdditionalPaymentData::CardRedirect {}
}
api_models::payments::PaymentMethodData::Voucher(_) => {
api_models::payments::AdditionalPaymentData::Voucher {}
}

View File

@ -225,6 +225,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::MandateAmountData,
api_models::payments::OnlineMandate,
api_models::payments::Card,
api_models::payments::CardRedirectData,
api_models::payments::CustomerAcceptance,
api_models::payments::PaymentsRequest,
api_models::payments::PaymentsCreateRequest,

View File

@ -237,8 +237,12 @@ impl ForeignFrom<api_enums::PaymentMethodType> for api_enums::PaymentMethod {
| api_enums::PaymentMethodType::DanamonVa
| api_enums::PaymentMethodType::MandiriVa
| api_enums::PaymentMethodType::Pix => Self::BankTransfer,
api_enums::PaymentMethodType::Givex => Self::GiftCard,
api_enums::PaymentMethodType::PaySafeCard => Self::GiftCard,
api_enums::PaymentMethodType::Givex | api_enums::PaymentMethodType::PaySafeCard => {
Self::GiftCard
}
api_enums::PaymentMethodType::Benefit | api_enums::PaymentMethodType::Knet => {
Self::CardRedirect
}
}
}
}
@ -260,6 +264,7 @@ impl ForeignTryFrom<api_models::payments::PaymentMethodData> for api_enums::Paym
api_models::payments::PaymentMethodData::Upi(..) => Ok(Self::Upi),
api_models::payments::PaymentMethodData::Voucher(..) => Ok(Self::Voucher),
api_models::payments::PaymentMethodData::GiftCard(..) => Ok(Self::GiftCard),
api_models::payments::PaymentMethodData::CardRedirect(..) => Ok(Self::CardRedirect),
api_models::payments::PaymentMethodData::MandatePayment => {
Err(errors::ApiErrorResponse::InvalidRequestData {
message: ("Mandate payments cannot have payment_method_data field".to_string()),

View File

@ -3602,6 +3602,32 @@
"Maestro"
]
},
"CardRedirectData": {
"oneOf": [
{
"type": "object",
"required": [
"knet"
],
"properties": {
"knet": {
"type": "object"
}
}
},
{
"type": "object",
"required": [
"benefit"
],
"properties": {
"benefit": {
"type": "object"
}
}
}
]
},
"CashappQr": {
"type": "object"
},
@ -7290,6 +7316,7 @@
"type": "string",
"enum": [
"card",
"card_redirect",
"pay_later",
"wallet",
"bank_redirect",
@ -7373,6 +7400,17 @@
}
}
},
{
"type": "object",
"required": [
"card_redirect"
],
"properties": {
"card_redirect": {
"$ref": "#/components/schemas/CardRedirectData"
}
}
},
{
"type": "object",
"required": [
@ -7681,6 +7719,7 @@
"bacs",
"bancontact_card",
"becs",
"benefit",
"bizum",
"blik",
"boleto",
@ -7709,6 +7748,7 @@
"klarna",
"kakao_pay",
"mandiri_va",
"knet",
"mb_way",
"mobile_pay",
"momo",