Skip to content
New issue

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

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

Already on GitHub? # to your account

refactor(open_banking): Added merchant data update in mca update #5655

Merged
merged 4 commits into from
Aug 27, 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
8 changes: 8 additions & 0 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -7766,6 +7766,14 @@
"example": "y3oqhf46pyzuxjbcn2giaqnb44",
"maxLength": 64,
"minLength": 1
},
"additional_merchant_data": {
"allOf": [
{
"$ref": "#/components/schemas/AdditionalMerchantData"
}
],
"nullable": true
}
},
"additionalProperties": false
Expand Down
8 changes: 8 additions & 0 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -12598,6 +12598,14 @@
},
"status": {
"$ref": "#/components/schemas/ConnectorStatus"
},
"additional_merchant_data": {
"allOf": [
{
"$ref": "#/components/schemas/AdditionalMerchantData"
}
],
"nullable": true
}
},
"additionalProperties": false
Expand Down
8 changes: 8 additions & 0 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,10 @@ pub struct MerchantConnectorUpdate {

#[schema(value_type = ConnectorStatus, example = "inactive")]
pub status: Option<api_enums::ConnectorStatus>,

/// In case the merchant needs to store any additional sensitive data
#[schema(value_type = Option<AdditionalMerchantData>)]
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 Expand Up @@ -1636,6 +1640,10 @@ pub struct MerchantConnectorUpdate {
/// The identifier for the Merchant Account
#[schema(value_type = String, max_length = 64, min_length = 1, example = "y3oqhf46pyzuxjbcn2giaqnb44")]
pub merchant_id: id_type::MerchantId,

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

#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
Expand Down
2 changes: 2 additions & 0 deletions crates/diesel_models/src/merchant_connector_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ pub struct MerchantConnectorAccountUpdateInternal {
pub pm_auth_config: Option<pii::SecretSerdeValue>,
pub status: Option<storage_enums::ConnectorStatus>,
pub connector_wallets_details: Option<Encryption>,
pub additional_merchant_data: Option<Encryption>,
}

#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
Expand All @@ -224,6 +225,7 @@ pub struct MerchantConnectorAccountUpdateInternal {
pub pm_auth_config: Option<pii::SecretSerdeValue>,
pub status: Option<storage_enums::ConnectorStatus>,
pub connector_wallets_details: Option<Encryption>,
pub additional_merchant_data: Option<Encryption>,
}

#[cfg(all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub enum MerchantConnectorAccountUpdate {
connector_label: Option<String>,
status: Option<enums::ConnectorStatus>,
connector_wallets_details: Option<Encryptable<pii::SecretSerdeValue>>,
additional_merchant_data: Option<Encryptable<pii::SecretSerdeValue>>,
},
ConnectorWalletDetailsUpdate {
connector_wallets_details: Encryptable<pii::SecretSerdeValue>,
Expand All @@ -131,6 +132,7 @@ pub enum MerchantConnectorAccountUpdate {
connector_label: Option<String>,
status: Option<enums::ConnectorStatus>,
connector_wallets_details: Option<Encryptable<pii::SecretSerdeValue>>,
additional_merchant_data: Option<Encryptable<pii::SecretSerdeValue>>,
},
ConnectorWalletDetailsUpdate {
connector_wallets_details: Encryptable<pii::SecretSerdeValue>,
Expand Down Expand Up @@ -453,6 +455,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInte
connector_label,
status,
connector_wallets_details,
additional_merchant_data,
} => Self {
connector_type,
connector_name,
Expand All @@ -471,6 +474,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInte
connector_label,
status,
connector_wallets_details: connector_wallets_details.map(Encryption::from),
additional_merchant_data: additional_merchant_data.map(Encryption::from),
},
MerchantConnectorAccountUpdate::ConnectorWalletDetailsUpdate {
connector_wallets_details,
Expand All @@ -492,6 +496,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInte
applepay_verified_domains: None,
pm_auth_config: None,
status: None,
additional_merchant_data: None,
},
}
}
Expand All @@ -514,6 +519,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInte
connector_label,
status,
connector_wallets_details,
additional_merchant_data,
} => Self {
connector_type,
connector_account_details: connector_account_details.map(Encryption::from),
Expand All @@ -528,6 +534,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInte
connector_label,
status,
connector_wallets_details: connector_wallets_details.map(Encryption::from),
additional_merchant_data: additional_merchant_data.map(Encryption::from),
},
MerchantConnectorAccountUpdate::ConnectorWalletDetailsUpdate {
connector_wallets_details,
Expand All @@ -545,6 +552,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInte
applepay_verified_domains: None,
pm_auth_config: None,
status: None,
additional_merchant_data: None,
},
}
}
Expand Down
88 changes: 85 additions & 3 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,30 @@ impl MerchantConnectorAccountUpdateBridge for api_models::admin::MerchantConnect

pm_auth_config_validation.validate_pm_auth_config().await?;

let merchant_recipient_data = if let Some(data) = &self.additional_merchant_data {
Some(
process_open_banking_connectors(
state,
merchant_account.get_id(),
&auth,
&self.connector_type,
&connector_enum,
types::AdditionalMerchantData::foreign_from(data.clone()),
)
.await?,
)
} else {
None
}
Sarthak1799 marked this conversation as resolved.
Show resolved Hide resolved
.map(|data| {
serde_json::to_value(types::AdditionalMerchantData::OpenBankingRecipientData(
data,
))
})
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to serialize MerchantRecipientData")?;

Ok(storage::MerchantConnectorAccountUpdate::Update {
connector_type: Some(self.connector_type),
connector_label: self.connector_label.clone(),
Expand Down Expand Up @@ -2061,6 +2085,23 @@ impl MerchantConnectorAccountUpdateBridge for api_models::admin::MerchantConnect
applepay_verified_domains: None,
pm_auth_config: self.pm_auth_config,
status: Some(connector_status),
additional_merchant_data: if let Some(mcd) = merchant_recipient_data {
Some(
domain_types::crypto_operation(
key_manager_state,
type_name!(domain::MerchantConnectorAccount),
domain_types::CryptoOperation::Encrypt(Secret::new(mcd)),
km_types::Identifier::Merchant(key_store.merchant_id.clone()),
key_store.key.peek(),
)
.await
.and_then(|val| val.try_into_operation())
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to encrypt additional_merchant_data")?,
)
} else {
None
},
connector_wallets_details: helpers::get_encrypted_apple_pay_connector_wallets_details(
state, &key_store, &metadata,
)
Expand Down Expand Up @@ -2163,6 +2204,30 @@ impl MerchantConnectorAccountUpdateBridge for api_models::admin::MerchantConnect
}
}

let merchant_recipient_data = if let Some(data) = &self.additional_merchant_data {
Some(
process_open_banking_connectors(
state,
merchant_account.get_id(),
&auth,
&self.connector_type,
&connector_enum,
types::AdditionalMerchantData::foreign_from(data.clone()),
)
.await?,
)
} else {
None
}
.map(|data| {
serde_json::to_value(types::AdditionalMerchantData::OpenBankingRecipientData(
data,
))
})
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to serialize MerchantRecipientData")?;

Ok(storage::MerchantConnectorAccountUpdate::Update {
connector_type: Some(self.connector_type),
connector_name: None,
Expand Down Expand Up @@ -2200,6 +2265,23 @@ impl MerchantConnectorAccountUpdateBridge for api_models::admin::MerchantConnect
applepay_verified_domains: None,
pm_auth_config: self.pm_auth_config,
status: Some(connector_status),
additional_merchant_data: if let Some(mcd) = merchant_recipient_data {
Some(
domain_types::crypto_operation(
key_manager_state,
type_name!(domain::MerchantConnectorAccount),
domain_types::CryptoOperation::Encrypt(Secret::new(mcd)),
km_types::Identifier::Merchant(key_store.merchant_id.clone()),
key_store.key.peek(),
)
.await
.and_then(|val| val.try_into_operation())
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to encrypt additional_merchant_data")?,
)
} else {
None
},
connector_wallets_details: helpers::get_encrypted_apple_pay_connector_wallets_details(
state, &key_store, &metadata,
)
Expand Down Expand Up @@ -2297,7 +2379,7 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {
})
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to get MerchantRecipientData")?;
.attach_printable("Failed to serialize MerchantRecipientData")?;
Ok(domain::MerchantConnectorAccount {
merchant_id: business_profile.merchant_id.clone(),
connector_type: self.connector_type,
Expand Down Expand Up @@ -2346,7 +2428,7 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {
key_manager_state,
type_name!(domain::MerchantConnectorAccount),
domain_types::CryptoOperation::Encrypt(Secret::new(mcd)),
identifier,
km_types::Identifier::Merchant(key_store.merchant_id.clone()),
key_store.key.peek(),
)
.await
Expand Down Expand Up @@ -2463,7 +2545,7 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {
})
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to get MerchantRecipientData")?;
.attach_printable("Failed to serialize MerchantRecipientData")?;
Ok(domain::MerchantConnectorAccount {
merchant_id: business_profile.merchant_id.clone(),
connector_type: self.connector_type,
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/connector_onboarding/paypal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pub async fn update_mca(
connector_webhook_details: None,
pm_auth_config: None,
test_mode: None,
additional_merchant_data: None,
};
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
let request = MerchantConnectorUpdate {
Expand All @@ -178,6 +179,7 @@ pub async fn update_mca(
connector_webhook_details: None,
pm_auth_config: None,
merchant_id: merchant_id.clone(),
additional_merchant_data: None,
};
let mca_response =
admin::update_connector(state.clone(), &merchant_id, None, &connector_id, request).await?;
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/verification/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub async fn check_existence_and_add_domain_to_db(
connector_label: None,
status: None,
connector_wallets_details: None,
additional_merchant_data: None,
};
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
let updated_mca = storage::MerchantConnectorAccountUpdate::Update {
Expand All @@ -102,6 +103,7 @@ pub async fn check_existence_and_add_domain_to_db(
connector_label: None,
status: None,
connector_wallets_details: None,
additional_merchant_data: None,
};
state
.store
Expand Down
Loading