Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(router): add api_version and make profile_id mandatory in mca v2 (#5602)
Sai Harsha Vardhan56791c27437f
diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.jsonindex ff4d3e5946..a52ebcdf9b 100644--- a/api-reference-v2/openapi_spec.json+++ b/api-reference-v2/openapi_spec.json@@ -20,7 +20,7 @@}],"paths": {- "/connector_accounts": {+ "/v2/connector_accounts": {"post": {"tags": ["Merchant Connector Account"@@ -95,7 +95,7 @@]}},- "/connector_accounts/{id}": {+ "/v2/connector_accounts/{id}": {"get": {"tags": ["Merchant Connector Account"@@ -7178,6 +7178,7 @@"required": ["connector_type","connector_name",+ "profile_id","merchant_id"],"properties": {@@ -7189,14 +7190,13 @@},"connector_label": {"type": "string",- "description": "This is an unique label you can generate and pass in order to identify this connector account on your Hyperswitch dashboard and reports. Eg: if your profile label is `default`, connector label can be `stripe_default`",+ "description": "This is an unique label you can generate and pass in order to identify this connector account on your Hyperswitch dashboard and reports, If not passed then if will take `connector_name`_`profile_name`. Eg: if your profile label is `default`, connector label can be `stripe_default`","example": "stripe_US_travel","nullable": true},"profile_id": {"type": "string",- "description": "Identifier for the business profile, if not provided default will be chosen from merchant account",- "nullable": true+ "description": "Identifier for the business profile, if not provided default will be chosen from merchant account"},"connector_account_details": {"allOf": [@@ -7395,6 +7395,7 @@"connector_type","connector_name","id",+ "profile_id","status"],"properties": {@@ -7418,7 +7419,6 @@"profile_id": {"type": "string","description": "Identifier for the business profile, if not provided default will be chosen from merchant account",- "nullable": true,"maxLength": 64},"payment_methods_enabled": {@@ -7519,6 +7519,7 @@"connector_type","connector_name","id",+ "profile_id","status"],"properties": {@@ -7542,7 +7543,6 @@"profile_id": {"type": "string","description": "Identifier for the business profile, if not provided default will be chosen from merchant account",- "nullable": true,"maxLength": 64},"connector_account_details": {@@ -7667,7 +7667,7 @@},"connector_label": {"type": "string",- "description": "This is an unique label you can generate and pass in order to identify this connector account on your Hyperswitch dashboard and reports. Eg: if your profile label is `default`, connector label can be `stripe_default`",+ "description": "This is an unique label you can generate and pass in order to identify this connector account on your Hyperswitch dashboard and reports, If not passed then if will take `connector_name`_`profile_name`. Eg: if your profile label is `default`, connector label can be `stripe_default`","example": "stripe_US_travel","nullable": true},diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.jsonindex 879d5043e4..0caaef1e53 100644--- a/api-reference/openapi_spec.json+++ b/api-reference/openapi_spec.json@@ -12175,6 +12175,7 @@"connector_type","connector_name","merchant_connector_id",+ "profile_id","status"],"properties": {@@ -12198,7 +12199,6 @@"profile_id": {"type": "string","description": "Identifier for the business profile, if not provided default will be chosen from merchant account",- "nullable": true,"maxLength": 64},"payment_methods_enabled": {@@ -12326,6 +12326,7 @@"connector_type","connector_name","merchant_connector_id",+ "profile_id","status"],"properties": {@@ -12349,7 +12350,6 @@"profile_id": {"type": "string","description": "Identifier for the business profile, if not provided default will be chosen from merchant account",- "nullable": true,"maxLength": 64},"connector_account_details": {diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex 3ed77eb511..f494b29712 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -691,12 +691,12 @@ pub struct MerchantConnectorCreate {/// Name of the Connector#[schema(value_type = Connector, example = "stripe")]pub connector_name: api_enums::Connector,- /// This is an unique label you can generate and pass in order to identify this connector account on your Hyperswitch dashboard and reports. Eg: if your profile label is `default`, connector label can be `stripe_default`+ /// This is an unique label you can generate and pass in order to identify this connector account on your Hyperswitch dashboard and reports, If not passed then if will take `connector_name`_`profile_name`. Eg: if your profile label is `default`, connector label can be `stripe_default`#[schema(example = "stripe_US_travel")]pub connector_label: Option<String>,/// Identifier for the business profile, if not provided default will be chosen from merchant account- pub profile_id: Option<String>,+ pub profile_id: String,/// An object containing the required details/credentials for a Connector account.#[schema(value_type = Option<MerchantConnectorDetails>,example = json!({ "auth_type": "HeaderKey","api_key": "Basic MyVerySecretApiKey" }))]@@ -1061,7 +1061,7 @@ pub struct MerchantConnectorResponse {/// Identifier for the business profile, if not provided default will be chosen from merchant account#[schema(max_length = 64)]- pub profile_id: Option<String>,+ pub profile_id: String,/// An object containing the required details/credentials for a Connector account.#[schema(value_type = Option<MerchantConnectorDetails>,example = json!({ "auth_type": "HeaderKey","api_key": "Basic MyVerySecretApiKey" }))]@@ -1168,7 +1168,7 @@ pub struct MerchantConnectorResponse {/// Identifier for the business profile, if not provided default will be chosen from merchant account#[schema(max_length = 64)]- pub profile_id: Option<String>,+ pub profile_id: String,/// An object containing the required details/credentials for a Connector account.#[schema(value_type = Option<MerchantConnectorDetails>,example = json!({ "auth_type": "HeaderKey","api_key": "Basic MyVerySecretApiKey" }))]@@ -1292,7 +1292,7 @@ pub struct MerchantConnectorListResponse {/// Identifier for the business profile, if not provided default will be chosen from merchant account#[schema(max_length = 64)]- pub profile_id: Option<String>,+ pub profile_id: String,/// An object containing the details about the payment methods that need to be enabled under this merchant connector account#[schema(example = json!([@@ -1401,7 +1401,7 @@ pub struct MerchantConnectorListResponse {/// Identifier for the business profile, if not provided default will be chosen from merchant account#[schema(max_length = 64)]- pub profile_id: Option<String>,+ pub profile_id: String,/// An object containing the details about the payment methods that need to be enabled under this merchant connector account#[schema(example = json!([@@ -1563,7 +1563,7 @@ pub struct MerchantConnectorUpdate {#[schema(value_type = ConnectorType, example = "payment_processor")]pub connector_type: api_enums::ConnectorType,- /// This is an unique label you can generate and pass in order to identify this connector account on your Hyperswitch dashboard and reports. Eg: if your profile label is `default`, connector label can be `stripe_default`+ /// This is an unique label you can generate and pass in order to identify this connector account on your Hyperswitch dashboard and reports, If not passed then if will take `connector_name`_`profile_name`. Eg: if your profile label is `default`, connector label can be `stripe_default`#[schema(example = "stripe_US_travel")]pub connector_label: Option<String>,diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rsindex a057f349ea..876240f44a 100644--- a/crates/diesel_models/src/merchant_connector_account.rs+++ b/crates/diesel_models/src/merchant_connector_account.rs@@ -55,6 +55,7 @@ pub struct MerchantConnectorAccount {pub status: storage_enums::ConnectorStatus,pub additional_merchant_data: Option<Encryption>,pub connector_wallets_details: Option<Encryption>,+ pub version: common_enums::ApiVersion,}#[cfg(all(@@ -94,7 +95,7 @@ pub struct MerchantConnectorAccount {pub connector_webhook_details: Option<pii::SecretSerdeValue>,#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]pub frm_config: Option<Vec<pii::SecretSerdeValue>>,- pub profile_id: Option<String>,+ pub profile_id: String,#[diesel(deserialize_as = super::OptionalDieselArray<String>)]pub applepay_verified_domains: Option<Vec<String>>,pub pm_auth_config: Option<pii::SecretSerdeValue>,@@ -102,6 +103,7 @@ pub struct MerchantConnectorAccount {pub additional_merchant_data: Option<Encryption>,pub connector_wallets_details: Option<Encryption>,pub id: String,+ pub version: common_enums::ApiVersion,}#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]@@ -144,6 +146,7 @@ pub struct MerchantConnectorAccountNew {pub status: storage_enums::ConnectorStatus,pub additional_merchant_data: Option<Encryption>,pub connector_wallets_details: Option<Encryption>,+ pub version: common_enums::ApiVersion,}#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]@@ -163,7 +166,7 @@ pub struct MerchantConnectorAccountNew {pub connector_webhook_details: Option<pii::SecretSerdeValue>,#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]pub frm_config: Option<Vec<pii::SecretSerdeValue>>,- pub profile_id: Option<String>,+ pub profile_id: String,#[diesel(deserialize_as = super::OptionalDieselArray<String>)]pub applepay_verified_domains: Option<Vec<String>>,pub pm_auth_config: Option<pii::SecretSerdeValue>,@@ -171,6 +174,7 @@ pub struct MerchantConnectorAccountNew {pub additional_merchant_data: Option<Encryption>,pub connector_wallets_details: Option<Encryption>,pub id: String,+ pub version: common_enums::ApiVersion,}#[cfg(all(diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex a1df3a889c..da07e2ecda 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -705,6 +705,7 @@ diesel::table! {status -> ConnectorStatus,additional_merchant_data -> Nullable<Bytea>,connector_wallets_details -> Nullable<Bytea>,+ version -> ApiVersion,}}diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rsindex e4ae651f72..59822bbdfb 100644--- a/crates/diesel_models/src/schema_v2.rs+++ b/crates/diesel_models/src/schema_v2.rs@@ -678,7 +678,7 @@ diesel::table! {connector_webhook_details -> Nullable<Jsonb>,frm_config -> Nullable<Array<Nullable<Jsonb>>>,#[max_length = 64]- profile_id -> Nullable<Varchar>,+ profile_id -> Varchar,applepay_verified_domains -> Nullable<Array<Nullable<Text>>>,pm_auth_config -> Nullable<Jsonb>,status -> ConnectorStatus,@@ -686,6 +686,7 @@ diesel::table! {connector_wallets_details -> Nullable<Bytea>,#[max_length = 64]id -> Varchar,+ version -> ApiVersion,}}diff --git a/crates/hyperswitch_domain_models/src/consts.rs b/crates/hyperswitch_domain_models/src/consts.rsindex 8499cd3d82..c19d813cfe 100644--- a/crates/hyperswitch_domain_models/src/consts.rs+++ b/crates/hyperswitch_domain_models/src/consts.rs@@ -3,12 +3,17 @@#[cfg(all(any(feature = "v1", feature = "v2"),not(feature = "customer_v2"),- not(feature = "merchant_account_v2")+ not(feature = "merchant_account_v2"),+ not(feature = "merchant_connector_account_v2")))]pub const API_VERSION: common_enums::ApiVersion = common_enums::ApiVersion::V1;#[cfg(all(feature = "v2",- any(feature = "customer_v2", feature = "merchant_account_v2")+ any(+ feature = "customer_v2",+ feature = "merchant_account_v2",+ feature = "merchant_connector_account_v2"+ )))]pub const API_VERSION: common_enums::ApiVersion = common_enums::ApiVersion::V2;diff --git a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs b/crates/hyperswitch_domain_models/src/merchant_connector_account.rsindex 006fd5d775..9e2f6918b4 100644--- a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs+++ b/crates/hyperswitch_domain_models/src/merchant_connector_account.rs@@ -36,12 +36,13 @@ pub struct MerchantConnectorAccount {pub created_at: time::PrimitiveDateTime,pub modified_at: time::PrimitiveDateTime,pub connector_webhook_details: Option<pii::SecretSerdeValue>,- pub profile_id: Option<String>,+ pub profile_id: String,pub applepay_verified_domains: Option<Vec<String>>,pub pm_auth_config: Option<pii::SecretSerdeValue>,pub status: enums::ConnectorStatus,pub connector_wallets_details: Option<Encryptable<pii::SecretSerdeValue>>,pub additional_merchant_data: Option<Encryptable<pii::SecretSerdeValue>>,+ pub version: common_enums::ApiVersion,}#[cfg(all(@@ -70,12 +71,13 @@ pub struct MerchantConnectorAccount {pub created_at: time::PrimitiveDateTime,pub modified_at: time::PrimitiveDateTime,pub connector_webhook_details: Option<pii::SecretSerdeValue>,- pub profile_id: Option<String>,+ pub profile_id: String,pub applepay_verified_domains: Option<Vec<String>>,pub pm_auth_config: Option<pii::SecretSerdeValue>,pub status: enums::ConnectorStatus,pub connector_wallets_details: Option<Encryptable<pii::SecretSerdeValue>>,pub additional_merchant_data: Option<Encryptable<pii::SecretSerdeValue>>,+ pub version: common_enums::ApiVersion,}#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]@@ -165,12 +167,13 @@ impl behaviour::Conversion for MerchantConnectorAccount {created_at: self.created_at,modified_at: self.modified_at,connector_webhook_details: self.connector_webhook_details,- profile_id: self.profile_id,+ profile_id: Some(self.profile_id),applepay_verified_domains: self.applepay_verified_domains,pm_auth_config: self.pm_auth_config,status: self.status,connector_wallets_details: self.connector_wallets_details.map(Encryption::from),additional_merchant_data: self.additional_merchant_data.map(|data| data.into()),+ version: self.version,},)}@@ -212,7 +215,11 @@ impl behaviour::Conversion for MerchantConnectorAccount {created_at: other.created_at,modified_at: other.modified_at,connector_webhook_details: other.connector_webhook_details,- profile_id: other.profile_id,+ profile_id: other+ .profile_id+ .ok_or(ValidationError::MissingRequiredField {+ field_name: "profile_id".to_string(),+ })?,applepay_verified_domains: other.applepay_verified_domains,pm_auth_config: other.pm_auth_config,status: other.status,@@ -251,6 +258,7 @@ impl behaviour::Conversion for MerchantConnectorAccount {} else {None},+ version: other.version,})}@@ -275,12 +283,13 @@ impl behaviour::Conversion for MerchantConnectorAccount {created_at: now,modified_at: now,connector_webhook_details: self.connector_webhook_details,- profile_id: self.profile_id,+ profile_id: Some(self.profile_id),applepay_verified_domains: self.applepay_verified_domains,pm_auth_config: self.pm_auth_config,status: self.status,connector_wallets_details: self.connector_wallets_details.map(Encryption::from),additional_merchant_data: self.additional_merchant_data.map(|data| data.into()),+ version: self.version,})}}@@ -313,6 +322,7 @@ impl behaviour::Conversion for MerchantConnectorAccount {status: self.status,connector_wallets_details: self.connector_wallets_details.map(Encryption::from),additional_merchant_data: self.additional_merchant_data.map(|data| data.into()),+ version: self.version,},)}@@ -389,6 +399,7 @@ impl behaviour::Conversion for MerchantConnectorAccount {} else {None},+ version: other.version,})}@@ -414,6 +425,7 @@ impl behaviour::Conversion for MerchantConnectorAccount {status: self.status,connector_wallets_details: self.connector_wallets_details.map(Encryption::from),additional_merchant_data: self.additional_merchant_data.map(|data| data.into()),+ version: self.version,})}}diff --git a/crates/kgraph_utils/benches/evaluation.rs b/crates/kgraph_utils/benches/evaluation.rsindex 5fdab57aac..ab2e8c80ca 100644--- a/crates/kgraph_utils/benches/evaluation.rs+++ b/crates/kgraph_utils/benches/evaluation.rs@@ -64,7 +64,7 @@ fn build_test_data(connector_label: Some("something".to_string()),frm_configs: None,connector_webhook_details: None,- profile_id: None,+ profile_id: "profile_id".to_string(),applepay_verified_domains: None,pm_auth_config: None,status: api_enums::ConnectorStatus::Inactive,@@ -90,7 +90,7 @@ fn build_test_data(business_sub_label: Some("something".to_string()),frm_configs: None,connector_webhook_details: None,- profile_id: None,+ profile_id: "profile_id".to_string(),applepay_verified_domains: None,pm_auth_config: None,status: api_enums::ConnectorStatus::Inactive,diff --git a/crates/kgraph_utils/src/mca.rs b/crates/kgraph_utils/src/mca.rsindex 2c61bdfe19..d4e0466971 100644--- a/crates/kgraph_utils/src/mca.rs+++ b/crates/kgraph_utils/src/mca.rs@@ -752,7 +752,7 @@ mod tests {}]),frm_configs: None,connector_webhook_details: None,- profile_id: None,+ profile_id: "profile_id".to_string(),applepay_verified_domains: None,pm_auth_config: None,status: api_enums::ConnectorStatus::Inactive,@@ -813,7 +813,7 @@ mod tests {}]),frm_configs: None,connector_webhook_details: None,- profile_id: None,+ profile_id: "profile_id".to_string(),applepay_verified_domains: None,pm_auth_config: None,status: api_enums::ConnectorStatus::Inactive,diff --git a/crates/openapi/src/routes/merchant_connector_account.rs b/crates/openapi/src/routes/merchant_connector_account.rsindex d09414d16f..d4bb0c1bd4 100644--- a/crates/openapi/src/routes/merchant_connector_account.rs+++ b/crates/openapi/src/routes/merchant_connector_account.rs@@ -64,7 +64,7 @@ pub async fn connector_create() {}#[cfg(feature = "v2")]#[utoipa::path(post,- path = "/connector_accounts",+ path = "/v2/connector_accounts",request_body(content = MerchantConnectorCreate,examples(@@ -146,7 +146,7 @@ pub async fn connector_retrieve() {}#[cfg(feature = "v2")]#[utoipa::path(get,- path = "/connector_accounts/{id}",+ path = "/v2/connector_accounts/{id}",params(("id" = i32, Path, description = "The unique identifier for the Merchant Connector")),@@ -232,7 +232,7 @@ pub async fn connector_update() {}#[cfg(feature = "v2")]#[utoipa::path(post,- path = "/connector_accounts/{id}",+ path = "/v2/connector_accounts/{id}",request_body(content = MerchantConnectorUpdate,examples(@@ -298,7 +298,7 @@ pub async fn connector_delete() {}#[cfg(feature = "v2")]#[utoipa::path(delete,- path = "/connector_accounts/{id}",+ path = "/v2/connector_accounts/{id}",params(("id" = i32, Path, description = "The unique identifier for the Merchant Connector")),diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex aca7632272..00bfe2f7c1 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -1768,7 +1768,7 @@ struct PMAuthConfigValidation<'a> {pm_auth_config: &'a Option<pii::SecretSerdeValue>,db: &'a dyn StorageInterface,merchant_id: &'a id_type::MerchantId,- profile_id: &'a Option<String>,+ profile_id: &'a String,key_store: &'a domain::MerchantKeyStore,key_manager_state: &'a KeyManagerState,}@@ -2336,7 +2336,7 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {}None => None,},- profile_id: Some(business_profile.profile_id.clone()),+ profile_id: business_profile.profile_id.clone(),applepay_verified_domains: None,pm_auth_config: self.pm_auth_config.clone(),status: connector_status,@@ -2356,11 +2356,10 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {} else {None},+ version: hyperswitch_domain_models::consts::API_VERSION,})}- /// If profile_id is not passed, use default profile if available- /// or return a `MissingRequiredField` errorasync fn validate_and_get_profile_id(self,merchant_account: &domain::MerchantAccount,@@ -2369,25 +2368,19 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {key_store: &domain::MerchantKeyStore,should_validate: bool,) -> RouterResult<String> {- match self.profile_id {- Some(profile_id) => {- // Check whether this business profile belongs to the merchant- if should_validate {- let _ = core_utils::validate_and_get_business_profile(- db,- key_manager_state,- key_store,- Some(&profile_id),- merchant_account.get_id(),- )- .await?;- }- Ok(profile_id.clone())- }- None => Err(report!(errors::ApiErrorResponse::MissingRequiredField {- field_name: "profile_id"- })),+ let profile_id = self.profile_id;+ // Check whether this business profile belongs to the merchant+ if should_validate {+ let _ = core_utils::validate_and_get_business_profile(+ db,+ key_manager_state,+ key_store,+ Some(&profile_id),+ merchant_account.get_id(),+ )+ .await?;}+ Ok(profile_id.clone())}}@@ -2509,7 +2502,7 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {}None => None,},- profile_id: Some(business_profile.profile_id.clone()),+ profile_id: business_profile.profile_id.clone(),applepay_verified_domains: None,pm_auth_config: self.pm_auth_config.clone(),status: connector_status,@@ -2533,6 +2526,7 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {} else {None},+ version: hyperswitch_domain_models::consts::API_VERSION,})}@@ -2649,7 +2643,7 @@ pub async fn create_connector(pm_auth_config: &req.pm_auth_config,db: store,merchant_id,- profile_id: &Some(profile_id.clone()),+ profile_id: &profile_id.clone(),key_store: &key_store,key_manager_state,};@@ -2765,7 +2759,7 @@ async fn validate_pm_auth(merchant_id: &id_type::MerchantId,key_store: &domain::MerchantKeyStore,merchant_account: domain::MerchantAccount,- profile_id: &Option<String>,+ profile_id: &String,) -> RouterResponse<()> {let config =serde_json::from_value::<api_models::pm_auth::PaymentMethodAuthConfig>(val.expose())@@ -2984,11 +2978,7 @@ pub async fn update_connector(.await?;// Profile id should always be present- let profile_id = mca- .profile_id- .clone()- .ok_or(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Missing `profile_id` in merchant connector account")?;+ let profile_id = mca.profile_id.clone();let request_connector_label = req.connector_label;diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rsindex dc1bbb9a73..32b5cc7d7b 100644--- a/crates/router/src/core/payment_methods/cards.rs+++ b/crates/router/src/core/payment_methods/cards.rs@@ -4610,7 +4610,9 @@ pub async fn get_mca_status(let mut mca_ids = HashSet::new();let mcas = mcas.into_iter()- .filter(|mca| mca.disabled == Some(false) && profile_id.clone() == mca.profile_id)+ .filter(|mca| {+ mca.disabled == Some(false) && profile_id.clone() == Some(mca.profile_id.clone())+ }).collect::<Vec<_>>();for mca in mcas {diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 2491cd2bc9..81717b953a 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -130,7 +130,7 @@ pub fn filter_mca_based_on_profile_and_connector_type(merchant_connector_accounts.into_iter().filter(|mca| {- profile_id.map_or(true, |id| mca.profile_id.as_ref() == Some(id))+ profile_id.map_or(true, |id| &mca.profile_id == id)&& mca.connector_type == connector_type}).collect()diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rsindex 9255c2bad0..a746f15a98 100644--- a/crates/router/src/core/routing/helpers.rs+++ b/crates/router/src/core/routing/helpers.rs@@ -413,13 +413,13 @@ pub async fn validate_connectors_in_routing_config(})?;let name_mca_id_set = all_mcas.iter()- .filter(|mca| mca.profile_id.as_deref() == Some(profile_id))+ .filter(|mca| mca.profile_id == profile_id).map(|mca| (&mca.connector_name, mca.get_id())).collect::<FxHashSet<_>>();let name_set = all_mcas.iter()- .filter(|mca| mca.profile_id.as_deref() == Some(profile_id))+ .filter(|mca| mca.profile_id == profile_id).map(|mca| &mca.connector_name).collect::<FxHashSet<_>>();diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rsindex d5af1f20af..980c983e05 100644--- a/crates/router/src/core/utils.rs+++ b/crates/router/src/core/utils.rs@@ -1336,7 +1336,7 @@ pub(super) trait GetProfileId {impl GetProfileId for MerchantConnectorAccount {fn get_profile_id(&self) -> Option<&String> {- self.profile_id.as_ref()+ Some(&self.profile_id)}}diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rsindex 7c292d158c..9d16cf62c0 100644--- a/crates/router/src/core/webhooks/incoming.rs+++ b/crates/router/src/core/webhooks/incoming.rs@@ -347,12 +347,7 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>()?,};- let profile_id = merchant_connector_account- .profile_id- .as_ref()- .get_required_value("profile_id")- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Could not find profile_id in merchant connector account")?;+ let profile_id = merchant_connector_account.profile_id.as_ref();let business_profile = state.storediff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rsindex d628ad0f25..f039728de4 100644--- a/crates/router/src/db/merchant_connector_account.rs+++ b/crates/router/src/db/merchant_connector_account.rs@@ -568,9 +568,7 @@ impl MerchantConnectorAccountInterface for Store {merchant_connector_accounts{let _connector_name = merchant_connector_account.connector_name.clone();- let _profile_id = merchant_connector_account.profile_id.clone().ok_or(- errors::StorageError::ValueNotFound("profile_id".to_string()),- )?;+ let _profile_id = merchant_connector_account.profile_id.clone();let _merchant_id = merchant_connector_account.merchant_id.clone();let _merchant_connector_id = merchant_connector_account.get_id().clone();@@ -653,12 +651,7 @@ impl MerchantConnectorAccountInterface for Store {key_store: &domain::MerchantKeyStore,) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {let _connector_name = this.connector_name.clone();- let _profile_id = this- .profile_id- .clone()- .ok_or(errors::StorageError::ValueNotFound(- "profile_id".to_string(),- ))?;+ let _profile_id = this.profile_id.clone();let _merchant_id = this.merchant_id.clone();let _merchant_connector_id = this.merchant_connector_id.clone();@@ -732,12 +725,7 @@ impl MerchantConnectorAccountInterface for Store {key_store: &domain::MerchantKeyStore,) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {let _connector_name = this.connector_name.clone();- let _profile_id = this- .profile_id- .clone()- .ok_or(errors::StorageError::ValueNotFound(- "profile_id".to_string(),- ))?;+ let _profile_id = this.profile_id.clone();let _merchant_id = this.merchant_id.clone();let _merchant_connector_id = this.get_id().clone();@@ -896,9 +884,7 @@ impl MerchantConnectorAccountInterface for Store {.await.map_err(|error| report!(errors::StorageError::from(error)))?;- let _profile_id = mca.profile_id.ok_or(errors::StorageError::ValueNotFound(- "profile_id".to_string(),- ))?;+ let _profile_id = mca.profile_id;cache::publish_and_redact_multiple(self,@@ -1173,12 +1159,13 @@ impl MerchantConnectorAccountInterface for MockDb {created_at: common_utils::date_time::now(),modified_at: common_utils::date_time::now(),connector_webhook_details: t.connector_webhook_details,- profile_id: t.profile_id,+ profile_id: Some(t.profile_id),applepay_verified_domains: t.applepay_verified_domains,pm_auth_config: t.pm_auth_config,status: t.status,connector_wallets_details: t.connector_wallets_details.map(Encryption::from),additional_merchant_data: t.additional_merchant_data.map(|data| data.into()),+ version: t.version,};accounts.push(account.clone());account@@ -1219,6 +1206,7 @@ impl MerchantConnectorAccountInterface for MockDb {status: t.status,connector_wallets_details: t.connector_wallets_details.map(Encryption::from),additional_merchant_data: t.additional_merchant_data.map(|data| data.into()),+ version: t.version,};accounts.push(account.clone());account@@ -1548,7 +1536,7 @@ mod merchant_connector_account_cache_tests {created_at: date_time::now(),modified_at: date_time::now(),connector_webhook_details: None,- profile_id: Some(profile_id.to_string()),+ profile_id: profile_id.to_string(),applepay_verified_domains: None,pm_auth_config: None,status: common_enums::ConnectorStatus::Inactive,@@ -1565,6 +1553,7 @@ mod merchant_connector_account_cache_tests {.unwrap(),),additional_merchant_data: None,+ version: hyperswitch_domain_models::consts::API_VERSION,};db.insert_merchant_connector_account(key_manager_state, mca.clone(), &merchant_key)@@ -1712,7 +1701,7 @@ mod merchant_connector_account_cache_tests {created_at: date_time::now(),modified_at: date_time::now(),connector_webhook_details: None,- profile_id: Some(profile_id.to_string()),+ profile_id: profile_id.to_string(),applepay_verified_domains: None,pm_auth_config: None,status: common_enums::ConnectorStatus::Inactive,@@ -1729,6 +1718,7 @@ mod merchant_connector_account_cache_tests {.unwrap(),),additional_merchant_data: None,+ version: hyperswitch_domain_models::consts::API_VERSION,};db.insert_merchant_connector_account(key_manager_state, mca.clone(), &merchant_key)diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rsindex 40f6d46f93..2bb1a5eee8 100644--- a/crates/router/src/routes/app.rs+++ b/crates/router/src/routes/app.rs@@ -1175,7 +1175,7 @@ pub struct MerchantConnectorAccount;))]impl MerchantConnectorAccount {pub fn server(state: AppState) -> Scope {- let mut route = web::scope("/connector_accounts").app_data(web::Data::new(state));+ let mut route = web::scope("/v2/connector_accounts").app_data(web::Data::new(state));#[cfg(feature = "olap")]{diff --git a/migrations/2022-09-29-093314_create_seed_data/down.sql b/migrations/2022-09-29-093314_create_seed_data/down.sqldeleted file mode 100644index ac76570d13..0000000000--- a/migrations/2022-09-29-093314_create_seed_data/down.sql+++ /dev/null@@ -1,5 +0,0 @@-DELETE FROM merchant_connector_account-WHERE merchant_id = 'juspay_merchant';--DELETE FROM merchant_account-WHERE merchant_id = 'juspay_merchant';diff --git a/migrations/2022-09-29-093314_create_seed_data/up.sql b/migrations/2022-09-29-093314_create_seed_data/up.sqldeleted file mode 100644index b2a864ad29..0000000000--- a/migrations/2022-09-29-093314_create_seed_data/up.sql+++ /dev/null@@ -1,27 +0,0 @@-INSERT INTO merchant_account (- merchant_id,- api_key,- merchant_name,- merchant_details,- custom_routing_rules,- publishable_key- )-VALUES (- 'juspay_merchant',- 'MySecretApiKey',- 'Juspay Merchant',- '{ "primary_email": "[email protected]" }',- '[ { "connectors_pecking_order": [ "stripe" ] } ]',- 'pk_MyPublicApiKey'- );--INSERT INTO merchant_connector_account (- merchant_id,- connector_name,- connector_account_details- )-VALUES (- 'juspay_merchant',- 'stripe',- '{ "auth_type": "HeaderKey", "api_key": "Basic MyStripeApiKey" }'- );diff --git a/migrations/2024-08-12-104928_add_api_version_in_mca/down.sql b/migrations/2024-08-12-104928_add_api_version_in_mca/down.sqlnew file mode 100644index 0000000000..a2d88488b1--- /dev/null+++ b/migrations/2024-08-12-104928_add_api_version_in_mca/down.sql@@ -0,0 +1,2 @@+-- This file should undo anything in `up.sql`+ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS version;\ No newline at end of filediff --git a/migrations/2024-08-12-104928_add_api_version_in_mca/up.sql b/migrations/2024-08-12-104928_add_api_version_in_mca/up.sqlnew file mode 100644index 0000000000..2ea9d27112--- /dev/null+++ b/migrations/2024-08-12-104928_add_api_version_in_mca/up.sql@@ -0,0 +1,3 @@+-- Your SQL goes here+ALTER TABLE merchant_connector_account+ADD COLUMN IF NOT EXISTS version "ApiVersion" NOT NULL DEFAULT 'v1';diff --git a/v2_migrations/2024-08-12-075913_make_profile_id_mandatory_in_mca/down.sql b/v2_migrations/2024-08-12-075913_make_profile_id_mandatory_in_mca/down.sqlnew file mode 100644index 0000000000..eca25b815c--- /dev/null+++ b/v2_migrations/2024-08-12-075913_make_profile_id_mandatory_in_mca/down.sql@@ -0,0 +1,2 @@+-- This file should undo anything in `up.sql`+ALTER TABLE merchant_connector_account ALTER COLUMN profile_id DROP NOT NULL;\ No newline at end of filediff --git a/v2_migrations/2024-08-12-075913_make_profile_id_mandatory_in_mca/up.sql b/v2_migrations/2024-08-12-075913_make_profile_id_mandatory_in_mca/up.sqlnew file mode 100644index 0000000000..216b8760d7--- /dev/null+++ b/v2_migrations/2024-08-12-075913_make_profile_id_mandatory_in_mca/up.sql@@ -0,0 +1,3 @@+-- Your SQL goes here+-- This migration is to make profile_id mandatory in mca table+ALTER TABLE merchant_connector_account ALTER COLUMN profile_id SET NOT NULL;