Skip to content

Commit

Permalink
fix(mca): Fixed some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak1799 committed Jul 15, 2024
1 parent cc1fba3 commit 6d50f73
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 64 deletions.
72 changes: 12 additions & 60 deletions crates/router/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,65 +606,6 @@ pub struct ResponseRouterData<Flow, R, Request, Response> {
pub http_code: u16,
}

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub enum MerchantAccountDataResponse {
Iban {
iban: Secret<String>,
name: String,
#[serde(skip_serializing_if = "Option::is_none")]
connector_recipient_id: Option<Secret<String>>,
},
Bacs {
account_number: Secret<String>,
sort_code: Secret<String>,
name: String,
#[serde(skip_serializing_if = "Option::is_none")]
connector_recipient_id: Option<Secret<String>>,
},
}

impl From<MerchantAccountData> 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<String>),
Expand All @@ -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<String>,
Expand Down Expand Up @@ -798,6 +738,18 @@ impl ForeignFrom<api_models::admin::AdditionalMerchantData> for AdditionalMercha
}
}

impl ForeignFrom<AdditionalMerchantData> 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<api_models::admin::ConnectorAuthType> for ConnectorAuthType {
fn foreign_from(value: api_models::admin::ConnectorAuthType) -> Self {
match value {
Expand Down
13 changes: 9 additions & 4 deletions crates/router/src/types/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -981,11 +982,15 @@ impl TryFrom<domain::MerchantConnectorAccount> 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::<router_types::AdditionalMerchantData>(
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),
})
}
}
Expand Down

0 comments on commit 6d50f73

Please sign in to comment.