From 771f48cfe0ec6d8625ca3ff3095f5d9806915779 Mon Sep 17 00:00:00 2001 From: Sai Harsha Vardhan <56996463+sai-harsha-vardhan@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:22:19 +0530 Subject: [PATCH] refactor(router): add domain type for merchant_connector_account id (#5685) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Sanchith Hegde --- api-reference-v2/openapi_spec.json | 6 -- crates/api_models/src/admin.rs | 50 +++++------ crates/api_models/src/connector_onboarding.rs | 12 +-- crates/api_models/src/disputes.rs | 3 +- crates/api_models/src/mandates.rs | 3 +- crates/api_models/src/payment_methods.rs | 8 +- crates/api_models/src/payments.rs | 5 +- crates/api_models/src/payouts.rs | 2 +- crates/api_models/src/pm_auth.rs | 4 +- crates/api_models/src/refunds.rs | 6 +- crates/api_models/src/routing.rs | 5 +- .../api_models/src/user/dashboard_metadata.rs | 4 +- crates/api_models/src/verifications.rs | 8 +- crates/common_utils/src/id_type.rs | 2 + .../src/id_type/merchant_connector_account.rs | 23 +++++ crates/common_utils/src/lib.rs | 8 ++ crates/diesel_models/src/authentication.rs | 4 +- crates/diesel_models/src/dispute.rs | 4 +- crates/diesel_models/src/file.rs | 8 +- crates/diesel_models/src/mandate.rs | 4 +- .../src/merchant_connector_account.rs | 14 ++-- crates/diesel_models/src/payment_attempt.rs | 12 +-- crates/diesel_models/src/payout_attempt.rs | 8 +- .../src/query/merchant_connector_account.rs | 14 +++- .../src/query/payment_attempt.rs | 2 +- crates/diesel_models/src/refund.rs | 4 +- crates/diesel_models/src/user/sample_data.rs | 2 +- crates/euclid/src/frontend/ast.rs | 2 +- .../src/merchant_connector_account.rs | 20 ++--- .../src/payments/payment_attempt.rs | 10 +-- .../src/payments/payment_intent.rs | 2 +- .../src/payouts/payout_attempt.rs | 8 +- crates/kgraph_utils/benches/evaluation.rs | 5 +- crates/kgraph_utils/src/mca.rs | 5 +- crates/router/src/core/admin.rs | 47 ++++++----- .../router/src/core/authentication/utils.rs | 2 +- .../src/core/connector_onboarding/paypal.rs | 2 +- crates/router/src/core/files/helpers.rs | 2 +- crates/router/src/core/mandate.rs | 2 +- .../router/src/core/payment_methods/cards.rs | 9 +- crates/router/src/core/payments.rs | 10 ++- .../router/src/core/payments/access_token.rs | 1 + crates/router/src/core/payments/helpers.rs | 76 +++++++++-------- .../router/src/core/payments/tokenization.rs | 8 +- crates/router/src/core/payouts.rs | 2 +- crates/router/src/core/pm_auth.rs | 9 +- crates/router/src/core/routing/helpers.rs | 11 ++- crates/router/src/core/verification.rs | 4 +- crates/router/src/core/verification/utils.rs | 7 +- crates/router/src/core/webhooks/incoming.rs | 11 ++- crates/router/src/db/kafka_store.rs | 10 +-- .../src/db/merchant_connector_account.rs | 83 +++++++++++-------- crates/router/src/routes/admin.rs | 21 +++-- crates/router/src/routes/verification.rs | 2 +- .../src/services/kafka/authentication.rs | 2 +- .../services/kafka/authentication_event.rs | 2 +- crates/router/src/services/kafka/dispute.rs | 2 +- .../src/services/kafka/dispute_event.rs | 2 +- .../src/services/kafka/payment_attempt.rs | 2 +- .../services/kafka/payment_attempt_event.rs | 2 +- crates/router/src/services/kafka/payout.rs | 2 +- crates/router/src/types/api.rs | 6 +- crates/router/src/types/storage.rs | 2 +- .../src/types/storage/payment_method.rs | 7 +- crates/router/src/utils.rs | 9 +- .../router/src/utils/connector_onboarding.rs | 17 ++-- crates/router/tests/connectors/utils.rs | 2 +- .../src/mock_db/payment_attempt.rs | 2 +- .../src/payments/payment_attempt.rs | 4 +- 69 files changed, 388 insertions(+), 271 deletions(-) create mode 100644 crates/common_utils/src/id_type/merchant_connector_account.rs diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index 48739ac77f93..5c57891d1034 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -8537,12 +8537,6 @@ "example": "\n[{\"gateway\":\"stripe\",\"payment_methods\":[{\"payment_method\":\"card\",\"payment_method_types\":[{\"payment_method_type\":\"credit\",\"card_networks\":[\"Visa\"],\"flow\":\"pre\",\"action\":\"cancel_txn\"},{\"payment_method_type\":\"debit\",\"card_networks\":[\"Visa\"],\"flow\":\"pre\"}]}]}]\n", "nullable": true }, - "merchant_connector_id": { - "type": "string", - "description": "Unique ID of the connector", - "example": "mca_5apGeP94tMts6rg3U3kR", - "nullable": true - }, "pm_auth_config": { "type": "object", "description": "pm_auth_config will relate MCA records to their respective chosen auth services, based on payment_method and pmt", diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs index 55a2444973da..5b2432cda9ff 100644 --- a/crates/api_models/src/admin.rs +++ b/crates/api_models/src/admin.rs @@ -670,16 +670,18 @@ pub struct MerchantId { any(feature = "v1", feature = "v2"), not(feature = "merchant_connector_account_v2") ))] -#[derive(Default, Debug, Deserialize, ToSchema, Serialize)] +#[derive(Debug, Deserialize, ToSchema, Serialize)] pub struct MerchantConnectorId { #[schema(value_type = String)] pub merchant_id: id_type::MerchantId, - pub merchant_connector_id: String, + #[schema(value_type = String)] + pub merchant_connector_id: id_type::MerchantConnectorAccountId, } #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))] -#[derive(Default, Debug, Deserialize, ToSchema, Serialize)] +#[derive(Debug, Deserialize, ToSchema, Serialize)] pub struct MerchantConnectorId { - pub id: String, + #[schema(value_type = String)] + pub id: id_type::MerchantConnectorAccountId, } #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))] @@ -757,10 +759,6 @@ pub struct MerchantConnectorCreate { #[schema(example = json!(consts::FRM_CONFIGS_EG))] pub frm_configs: Option>, - /// Unique ID of the connector - #[schema(example = "mca_5apGeP94tMts6rg3U3kR")] - pub merchant_connector_id: Option, - /// pm_auth_config will relate MCA records to their respective chosen auth services, based on payment_method and pmt #[schema(value_type = Option)] pub pm_auth_config: Option, @@ -904,8 +902,8 @@ pub struct MerchantConnectorCreate { pub business_sub_label: Option, /// Unique ID of the connector - #[schema(example = "mca_5apGeP94tMts6rg3U3kR")] - pub merchant_connector_id: Option, + #[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = Option)] + pub merchant_connector_id: Option, #[schema(value_type = Option)] pub pm_auth_config: Option, @@ -1031,11 +1029,15 @@ pub struct MerchantConnectorWebhookDetails { #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, ToSchema)] pub struct MerchantConnectorInfo { pub connector_label: String, - pub merchant_connector_id: String, + #[schema(value_type = String)] + pub merchant_connector_id: id_type::MerchantConnectorAccountId, } impl MerchantConnectorInfo { - pub fn new(connector_label: String, merchant_connector_id: String) -> Self { + pub fn new( + connector_label: String, + merchant_connector_id: id_type::MerchantConnectorAccountId, + ) -> Self { Self { connector_label, merchant_connector_id, @@ -1060,8 +1062,8 @@ pub struct MerchantConnectorResponse { pub connector_label: Option, /// Unique ID of the merchant connector account - #[schema(example = "mca_5apGeP94tMts6rg3U3kR")] - pub id: String, + #[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)] + pub id: id_type::MerchantConnectorAccountId, /// Identifier for the business profile, if not provided default will be chosen from merchant account #[schema(max_length = 64, value_type = String)] @@ -1167,8 +1169,8 @@ pub struct MerchantConnectorResponse { pub connector_label: Option, /// Unique ID of the merchant connector account - #[schema(example = "mca_5apGeP94tMts6rg3U3kR")] - pub merchant_connector_id: String, + #[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)] + pub merchant_connector_id: id_type::MerchantConnectorAccountId, /// Identifier for the business profile, if not provided default will be chosen from merchant account #[schema(max_length = 64, value_type = String)] @@ -1291,8 +1293,8 @@ pub struct MerchantConnectorListResponse { pub connector_label: Option, /// Unique ID of the merchant connector account - #[schema(example = "mca_5apGeP94tMts6rg3U3kR")] - pub merchant_connector_id: String, + #[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)] + pub merchant_connector_id: id_type::MerchantConnectorAccountId, /// Identifier for the business profile, if not provided default will be chosen from merchant account #[schema(max_length = 64, value_type = String)] @@ -1400,8 +1402,8 @@ pub struct MerchantConnectorListResponse { pub connector_label: Option, /// Unique ID of the merchant connector account - #[schema(example = "mca_5apGeP94tMts6rg3U3kR")] - pub id: String, + #[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)] + pub id: id_type::MerchantConnectorAccountId, /// Identifier for the business profile, if not provided default will be chosen from merchant account #[schema(max_length = 64, value_type = String)] @@ -1760,8 +1762,8 @@ pub struct MerchantConnectorDeleteResponse { #[schema(max_length = 255, example = "y3oqhf46pyzuxjbcn2giaqnb44", value_type = String)] pub merchant_id: id_type::MerchantId, /// Unique ID of the connector - #[schema(example = "mca_5apGeP94tMts6rg3U3kR")] - pub merchant_connector_id: String, + #[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)] + pub merchant_connector_id: id_type::MerchantConnectorAccountId, /// If the connector is deleted or not #[schema(example = false)] pub deleted: bool, @@ -1774,8 +1776,8 @@ pub struct MerchantConnectorDeleteResponse { #[schema(max_length = 255, example = "y3oqhf46pyzuxjbcn2giaqnb44", value_type = String)] pub merchant_id: id_type::MerchantId, /// Unique ID of the connector - #[schema(example = "mca_5apGeP94tMts6rg3U3kR")] - pub id: String, + #[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)] + pub id: id_type::MerchantConnectorAccountId, /// If the connector is deleted or not #[schema(example = false)] pub deleted: bool, diff --git a/crates/api_models/src/connector_onboarding.rs b/crates/api_models/src/connector_onboarding.rs index de4b8843dfc9..2dca57d5953f 100644 --- a/crates/api_models/src/connector_onboarding.rs +++ b/crates/api_models/src/connector_onboarding.rs @@ -1,9 +1,11 @@ +use common_utils::id_type; + use super::{admin, enums}; #[derive(serde::Deserialize, serde::Serialize, Debug, Clone)] pub struct ActionUrlRequest { pub connector: enums::Connector, - pub connector_id: String, + pub connector_id: id_type::MerchantConnectorAccountId, pub return_url: String, } @@ -15,8 +17,8 @@ pub enum ActionUrlResponse { #[derive(serde::Deserialize, serde::Serialize, Debug, Clone)] pub struct OnboardingSyncRequest { - pub profile_id: common_utils::id_type::ProfileId, - pub connector_id: String, + pub profile_id: id_type::ProfileId, + pub connector_id: id_type::MerchantConnectorAccountId, pub connector: enums::Connector, } @@ -45,7 +47,7 @@ pub enum PayPalOnboardingStatus { #[derive(serde::Serialize, Debug, Clone)] pub struct PayPalOnboardingDone { - pub payer_id: common_utils::id_type::MerchantId, + pub payer_id: id_type::MerchantId, } #[derive(serde::Serialize, Debug, Clone)] @@ -55,6 +57,6 @@ pub struct PayPalIntegrationDone { #[derive(serde::Deserialize, serde::Serialize, Debug, Clone)] pub struct ResetTrackingIdRequest { - pub connector_id: String, + pub connector_id: id_type::MerchantConnectorAccountId, pub connector: enums::Connector, } diff --git a/crates/api_models/src/disputes.rs b/crates/api_models/src/disputes.rs index 5e9db4cdfd17..42803c519cb9 100644 --- a/crates/api_models/src/disputes.rs +++ b/crates/api_models/src/disputes.rs @@ -47,7 +47,8 @@ pub struct DisputeResponse { #[schema(value_type = Option)] pub profile_id: Option, /// The `merchant_connector_id` of the connector / processor through which the dispute was processed - pub merchant_connector_id: Option, + #[schema(value_type = Option)] + pub merchant_connector_id: Option, } #[derive(Clone, Debug, Serialize, ToSchema, Eq, PartialEq)] diff --git a/crates/api_models/src/mandates.rs b/crates/api_models/src/mandates.rs index b62a2c38b9c6..44a833194249 100644 --- a/crates/api_models/src/mandates.rs +++ b/crates/api_models/src/mandates.rs @@ -129,5 +129,6 @@ pub struct ProcessorPaymentToken { pub processor_payment_token: String, #[schema(value_type = Connector, example = "stripe")] pub connector: api_enums::Connector, - pub merchant_connector_id: String, + #[schema(value_type = String)] + pub merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId, } diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs index de94d4f5872b..2204a7fc584e 100644 --- a/crates/api_models/src/payment_methods.rs +++ b/crates/api_models/src/payment_methods.rs @@ -215,7 +215,9 @@ pub struct PaymentMethodMigrate { } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -pub struct PaymentsMandateReference(pub HashMap); +pub struct PaymentsMandateReference( + pub HashMap, +); #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct PaymentsMandateReferenceRecord { @@ -733,7 +735,7 @@ pub struct BankAccountTokenData { pub struct BankAccountConnectorDetails { pub connector: String, pub account_id: masking::Secret, - pub mca_id: String, + pub mca_id: id_type::MerchantConnectorAccountId, pub access_token: BankAccountAccessCreds, } @@ -1983,7 +1985,7 @@ pub struct PaymentMethodRecord { pub billing_address_line2: Option>, pub billing_address_line3: Option>, pub raw_card_number: Option>, - pub merchant_connector_id: String, + pub merchant_connector_id: id_type::MerchantConnectorAccountId, pub original_transaction_amount: Option, pub original_transaction_currency: Option, pub line_number: Option, diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index be657cb948b9..04bcae4c56c2 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -3829,7 +3829,8 @@ pub struct PaymentsResponse { pub merchant_decision: Option, /// Identifier of the connector ( merchant connector account ) which was chosen to make the payment - pub merchant_connector_id: Option, + #[schema(value_type = Option)] + pub merchant_connector_id: Option, /// If true, incremental authorization can be performed on this payment, in case the funds authorized initially fall short. pub incremental_authorization_allowed: Option, @@ -4059,7 +4060,7 @@ pub struct PaymentListFilterConstraints { /// The list of authentication types to filter payments list pub authentication_type: Option>, /// The list of merchant connector ids to filter payments list for selected label - pub merchant_connector_id: Option>, + pub merchant_connector_id: Option>, /// The order in which payments list should be sorted #[serde(default)] pub order: Order, diff --git a/crates/api_models/src/payouts.rs b/crates/api_models/src/payouts.rs index b6b040a36f34..aad0cfcf3031 100644 --- a/crates/api_models/src/payouts.rs +++ b/crates/api_models/src/payouts.rs @@ -473,7 +473,7 @@ pub struct PayoutCreateResponse { /// Unique identifier of the merchant connector account #[schema(value_type = Option, example = "mca_sAD3OZLATetvjLOYhUSy")] - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, /// Current status of the Payout #[schema(value_type = PayoutStatus, example = RequiresConfirmation)] diff --git a/crates/api_models/src/pm_auth.rs b/crates/api_models/src/pm_auth.rs index 4a1c8eaa31b2..a949f618bdc9 100644 --- a/crates/api_models/src/pm_auth.rs +++ b/crates/api_models/src/pm_auth.rs @@ -1,7 +1,7 @@ use common_enums::{PaymentMethod, PaymentMethodType}; use common_utils::{ events::{ApiEventMetric, ApiEventsType}, - impl_api_event_type, + id_type, impl_api_event_type, }; #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] @@ -46,7 +46,7 @@ pub struct PaymentMethodAuthConnectorChoice { pub payment_method: PaymentMethod, pub payment_method_type: PaymentMethodType, pub connector_name: String, - pub mca_id: String, + pub mca_id: id_type::MerchantConnectorAccountId, } impl_api_event_type!( diff --git a/crates/api_models/src/refunds.rs b/crates/api_models/src/refunds.rs index 656416dce96e..1f3361d004ed 100644 --- a/crates/api_models/src/refunds.rs +++ b/crates/api_models/src/refunds.rs @@ -159,7 +159,8 @@ pub struct RefundResponse { #[schema(value_type = Option)] pub profile_id: Option, /// The merchant_connector_id of the processor through which this payment went through - pub merchant_connector_id: Option, + #[schema(value_type = Option)] + pub merchant_connector_id: Option, /// Charge specific fields for controlling the revert of funds from either platform or connected account #[schema(value_type = Option)] pub charges: Option, @@ -186,7 +187,8 @@ pub struct RefundListRequest { /// The list of connectors to filter refunds list pub connector: Option>, /// The list of merchant connector ids to filter the refunds list for selected label - pub merchant_connector_id: Option>, + #[schema(value_type = Option>)] + pub merchant_connector_id: Option>, /// The list of currencies to filter refunds list #[schema(value_type = Option>)] pub currency: Option>, diff --git a/crates/api_models/src/routing.rs b/crates/api_models/src/routing.rs index 04a58aed0d94..f9bcf3901b99 100644 --- a/crates/api_models/src/routing.rs +++ b/crates/api_models/src/routing.rs @@ -173,7 +173,8 @@ pub struct RoutableConnectorChoice { #[serde(skip)] pub choice_kind: RoutableChoiceKind, pub connector: RoutableConnectors, - pub merchant_connector_id: Option, + #[schema(value_type = Option)] + pub merchant_connector_id: Option, } #[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)] @@ -188,7 +189,7 @@ pub enum RoutableChoiceSerde { OnlyConnector(Box), FullStruct { connector: RoutableConnectors, - merchant_connector_id: Option, + merchant_connector_id: Option, }, } diff --git a/crates/api_models/src/user/dashboard_metadata.rs b/crates/api_models/src/user/dashboard_metadata.rs index d8a437e31a67..91d1471d9eec 100644 --- a/crates/api_models/src/user/dashboard_metadata.rs +++ b/crates/api_models/src/user/dashboard_metadata.rs @@ -1,5 +1,5 @@ use common_enums::CountryAlpha2; -use common_utils::pii; +use common_utils::{id_type, pii}; use masking::Secret; use strum::EnumString; @@ -43,7 +43,7 @@ pub struct SetupProcessor { #[derive(Debug, serde::Deserialize, serde::Serialize)] pub struct ProcessorConnected { - pub processor_id: String, + pub processor_id: id_type::MerchantConnectorAccountId, pub processor_name: String, } diff --git a/crates/api_models/src/verifications.rs b/crates/api_models/src/verifications.rs index 5fa1b8cd4c8b..e84f17583990 100644 --- a/crates/api_models/src/verifications.rs +++ b/crates/api_models/src/verifications.rs @@ -1,3 +1,5 @@ +use common_utils::id_type; + /// The request body for verification of merchant (everything except domain_names are prefilled) #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[serde(rename_all = "camelCase")] @@ -13,7 +15,7 @@ pub struct ApplepayMerchantVerificationConfigs { #[serde(rename_all = "snake_case")] pub struct ApplepayMerchantVerificationRequest { pub domain_names: Vec, - pub merchant_connector_account_id: String, + pub merchant_connector_account_id: id_type::MerchantConnectorAccountId, } /// Response to be sent for the verify/applepay api @@ -27,8 +29,8 @@ pub struct ApplepayMerchantResponse { #[derive(Debug, serde::Deserialize)] #[serde(rename_all = "snake_case")] pub struct ApplepayGetVerifiedDomainsParam { - pub merchant_id: common_utils::id_type::MerchantId, - pub merchant_connector_account_id: String, + pub merchant_id: id_type::MerchantId, + pub merchant_connector_account_id: id_type::MerchantConnectorAccountId, } /// Response to be sent for derivation of the already verified domains #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] diff --git a/crates/common_utils/src/id_type.rs b/crates/common_utils/src/id_type.rs index cc4c56d6abb5..b6de37fab4f5 100644 --- a/crates/common_utils/src/id_type.rs +++ b/crates/common_utils/src/id_type.rs @@ -5,6 +5,7 @@ use std::{borrow::Cow, fmt::Debug}; mod customer; mod merchant; +mod merchant_connector_account; mod organization; mod profile; @@ -19,6 +20,7 @@ use diesel::{ sql_types, }; pub use merchant::MerchantId; +pub use merchant_connector_account::MerchantConnectorAccountId; pub use organization::OrganizationId; pub use profile::ProfileId; use serde::{Deserialize, Serialize}; diff --git a/crates/common_utils/src/id_type/merchant_connector_account.rs b/crates/common_utils/src/id_type/merchant_connector_account.rs new file mode 100644 index 000000000000..f1bdb171b21a --- /dev/null +++ b/crates/common_utils/src/id_type/merchant_connector_account.rs @@ -0,0 +1,23 @@ +use crate::errors::{CustomResult, ValidationError}; + +crate::id_type!( + MerchantConnectorAccountId, + "A type for merchant_connector_id that can be used for merchant_connector_account ids" +); +crate::impl_id_type_methods!(MerchantConnectorAccountId, "merchant_connector_id"); + +// This is to display the `MerchantConnectorAccountId` as MerchantConnectorAccountId(abcd) +crate::impl_debug_id_type!(MerchantConnectorAccountId); +crate::impl_generate_id_id_type!(MerchantConnectorAccountId, "mca"); +crate::impl_try_from_cow_str_id_type!(MerchantConnectorAccountId, "merchant_connector_id"); + +crate::impl_serializable_secret_id_type!(MerchantConnectorAccountId); +crate::impl_queryable_id_type!(MerchantConnectorAccountId); +crate::impl_to_sql_from_sql_id_type!(MerchantConnectorAccountId); + +impl MerchantConnectorAccountId { + /// Get a merchant connector account id from String + pub fn wrap(merchant_connector_account_id: String) -> CustomResult { + Self::try_from(std::borrow::Cow::from(merchant_connector_account_id)) + } +} diff --git a/crates/common_utils/src/lib.rs b/crates/common_utils/src/lib.rs index 67a67bee5c3d..f51ed6eab058 100644 --- a/crates/common_utils/src/lib.rs +++ b/crates/common_utils/src/lib.rs @@ -233,6 +233,14 @@ pub fn generate_profile_id_of_default_length() -> id_type::ProfileId { id_type::ProfileId::generate() } +/// Generate a merchant_connector_account id with default length, with prefix as `mca` +pub fn generate_merchant_connector_account_id_of_default_length( +) -> id_type::MerchantConnectorAccountId { + use id_type::GenerateId; + + id_type::MerchantConnectorAccountId::generate() +} + /// Generate a nanoid with the given prefix and a default length #[inline] pub fn generate_id_with_default_len(prefix: &str) -> String { diff --git a/crates/diesel_models/src/authentication.rs b/crates/diesel_models/src/authentication.rs index 606644255bcb..488066ff2534 100644 --- a/crates/diesel_models/src/authentication.rs +++ b/crates/diesel_models/src/authentication.rs @@ -43,7 +43,7 @@ pub struct Authentication { pub acs_signed_content: Option, pub profile_id: common_utils::id_type::ProfileId, pub payment_id: Option, - pub merchant_connector_id: String, + pub merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId, pub ds_trans_id: Option, pub directory_server_id: Option, pub acquirer_country_code: Option, @@ -90,7 +90,7 @@ pub struct AuthenticationNew { pub acs_signed_content: Option, pub profile_id: common_utils::id_type::ProfileId, pub payment_id: Option, - pub merchant_connector_id: String, + pub merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId, pub ds_trans_id: Option, pub directory_server_id: Option, pub acquirer_country_code: Option, diff --git a/crates/diesel_models/src/dispute.rs b/crates/diesel_models/src/dispute.rs index 14fe16c98261..45004e10ba5c 100644 --- a/crates/diesel_models/src/dispute.rs +++ b/crates/diesel_models/src/dispute.rs @@ -28,7 +28,7 @@ pub struct DisputeNew { pub connector: String, pub evidence: Option>, pub profile_id: Option, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub dispute_amount: i64, } @@ -57,7 +57,7 @@ pub struct Dispute { pub connector: String, pub evidence: Secret, pub profile_id: Option, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub dispute_amount: i64, } diff --git a/crates/diesel_models/src/file.rs b/crates/diesel_models/src/file.rs index 523bb1f26ef1..99265bfa807c 100644 --- a/crates/diesel_models/src/file.rs +++ b/crates/diesel_models/src/file.rs @@ -18,7 +18,7 @@ pub struct FileMetadataNew { pub available: bool, pub connector_label: Option, pub profile_id: Option, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, } #[derive(Clone, Debug, Deserialize, Serialize, Identifiable, Queryable, Selectable)] @@ -37,7 +37,7 @@ pub struct FileMetadata { pub created_at: time::PrimitiveDateTime, pub connector_label: Option, pub profile_id: Option, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, } #[derive(Debug)] @@ -47,7 +47,7 @@ pub enum FileMetadataUpdate { file_upload_provider: Option, available: bool, profile_id: Option, - merchant_connector_id: Option, + merchant_connector_id: Option, }, } @@ -58,7 +58,7 @@ pub struct FileMetadataUpdateInternal { file_upload_provider: Option, available: bool, profile_id: Option, - merchant_connector_id: Option, + merchant_connector_id: Option, } impl From for FileMetadataUpdateInternal { diff --git a/crates/diesel_models/src/mandate.rs b/crates/diesel_models/src/mandate.rs index bfac1849a586..dc6916f3c4ba 100644 --- a/crates/diesel_models/src/mandate.rs +++ b/crates/diesel_models/src/mandate.rs @@ -33,7 +33,7 @@ pub struct Mandate { pub metadata: Option, pub connector_mandate_ids: Option, pub original_payment_id: Option, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub updated_by: Option, } @@ -71,7 +71,7 @@ pub struct MandateNew { pub metadata: Option, pub connector_mandate_ids: Option, pub original_payment_id: Option, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub updated_by: Option, } diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rs index e674b9b75871..cd92f5492a13 100644 --- a/crates/diesel_models/src/merchant_connector_account.rs +++ b/crates/diesel_models/src/merchant_connector_account.rs @@ -33,7 +33,7 @@ pub struct MerchantConnectorAccount { pub connector_account_details: Encryption, pub test_mode: Option, pub disabled: Option, - pub merchant_connector_id: String, + pub merchant_connector_id: id_type::MerchantConnectorAccountId, #[diesel(deserialize_as = super::OptionalDieselArray)] pub payment_methods_enabled: Option>, pub connector_type: storage_enums::ConnectorType, @@ -63,7 +63,7 @@ pub struct MerchantConnectorAccount { not(feature = "merchant_connector_account_v2") ))] impl MerchantConnectorAccount { - pub fn get_id(&self) -> String { + pub fn get_id(&self) -> id_type::MerchantConnectorAccountId { self.merchant_connector_id.clone() } } @@ -102,13 +102,13 @@ pub struct MerchantConnectorAccount { pub status: storage_enums::ConnectorStatus, pub additional_merchant_data: Option, pub connector_wallets_details: Option, - pub id: String, + pub id: id_type::MerchantConnectorAccountId, pub version: common_enums::ApiVersion, } #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))] impl MerchantConnectorAccount { - pub fn get_id(&self) -> String { + pub fn get_id(&self) -> id_type::MerchantConnectorAccountId { self.id.clone() } } @@ -126,7 +126,7 @@ pub struct MerchantConnectorAccountNew { pub connector_account_details: Option, pub test_mode: Option, pub disabled: Option, - pub merchant_connector_id: String, + pub merchant_connector_id: id_type::MerchantConnectorAccountId, pub payment_methods_enabled: Option>, pub metadata: Option, pub connector_label: Option, @@ -173,7 +173,7 @@ pub struct MerchantConnectorAccountNew { pub status: storage_enums::ConnectorStatus, pub additional_merchant_data: Option, pub connector_wallets_details: Option, - pub id: String, + pub id: id_type::MerchantConnectorAccountId, pub version: common_enums::ApiVersion, } @@ -190,7 +190,7 @@ pub struct MerchantConnectorAccountUpdateInternal { pub connector_label: Option, pub test_mode: Option, pub disabled: Option, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub payment_methods_enabled: Option>, pub frm_configs: Option, pub metadata: Option, diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 84811f226249..ec87b2da2e4d 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -62,7 +62,7 @@ pub struct PaymentAttempt { pub connector_response_reference_id: Option, pub amount_capturable: i64, pub updated_by: String, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub authentication_data: Option, pub encoded_data: Option, pub unified_code: Option, @@ -133,7 +133,7 @@ pub struct PaymentAttempt { pub connector_response_reference_id: Option, pub amount_capturable: i64, pub updated_by: String, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub authentication_data: Option, pub encoded_data: Option, pub unified_code: Option, @@ -215,7 +215,7 @@ pub struct PaymentAttemptNew { pub multiple_capture_count: Option, pub amount_capturable: i64, pub updated_by: String, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub authentication_data: Option, pub encoded_data: Option, pub unified_code: Option, @@ -280,7 +280,7 @@ pub enum PaymentAttemptUpdate { surcharge_amount: Option, tax_amount: Option, updated_by: String, - merchant_connector_id: Option, + merchant_connector_id: Option, }, AuthenticationTypeUpdate { authentication_type: storage_enums::AuthenticationType, @@ -308,7 +308,7 @@ pub enum PaymentAttemptUpdate { tax_amount: Option, fingerprint_id: Option, updated_by: String, - merchant_connector_id: Option, + merchant_connector_id: Option, payment_method_id: Option, external_three_ds_authentication_attempted: Option, authentication_connector: Option, @@ -475,7 +475,7 @@ pub struct PaymentAttemptUpdateInternal { tax_amount: Option, amount_capturable: Option, updated_by: String, - merchant_connector_id: Option>, + merchant_connector_id: Option>, authentication_data: Option, encoded_data: Option, unified_code: Option>, diff --git a/crates/diesel_models/src/payout_attempt.rs b/crates/diesel_models/src/payout_attempt.rs index 7e9b2ec4e1c7..619e694f4111 100644 --- a/crates/diesel_models/src/payout_attempt.rs +++ b/crates/diesel_models/src/payout_attempt.rs @@ -28,7 +28,7 @@ pub struct PayoutAttempt { #[serde(with = "common_utils::custom_serde::iso8601")] pub last_modified_at: PrimitiveDateTime, pub profile_id: common_utils::id_type::ProfileId, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub routing_info: Option, } @@ -64,7 +64,7 @@ pub struct PayoutAttemptNew { #[serde(with = "common_utils::custom_serde::iso8601")] pub last_modified_at: PrimitiveDateTime, pub profile_id: common_utils::id_type::ProfileId, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub routing_info: Option, } @@ -89,7 +89,7 @@ pub enum PayoutAttemptUpdate { UpdateRouting { connector: String, routing_info: Option, - merchant_connector_id: Option, + merchant_connector_id: Option, }, } @@ -109,7 +109,7 @@ pub struct PayoutAttemptUpdateInternal { pub last_modified_at: PrimitiveDateTime, pub address_id: Option, pub customer_id: Option, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, } impl Default for PayoutAttemptUpdateInternal { diff --git a/crates/diesel_models/src/query/merchant_connector_account.rs b/crates/diesel_models/src/query/merchant_connector_account.rs index 7eeddd5d5926..ed3f1562f7cb 100644 --- a/crates/diesel_models/src/query/merchant_connector_account.rs +++ b/crates/diesel_models/src/query/merchant_connector_account.rs @@ -51,7 +51,7 @@ impl MerchantConnectorAccount { pub async fn delete_by_merchant_id_merchant_connector_id( conn: &PgPooledConn, merchant_id: &common_utils::id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &common_utils::id_type::MerchantConnectorAccountId, ) -> StorageResult { generics::generic_delete::<::Table, _>( conn, @@ -115,7 +115,7 @@ impl MerchantConnectorAccount { pub async fn find_by_merchant_id_merchant_connector_id( conn: &PgPooledConn, merchant_id: &common_utils::id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &common_utils::id_type::MerchantConnectorAccountId, ) -> StorageResult { generics::generic_find_one::<::Table, _, _>( conn, @@ -182,12 +182,18 @@ impl MerchantConnectorAccount { } } - pub async fn delete_by_id(conn: &PgPooledConn, id: &str) -> StorageResult { + pub async fn delete_by_id( + conn: &PgPooledConn, + id: &common_utils::id_type::MerchantConnectorAccountId, + ) -> StorageResult { generics::generic_delete::<::Table, _>(conn, dsl::id.eq(id.to_owned())) .await } - pub async fn find_by_id(conn: &PgPooledConn, id: &str) -> StorageResult { + pub async fn find_by_id( + conn: &PgPooledConn, + id: &common_utils::id_type::MerchantConnectorAccountId, + ) -> StorageResult { generics::generic_find_one::<::Table, _, _>( conn, dsl::id.eq(id.to_owned()), diff --git a/crates/diesel_models/src/query/payment_attempt.rs b/crates/diesel_models/src/query/payment_attempt.rs index 68f16b34457d..2af603f69547 100644 --- a/crates/diesel_models/src/query/payment_attempt.rs +++ b/crates/diesel_models/src/query/payment_attempt.rs @@ -322,7 +322,7 @@ impl PaymentAttempt { payment_method: Option>, payment_method_type: Option>, authentication_type: Option>, - merchant_connector_id: Option>, + merchant_connector_id: Option>, ) -> StorageResult { let mut filter = ::table() .count() diff --git a/crates/diesel_models/src/refund.rs b/crates/diesel_models/src/refund.rs index 3b73a6036778..10c1fbb9b298 100644 --- a/crates/diesel_models/src/refund.rs +++ b/crates/diesel_models/src/refund.rs @@ -48,7 +48,7 @@ pub struct Refund { pub refund_error_code: Option, pub profile_id: Option, pub updated_by: String, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub charges: Option, } @@ -90,7 +90,7 @@ pub struct RefundNew { pub refund_reason: Option, pub profile_id: Option, pub updated_by: String, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub charges: Option, } diff --git a/crates/diesel_models/src/user/sample_data.rs b/crates/diesel_models/src/user/sample_data.rs index 035d99e554b2..dbdae51c45ad 100644 --- a/crates/diesel_models/src/user/sample_data.rs +++ b/crates/diesel_models/src/user/sample_data.rs @@ -64,7 +64,7 @@ pub struct PaymentAttemptBatchNew { pub multiple_capture_count: Option, pub amount_capturable: i64, pub updated_by: String, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub authentication_data: Option, pub encoded_data: Option, pub unified_code: Option, diff --git a/crates/euclid/src/frontend/ast.rs b/crates/euclid/src/frontend/ast.rs index c77736effa9b..5a7b88acfbc2 100644 --- a/crates/euclid/src/frontend/ast.rs +++ b/crates/euclid/src/frontend/ast.rs @@ -164,7 +164,7 @@ pub struct RoutableConnectorChoice { #[serde(skip)] pub choice_kind: RoutableChoiceKind, pub connector: RoutableConnectors, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, } #[derive(Debug, Default, Clone, Deserialize, Serialize, ToSchema)] diff --git a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs b/crates/hyperswitch_domain_models/src/merchant_connector_account.rs index a841e2d1507d..c97fcbdfe86b 100644 --- a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs +++ b/crates/hyperswitch_domain_models/src/merchant_connector_account.rs @@ -3,7 +3,7 @@ use common_utils::{ date_time, encryption::Encryption, errors::{CustomResult, ValidationError}, - pii, type_name, + id_type, pii, type_name, types::keymanager::{Identifier, KeyManagerState}, }; use diesel_models::{enums, merchant_connector_account::MerchantConnectorAccountUpdateInternal}; @@ -19,12 +19,12 @@ use crate::type_encryption::{crypto_operation, AsyncLift, CryptoOperation}; ))] #[derive(Clone, Debug)] pub struct MerchantConnectorAccount { - pub merchant_id: common_utils::id_type::MerchantId, + pub merchant_id: id_type::MerchantId, pub connector_name: String, pub connector_account_details: Encryptable, pub test_mode: Option, pub disabled: Option, - pub merchant_connector_id: String, + pub merchant_connector_id: id_type::MerchantConnectorAccountId, pub payment_methods_enabled: Option>, pub connector_type: enums::ConnectorType, pub metadata: Option, @@ -36,7 +36,7 @@ pub struct MerchantConnectorAccount { pub created_at: time::PrimitiveDateTime, pub modified_at: time::PrimitiveDateTime, pub connector_webhook_details: Option, - pub profile_id: common_utils::id_type::ProfileId, + pub profile_id: id_type::ProfileId, pub applepay_verified_domains: Option>, pub pm_auth_config: Option, pub status: enums::ConnectorStatus, @@ -50,7 +50,7 @@ pub struct MerchantConnectorAccount { not(feature = "merchant_connector_account_v2") ))] impl MerchantConnectorAccount { - pub fn get_id(&self) -> String { + pub fn get_id(&self) -> id_type::MerchantConnectorAccountId { self.merchant_connector_id.clone() } } @@ -58,8 +58,8 @@ impl MerchantConnectorAccount { #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))] #[derive(Clone, Debug)] pub struct MerchantConnectorAccount { - pub id: String, - pub merchant_id: common_utils::id_type::MerchantId, + pub id: id_type::MerchantConnectorAccountId, + pub merchant_id: id_type::MerchantId, pub connector_name: String, pub connector_account_details: Encryptable, pub disabled: Option, @@ -71,7 +71,7 @@ pub struct MerchantConnectorAccount { pub created_at: time::PrimitiveDateTime, pub modified_at: time::PrimitiveDateTime, pub connector_webhook_details: Option, - pub profile_id: common_utils::id_type::ProfileId, + pub profile_id: id_type::ProfileId, pub applepay_verified_domains: Option>, pub pm_auth_config: Option, pub status: enums::ConnectorStatus, @@ -82,7 +82,7 @@ pub struct MerchantConnectorAccount { #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))] impl MerchantConnectorAccount { - pub fn get_id(&self) -> String { + pub fn get_id(&self) -> id_type::MerchantConnectorAccountId { self.id.clone() } } @@ -99,7 +99,7 @@ pub enum MerchantConnectorAccountUpdate { connector_account_details: Option>, test_mode: Option, disabled: Option, - merchant_connector_id: Option, + merchant_connector_id: Option, payment_methods_enabled: Option>, metadata: Option, frm_configs: Option>, diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index 5f2bc035f572..12880172d3d3 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -111,7 +111,7 @@ pub trait PaymentAttemptInterface { payment_method: Option>, payment_method_type: Option>, authentication_type: Option>, - merchant_connector_id: Option>, + merchant_connector_id: Option>, storage_scheme: storage_enums::MerchantStorageScheme, ) -> error_stack::Result; } @@ -168,7 +168,7 @@ pub struct PaymentAttempt { pub updated_by: String, pub authentication_data: Option, pub encoded_data: Option, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub unified_code: Option, pub unified_message: Option, pub external_three_ds_authentication_attempted: Option, @@ -258,7 +258,7 @@ pub struct PaymentAttemptNew { pub updated_by: String, pub authentication_data: Option, pub encoded_data: Option, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub unified_code: Option, pub unified_message: Option, pub external_three_ds_authentication_attempted: Option, @@ -317,7 +317,7 @@ pub enum PaymentAttemptUpdate { surcharge_amount: Option, tax_amount: Option, updated_by: String, - merchant_connector_id: Option, + merchant_connector_id: Option, }, AuthenticationTypeUpdate { authentication_type: storage_enums::AuthenticationType, @@ -344,7 +344,7 @@ pub enum PaymentAttemptUpdate { updated_by: String, surcharge_amount: Option, tax_amount: Option, - merchant_connector_id: Option, + merchant_connector_id: Option, external_three_ds_authentication_attempted: Option, authentication_connector: Option, authentication_id: Option, diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs index 4c59a90ba15a..dcb06733cc87 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs @@ -745,7 +745,7 @@ pub struct PaymentIntentListParams { pub payment_method: Option>, pub payment_method_type: Option>, pub authentication_type: Option>, - pub merchant_connector_id: Option>, + pub merchant_connector_id: Option>, pub profile_id: Option, pub customer_id: Option, pub starting_after_id: Option, diff --git a/crates/hyperswitch_domain_models/src/payouts/payout_attempt.rs b/crates/hyperswitch_domain_models/src/payouts/payout_attempt.rs index 8182ed35bab1..f747eb96c4a3 100644 --- a/crates/hyperswitch_domain_models/src/payouts/payout_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payouts/payout_attempt.rs @@ -76,7 +76,7 @@ pub struct PayoutAttempt { #[serde(with = "common_utils::custom_serde::iso8601")] pub last_modified_at: PrimitiveDateTime, pub profile_id: id_type::ProfileId, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub routing_info: Option, } @@ -99,7 +99,7 @@ pub struct PayoutAttemptNew { pub created_at: PrimitiveDateTime, pub last_modified_at: PrimitiveDateTime, pub profile_id: id_type::ProfileId, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub routing_info: Option, } @@ -124,7 +124,7 @@ pub enum PayoutAttemptUpdate { UpdateRouting { connector: String, routing_info: Option, - merchant_connector_id: Option, + merchant_connector_id: Option, }, } @@ -142,7 +142,7 @@ pub struct PayoutAttemptUpdateInternal { pub routing_info: Option, pub address_id: Option, pub customer_id: Option, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, } impl From for PayoutAttemptUpdateInternal { diff --git a/crates/kgraph_utils/benches/evaluation.rs b/crates/kgraph_utils/benches/evaluation.rs index 5a078de1d798..8e3bec16b2ac 100644 --- a/crates/kgraph_utils/benches/evaluation.rs +++ b/crates/kgraph_utils/benches/evaluation.rs @@ -58,7 +58,7 @@ fn build_test_data( let stripe_account = MerchantConnectorResponse { connector_type: api_enums::ConnectorType::FizOperations, connector_name: "stripe".to_string(), - id: "something".to_string(), + id: common_utils::generate_merchant_connector_account_id_of_default_length(), connector_account_details: masking::Secret::new(serde_json::json!({})), disabled: None, metadata: None, @@ -80,7 +80,8 @@ fn build_test_data( let stripe_account = MerchantConnectorResponse { connector_type: api_enums::ConnectorType::FizOperations, connector_name: "stripe".to_string(), - merchant_connector_id: "something".to_string(), + merchant_connector_id: + common_utils::generate_merchant_connector_account_id_of_default_length(), connector_account_details: masking::Secret::new(serde_json::json!({})), test_mode: None, disabled: None, diff --git a/crates/kgraph_utils/src/mca.rs b/crates/kgraph_utils/src/mca.rs index 1e099589b008..fa98ae915e87 100644 --- a/crates/kgraph_utils/src/mca.rs +++ b/crates/kgraph_utils/src/mca.rs @@ -710,7 +710,7 @@ mod tests { let stripe_account = MerchantConnectorResponse { connector_type: api_enums::ConnectorType::FizOperations, connector_name: "stripe".to_string(), - id: "something".to_string(), + id: common_utils::generate_merchant_connector_account_id_of_default_length(), connector_label: Some("something".to_string()), connector_account_details: masking::Secret::new(serde_json::json!({})), disabled: None, @@ -767,7 +767,8 @@ mod tests { let stripe_account = MerchantConnectorResponse { connector_type: api_enums::ConnectorType::FizOperations, connector_name: "stripe".to_string(), - merchant_connector_id: "something".to_string(), + merchant_connector_id: + common_utils::generate_merchant_connector_account_id_of_default_length(), business_country: Some(api_enums::CountryAlpha2::US), connector_label: Some("something".to_string()), business_label: Some("food".to_string()), diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index 084ac8eacc74..cb95feee9e95 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -1842,7 +1842,7 @@ impl<'a> ConnectorTypeAndConnectorName<'a> { ))] struct MerchantDefaultConfigUpdate<'a> { routable_connector: &'a Option, - merchant_connector_id: &'a String, + merchant_connector_id: &'a id_type::MerchantConnectorAccountId, store: &'a dyn StorageInterface, merchant_id: &'a id_type::MerchantId, profile_id: &'a id_type::ProfileId, @@ -1907,7 +1907,7 @@ impl<'a> MerchantDefaultConfigUpdate<'a> { ))] struct DefaultFallbackRoutingConfigUpdate<'a> { routable_connector: &'a Option, - merchant_connector_id: &'a String, + merchant_connector_id: &'a common_utils::id_type::MerchantConnectorAccountId, store: &'a dyn StorageInterface, business_profile: domain::BusinessProfile, key_store: hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, @@ -1954,7 +1954,7 @@ trait MerchantConnectorAccountUpdateBridge { self, db: &dyn StorageInterface, merchant_id: &id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &id_type::MerchantConnectorAccountId, key_store: &domain::MerchantKeyStore, key_manager_state: &KeyManagerState, ) -> RouterResult; @@ -1980,7 +1980,7 @@ impl MerchantConnectorAccountUpdateBridge for api_models::admin::MerchantConnect self, db: &dyn StorageInterface, _merchant_id: &id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &id_type::MerchantConnectorAccountId, key_store: &domain::MerchantKeyStore, key_manager_state: &KeyManagerState, ) -> RouterResult { @@ -2148,7 +2148,7 @@ impl MerchantConnectorAccountUpdateBridge for api_models::admin::MerchantConnect self, db: &dyn StorageInterface, merchant_id: &id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &id_type::MerchantConnectorAccountId, key_store: &domain::MerchantKeyStore, key_manager_state: &KeyManagerState, ) -> RouterResult { @@ -2161,7 +2161,7 @@ impl MerchantConnectorAccountUpdateBridge for api_models::admin::MerchantConnect .await .to_not_found_response( errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: merchant_connector_id.to_string(), + id: merchant_connector_id.get_string_repr().to_string(), }, ) } @@ -2433,7 +2433,7 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate { connector_label: Some(connector_label.clone()), created_at: date_time::now(), modified_at: date_time::now(), - id: common_utils::generate_time_ordered_id("mca"), + id: common_utils::generate_merchant_connector_account_id_of_default_length(), connector_webhook_details: match self.connector_webhook_details { Some(connector_webhook_details) => { connector_webhook_details.encode_to_value( @@ -2580,7 +2580,7 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate { merchant_id: business_profile.merchant_id.clone(), connector_type: self.connector_type, connector_name: self.connector_name.to_string(), - merchant_connector_id: utils::generate_id(consts::ID_LENGTH, "mca"), + merchant_connector_id: common_utils::generate_merchant_connector_account_id_of_default_length(), connector_account_details: domain_types::crypto_operation( key_manager_state, type_name!(domain::MerchantConnectorAccount), @@ -2913,7 +2913,7 @@ pub async fn retrieve_connector( state: SessionState, merchant_id: id_type::MerchantId, profile_id: Option, - merchant_connector_id: String, + merchant_connector_id: id_type::MerchantConnectorAccountId, ) -> RouterResponse { let store = state.store.as_ref(); let key_manager_state = &(&state).into(); @@ -2940,7 +2940,7 @@ pub async fn retrieve_connector( ) .await .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: merchant_connector_id.clone(), + id: merchant_connector_id.get_string_repr().to_string(), })?; core_utils::validate_profile_id_from_auth_layer(profile_id, &mca)?; @@ -2953,7 +2953,7 @@ pub async fn retrieve_connector( pub async fn retrieve_connector( state: SessionState, merchant_id: id_type::MerchantId, - id: String, + id: id_type::MerchantConnectorAccountId, ) -> RouterResponse { let store = state.store.as_ref(); let key_manager_state = &(&state).into(); @@ -2970,14 +2970,14 @@ pub async fn retrieve_connector( .find_merchant_connector_account_by_id(key_manager_state, &id, &key_store) .await .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: id.clone(), + id: id.clone().get_string_repr().to_string(), })?; // Validate if the merchant_id sent in the request is valid if mca.merchant_id != merchant_id { return Err(errors::ApiErrorResponse::InvalidRequestData { message: format!( - "Invalid merchant_id {} provided for merchant_connector_account {}", + "Invalid merchant_id {} provided for merchant_connector_account {:?}", merchant_id.get_string_repr(), id ), @@ -3039,7 +3039,7 @@ pub async fn update_connector( state: SessionState, merchant_id: &id_type::MerchantId, profile_id: Option, - merchant_connector_id: &str, + merchant_connector_id: &id_type::MerchantConnectorAccountId, req: api_models::admin::MerchantConnectorUpdate, ) -> RouterResponse { let db = state.store.as_ref(); @@ -3101,7 +3101,10 @@ pub async fn update_connector( }, ) .attach_printable_lazy(|| { - format!("Failed while updating MerchantConnectorAccount: id: {merchant_connector_id}") + format!( + "Failed while updating MerchantConnectorAccount: id: {:?}", + merchant_connector_id + ) })?; let response = updated_mca.foreign_try_into()?; @@ -3116,7 +3119,7 @@ pub async fn update_connector( pub async fn delete_connector( state: SessionState, merchant_id: id_type::MerchantId, - merchant_connector_id: String, + merchant_connector_id: id_type::MerchantConnectorAccountId, ) -> RouterResponse { let db = state.store.as_ref(); let key_manager_state = &(&state).into(); @@ -3143,7 +3146,7 @@ pub async fn delete_connector( ) .await .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: merchant_connector_id.clone(), + id: merchant_connector_id.get_string_repr().to_string(), })?; let is_deleted = db @@ -3153,7 +3156,7 @@ pub async fn delete_connector( ) .await .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: merchant_connector_id.clone(), + id: merchant_connector_id.get_string_repr().to_string(), })?; let response = api::MerchantConnectorDeleteResponse { @@ -3168,7 +3171,7 @@ pub async fn delete_connector( pub async fn delete_connector( state: SessionState, merchant_id: id_type::MerchantId, - id: String, + id: id_type::MerchantConnectorAccountId, ) -> RouterResponse { let db = state.store.as_ref(); let key_manager_state = &(&state).into(); @@ -3185,14 +3188,14 @@ pub async fn delete_connector( .find_merchant_connector_account_by_id(key_manager_state, &id, &key_store) .await .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: id.clone(), + id: id.clone().get_string_repr().to_string(), })?; // Validate if the merchant_id sent in the request is valid if mca.merchant_id != merchant_id { return Err(errors::ApiErrorResponse::InvalidRequestData { message: format!( - "Invalid merchant_id {} provided for merchant_connector_account {}", + "Invalid merchant_id {} provided for merchant_connector_account {:?}", merchant_id.get_string_repr(), id ), @@ -3204,7 +3207,7 @@ pub async fn delete_connector( .delete_merchant_connector_account_by_id(&id) .await .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: id.clone(), + id: id.clone().get_string_repr().to_string(), })?; let response = api::MerchantConnectorDeleteResponse { diff --git a/crates/router/src/core/authentication/utils.rs b/crates/router/src/core/authentication/utils.rs index 58862d189068..cd93a1cf6271 100644 --- a/crates/router/src/core/authentication/utils.rs +++ b/crates/router/src/core/authentication/utils.rs @@ -180,7 +180,7 @@ pub async fn create_new_authentication( token: String, profile_id: common_utils::id_type::ProfileId, payment_id: Option, - merchant_connector_id: String, + merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId, ) -> RouterResult { let authentication_id = common_utils::generate_id_with_default_len(consts::AUTHENTICATION_ID_PREFIX); diff --git a/crates/router/src/core/connector_onboarding/paypal.rs b/crates/router/src/core/connector_onboarding/paypal.rs index f967f2aece3f..a61fab395f07 100644 --- a/crates/router/src/core/connector_onboarding/paypal.rs +++ b/crates/router/src/core/connector_onboarding/paypal.rs @@ -141,7 +141,7 @@ async fn find_paypal_merchant_by_tracking_id( pub async fn update_mca( state: &SessionState, merchant_id: common_utils::id_type::MerchantId, - connector_id: String, + connector_id: common_utils::id_type::MerchantConnectorAccountId, auth_details: oss_types::ConnectorAuthType, ) -> RouterResult { let connector_auth_json = auth_details diff --git a/crates/router/src/core/files/helpers.rs b/crates/router/src/core/files/helpers.rs index 14e404e88a04..bd4fc749758e 100644 --- a/crates/router/src/core/files/helpers.rs +++ b/crates/router/src/core/files/helpers.rs @@ -246,7 +246,7 @@ pub async fn upload_and_get_provider_provider_file_id_profile_id( String, api_models::enums::FileUploadProvider, Option, - Option, + Option, ), errors::ApiErrorResponse, > { diff --git a/crates/router/src/core/mandate.rs b/crates/router/src/core/mandate.rs index e74f7f11a73f..8118d8a322a1 100644 --- a/crates/router/src/core/mandate.rs +++ b/crates/router/src/core/mandate.rs @@ -353,7 +353,7 @@ pub async fn mandate_procedure( resp: &types::RouterData, customer_id: &Option, pm_id: Option, - merchant_connector_id: Option, + merchant_connector_id: Option, storage_scheme: MerchantStorageScheme, ) -> errors::RouterResult> where diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 586e93a0fe62..9896ff3008e9 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -2763,7 +2763,10 @@ pub async fn list_payment_methods( // No PM_FILTER_CGRAPH Cache present in MokaCache let mut builder = cgraph::ConstraintGraphBuilder::new(); for mca in &filtered_mcas { - let domain_id = builder.make_domain(mca.get_id(), mca.connector_name.as_str()); + let domain_id = builder.make_domain( + mca.get_id().get_string_repr().to_string(), + mca.connector_name.as_str(), + ); let Ok(domain_id) = domain_id else { logger::error!("Failed to construct domain for list payment methods"); @@ -3778,7 +3781,7 @@ pub async fn call_surcharge_decision_management_for_saved_card( #[allow(clippy::too_many_arguments)] pub async fn filter_payment_methods( graph: &cgraph::ConstraintGraph, - mca_id: String, + mca_id: id_type::MerchantConnectorAccountId, payment_methods: &[Secret], req: &mut api::PaymentMethodListRequest, resp: &mut Vec, @@ -3928,7 +3931,7 @@ pub async fn filter_payment_methods( let context = AnalysisContext::from_dir_values(context_values.clone()); logger::info!("Context created for List Payment method is {:?}", context); - let domain_ident: &[String] = &[mca_id.clone()]; + let domain_ident: &[String] = &[mca_id.clone().get_string_repr().to_string()]; let result = graph.key_value_analysis( pm_dir_value.clone(), &context, diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 72a188a47eca..586d1989dec0 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -2008,8 +2008,10 @@ where &connector_name, ); - let connector_label = if let Some(connector_label) = - merchant_connector_account.get_mca_id().or(connector_label) + let connector_label = if let Some(connector_label) = merchant_connector_account + .get_mca_id() + .map(|mca_id| mca_id.get_string_repr().to_string()) + .or(connector_label) { connector_label } else { @@ -2284,7 +2286,7 @@ pub async fn construct_profile_id_and_get_mca<'a, F>( merchant_account: &domain::MerchantAccount, payment_data: &mut PaymentData, connector_name: &str, - merchant_connector_id: Option<&String>, + merchant_connector_id: Option<&id_type::MerchantConnectorAccountId>, key_store: &domain::MerchantKeyStore, _should_validate: bool, ) -> RouterResult @@ -2710,7 +2712,7 @@ where #[derive(Clone)] pub struct MandateConnectorDetails { pub connector: String, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, } #[derive(Clone)] diff --git a/crates/router/src/core/payments/access_token.rs b/crates/router/src/core/payments/access_token.rs index 78ef29e473dd..8ac89f76ad3b 100644 --- a/crates/router/src/core/payments/access_token.rs +++ b/crates/router/src/core/payments/access_token.rs @@ -76,6 +76,7 @@ pub async fn add_access_token< let merchant_connector_id_or_connector_name = connector .merchant_connector_id .clone() + .map(|mca_id| mca_id.get_string_repr().to_string()) .or(creds_identifier.cloned()) .unwrap_or(connector.connector_name.to_string()); diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 176e7d96acae..181e2232d90b 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -2693,7 +2693,7 @@ pub fn generate_mandate( network_txn_id: Option, payment_method_data_option: Option, mandate_reference: Option, - merchant_connector_id: Option, + merchant_connector_id: Option, ) -> CustomResult, errors::ApiErrorResponse> { match (setup_mandate_details, customer_id) { (Some(data), Some(cus_id)) => { @@ -3205,7 +3205,7 @@ impl MerchantConnectorAccountType { None } - pub fn get_mca_id(&self) -> Option { + pub fn get_mca_id(&self) -> Option { match self { Self::DbVal(db_val) => Some(db_val.get_id()), Self::CacheVal(_) => None, @@ -3239,7 +3239,7 @@ pub async fn get_merchant_connector_account( key_store: &domain::MerchantKeyStore, profile_id: &id_type::ProfileId, connector_name: &str, - merchant_connector_id: Option<&String>, + merchant_connector_id: Option<&id_type::MerchantConnectorAccountId>, ) -> RouterResult { let db = &*state.store; let key_manager_state: &KeyManagerState = &state.into(); @@ -3332,7 +3332,7 @@ pub async fn get_merchant_connector_account( .await .to_not_found_response( errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: merchant_connector_id.to_string(), + id: merchant_connector_id.get_string_repr().to_string(), }, ) } @@ -4232,7 +4232,7 @@ pub async fn get_apple_pay_retryable_connectors( payment_data: &mut PaymentData, key_store: &domain::MerchantKeyStore, pre_routing_connector_data_list: &[api::ConnectorData], - merchant_connector_id: Option<&String>, + merchant_connector_id: Option<&id_type::MerchantConnectorAccountId>, business_profile: domain::BusinessProfile, ) -> CustomResult>, errors::ApiErrorResponse> where @@ -5199,7 +5199,7 @@ pub async fn validate_merchant_connector_ids_in_connector_mandate_details( .to_not_found_response(errors::ApiErrorResponse::InternalServerError)?; let merchant_connector_account_details_hash_map: std::collections::HashMap< - String, + id_type::MerchantConnectorAccountId, domain::MerchantConnectorAccount, > = merchant_connector_account_list .iter() @@ -5214,33 +5214,43 @@ pub async fn validate_merchant_connector_ids_in_connector_mandate_details( for (migrating_merchant_connector_id, migrating_connector_mandate_details) in connector_mandate_details.0.clone() { - match (card_network.clone() ,merchant_connector_account_details_hash_map.get(&migrating_merchant_connector_id)) { - (Some(enums::CardNetwork::Discover),Some(merchant_connector_account_details)) => if let ("cybersource", None) = ( - merchant_connector_account_details.connector_name.as_str(), - migrating_connector_mandate_details - .original_payment_authorized_amount - .zip( - migrating_connector_mandate_details - .original_payment_authorized_currency, - ), - ) { - Err(errors::ApiErrorResponse::MissingRequiredFields { - field_names: vec![ - "original_payment_authorized_currency", - "original_payment_authorized_amount", - ], - }).attach_printable(format!("Invalid connector_mandate_details provided for connector {migrating_merchant_connector_id}"))? - }, - (_, Some(_)) => (), - (_, None) => { - Err(errors::ApiErrorResponse::InvalidDataValue { - field_name: "merchant_connector_id", - }) - .attach_printable_lazy(|| { - format!("{migrating_merchant_connector_id} invalid merchant connector id in connector_mandate_details") - })? - }, - } + match ( + card_network.clone(), + merchant_connector_account_details_hash_map.get(&migrating_merchant_connector_id), + ) { + (Some(enums::CardNetwork::Discover), Some(merchant_connector_account_details)) => { + if let ("cybersource", None) = ( + merchant_connector_account_details.connector_name.as_str(), + migrating_connector_mandate_details + .original_payment_authorized_amount + .zip( + migrating_connector_mandate_details + .original_payment_authorized_currency, + ), + ) { + Err(errors::ApiErrorResponse::MissingRequiredFields { + field_names: vec![ + "original_payment_authorized_currency", + "original_payment_authorized_amount", + ], + }) + .attach_printable(format!( + "Invalid connector_mandate_details provided for connector {:?}", + migrating_merchant_connector_id + ))? + } + } + (_, Some(_)) => (), + (_, None) => Err(errors::ApiErrorResponse::InvalidDataValue { + field_name: "merchant_connector_id", + }) + .attach_printable_lazy(|| { + format!( + "{:?} invalid merchant connector id in connector_mandate_details", + migrating_merchant_connector_id + ) + })?, + } } Ok(()) } diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs index f26ed588a010..6a2689da4002 100644 --- a/crates/router/src/core/payments/tokenization.rs +++ b/crates/router/src/core/payments/tokenization.rs @@ -67,7 +67,7 @@ impl From<&types::RouterData pub async fn save_payment_method( state: &SessionState, connector_name: String, - merchant_connector_id: Option, + merchant_connector_id: Option, save_payment_method_data: SavePaymentMethodData, customer_id: Option, merchant_account: &domain::MerchantAccount, @@ -657,7 +657,7 @@ where pub async fn save_payment_method( _state: &SessionState, _connector_name: String, - _merchant_connector_id: Option, + _merchant_connector_id: Option, _save_payment_method_data: SavePaymentMethodData, _customer_id: Option, _merchant_account: &domain::MerchantAccount, @@ -983,7 +983,7 @@ pub fn add_connector_mandate_details_in_payment_method( payment_method_type: Option, authorized_amount: Option, authorized_currency: Option, - merchant_connector_id: Option, + merchant_connector_id: Option, connector_mandate_id: Option, ) -> Option { let mut mandate_details = HashMap::new(); @@ -1011,7 +1011,7 @@ pub fn update_connector_mandate_details_in_payment_method( payment_method_type: Option, authorized_amount: Option, authorized_currency: Option, - merchant_connector_id: Option, + merchant_connector_id: Option, connector_mandate_id: Option, ) -> RouterResult> { let mandate_reference = match payment_method.connector_mandate_details { diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs index 1f24298d998a..57c4152ee29b 100644 --- a/crates/router/src/core/payouts.rs +++ b/crates/router/src/core/payouts.rs @@ -2763,7 +2763,7 @@ pub async fn get_mca_from_profile_id( merchant_account: &domain::MerchantAccount, profile_id: &common_utils::id_type::ProfileId, connector_name: &str, - merchant_connector_id: Option<&String>, + merchant_connector_id: Option<&common_utils::id_type::MerchantConnectorAccountId>, key_store: &domain::MerchantKeyStore, ) -> RouterResult { let merchant_connector_account = payment_helpers::get_merchant_connector_account( diff --git a/crates/router/src/core/pm_auth.rs b/crates/router/src/core/pm_auth.rs index 47f843030eeb..4a462b4bc621 100644 --- a/crates/router/src/core/pm_auth.rs +++ b/crates/router/src/core/pm_auth.rs @@ -307,7 +307,7 @@ async fn store_bank_details_in_payment_methods( state: SessionState, bank_account_details_resp: pm_auth_types::BankAccountCredentialsResponse, connector_details: (&str, Secret), - mca_id: String, + mca_id: common_utils::id_type::MerchantConnectorAccountId, ) -> RouterResult<()> { let key = key_store.key.get_inner().peek(); let db = &*state.clone().store; @@ -753,7 +753,12 @@ pub async fn retrieve_payment_method_from_auth_service( ) .await .to_not_found_response(ApiErrorResponse::MerchantConnectorAccountNotFound { - id: auth_token.connector_details.mca_id.clone(), + id: auth_token + .connector_details + .mca_id + .get_string_repr() + .to_string() + .clone(), }) .attach_printable( "error while fetching merchant_connector_account from merchant_id and connector name", diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rs index 5cbb1e9fdf68..448cebbf06e6 100644 --- a/crates/router/src/core/routing/helpers.rs +++ b/crates/router/src/core/routing/helpers.rs @@ -251,7 +251,12 @@ pub struct RoutingAlgorithmHelpers<'h> { } #[derive(Clone, Debug)] -pub struct ConnectNameAndMCAIdForProfile<'a>(pub FxHashSet<(&'a String, String)>); +pub struct ConnectNameAndMCAIdForProfile<'a>( + pub FxHashSet<( + &'a String, + common_utils::id_type::MerchantConnectorAccountId, + )>, +); #[derive(Clone, Debug)] pub struct ConnectNameForProfile<'a>(pub FxHashSet<&'a String>); @@ -322,7 +327,7 @@ impl<'h> RoutingAlgorithmHelpers<'h> { self.name_mca_id_set.0.contains(&(&choice.connector.to_string(), mca_id.clone())), errors::ApiErrorResponse::InvalidRequestData { message: format!( - "connector with name '{}' and merchant connector account id '{}' not found for the given profile", + "connector with name '{}' and merchant connector account id '{:?}' not found for the given profile", choice.connector, mca_id, ) @@ -430,7 +435,7 @@ pub async fn validate_connectors_in_routing_config( name_mca_id_set.contains(&(&choice.connector.to_string(), mca_id.clone())), errors::ApiErrorResponse::InvalidRequestData { message: format!( - "connector with name '{}' and merchant connector account id '{}' not found for the given profile", + "connector with name '{}' and merchant connector account id '{:?}' not found for the given profile", choice.connector, mca_id, ) diff --git a/crates/router/src/core/verification.rs b/crates/router/src/core/verification.rs index 44bb67d0baf2..8dc312b7f583 100644 --- a/crates/router/src/core/verification.rs +++ b/crates/router/src/core/verification.rs @@ -87,7 +87,7 @@ pub async fn verify_merchant_creds_for_applepay( pub async fn get_verified_apple_domains_with_mid_mca_id( state: SessionState, merchant_id: common_utils::id_type::MerchantId, - merchant_connector_id: String, + merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId, ) -> CustomResult< services::ApplicationResponse, errors::ApiErrorResponse, @@ -111,7 +111,7 @@ pub async fn get_verified_apple_domains_with_mid_mca_id( .find_by_merchant_connector_account_merchant_id_merchant_connector_id( key_manager_state, &merchant_id, - merchant_connector_id.as_str(), + &merchant_connector_id, &key_store, ) .await diff --git a/crates/router/src/core/verification/utils.rs b/crates/router/src/core/verification/utils.rs index c4fbf7ab0813..e868fe930b75 100644 --- a/crates/router/src/core/verification/utils.rs +++ b/crates/router/src/core/verification/utils.rs @@ -16,7 +16,7 @@ pub async fn check_existence_and_add_domain_to_db( state: &SessionState, merchant_id: common_utils::id_type::MerchantId, profile_id_from_auth_layer: Option, - merchant_connector_id: String, + merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId, domain_from_req: Vec, ) -> CustomResult, errors::ApiErrorResponse> { let key_manager_state = &state.into(); @@ -116,7 +116,10 @@ pub async fn check_existence_and_add_domain_to_db( .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable_lazy(|| { - format!("Failed while updating MerchantConnectorAccount: id: {merchant_connector_id}") + format!( + "Failed while updating MerchantConnectorAccount: id: {:?}", + merchant_connector_id + ) })?; Ok(already_verified_domains.clone()) diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs index 01a1046be369..0a0a35c23cc3 100644 --- a/crates/router/src/core/webhooks/incoming.rs +++ b/crates/router/src/core/webhooks/incoming.rs @@ -1598,7 +1598,7 @@ async fn verify_webhook_source_verification_call( fn get_connector_by_connector_name( state: &SessionState, connector_name: &str, - merchant_connector_id: Option, + merchant_connector_id: Option, ) -> CustomResult<(ConnectorEnum, String), errors::ApiErrorResponse> { let authentication_connector = api_models::enums::convert_authentication_connector(connector_name); @@ -1666,7 +1666,14 @@ async fn fetch_optional_mca_and_connector( .find_by_merchant_connector_account_merchant_id_merchant_connector_id( &state.into(), merchant_account.get_id(), - connector_name_or_mca_id, + &common_utils::id_type::MerchantConnectorAccountId::wrap( + connector_name_or_mca_id.to_owned(), + ) + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable( + "Error while converting MerchanConnectorAccountId from string + ", + )?, key_store, ) .await diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs index 37613d5961e6..403b79a03778 100644 --- a/crates/router/src/db/kafka_store.rs +++ b/crates/router/src/db/kafka_store.rs @@ -1162,7 +1162,7 @@ impl MerchantConnectorAccountInterface for KafkaStore { &self, state: &KeyManagerState, merchant_id: &id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &id_type::MerchantConnectorAccountId, key_store: &domain::MerchantKeyStore, ) -> CustomResult { self.diesel_store @@ -1179,7 +1179,7 @@ impl MerchantConnectorAccountInterface for KafkaStore { async fn find_merchant_connector_account_by_id( &self, state: &KeyManagerState, - id: &str, + id: &id_type::MerchantConnectorAccountId, key_store: &domain::MerchantKeyStore, ) -> CustomResult { self.diesel_store @@ -1223,7 +1223,7 @@ impl MerchantConnectorAccountInterface for KafkaStore { async fn delete_merchant_connector_account_by_merchant_id_merchant_connector_id( &self, merchant_id: &id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &id_type::MerchantConnectorAccountId, ) -> CustomResult { self.diesel_store .delete_merchant_connector_account_by_merchant_id_merchant_connector_id( @@ -1236,7 +1236,7 @@ impl MerchantConnectorAccountInterface for KafkaStore { #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))] async fn delete_merchant_connector_account_by_id( &self, - id: &str, + id: &id_type::MerchantConnectorAccountId, ) -> CustomResult { self.diesel_store .delete_merchant_connector_account_by_id(id) @@ -1472,7 +1472,7 @@ impl PaymentAttemptInterface for KafkaStore { payment_method: Option>, payment_method_type: Option>, authentication_type: Option>, - merchant_connector_id: Option>, + merchant_connector_id: Option>, storage_scheme: MerchantStorageScheme, ) -> CustomResult { self.diesel_store diff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rs index 1908e01e94f6..831804b0c6e3 100644 --- a/crates/router/src/db/merchant_connector_account.rs +++ b/crates/router/src/db/merchant_connector_account.rs @@ -173,7 +173,7 @@ where &self, state: &KeyManagerState, merchant_id: &common_utils::id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &common_utils::id_type::MerchantConnectorAccountId, key_store: &domain::MerchantKeyStore, ) -> CustomResult; @@ -181,7 +181,7 @@ where async fn find_merchant_connector_account_by_id( &self, state: &KeyManagerState, - id: &str, + id: &common_utils::id_type::MerchantConnectorAccountId, key_store: &domain::MerchantKeyStore, ) -> CustomResult; @@ -216,13 +216,13 @@ where async fn delete_merchant_connector_account_by_merchant_id_merchant_connector_id( &self, merchant_id: &common_utils::id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &common_utils::id_type::MerchantConnectorAccountId, ) -> CustomResult; #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))] async fn delete_merchant_connector_account_by_id( &self, - id: &str, + id: &common_utils::id_type::MerchantConnectorAccountId, ) -> CustomResult; } @@ -387,7 +387,7 @@ impl MerchantConnectorAccountInterface for Store { &self, state: &KeyManagerState, merchant_id: &common_utils::id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &common_utils::id_type::MerchantConnectorAccountId, key_store: &domain::MerchantKeyStore, ) -> CustomResult { let find_call = || async { @@ -421,7 +421,7 @@ impl MerchantConnectorAccountInterface for Store { &format!( "{}_{}", merchant_id.get_string_repr(), - merchant_connector_id + merchant_connector_id.get_string_repr() ), find_call, &cache::ACCOUNTS_CACHE, @@ -442,7 +442,7 @@ impl MerchantConnectorAccountInterface for Store { async fn find_merchant_connector_account_by_id( &self, state: &KeyManagerState, - id: &str, + id: &common_utils::id_type::MerchantConnectorAccountId, key_store: &domain::MerchantKeyStore, ) -> CustomResult { let find_call = || async { @@ -467,17 +467,22 @@ impl MerchantConnectorAccountInterface for Store { #[cfg(feature = "accounts_cache")] { - cache::get_or_populate_in_memory(self, id, find_call, &cache::ACCOUNTS_CACHE) - .await? - .convert( - state, - key_store.key.get_inner(), - common_utils::types::keymanager::Identifier::Merchant( - key_store.merchant_id.clone(), - ), - ) - .await - .change_context(errors::StorageError::DecryptionError) + cache::get_or_populate_in_memory( + self, + id.get_string_repr(), + find_call, + &cache::ACCOUNTS_CACHE, + ) + .await? + .convert( + state, + key_store.key.get_inner(), + common_utils::types::keymanager::Identifier::Merchant( + key_store.merchant_id.clone(), + ), + ) + .await + .change_context(errors::StorageError::DecryptionError) } } @@ -593,7 +598,7 @@ impl MerchantConnectorAccountInterface for Store { format!( "{}_{}", _merchant_id.get_string_repr(), - _merchant_connector_id + _merchant_connector_id.get_string_repr() ) .into(), ), @@ -693,7 +698,7 @@ impl MerchantConnectorAccountInterface for Store { format!( "{}_{}", _merchant_id.get_string_repr(), - _merchant_connector_id + _merchant_connector_id.get_string_repr() ) .into(), ), @@ -775,7 +780,7 @@ impl MerchantConnectorAccountInterface for Store { format!( "{}_{}", _merchant_id.get_string_repr(), - _merchant_connector_id + _merchant_connector_id.get_string_repr() ) .into(), ), @@ -815,7 +820,7 @@ impl MerchantConnectorAccountInterface for Store { async fn delete_merchant_connector_account_by_merchant_id_merchant_connector_id( &self, merchant_id: &common_utils::id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &common_utils::id_type::MerchantConnectorAccountId, ) -> CustomResult { let conn = connection::pg_connection_write(self).await?; let delete_call = || async { @@ -890,7 +895,7 @@ impl MerchantConnectorAccountInterface for Store { #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))] async fn delete_merchant_connector_account_by_id( &self, - id: &str, + id: &common_utils::id_type::MerchantConnectorAccountId, ) -> CustomResult { let conn = connection::pg_connection_write(self).await?; let delete_call = || async { @@ -1092,7 +1097,7 @@ impl MerchantConnectorAccountInterface for MockDb { &self, state: &KeyManagerState, merchant_id: &common_utils::id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &common_utils::id_type::MerchantConnectorAccountId, key_store: &domain::MerchantKeyStore, ) -> CustomResult { match self @@ -1102,7 +1107,7 @@ impl MerchantConnectorAccountInterface for MockDb { .iter() .find(|account| { account.merchant_id == *merchant_id - && account.merchant_connector_id == merchant_connector_id + && account.merchant_connector_id == *merchant_connector_id }) .cloned() .async_map(|account| async { @@ -1131,7 +1136,7 @@ impl MerchantConnectorAccountInterface for MockDb { async fn find_merchant_connector_account_by_id( &self, state: &KeyManagerState, - id: &str, + id: &common_utils::id_type::MerchantConnectorAccountId, key_store: &domain::MerchantKeyStore, ) -> CustomResult { match self @@ -1139,7 +1144,7 @@ impl MerchantConnectorAccountInterface for MockDb { .lock() .await .iter() - .find(|account| account.get_id() == id) + .find(|account| account.get_id() == *id) .cloned() .async_map(|account| async { account @@ -1393,12 +1398,12 @@ impl MerchantConnectorAccountInterface for MockDb { async fn delete_merchant_connector_account_by_merchant_id_merchant_connector_id( &self, merchant_id: &common_utils::id_type::MerchantId, - merchant_connector_id: &str, + merchant_connector_id: &common_utils::id_type::MerchantConnectorAccountId, ) -> CustomResult { let mut accounts = self.merchant_connector_accounts.lock().await; match accounts.iter().position(|account| { account.merchant_id == *merchant_id - && account.merchant_connector_id == merchant_connector_id + && account.merchant_connector_id == *merchant_connector_id }) { Some(index) => { accounts.remove(index); @@ -1416,10 +1421,10 @@ impl MerchantConnectorAccountInterface for MockDb { #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))] async fn delete_merchant_connector_account_by_id( &self, - id: &str, + id: &common_utils::id_type::MerchantConnectorAccountId, ) -> CustomResult { let mut accounts = self.merchant_connector_accounts.lock().await; - match accounts.iter().position(|account| account.get_id() == id) { + match accounts.iter().position(|account| account.get_id() == *id) { Some(index) => { accounts.remove(index); return Ok(true); @@ -1562,7 +1567,10 @@ mod merchant_connector_account_cache_tests { .unwrap(), test_mode: None, disabled: None, - merchant_connector_id: merchant_connector_id.to_string(), + merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId::wrap( + merchant_connector_id.to_string(), + ) + .unwrap(), payment_methods_enabled: None, connector_type: ConnectorType::FinOperations, metadata: None, @@ -1628,7 +1636,10 @@ mod merchant_connector_account_cache_tests { let delete_call = || async { db.delete_merchant_connector_account_by_merchant_id_merchant_connector_id( &merchant_id, - merchant_connector_id, + &common_utils::id_type::MerchantConnectorAccountId::wrap( + merchant_connector_id.to_string(), + ) + .unwrap(), ) .await }; @@ -1685,7 +1696,7 @@ mod merchant_connector_account_cache_tests { common_utils::id_type::MerchantId::try_from(std::borrow::Cow::from("test_merchant")) .unwrap(); let connector_label = "stripe_USA"; - let id = "simple_id"; + let id = common_utils::generate_merchant_connector_account_id_of_default_length(); let profile_id = common_utils::id_type::ProfileId::try_from(std::borrow::Cow::from("pro_max_ultra")) .unwrap(); @@ -1723,7 +1734,7 @@ mod merchant_connector_account_cache_tests { .unwrap(); let mca = domain::MerchantConnectorAccount { - id: id.to_string(), + id: id.clone(), merchant_id: merchant_id.clone(), connector_name: "stripe".to_string(), connector_account_details: domain::types::crypto_operation( @@ -1803,7 +1814,7 @@ mod merchant_connector_account_cache_tests { .await .unwrap(); - let delete_call = || async { db.delete_merchant_connector_account_by_id(id).await }; + let delete_call = || async { db.delete_merchant_connector_account_by_id(&id).await }; cache::publish_and_redact( &db, diff --git a/crates/router/src/routes/admin.rs b/crates/router/src/routes/admin.rs index 343246e31a09..7616e83beef1 100644 --- a/crates/router/src/routes/admin.rs +++ b/crates/router/src/routes/admin.rs @@ -410,7 +410,10 @@ pub async fn connector_create( pub async fn connector_retrieve( state: web::Data, req: HttpRequest, - path: web::Path<(common_utils::id_type::MerchantId, String)>, + path: web::Path<( + common_utils::id_type::MerchantId, + common_utils::id_type::MerchantConnectorAccountId, + )>, ) -> HttpResponse { let flow = Flow::MerchantConnectorsRetrieve; let (merchant_id, merchant_connector_id) = path.into_inner(); @@ -468,7 +471,7 @@ pub async fn connector_retrieve( pub async fn connector_retrieve( state: web::Data, req: HttpRequest, - path: web::Path, + path: web::Path, ) -> HttpResponse { let flow = Flow::MerchantConnectorsRetrieve; let id = path.into_inner(); @@ -623,7 +626,10 @@ pub async fn payment_connector_list_profile( pub async fn connector_update( state: web::Data, req: HttpRequest, - path: web::Path<(common_utils::id_type::MerchantId, String)>, + path: web::Path<( + common_utils::id_type::MerchantId, + common_utils::id_type::MerchantConnectorAccountId, + )>, json_payload: web::Json, ) -> HttpResponse { let flow = Flow::MerchantConnectorsUpdate; @@ -680,7 +686,7 @@ pub async fn connector_update( pub async fn connector_update( state: web::Data, req: HttpRequest, - path: web::Path, + path: web::Path, json_payload: web::Json, ) -> HttpResponse { let flow = Flow::MerchantConnectorsUpdate; @@ -733,7 +739,10 @@ pub async fn connector_update( pub async fn connector_delete( state: web::Data, req: HttpRequest, - path: web::Path<(common_utils::id_type::MerchantId, String)>, + path: web::Path<( + common_utils::id_type::MerchantId, + common_utils::id_type::MerchantConnectorAccountId, + )>, ) -> HttpResponse { let flow = Flow::MerchantConnectorsDelete; let (merchant_id, merchant_connector_id) = path.into_inner(); @@ -784,7 +793,7 @@ pub async fn connector_delete( pub async fn connector_delete( state: web::Data, req: HttpRequest, - path: web::Path, + path: web::Path, ) -> HttpResponse { let flow = Flow::MerchantConnectorsDelete; let id = path.into_inner(); diff --git a/crates/router/src/routes/verification.rs b/crates/router/src/routes/verification.rs index d064da0517fb..b818fcfc1d43 100644 --- a/crates/router/src/routes/verification.rs +++ b/crates/router/src/routes/verification.rs @@ -59,7 +59,7 @@ pub async fn retrieve_apple_pay_verified_domains( verification::get_verified_apple_domains_with_mid_mca_id( state, merchant_id.to_owned(), - mca_id.to_string(), + mca_id.clone(), ) }, auth::auth_type( diff --git a/crates/router/src/services/kafka/authentication.rs b/crates/router/src/services/kafka/authentication.rs index 42079525d8ae..0dfda622d3bd 100644 --- a/crates/router/src/services/kafka/authentication.rs +++ b/crates/router/src/services/kafka/authentication.rs @@ -37,7 +37,7 @@ pub struct KafkaAuthentication<'a> { pub acs_signed_content: Option<&'a String>, pub profile_id: &'a common_utils::id_type::ProfileId, pub payment_id: Option<&'a String>, - pub merchant_connector_id: &'a String, + pub merchant_connector_id: &'a common_utils::id_type::MerchantConnectorAccountId, pub ds_trans_id: Option<&'a String>, pub directory_server_id: Option<&'a String>, pub acquirer_country_code: Option<&'a String>, diff --git a/crates/router/src/services/kafka/authentication_event.rs b/crates/router/src/services/kafka/authentication_event.rs index 6213488a6d3f..8d48e56a6137 100644 --- a/crates/router/src/services/kafka/authentication_event.rs +++ b/crates/router/src/services/kafka/authentication_event.rs @@ -38,7 +38,7 @@ pub struct KafkaAuthenticationEvent<'a> { pub acs_signed_content: Option<&'a String>, pub profile_id: &'a common_utils::id_type::ProfileId, pub payment_id: Option<&'a String>, - pub merchant_connector_id: &'a String, + pub merchant_connector_id: &'a common_utils::id_type::MerchantConnectorAccountId, pub ds_trans_id: Option<&'a String>, pub directory_server_id: Option<&'a String>, pub acquirer_country_code: Option<&'a String>, diff --git a/crates/router/src/services/kafka/dispute.rs b/crates/router/src/services/kafka/dispute.rs index 6f789cbe94e8..62a4310a6408 100644 --- a/crates/router/src/services/kafka/dispute.rs +++ b/crates/router/src/services/kafka/dispute.rs @@ -31,7 +31,7 @@ pub struct KafkaDispute<'a> { pub connector: &'a String, pub evidence: &'a Secret, pub profile_id: Option<&'a common_utils::id_type::ProfileId>, - pub merchant_connector_id: Option<&'a String>, + pub merchant_connector_id: Option<&'a common_utils::id_type::MerchantConnectorAccountId>, } impl<'a> KafkaDispute<'a> { diff --git a/crates/router/src/services/kafka/dispute_event.rs b/crates/router/src/services/kafka/dispute_event.rs index e42549125974..9b73cc2e5101 100644 --- a/crates/router/src/services/kafka/dispute_event.rs +++ b/crates/router/src/services/kafka/dispute_event.rs @@ -32,7 +32,7 @@ pub struct KafkaDisputeEvent<'a> { pub connector: &'a String, pub evidence: &'a Secret, pub profile_id: Option<&'a common_utils::id_type::ProfileId>, - pub merchant_connector_id: Option<&'a String>, + pub merchant_connector_id: Option<&'a common_utils::id_type::MerchantConnectorAccountId>, } impl<'a> KafkaDisputeEvent<'a> { diff --git a/crates/router/src/services/kafka/payment_attempt.rs b/crates/router/src/services/kafka/payment_attempt.rs index df566ad8a8de..08ec50f06b7c 100644 --- a/crates/router/src/services/kafka/payment_attempt.rs +++ b/crates/router/src/services/kafka/payment_attempt.rs @@ -47,7 +47,7 @@ pub struct KafkaPaymentAttempt<'a> { pub error_reason: Option<&'a String>, pub multiple_capture_count: Option, pub amount_capturable: MinorUnit, - pub merchant_connector_id: Option<&'a String>, + pub merchant_connector_id: Option<&'a common_utils::id_type::MerchantConnectorAccountId>, pub net_amount: MinorUnit, pub unified_code: Option<&'a String>, pub unified_message: Option<&'a String>, diff --git a/crates/router/src/services/kafka/payment_attempt_event.rs b/crates/router/src/services/kafka/payment_attempt_event.rs index 95c5d9edd561..c6337a3b5f04 100644 --- a/crates/router/src/services/kafka/payment_attempt_event.rs +++ b/crates/router/src/services/kafka/payment_attempt_event.rs @@ -48,7 +48,7 @@ pub struct KafkaPaymentAttemptEvent<'a> { pub error_reason: Option<&'a String>, pub multiple_capture_count: Option, pub amount_capturable: MinorUnit, - pub merchant_connector_id: Option<&'a String>, + pub merchant_connector_id: Option<&'a common_utils::id_type::MerchantConnectorAccountId>, pub net_amount: MinorUnit, pub unified_code: Option<&'a String>, pub unified_message: Option<&'a String>, diff --git a/crates/router/src/services/kafka/payout.rs b/crates/router/src/services/kafka/payout.rs index 08733c46008f..7a6254bd527d 100644 --- a/crates/router/src/services/kafka/payout.rs +++ b/crates/router/src/services/kafka/payout.rs @@ -37,7 +37,7 @@ pub struct KafkaPayout<'a> { pub error_code: Option<&'a String>, pub business_country: Option, pub business_label: Option<&'a String>, - pub merchant_connector_id: Option<&'a String>, + pub merchant_connector_id: Option<&'a id_type::MerchantConnectorAccountId>, } impl<'a> KafkaPayout<'a> { diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs index 775cc91ebefd..681cd6fd1101 100644 --- a/crates/router/src/types/api.rs +++ b/crates/router/src/types/api.rs @@ -201,7 +201,7 @@ pub struct ConnectorData { pub connector: ConnectorEnum, pub connector_name: types::Connector, pub get_token: GetToken, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, } #[derive(Clone)] @@ -264,7 +264,7 @@ impl ConnectorData { connectors: &Connectors, name: &str, connector_type: GetToken, - connector_id: Option, + connector_id: Option, ) -> CustomResult { let connector = Self::convert_connector(connectors, name)?; let connector_name = api_enums::Connector::from_str(name) @@ -284,7 +284,7 @@ impl ConnectorData { connectors: &Connectors, name: &str, connector_type: GetToken, - connector_id: Option, + connector_id: Option, ) -> CustomResult { let connector = Self::convert_connector(connectors, name)?; let payout_connector_name = api_enums::PayoutConnectors::from_str(name) diff --git a/crates/router/src/types/storage.rs b/crates/router/src/types/storage.rs index c372a9c09bba..966564238978 100644 --- a/crates/router/src/types/storage.rs +++ b/crates/router/src/types/storage.rs @@ -74,7 +74,7 @@ use crate::types::api::routing; pub struct RoutingData { pub routed_through: Option, - pub merchant_connector_id: Option, + pub merchant_connector_id: Option, pub routing_info: PaymentRoutingInfo, pub algorithm: Option, diff --git a/crates/router/src/types/storage/payment_method.rs b/crates/router/src/types/storage/payment_method.rs index 31b039ab4545..0e7bdb14d4a0 100644 --- a/crates/router/src/types/storage/payment_method.rs +++ b/crates/router/src/types/storage/payment_method.rs @@ -95,10 +95,13 @@ pub struct PaymentsMandateReferenceRecord { } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -pub struct PaymentsMandateReference(pub HashMap); +pub struct PaymentsMandateReference( + pub HashMap, +); impl Deref for PaymentsMandateReference { - type Target = HashMap; + type Target = + HashMap; fn deref(&self) -> &Self::Target { &self.0 diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rs index 7e5f8571340f..ce8419ad3c27 100644 --- a/crates/router/src/utils.rs +++ b/crates/router/src/utils.rs @@ -384,7 +384,10 @@ pub async fn find_mca_from_authentication_id_type( .await .to_not_found_response( errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: authentication.merchant_connector_id.to_string(), + id: authentication + .merchant_connector_id + .get_string_repr() + .to_string(), }, ) } @@ -430,7 +433,7 @@ pub async fn get_mca_from_payment_intent( .await .to_not_found_response( errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: merchant_connector_id, + id: merchant_connector_id.get_string_repr().to_string(), }, ) } @@ -528,7 +531,7 @@ pub async fn get_mca_from_payout_attempt( .await .to_not_found_response( errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: merchant_connector_id, + id: merchant_connector_id.get_string_repr().to_string(), }, ) } diff --git a/crates/router/src/utils/connector_onboarding.rs b/crates/router/src/utils/connector_onboarding.rs index 7813a7cb31f9..3c1aea6f7a63 100644 --- a/crates/router/src/utils/connector_onboarding.rs +++ b/crates/router/src/utils/connector_onboarding.rs @@ -42,7 +42,7 @@ pub fn is_enabled( pub async fn check_if_connector_exists( state: &SessionState, - connector_id: &str, + connector_id: &common_utils::id_type::MerchantConnectorAccountId, merchant_id: &common_utils::id_type::MerchantId, ) -> RouterResult<()> { let key_manager_state = &state.into(); @@ -70,7 +70,7 @@ pub async fn check_if_connector_exists( ) .await .to_not_found_response(ApiErrorResponse::MerchantConnectorAccountNotFound { - id: connector_id.to_string(), + id: connector_id.get_string_repr().to_string(), })?; #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))] @@ -85,7 +85,7 @@ pub async fn check_if_connector_exists( pub async fn set_tracking_id_in_configs( state: &SessionState, - connector_id: &str, + connector_id: &common_utils::id_type::MerchantConnectorAccountId, connector: enums::Connector, ) -> RouterResult<()> { let timestamp = common_utils::date_time::now_unix_timestamp().to_string(); @@ -130,7 +130,7 @@ pub async fn set_tracking_id_in_configs( pub async fn get_tracking_id_from_configs( state: &SessionState, - connector_id: &str, + connector_id: &common_utils::id_type::MerchantConnectorAccountId, connector: enums::Connector, ) -> RouterResult { let timestamp = state @@ -144,14 +144,17 @@ pub async fn get_tracking_id_from_configs( .attach_printable("Error getting data from configs table")? .config; - Ok(format!("{}_{}", connector_id, timestamp)) + Ok(format!("{}_{}", connector_id.get_string_repr(), timestamp)) } -fn build_key(connector_id: &str, connector: enums::Connector) -> String { +fn build_key( + connector_id: &common_utils::id_type::MerchantConnectorAccountId, + connector: enums::Connector, +) -> String { format!( "{}_{}_{}", consts::CONNECTOR_ONBOARDING_CONFIG_PREFIX, connector, - connector_id, + connector_id.get_string_repr(), ) } diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs index 16e1d6a7c22c..b9be08c43545 100644 --- a/crates/router/tests/connectors/utils.rs +++ b/crates/router/tests/connectors/utils.rs @@ -47,7 +47,7 @@ pub fn construct_connector_data_old( connector: types::api::BoxedConnector, connector_name: types::Connector, get_token: types::api::GetToken, - merchant_connector_id: Option, + merchant_connector_id: Option, ) -> types::api::ConnectorData { types::api::ConnectorData { connector: ConnectorEnum::Old(connector), diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rs index ed3c47b9c96f..37e01cbbb5cb 100644 --- a/crates/storage_impl/src/mock_db/payment_attempt.rs +++ b/crates/storage_impl/src/mock_db/payment_attempt.rs @@ -44,7 +44,7 @@ impl PaymentAttemptInterface for MockDb { _payment_method: Option>, _payment_method_type: Option>, _authentication_type: Option>, - _merchanat_connector_id: Option>, + _merchanat_connector_id: Option>, _storage_scheme: storage_enums::MerchantStorageScheme, ) -> CustomResult { Err(StorageError::MockDbError)? diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index a599618615f5..382abacfa787 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -295,7 +295,7 @@ impl PaymentAttemptInterface for RouterStore { payment_method: Option>, payment_method_type: Option>, authentication_type: Option>, - merchant_connector_id: Option>, + merchant_connector_id: Option>, _storage_scheme: MerchantStorageScheme, ) -> CustomResult { let conn = self @@ -1064,7 +1064,7 @@ impl PaymentAttemptInterface for KVRouterStore { payment_method: Option>, payment_method_type: Option>, authentication_type: Option>, - merchant_connector_id: Option>, + merchant_connector_id: Option>, storage_scheme: MerchantStorageScheme, ) -> CustomResult { self.router_store