From 6d50f731cdb690df4f822cfdbfb18e2df019a317 Mon Sep 17 00:00:00 2001 From: Sarthak Soni Date: Mon, 15 Jul 2024 19:14:43 +0530 Subject: [PATCH] fix(mca): Fixed some errors --- crates/router/src/types.rs | 72 +++++-------------------- crates/router/src/types/transformers.rs | 13 +++-- 2 files changed, 21 insertions(+), 64 deletions(-) diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 42b5fe6e9f15..cc735612ac3b 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -606,65 +606,6 @@ pub struct ResponseRouterData { pub http_code: u16, } -#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] -#[serde(rename_all = "snake_case")] -pub enum MerchantAccountDataResponse { - Iban { - iban: Secret, - name: String, - #[serde(skip_serializing_if = "Option::is_none")] - connector_recipient_id: Option>, - }, - Bacs { - account_number: Secret, - sort_code: Secret, - name: String, - #[serde(skip_serializing_if = "Option::is_none")] - connector_recipient_id: Option>, - }, -} - -impl From for MerchantAccountDataResponse { - fn from(value: MerchantAccountData) -> Self { - match value { - MerchantAccountData::Bacs { - account_number, - sort_code, - name, - connector_recipient_id, - } => Self::Bacs { - account_number, - sort_code, - name, - connector_recipient_id: if let Some(conn) = connector_recipient_id { - match conn { - RecipientIdType::ConnectorId(id) => Some(id), - RecipientIdType::LockerId(_id) => None, - } - } else { - None - }, - }, - MerchantAccountData::Iban { - iban, - name, - connector_recipient_id, - } => Self::Iban { - iban, - name, - connector_recipient_id: if let Some(conn) = connector_recipient_id { - match conn { - RecipientIdType::ConnectorId(id) => Some(id), - RecipientIdType::LockerId(_id) => None, - } - } else { - None - }, - }, - } - } -} - #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] pub enum RecipientIdType { ConnectorId(Secret), @@ -673,7 +614,6 @@ pub enum RecipientIdType { #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "snake_case")] -#[serde(into = "MerchantAccountDataResponse")] pub enum MerchantAccountData { Iban { iban: Secret, @@ -798,6 +738,18 @@ impl ForeignFrom for AdditionalMercha } } +impl ForeignFrom for api_models::admin::AdditionalMerchantData { + fn foreign_from(value: AdditionalMerchantData) -> Self { + match value { + AdditionalMerchantData::OpenBankingRecipientData(data) => { + Self::OpenBankingRecipientData( + api_models::admin::MerchantRecipientData::foreign_from(data), + ) + } + } + } +} + impl ForeignFrom for ConnectorAuthType { fn foreign_from(value: api_models::admin::ConnectorAuthType) -> Self { match value { diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs index 89df41ebf0bc..d1f01ac8ef76 100644 --- a/crates/router/src/types/transformers.rs +++ b/crates/router/src/types/transformers.rs @@ -26,6 +26,7 @@ use crate::{ }, services::authentication::get_header_value_by_key, types::{ + self as router_types, api::{self as api_types, routing as routing_types}, storage, }, @@ -981,11 +982,15 @@ impl TryFrom for api_models::admin::MerchantCo .additional_merchant_data .map(|data| { let data = data.into_inner(); - serde_json::Value::parse_value(data.expose(), "AdditionalMerchantData") - .attach_printable("Unable to deserialize additional_merchant_data") - .change_context(errors::ApiErrorResponse::InternalServerError) + serde_json::Value::parse_value::( + data.expose(), + "AdditionalMerchantData", + ) + .attach_printable("Unable to deserialize additional_merchant_data") + .change_context(errors::ApiErrorResponse::InternalServerError) }) - .transpose()?, + .transpose()? + .map(api_models::admin::AdditionalMerchantData::foreign_from), }) } }