From c22be0c9274350a531cd74b64eb6b311579dca79 Mon Sep 17 00:00:00 2001 From: Debarati Ghatak <88573135+cookieg13@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:01:20 +0530 Subject: [PATCH] feat(connector): [Adyen ] Add fixes for AdyenPaymentRequest struct (#6803) --- .../src/connector/adyen/transformers.rs | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rs index 16cab2fda470..7aaf9b5e2bb2 100644 --- a/crates/router/src/connector/adyen/transformers.rs +++ b/crates/router/src/connector/adyen/transformers.rs @@ -89,6 +89,7 @@ pub enum AuthType { #[default] PreAuth, } +#[serde_with::skip_serializing_none] #[derive(Clone, Default, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct AdditionalData { @@ -107,6 +108,7 @@ pub struct AdditionalData { funds_availability: Option, } +#[serde_with::skip_serializing_none] #[derive(Default, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ShopperName { @@ -114,6 +116,7 @@ pub struct ShopperName { last_name: Option>, } +#[serde_with::skip_serializing_none] #[derive(Default, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Address { @@ -122,9 +125,10 @@ pub struct Address { house_number_or_name: Secret, postal_code: Secret, state_or_province: Option>, - street: Secret, + street: Option>, } +#[serde_with::skip_serializing_none] #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct LineItem { @@ -143,7 +147,6 @@ pub struct AdyenPaymentRequest<'a> { amount: Amount, merchant_account: Secret, payment_method: AdyenPaymentMethod<'a>, - #[serde(skip_serializing_if = "Option::is_none")] mpi_data: Option, reference: String, return_url: String, @@ -170,13 +173,13 @@ pub struct AdyenPaymentRequest<'a> { merchant_order_reference: Option, } +#[serde_with::skip_serializing_none] #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] struct AdyenMpiData { directory_response: String, authentication_response: String, token_authentication_verification_value: Secret, - #[serde(skip_serializing_if = "Option::is_none")] eci: Option, } @@ -500,7 +503,7 @@ pub struct Amount { } #[derive(Debug, Clone, Serialize)] -#[serde(tag = "type")] +#[serde(untagged)] #[serde(rename_all = "lowercase")] pub enum AdyenPaymentMethod<'a> { AdyenAffirm(Box), @@ -1088,6 +1091,7 @@ pub struct BlikRedirectionData { blik_code: Secret, } +#[serde_with::skip_serializing_none] #[derive(Debug, Clone, Serialize)] #[serde(rename_all = "camelCase")] pub struct BankRedirectionWithIssuer<'a> { @@ -1104,6 +1108,7 @@ pub struct AdyenMandate { stored_payment_method_id: Secret, } +#[serde_with::skip_serializing_none] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct AdyenCard { @@ -1211,6 +1216,7 @@ pub struct AdyenApplePay { apple_pay_token: Secret, } +#[serde_with::skip_serializing_none] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct DokuBankData { @@ -1219,6 +1225,7 @@ pub struct DokuBankData { shopper_email: Email, } // Refunds Request and Response +#[serde_with::skip_serializing_none] #[derive(Default, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct AdyenRefundRequest { @@ -1726,16 +1733,22 @@ fn get_additional_data(item: &types::PaymentsAuthorizeRouterData) -> Option additionalData: {} + //returning None, ensures that additionalData key will not be present in the serialized JSON + None + } else { + Some(AdditionalData { + authorisation_type, + manual_capture, + execute_three_d, + network_tx_reference: None, + recurring_detail_reference: None, + recurring_shopper_reference: None, + recurring_processing_model: None, + ..AdditionalData::default() + }) + } } fn get_channel_type(pm_type: Option) -> Option { @@ -1766,7 +1779,7 @@ pub fn get_address_info( house_number_or_name: a.get_line1()?.to_owned(), postal_code: a.get_zip()?.to_owned(), state_or_province: a.state.clone(), - street: a.get_line2()?.to_owned(), + street: a.get_optional_line2().to_owned(), }) }, )