diff --git a/crates/router/src/connector/rapyd/transformers.rs b/crates/router/src/connector/rapyd/transformers.rs index 3eb8926f21..a34a345b57 100644 --- a/crates/router/src/connector/rapyd/transformers.rs +++ b/crates/router/src/connector/rapyd/transformers.rs @@ -11,6 +11,7 @@ use crate::{ storage::enums, transformers::{self, ForeignFrom}, }, + utils::OptionExt, }; #[derive(Default, Debug, Serialize)] @@ -18,8 +19,9 @@ pub struct RapydPaymentsRequest { pub amount: i64, pub currency: enums::Currency, pub payment_method: PaymentMethod, - pub payment_method_options: PaymentMethodOptions, - pub capture: bool, + pub payment_method_options: Option, + pub capture: Option, + pub description: Option, } #[derive(Default, Debug, Serialize)] @@ -31,7 +33,9 @@ pub struct PaymentMethodOptions { pub struct PaymentMethod { #[serde(rename = "type")] pub pm_type: String, - pub fields: PaymentFields, + pub fields: Option, + pub address: Option
, + pub digital_wallet: Option, } #[derive(Default, Debug, Serialize)] @@ -43,38 +47,94 @@ pub struct PaymentFields { pub cvv: Secret, } +#[derive(Default, Debug, Serialize)] +pub struct Address { + name: String, + line_1: String, + line_2: Option, + line_3: Option, + city: Option, + state: Option, + country: Option, + zip: Option, + phone_number: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct RapydWallet { + #[serde(rename = "type")] + payment_type: String, + #[serde(rename = "details")] + apple_pay_token: Option, +} + impl TryFrom<&types::PaymentsAuthorizeRouterData> for RapydPaymentsRequest { type Error = error_stack::Report; fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result { - match item.request.payment_method_data { + let (capture, payment_method_options) = match item.payment_method { + storage_models::enums::PaymentMethodType::Card => { + let three_ds_enabled = matches!(item.auth_type, enums::AuthenticationType::ThreeDs); + let payment_method_options = PaymentMethodOptions { + three_ds: three_ds_enabled, + }; + ( + Some(matches!( + item.request.capture_method, + Some(enums::CaptureMethod::Automatic) | None + )), + Some(payment_method_options), + ) + } + _ => (None, None), + }; + let payment_method = match item.request.payment_method_data { api_models::payments::PaymentMethod::Card(ref ccard) => { - let payment_method = PaymentMethod { + Some(PaymentMethod { pm_type: "in_amex_card".to_owned(), //[#369] Map payment method type based on country - fields: PaymentFields { + fields: Some(PaymentFields { number: ccard.card_number.to_owned(), expiration_month: ccard.card_exp_month.to_owned(), expiration_year: ccard.card_exp_year.to_owned(), name: ccard.card_holder_name.to_owned(), cvv: ccard.card_cvc.to_owned(), - }, - }; - let three_ds_enabled = matches!(item.auth_type, enums::AuthenticationType::ThreeDs); - let payment_method_options = PaymentMethodOptions { - three_ds: three_ds_enabled, - }; - Ok(Self { - amount: item.request.amount, - currency: item.request.currency, - payment_method, - capture: matches!( - item.request.capture_method, - Some(enums::CaptureMethod::Automatic) | None - ), - payment_method_options, + }), + address: None, + digital_wallet: None, }) } - _ => Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into()), + api_models::payments::PaymentMethod::Wallet(ref wallet_data) => { + let digital_wallet = match wallet_data.issuer_name { + api_models::enums::WalletIssuer::GooglePay => Some(RapydWallet { + payment_type: "google_pay".to_string(), + apple_pay_token: wallet_data.token.to_owned(), + }), + api_models::enums::WalletIssuer::ApplePay => Some(RapydWallet { + payment_type: "apple_pay".to_string(), + apple_pay_token: wallet_data.token.to_owned(), + }), + _ => None, + }; + Some(PaymentMethod { + pm_type: "by_visa_card".to_string(), //[#369] + fields: None, + address: None, + digital_wallet, + }) + } + _ => None, } + .get_required_value("payment_method not implemnted") + .change_context(errors::ConnectorError::NotImplemented( + "payment_method".to_owned(), + ))?; + Ok(Self { + amount: item.request.amount, + currency: item.request.currency, + payment_method, + capture, + payment_method_options, + description: None, + }) } }