Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(connector): [Mifinity]Move destination_account_number from pmd to Mifinity Metadata #4962

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -11802,13 +11802,9 @@
"MifinityData": {
"type": "object",
"required": [
"destination_account_number",
"date_of_birth"
],
"properties": {
"destination_account_number": {
"type": "string"
},
"date_of_birth": {
"type": "string",
"format": "date"
Expand Down
2 changes: 0 additions & 2 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2580,8 +2580,6 @@ pub struct SwishQrData {}

#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct MifinityData {
#[schema(value_type = String)]
pub destination_account_number: Secret<String>,
#[schema(value_type = Date)]
pub date_of_birth: Secret<Date>,
}
Expand Down
2 changes: 2 additions & 0 deletions crates/connector_configs/src/common_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub struct ApiModelMetaData {
pub klarna_region: Option<KlarnaEndpoint>,
pub source_balance_account: Option<String>,
pub brand_id: Option<String>,
pub destination_account_number: Option<String>,
}

#[serde_with::skip_serializing_none]
Expand Down Expand Up @@ -217,4 +218,5 @@ pub struct DashboardMetaData {
pub klarna_region: Option<KlarnaEndpoint>,
pub source_balance_account: Option<String>,
pub brand_id: Option<String>,
pub destination_account_number: Option<String>,
}
1 change: 1 addition & 0 deletions crates/connector_configs/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub struct ConfigMetadata {
pub klarna_region: Option<Vec<KlarnaEndpoint>>,
pub source_balance_account: Option<String>,
pub brand_id: Option<String>,
pub destination_account_number: Option<String>,
}

#[serde_with::skip_serializing_none]
Expand Down
1 change: 1 addition & 0 deletions crates/connector_configs/src/response_modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ impl From<ApiModelMetaData> for DashboardMetaData {
klarna_region: api_model.klarna_region,
source_balance_account: api_model.source_balance_account,
brand_id: api_model.brand_id,
destination_account_number: api_model.destination_account_number,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/connector_configs/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ impl DashboardRequestPayload {
klarna_region: None,
source_balance_account: None,
brand_id: None,
destination_account_number: None,
};
let meta_data = match request.metadata {
Some(data) => data,
Expand Down Expand Up @@ -231,6 +232,7 @@ impl DashboardRequestPayload {
let klarna_region = meta_data.klarna_region;
let source_balance_account = meta_data.source_balance_account;
let brand_id = meta_data.brand_id;
let destination_account_number = meta_data.destination_account_number;

Some(ApiModelMetaData {
google_pay,
Expand All @@ -255,6 +257,7 @@ impl DashboardRequestPayload {
klarna_region,
source_balance_account,
brand_id,
destination_account_number,
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/connector_configs/toml/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@ klarna_region=["Europe","NorthAmerica","Oceania"]
api_key="key"
[mifinity.metadata]
brand_id="Brand ID"
destination_account_number="Destination Account Number"

[mollie]
[[mollie.credit]]
Expand Down
1 change: 1 addition & 0 deletions crates/connector_configs/toml/production.toml
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ klarna_region=["Europe","NorthAmerica","Oceania"]
api_key="key"
[mifinity.metadata]
brand_id="Brand ID"
destination_account_number="Destination Account Number"


[mollie]
Expand Down
1 change: 1 addition & 0 deletions crates/connector_configs/toml/sandbox.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@ klarna_region=["Europe","NorthAmerica","Oceania"]
api_key="key"
[mifinity.metadata]
brand_id="Brand ID"
destination_account_number="Destination Account Number"

[mollie]
[[mollie.credit]]
Expand Down
2 changes: 0 additions & 2 deletions crates/hyperswitch_domain_models/src/payment_method_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ pub enum WalletData {

#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct MifinityData {
pub destination_account_number: Secret<String>,
pub date_of_birth: Secret<Date>,
}

Expand Down Expand Up @@ -594,7 +593,6 @@ impl From<api_models::payments::WalletData> for WalletData {
api_models::payments::WalletData::SwishQr(_) => Self::SwishQr(SwishQrData {}),
api_models::payments::WalletData::Mifinity(mifinity_data) => {
Self::Mifinity(MifinityData {
destination_account_number: mifinity_data.destination_account_number,
date_of_birth: mifinity_data.date_of_birth,
})
}
Expand Down
23 changes: 10 additions & 13 deletions crates/router/src/connector/mifinity/transformers.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use common_utils::pii::{self, Email};
use error_stack::ResultExt;
use masking::{ExposeInterface, Secret};
use masking::Secret;
use serde::{Deserialize, Serialize};
use time::Date;

use crate::{
connector::utils::{self, PaymentsAuthorizeRequestData, PhoneDetailsData, RouterData},
core::errors::{self, CustomResult},
core::errors,
services,
types::{self, api, domain, storage::enums},
};
Expand Down Expand Up @@ -36,6 +36,7 @@ pub mod auth_headers {
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct MifinityConnectorMetadataObject {
pub brand_id: Secret<String>,
pub destination_account_number: Secret<String>,
}

impl TryFrom<&Option<pii::SecretSerdeValue>> for MifinityConnectorMetadataObject {
Expand All @@ -49,14 +50,6 @@ impl TryFrom<&Option<pii::SecretSerdeValue>> for MifinityConnectorMetadataObject
}
}

fn get_brand_id(
connector_metadata: &Option<pii::SecretSerdeValue>,
) -> CustomResult<String, errors::ConnectorError> {
let mifinity_metadata = MifinityConnectorMetadataObject::try_from(connector_metadata)?;
let brand_id = mifinity_metadata.brand_id.clone().expose();
Ok(brand_id)
}

#[derive(Debug, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct MifinityPaymentsRequest {
Expand Down Expand Up @@ -103,6 +96,11 @@ impl TryFrom<&MifinityRouterData<&types::PaymentsAuthorizeRouterData>> for Mifin
fn try_from(
item: &MifinityRouterData<&types::PaymentsAuthorizeRouterData>,
) -> Result<Self, Self::Error> {
let metadata: MifinityConnectorMetadataObject =
utils::to_connector_meta_from_secret(item.router_data.connector_meta_data.clone())
.change_context(errors::ConnectorError::InvalidConnectorConfig {
config: "merchant_connector_account.metadata",
})?;
match item.router_data.request.payment_method_data.clone() {
domain::PaymentMethodData::Wallet(wallet_data) => match wallet_data {
domain::WalletData::Mifinity(data) => {
Expand Down Expand Up @@ -135,10 +133,9 @@ impl TryFrom<&MifinityRouterData<&types::PaymentsAuthorizeRouterData>> for Mifin
field_name: "client_reference",
},
)?;
let destination_account_number = data.destination_account_number;
let destination_account_number = metadata.destination_account_number;
let trace_id = item.router_data.connector_request_reference_id.clone();
let brand_id =
Secret::new(get_brand_id(&item.router_data.connector_meta_data)?);
let brand_id = metadata.brand_id;
Ok(Self {
money,
client,
Expand Down
Loading