Skip to content

Commit

Permalink
fix(mca): Resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak1799 committed Jul 11, 2024
1 parent f1affe5 commit d177e87
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 58 deletions.
18 changes: 6 additions & 12 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,15 +655,7 @@ pub struct MerchantConnectorCreate {

/// In case the merchant needs to store any additional sensitive data
#[schema(value_type = Option<AdditionalMerchantData>)]
pub additional_merchant_data: Option<pii::SecretSerdeValue>,
}

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
pub enum RecipientIdType {
#[schema(value_type= String)]
ConnectorId(Secret<String>),
#[schema(value_type= String)]
LockerId(Secret<String>),
pub additional_merchant_data: Option<AdditionalMerchantData>,
}

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
Expand All @@ -673,24 +665,26 @@ pub enum AdditionalMerchantData {
}

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

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum MerchantRecipientData {
#[schema(value_type= Option<String>)]
ConnectorRecipientId(Secret<String>),
Expand Down Expand Up @@ -852,7 +846,7 @@ pub struct MerchantConnectorResponse {
pub status: api_enums::ConnectorStatus,

#[schema(value_type = Option<AdditionalMerchantData>)]
pub additional_merchant_data: Option<pii::SecretSerdeValue>,
pub additional_merchant_data: Option<AdditionalMerchantData>,
}

/// Create a new Merchant Connector for the merchant account. The connector could be a payment processor / facilitator / acquirer or specialized services like Fraud / Accounting etc."
Expand Down
1 change: 0 additions & 1 deletion crates/openapi/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::admin::AdditionalMerchantData,
api_models::admin::MerchantRecipientData,
api_models::admin::MerchantAccountData,
api_models::admin::RecipientIdType,
api_models::admin::MerchantConnectorUpdate,
api_models::admin::PrimaryBusinessDetails,
api_models::admin::FrmConfigs,
Expand Down
41 changes: 21 additions & 20 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use common_utils::{
use diesel_models::configs;
use error_stack::{report, FutureExt, ResultExt};
use futures::future::try_join_all;
use masking::{ExposeInterface, PeekInterface, Secret};
use masking::{PeekInterface, Secret};
use pm_auth::{connector::plaid::transformers::PlaidAuthType, types as pm_auth_types};
use regex::Regex;
use router_env::metrics::add_attributes;
Expand Down Expand Up @@ -1173,14 +1173,18 @@ pub async fn create_payment_connector(
&auth,
&req.connector_type,
&req.connector_name,
data.clone(),
types::AdditionalMerchantData::foreign_from(data.clone()),
)
.await?,
)
} else {
None
}
.map(serde_json::to_value)
.map(|data| {
serde_json::to_value(types::AdditionalMerchantData::OpenBankingRecipientData(
data,
))
})
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to get MerchantRecipientData")?;
Expand Down Expand Up @@ -2597,24 +2601,18 @@ async fn process_open_banking_connectors(
auth: &types::ConnectorAuthType,
connector_type: &api_enums::ConnectorType,
connector: &api_enums::Connector,
merchant_data: Secret<serde_json::Value>,
additional_merchant_data: types::AdditionalMerchantData,
) -> RouterResult<types::MerchantRecipientData> {
// incorporate a connector check as well
if connector_type != &api_enums::ConnectorType::PaymentProcessor {
return Err(errors::ApiErrorResponse::InvalidConnectorConfiguration {
config: "OpenBanking connector for Payment Initiation should be a payment processor"
.to_string(),
}
.into());
}

let additional_merchant_data =
serde_json::from_value::<types::AdditionalMerchantData>(merchant_data.expose())
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("failed to decode MerchantRecipientData")?;

let new_merchant_data = match additional_merchant_data {
types::AdditionalMerchantData::OpenBankingRecipientData(merchant_data) => {
if connector_type != &api_enums::ConnectorType::PaymentProcessor {
return Err(errors::ApiErrorResponse::InvalidConnectorConfiguration {
config:
"OpenBanking connector for Payment Initiation should be a payment processor"
.to_string(),
}
.into());
}
match &merchant_data {
types::MerchantRecipientData::AccountData(acc_data) => {
validate_bank_account_data(acc_data)?;
Expand Down Expand Up @@ -2811,8 +2809,11 @@ async fn connector_recipient_create_call(
merchant_id: Some(merchant_id.to_owned()),
connector: Some(connector_name),
request: req,
response: Ok(pm_auth_types::RecipientCreateResponse {
recipient_id: "".to_string(),
response: Err(pm_auth_types::ErrorResponse {
status_code: http::StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
code: consts::NO_ERROR_CODE.to_string(),
message: consts::UNSUPPORTED_ERROR_MESSAGE.to_string(),
reason: None,
}),
connector_http_status_code: None,
connector_auth_type: auth,
Expand Down
44 changes: 20 additions & 24 deletions crates/router/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,24 +688,6 @@ pub enum MerchantAccountData {
},
}

impl ForeignFrom<RecipientIdType> for api_models::admin::RecipientIdType {
fn foreign_from(from: RecipientIdType) -> Self {
match from {
RecipientIdType::ConnectorId(id) => Self::ConnectorId(id),
RecipientIdType::LockerId(id) => Self::LockerId(id),
}
}
}

impl From<api_models::admin::RecipientIdType> for RecipientIdType {
fn from(from: api_models::admin::RecipientIdType) -> Self {
match from {
api_models::admin::RecipientIdType::ConnectorId(id) => Self::ConnectorId(id),
api_models::admin::RecipientIdType::LockerId(id) => Self::LockerId(id),
}
}
}

impl ForeignFrom<MerchantAccountData> for api_models::admin::MerchantAccountData {
fn foreign_from(from: MerchantAccountData) -> Self {
match from {
Expand All @@ -716,8 +698,10 @@ impl ForeignFrom<MerchantAccountData> for api_models::admin::MerchantAccountData
} => Self::Iban {
iban,
name,
connector_recipient_id: connector_recipient_id
.map(api_models::admin::RecipientIdType::foreign_from),
connector_recipient_id: match connector_recipient_id {
Some(RecipientIdType::ConnectorId(id)) => Some(id.clone()),
_ => None,
},
},
MerchantAccountData::Bacs {
account_number,
Expand All @@ -728,8 +712,10 @@ impl ForeignFrom<MerchantAccountData> for api_models::admin::MerchantAccountData
account_number,
sort_code,
name,
connector_recipient_id: connector_recipient_id
.map(api_models::admin::RecipientIdType::foreign_from),
connector_recipient_id: match connector_recipient_id {
Some(RecipientIdType::ConnectorId(id)) => Some(id.clone()),
_ => None,
},
},
}
}
Expand All @@ -745,7 +731,7 @@ impl From<api_models::admin::MerchantAccountData> for MerchantAccountData {
} => Self::Iban {
iban,
name,
connector_recipient_id: connector_recipient_id.map(RecipientIdType::from),
connector_recipient_id: connector_recipient_id.map(RecipientIdType::ConnectorId),
},
api_models::admin::MerchantAccountData::Bacs {
account_number,
Expand All @@ -756,7 +742,7 @@ impl From<api_models::admin::MerchantAccountData> for MerchantAccountData {
account_number,
sort_code,
name,
connector_recipient_id: connector_recipient_id.map(RecipientIdType::from),
connector_recipient_id: connector_recipient_id.map(RecipientIdType::ConnectorId),
},
}
}
Expand Down Expand Up @@ -802,6 +788,16 @@ pub enum AdditionalMerchantData {
OpenBankingRecipientData(MerchantRecipientData),
}

impl ForeignFrom<api_models::admin::AdditionalMerchantData> for AdditionalMerchantData {
fn foreign_from(value: api_models::admin::AdditionalMerchantData) -> Self {
match value {
api_models::admin::AdditionalMerchantData::OpenBankingRecipientData(data) => {
Self::OpenBankingRecipientData(MerchantRecipientData::from(data))
}
}
}
}

impl ForeignFrom<api_models::admin::ConnectorAuthType> for ConnectorAuthType {
fn foreign_from(value: api_models::admin::ConnectorAuthType) -> Self {
match value {
Expand Down
10 changes: 9 additions & 1 deletion crates/router/src/types/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,15 @@ impl TryFrom<domain::MerchantConnectorAccount> for api_models::admin::MerchantCo
applepay_verified_domains: item.applepay_verified_domains,
pm_auth_config: item.pm_auth_config,
status: item.status,
additional_merchant_data: item.additional_merchant_data.map(|data| data.into_inner()),
additional_merchant_data: item
.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)
})
.transpose()?,
})
}
}
Expand Down

0 comments on commit d177e87

Please sign in to comment.