From b63d723b8bd2cfc146db762be4a11be64a72d196 Mon Sep 17 00:00:00 2001 From: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:31:01 +0530 Subject: [PATCH] refactor: introduce a domain type for profile ID (#5687) --- Cargo.lock | 1 + api-reference-v2/openapi_spec.json | 3 +- api-reference/openapi_spec.json | 7 +- crates/api_models/src/admin.rs | 41 +++---- crates/api_models/src/connector_onboarding.rs | 2 +- crates/api_models/src/disputes.rs | 6 +- crates/api_models/src/payments.rs | 8 +- crates/api_models/src/payouts.rs | 9 +- crates/api_models/src/refunds.rs | 6 +- crates/api_models/src/routing.rs | 25 ++-- crates/api_models/src/user.rs | 2 +- crates/api_models/src/user/sample_data.rs | 2 +- crates/api_models/src/webhook_events.rs | 7 +- crates/common_utils/src/events.rs | 3 + crates/common_utils/src/id_type.rs | 8 ++ crates/common_utils/src/id_type/customer.rs | 1 + crates/common_utils/src/id_type/merchant.rs | 1 + .../common_utils/src/id_type/organization.rs | 1 + crates/common_utils/src/id_type/profile.rs | 22 ++++ crates/common_utils/src/lib.rs | 15 ++- crates/common_utils/src/macros.rs | 12 ++ crates/connector_configs/Cargo.toml | 1 + crates/connector_configs/src/common_config.rs | 2 +- crates/diesel_models/src/authentication.rs | 4 +- crates/diesel_models/src/business_profile.rs | 8 +- crates/diesel_models/src/dispute.rs | 4 +- crates/diesel_models/src/events.rs | 4 +- crates/diesel_models/src/file.rs | 8 +- crates/diesel_models/src/merchant_account.rs | 8 +- .../src/merchant_connector_account.rs | 8 +- crates/diesel_models/src/payment_intent.rs | 6 +- crates/diesel_models/src/payment_link.rs | 4 +- crates/diesel_models/src/payout_attempt.rs | 12 +- crates/diesel_models/src/payouts.rs | 8 +- .../src/query/business_profile.rs | 9 +- crates/diesel_models/src/query/events.rs | 6 +- .../src/query/merchant_connector_account.rs | 2 +- .../src/query/routing_algorithm.rs | 14 +-- crates/diesel_models/src/query/user_role.rs | 8 +- crates/diesel_models/src/refund.rs | 4 +- crates/diesel_models/src/routing_algorithm.rs | 4 +- crates/diesel_models/src/user_role.rs | 4 +- .../src/business_profile.rs | 4 +- .../src/merchant_account.rs | 6 +- .../src/merchant_connector_account.rs | 4 +- .../hyperswitch_domain_models/src/payments.rs | 2 +- .../src/payments/payment_intent.rs | 4 +- .../hyperswitch_domain_models/src/payouts.rs | 2 +- .../src/payouts/payout_attempt.rs | 36 +----- .../src/payouts/payouts.rs | 45 +------ crates/kgraph_utils/benches/evaluation.rs | 6 +- crates/kgraph_utils/src/mca.rs | 6 +- crates/router/src/core/admin.rs | 105 ++++++++-------- .../router/src/core/authentication/utils.rs | 4 +- crates/router/src/core/customers.rs | 4 +- crates/router/src/core/disputes.rs | 12 +- crates/router/src/core/files/helpers.rs | 2 +- crates/router/src/core/fraud_check.rs | 8 +- crates/router/src/core/fraud_check/types.rs | 2 +- crates/router/src/core/mandate/helpers.rs | 3 +- crates/router/src/core/payment_link.rs | 4 +- .../router/src/core/payment_methods/cards.rs | 6 +- crates/router/src/core/payments.rs | 23 ++-- crates/router/src/core/payments/helpers.rs | 13 +- .../payments/operations/payment_approve.rs | 2 +- .../payments/operations/payment_cancel.rs | 2 +- .../payments/operations/payment_capture.rs | 2 +- .../operations/payment_complete_authorize.rs | 2 +- .../payments/operations/payment_confirm.rs | 4 +- .../payments/operations/payment_create.rs | 8 +- .../payments/operations/payment_reject.rs | 2 +- .../payments/operations/payment_session.rs | 2 +- .../core/payments/operations/payment_start.rs | 2 +- .../payments/operations/payment_status.rs | 2 +- .../payments/operations/payment_update.rs | 2 +- .../payments_incremental_authorization.rs | 2 +- crates/router/src/core/payments/routing.rs | 49 +++++--- crates/router/src/core/payouts.rs | 49 +++++--- crates/router/src/core/payouts/retry.rs | 12 +- crates/router/src/core/payouts/validator.rs | 2 +- crates/router/src/core/refunds.rs | 12 +- crates/router/src/core/routing.rs | 43 ++++--- crates/router/src/core/routing/helpers.rs | 15 +-- crates/router/src/core/utils.rs | 61 ++++++---- crates/router/src/core/verification.rs | 2 +- crates/router/src/core/verification/utils.rs | 2 +- crates/router/src/core/verify_connector.rs | 2 +- crates/router/src/core/webhooks/incoming.rs | 4 +- crates/router/src/core/webhooks/outgoing.rs | 2 +- crates/router/src/core/webhooks/types.rs | 2 +- .../src/core/webhooks/webhook_events.rs | 8 +- crates/router/src/db/business_profile.rs | 32 ++--- crates/router/src/db/events.rs | 15 +-- crates/router/src/db/kafka_store.rs | 26 ++-- crates/router/src/db/merchant_account.rs | 2 +- .../src/db/merchant_connector_account.rs | 112 +++++++++++++----- crates/router/src/db/routing_algorithm.rs | 18 +-- crates/router/src/db/user_role.rs | 24 ++-- crates/router/src/routes/admin.rs | 29 +++-- crates/router/src/routes/payments.rs | 2 +- crates/router/src/routes/routing.rs | 12 +- crates/router/src/services/authentication.rs | 10 +- .../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_intent.rs | 2 +- .../services/kafka/payment_intent_event.rs | 2 +- crates/router/src/services/kafka/payout.rs | 2 +- crates/router/src/types/api/admin.rs | 2 +- crates/router/src/types/domain/event.rs | 2 +- crates/router/src/utils.rs | 13 +- crates/router/src/utils/user.rs | 2 +- crates/router/src/utils/user_role.rs | 2 +- crates/router/src/workflows/payment_sync.rs | 2 +- .../src/payouts/payout_attempt.rs | 5 +- crates/storage_impl/src/payouts/payouts.rs | 15 +-- scripts/ci-checks-v2.sh | 7 +- 118 files changed, 707 insertions(+), 547 deletions(-) create mode 100644 crates/common_utils/src/id_type/profile.rs diff --git a/Cargo.lock b/Cargo.lock index 5a8ebcc0f3..4a37b597d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2096,6 +2096,7 @@ name = "connector_configs" version = "0.1.0" dependencies = [ "api_models", + "common_utils", "serde", "serde_with", "toml 0.8.12", diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index bdbdd9aec7..125f15d868 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -8445,7 +8445,8 @@ }, "profile_id": { "type": "string", - "description": "Identifier for the business profile, if not provided default will be chosen from merchant account" + "description": "Identifier for the business profile, if not provided default will be chosen from merchant account", + "maxLength": 64 }, "connector_account_details": { "allOf": [ diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index cfd2fe4350..fdc8c8ba87 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -7786,7 +7786,7 @@ }, "profile_id": { "type": "string", - "description": "The default business profile that must be used for creating merchant accounts and payments", + "description": "The identifier for business profile. This must be used for creating merchant accounts, payments and payouts", "example": "pro_abcdefghijklmnopqrstuvwxyz", "maxLength": 64 }, @@ -12510,7 +12510,7 @@ }, "default_profile": { "type": "string", - "description": "The default business profile that must be used for creating merchant accounts and payments\nTo unset this field, pass an empty string", + "description": "The default business profile that must be used for creating merchant accounts and payments", "nullable": true, "maxLength": 64 }, @@ -12548,7 +12548,8 @@ "profile_id": { "type": "string", "description": "Identifier for the business profile, if not provided default will be chosen from merchant account", - "nullable": true + "nullable": true, + "maxLength": 64 }, "connector_account_details": { "allOf": [ diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs index 18ad5dbf84..a23b891f65 100644 --- a/crates/api_models/src/admin.rs +++ b/crates/api_models/src/admin.rs @@ -330,9 +330,8 @@ pub struct MerchantAccountUpdate { pub frm_routing_algorithm: Option, /// The default business profile that must be used for creating merchant accounts and payments - /// To unset this field, pass an empty string - #[schema(max_length = 64)] - pub default_profile: Option, + #[schema(max_length = 64, value_type = Option)] + pub default_profile: Option, /// Default payment method collect link config #[schema(value_type = Option)] @@ -526,8 +525,8 @@ pub struct MerchantAccountResponse { pub is_recon_enabled: bool, /// The default business profile that must be used for creating merchant accounts and payments - #[schema(max_length = 64)] - pub default_profile: Option, + #[schema(max_length = 64, value_type = Option)] + pub default_profile: Option, /// Used to indicate the status of the recon module for a merchant account #[schema(value_type = ReconStatus, example = "not_requested")] @@ -699,7 +698,8 @@ pub struct MerchantConnectorCreate { pub connector_label: Option, /// Identifier for the business profile, if not provided default will be chosen from merchant account - pub profile_id: String, + #[schema(max_length = 64, value_type = String)] + pub profile_id: id_type::ProfileId, /// An object containing the required details/credentials for a Connector account. #[schema(value_type = Option,example = json!({ "auth_type": "HeaderKey","api_key": "Basic MyVerySecretApiKey" }))] @@ -829,7 +829,8 @@ pub struct MerchantConnectorCreate { pub connector_label: Option, /// Identifier for the business profile, if not provided default will be chosen from merchant account - pub profile_id: Option, + #[schema(max_length = 64, value_type = Option)] + pub profile_id: Option, /// An object containing the required details/credentials for a Connector account. #[schema(value_type = Option,example = json!({ "auth_type": "HeaderKey","api_key": "Basic MyVerySecretApiKey" }))] @@ -1063,8 +1064,8 @@ pub struct MerchantConnectorResponse { pub id: String, /// Identifier for the business profile, if not provided default will be chosen from merchant account - #[schema(max_length = 64)] - pub profile_id: String, + #[schema(max_length = 64, value_type = String)] + pub profile_id: id_type::ProfileId, /// An object containing the required details/credentials for a Connector account. #[schema(value_type = Option,example = json!({ "auth_type": "HeaderKey","api_key": "Basic MyVerySecretApiKey" }))] @@ -1170,8 +1171,8 @@ pub struct MerchantConnectorResponse { pub merchant_connector_id: String, /// Identifier for the business profile, if not provided default will be chosen from merchant account - #[schema(max_length = 64)] - pub profile_id: String, + #[schema(max_length = 64, value_type = String)] + pub profile_id: id_type::ProfileId, /// An object containing the required details/credentials for a Connector account. #[schema(value_type = Option,example = json!({ "auth_type": "HeaderKey","api_key": "Basic MyVerySecretApiKey" }))] @@ -1294,8 +1295,8 @@ pub struct MerchantConnectorListResponse { pub merchant_connector_id: String, /// Identifier for the business profile, if not provided default will be chosen from merchant account - #[schema(max_length = 64)] - pub profile_id: String, + #[schema(max_length = 64, value_type = String)] + pub profile_id: id_type::ProfileId, /// An object containing the details about the payment methods that need to be enabled under this merchant connector account #[schema(example = json!([ @@ -1403,8 +1404,8 @@ pub struct MerchantConnectorListResponse { pub id: String, /// Identifier for the business profile, if not provided default will be chosen from merchant account - #[schema(max_length = 64)] - pub profile_id: String, + #[schema(max_length = 64, value_type = String)] + pub profile_id: id_type::ProfileId, /// An object containing the details about the payment methods that need to be enabled under this merchant connector account #[schema(example = json!([ @@ -2076,9 +2077,9 @@ pub struct BusinessProfileResponse { #[schema(max_length = 64, example = "y3oqhf46pyzuxjbcn2giaqnb44", value_type = String)] pub merchant_id: id_type::MerchantId, - /// The default business profile that must be used for creating merchant accounts and payments - #[schema(max_length = 64, example = "pro_abcdefghijklmnopqrstuvwxyz")] - pub profile_id: String, + /// The identifier for business profile. This must be used for creating merchant accounts, payments and payouts + #[schema(max_length = 64, value_type = String, example = "pro_abcdefghijklmnopqrstuvwxyz")] + pub profile_id: id_type::ProfileId, /// Name of the business profile #[schema(max_length = 64)] @@ -2193,8 +2194,8 @@ pub struct BusinessProfileResponse { pub merchant_id: id_type::MerchantId, /// The identifier for business profile. This must be used for creating merchant accounts, payments and payouts - #[schema(max_length = 64, example = "pro_abcdefghijklmnopqrstuvwxyz")] - pub id: String, + #[schema(max_length = 64, value_type = String, example = "pro_abcdefghijklmnopqrstuvwxyz")] + pub id: id_type::ProfileId, /// Name of the business profile #[schema(max_length = 64)] diff --git a/crates/api_models/src/connector_onboarding.rs b/crates/api_models/src/connector_onboarding.rs index 1ed18392dc..de4b8843df 100644 --- a/crates/api_models/src/connector_onboarding.rs +++ b/crates/api_models/src/connector_onboarding.rs @@ -15,7 +15,7 @@ pub enum ActionUrlResponse { #[derive(serde::Deserialize, serde::Serialize, Debug, Clone)] pub struct OnboardingSyncRequest { - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub connector_id: String, pub connector: enums::Connector, } diff --git a/crates/api_models/src/disputes.rs b/crates/api_models/src/disputes.rs index e4c38cef86..5e9db4cdfd 100644 --- a/crates/api_models/src/disputes.rs +++ b/crates/api_models/src/disputes.rs @@ -44,7 +44,8 @@ pub struct DisputeResponse { #[serde(with = "common_utils::custom_serde::iso8601")] pub created_at: PrimitiveDateTime, /// The `profile_id` associated with the dispute - pub profile_id: Option, + #[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, } @@ -109,7 +110,8 @@ pub struct DisputeListConstraints { /// limit on the number of objects to return pub limit: Option, /// The identifier for business profile - pub profile_id: Option, + #[schema(value_type = Option)] + pub profile_id: Option, /// status of the dispute pub dispute_status: Option, /// stage of the dispute diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 99735f5792..be657cb948 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -480,7 +480,8 @@ pub struct PaymentsRequest { /// The business profile to be used for this payment, if not passed the default business profile associated with the merchant account will be used. It is mandatory in case multiple business profiles have been set up. #[remove_in(PaymentsUpdateRequest, PaymentsConfirmRequest)] - pub profile_id: Option, + #[schema(value_type = Option)] + pub profile_id: Option, #[remove_in(PaymentsConfirmRequest)] #[schema(value_type = Option)] @@ -3815,7 +3816,8 @@ pub struct PaymentsResponse { /// Details for Payment link pub payment_link: Option, /// The business profile that is associated with this payment - pub profile_id: Option, + #[schema(value_type = Option)] + pub profile_id: Option, /// Details of surcharge applied on this payment pub surcharge_details: Option, @@ -4031,7 +4033,7 @@ pub struct PaymentListFilterConstraints { /// The identifier for payment pub payment_id: Option, /// The identifier for business profile - pub profile_id: Option, + pub profile_id: Option, /// The identifier for customer pub customer_id: Option, /// The limit on the number of objects. The default limit is 10 and max limit is 20 diff --git a/crates/api_models/src/payouts.rs b/crates/api_models/src/payouts.rs index 0010c2988e..b755a07d7f 100644 --- a/crates/api_models/src/payouts.rs +++ b/crates/api_models/src/payouts.rs @@ -144,7 +144,8 @@ pub struct PayoutCreateRequest { pub payout_token: Option, /// The business profile to use for this payout, especially if there are multiple business profiles associated with the account, otherwise default business profile associated with the merchant account will be used. - pub profile_id: Option, + #[schema(value_type = Option)] + pub profile_id: Option, /// The send method which will be required for processing payouts, check options for better understanding. #[schema(value_type = Option, example = "instant")] @@ -481,7 +482,8 @@ pub struct PayoutCreateResponse { pub error_code: Option, /// The business profile that is associated with this payout - pub profile_id: String, + #[schema(value_type = String)] + pub profile_id: id_type::ProfileId, /// Time when the payout was created #[schema(example = "2022-09-10T10:11:12Z")] @@ -685,7 +687,8 @@ pub struct PayoutListFilterConstraints { )] pub payout_id: Option, /// The identifier for business profile - pub profile_id: Option, + #[schema(value_type = Option)] + pub profile_id: Option, /// The identifier for customer #[schema(value_type = Option,example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")] pub customer_id: Option, diff --git a/crates/api_models/src/refunds.rs b/crates/api_models/src/refunds.rs index dd6f1a2250..656416dce9 100644 --- a/crates/api_models/src/refunds.rs +++ b/crates/api_models/src/refunds.rs @@ -156,7 +156,8 @@ pub struct RefundResponse { #[schema(example = "stripe")] pub connector: String, /// The id of business profile for this refund - pub profile_id: Option, + #[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, /// Charge specific fields for controlling the revert of funds from either platform or connected account @@ -171,7 +172,8 @@ pub struct RefundListRequest { /// The identifier for the refund pub refund_id: Option, /// The identifier for business profile - pub profile_id: Option, + #[schema(value_type = Option)] + pub profile_id: Option, /// Limit on the number of objects to return pub limit: Option, /// The starting point within a list of objects diff --git a/crates/api_models/src/routing.rs b/crates/api_models/src/routing.rs index 2c52f726c8..04a58aed0d 100644 --- a/crates/api_models/src/routing.rs +++ b/crates/api_models/src/routing.rs @@ -36,7 +36,8 @@ pub struct RoutingConfigRequest { pub name: String, pub description: String, pub algorithm: RoutingAlgorithm, - pub profile_id: String, + #[schema(value_type = String)] + pub profile_id: common_utils::id_type::ProfileId, } #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "routing_v2")))] @@ -45,12 +46,14 @@ pub struct RoutingConfigRequest { pub name: Option, pub description: Option, pub algorithm: Option, - pub profile_id: Option, + #[schema(value_type = Option)] + pub profile_id: Option, } #[derive(Debug, serde::Serialize, ToSchema)] pub struct ProfileDefaultRoutingConfig { - pub profile_id: String, + #[schema(value_type = String)] + pub profile_id: common_utils::id_type::ProfileId, pub connectors: Vec, } @@ -62,13 +65,13 @@ pub struct RoutingRetrieveQuery { #[derive(Debug, serde::Deserialize, serde::Serialize)] pub struct RoutingRetrieveLinkQuery { - pub profile_id: Option, + pub profile_id: Option, } #[derive(Debug, serde::Deserialize, serde::Serialize)] pub struct RoutingRetrieveLinkQueryWrapper { pub routing_query: RoutingRetrieveQuery, - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)] /// Response of the retrieved routing configs for a merchant account @@ -87,7 +90,8 @@ pub enum LinkedRoutingConfigRetrieveResponse { /// Routing Algorithm specific to merchants pub struct MerchantRoutingAlgorithm { pub id: String, - pub profile_id: String, + #[schema(value_type = String)] + pub profile_id: common_utils::id_type::ProfileId, pub name: String, pub description: String, pub algorithm: RoutingAlgorithm, @@ -257,10 +261,9 @@ pub enum RoutingAlgorithmKind { } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] - pub struct RoutingPayloadWrapper { pub updated_config: Vec, - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)] @@ -453,8 +456,8 @@ impl RoutingAlgorithmRef { pub struct RoutingDictionaryRecord { pub id: String, - - pub profile_id: String, + #[schema(value_type = String)] + pub profile_id: common_utils::id_type::ProfileId, pub name: String, pub kind: RoutingAlgorithmKind, pub description: String, @@ -485,6 +488,6 @@ pub struct RoutingAlgorithmId { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct RoutingLinkWrapper { - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub algorithm_id: RoutingAlgorithmId, } diff --git a/crates/api_models/src/user.rs b/crates/api_models/src/user.rs index 9867aba7b3..1fdf47425e 100644 --- a/crates/api_models/src/user.rs +++ b/crates/api_models/src/user.rs @@ -405,6 +405,6 @@ pub struct ListMerchantsForUserInOrgResponse { #[derive(Debug, serde::Serialize)] pub struct ListProfilesForUserInOrgAndMerchantAccountResponse { - pub profile_id: String, + pub profile_id: id_type::ProfileId, pub profile_name: String, } diff --git a/crates/api_models/src/user/sample_data.rs b/crates/api_models/src/user/sample_data.rs index 6d20b20f36..dc95de913f 100644 --- a/crates/api_models/src/user/sample_data.rs +++ b/crates/api_models/src/user/sample_data.rs @@ -19,5 +19,5 @@ pub struct SampleDataRequest { pub auth_type: Option>, pub business_country: Option, pub business_label: Option, - pub profile_id: Option, + pub profile_id: Option, } diff --git a/crates/api_models/src/webhook_events.rs b/crates/api_models/src/webhook_events.rs index fa61cc0f25..f9741147cd 100644 --- a/crates/api_models/src/webhook_events.rs +++ b/crates/api_models/src/webhook_events.rs @@ -26,7 +26,8 @@ pub struct EventListConstraints { pub object_id: Option, /// Filter all events associated with the specified business profile ID. - pub profile_id: Option, + #[schema(value_type = Option)] + pub profile_id: Option, } #[derive(Debug)] @@ -54,8 +55,8 @@ pub struct EventListItemResponse { pub merchant_id: common_utils::id_type::MerchantId, /// The identifier for the Business Profile. - #[schema(max_length = 64, example = "SqB0zwDGR5wHppWf0bx7GKr1f2")] - pub profile_id: String, + #[schema(max_length = 64, value_type = String, example = "SqB0zwDGR5wHppWf0bx7GKr1f2")] + pub profile_id: common_utils::id_type::ProfileId, /// The identifier for the object (Payment Intent ID, Refund ID, etc.) #[schema(max_length = 64, example = "QHrfd5LUDdZaKtAjdJmMu0dMa1")] diff --git a/crates/common_utils/src/events.rs b/crates/common_utils/src/events.rs index 4377714396..48b2e9d98c 100644 --- a/crates/common_utils/src/events.rs +++ b/crates/common_utils/src/events.rs @@ -35,6 +35,9 @@ pub enum ApiEventsType { Customer { customer_id: id_type::CustomerId, }, + BusinessProfile { + profile_id: id_type::ProfileId, + }, User { user_id: String, }, diff --git a/crates/common_utils/src/id_type.rs b/crates/common_utils/src/id_type.rs index 55e2e3ffb1..cc4c56d6ab 100644 --- a/crates/common_utils/src/id_type.rs +++ b/crates/common_utils/src/id_type.rs @@ -6,6 +6,7 @@ use std::{borrow::Cow, fmt::Debug}; mod customer; mod merchant; mod organization; +mod profile; mod global_id; @@ -19,6 +20,7 @@ use diesel::{ }; pub use merchant::MerchantId; pub use organization::OrganizationId; +pub use profile::ProfileId; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -198,6 +200,12 @@ where } } +/// An interface to generate object identifiers. +pub trait GenerateId { + /// Generates a random object identifier. + fn generate() -> Self; +} + #[cfg(test)] mod alphanumeric_id_tests { #![allow(clippy::unwrap_used)] diff --git a/crates/common_utils/src/id_type/customer.rs b/crates/common_utils/src/id_type/customer.rs index 6504912596..9d02f20138 100644 --- a/crates/common_utils/src/id_type/customer.rs +++ b/crates/common_utils/src/id_type/customer.rs @@ -9,6 +9,7 @@ crate::impl_debug_id_type!(CustomerId); crate::impl_default_id_type!(CustomerId, "cus"); crate::impl_try_from_cow_str_id_type!(CustomerId, "customer_id"); +crate::impl_generate_id_id_type!(CustomerId, "cus"); crate::impl_serializable_secret_id_type!(CustomerId); crate::impl_queryable_id_type!(CustomerId); crate::impl_to_sql_from_sql_id_type!(CustomerId); diff --git a/crates/common_utils/src/id_type/merchant.rs b/crates/common_utils/src/id_type/merchant.rs index 8358f39051..08b80249ae 100644 --- a/crates/common_utils/src/id_type/merchant.rs +++ b/crates/common_utils/src/id_type/merchant.rs @@ -25,6 +25,7 @@ crate::impl_debug_id_type!(MerchantId); crate::impl_default_id_type!(MerchantId, "mer"); crate::impl_try_from_cow_str_id_type!(MerchantId, "merchant_id"); +crate::impl_generate_id_id_type!(MerchantId, "mer"); crate::impl_serializable_secret_id_type!(MerchantId); crate::impl_queryable_id_type!(MerchantId); crate::impl_to_sql_from_sql_id_type!(MerchantId); diff --git a/crates/common_utils/src/id_type/organization.rs b/crates/common_utils/src/id_type/organization.rs index 336442e605..f88a62daa1 100644 --- a/crates/common_utils/src/id_type/organization.rs +++ b/crates/common_utils/src/id_type/organization.rs @@ -9,6 +9,7 @@ crate::impl_debug_id_type!(OrganizationId); crate::impl_default_id_type!(OrganizationId, "org"); crate::impl_try_from_cow_str_id_type!(OrganizationId, "organization_id"); +crate::impl_generate_id_id_type!(OrganizationId, "org"); crate::impl_serializable_secret_id_type!(OrganizationId); crate::impl_queryable_id_type!(OrganizationId); crate::impl_to_sql_from_sql_id_type!(OrganizationId); diff --git a/crates/common_utils/src/id_type/profile.rs b/crates/common_utils/src/id_type/profile.rs new file mode 100644 index 0000000000..e9d90e7bba --- /dev/null +++ b/crates/common_utils/src/id_type/profile.rs @@ -0,0 +1,22 @@ +crate::id_type!( + ProfileId, + "A type for profile_id that can be used for business profile ids" +); +crate::impl_id_type_methods!(ProfileId, "profile_id"); + +// This is to display the `ProfileId` as ProfileId(abcd) +crate::impl_debug_id_type!(ProfileId); +crate::impl_try_from_cow_str_id_type!(ProfileId, "profile_id"); + +crate::impl_generate_id_id_type!(ProfileId, "pro"); +crate::impl_serializable_secret_id_type!(ProfileId); +crate::impl_queryable_id_type!(ProfileId); +crate::impl_to_sql_from_sql_id_type!(ProfileId); + +impl crate::events::ApiEventMetric for ProfileId { + fn get_api_event_type(&self) -> Option { + Some(crate::events::ApiEventsType::BusinessProfile { + profile_id: self.clone(), + }) + } +} diff --git a/crates/common_utils/src/lib.rs b/crates/common_utils/src/lib.rs index 400da34998..67a67bee5c 100644 --- a/crates/common_utils/src/lib.rs +++ b/crates/common_utils/src/lib.rs @@ -214,12 +214,23 @@ fn generate_ref_id_with_default_length id_type::CustomerId { - id_type::CustomerId::default() + use id_type::GenerateId; + + id_type::CustomerId::generate() } /// Generate a organization id with default length, with prefix as `org` pub fn generate_organization_id_of_default_length() -> id_type::OrganizationId { - id_type::OrganizationId::default() + use id_type::GenerateId; + + id_type::OrganizationId::generate() +} + +/// Generate a profile id with default length, with prefix as `pro` +pub fn generate_profile_id_of_default_length() -> id_type::ProfileId { + use id_type::GenerateId; + + id_type::ProfileId::generate() } /// Generate a nanoid with the given prefix and a default length diff --git a/crates/common_utils/src/macros.rs b/crates/common_utils/src/macros.rs index 06554ee9b5..94d8074c30 100644 --- a/crates/common_utils/src/macros.rs +++ b/crates/common_utils/src/macros.rs @@ -233,6 +233,18 @@ mod id_type { }; } + /// Implements the `GenerateId` trait on the specified ID type. + #[macro_export] + macro_rules! impl_generate_id_id_type { + ($type:ty, $prefix:literal) => { + impl $crate::id_type::GenerateId for $type { + fn generate() -> Self { + Self($crate::generate_ref_id_with_default_length($prefix)) + } + } + }; + } + /// Implements the `SerializableSecret` trait on the specified ID type. #[macro_export] macro_rules! impl_serializable_secret_id_type { diff --git a/crates/connector_configs/Cargo.toml b/crates/connector_configs/Cargo.toml index 1541a0864c..1809d75583 100644 --- a/crates/connector_configs/Cargo.toml +++ b/crates/connector_configs/Cargo.toml @@ -17,6 +17,7 @@ payouts = ["api_models/payouts"] [dependencies] # First party crates api_models = { version = "0.1.0", path = "../api_models", package = "api_models" } +common_utils = { version = "0.1.0", path = "../common_utils" } # Third party crates serde = { version = "1.0.197", features = ["derive"] } diff --git a/crates/connector_configs/src/common_config.rs b/crates/connector_configs/src/common_config.rs index 88b8165853..d0becb8046 100644 --- a/crates/connector_configs/src/common_config.rs +++ b/crates/connector_configs/src/common_config.rs @@ -161,7 +161,7 @@ pub struct Provider { #[serde(rename_all = "snake_case")] pub struct ConnectorApiIntegrationPayload { pub connector_type: String, - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub connector_name: api_models::enums::Connector, #[serde(skip_deserializing)] #[schema(example = "stripe_US_travel")] diff --git a/crates/diesel_models/src/authentication.rs b/crates/diesel_models/src/authentication.rs index cb518805eb..606644255b 100644 --- a/crates/diesel_models/src/authentication.rs +++ b/crates/diesel_models/src/authentication.rs @@ -41,7 +41,7 @@ pub struct Authentication { pub acs_reference_number: Option, pub acs_trans_id: Option, pub acs_signed_content: Option, - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub payment_id: Option, pub merchant_connector_id: String, pub ds_trans_id: Option, @@ -88,7 +88,7 @@ pub struct AuthenticationNew { pub acs_reference_number: Option, pub acs_trans_id: Option, pub acs_signed_content: Option, - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub payment_id: Option, pub merchant_connector_id: String, pub ds_trans_id: Option, diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs index cab1aec410..20add83bd2 100644 --- a/crates/diesel_models/src/business_profile.rs +++ b/crates/diesel_models/src/business_profile.rs @@ -25,7 +25,7 @@ use crate::schema_v2::business_profile; #[derive(Clone, Debug, Identifiable, Queryable, Selectable, router_derive::DebugAsDisplay)] #[diesel(table_name = business_profile, primary_key(profile_id), check_for_backend(diesel::pg::Pg))] pub struct BusinessProfile { - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub merchant_id: common_utils::id_type::MerchantId, pub profile_name: String, pub created_at: time::PrimitiveDateTime, @@ -67,7 +67,7 @@ pub struct BusinessProfile { #[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)] #[diesel(table_name = business_profile, primary_key(profile_id))] pub struct BusinessProfileNew { - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub merchant_id: common_utils::id_type::MerchantId, pub profile_name: String, pub created_at: time::PrimitiveDateTime, @@ -242,7 +242,7 @@ impl BusinessProfileUpdateInternal { #[derive(Clone, Debug, Identifiable, Queryable, Selectable, router_derive::DebugAsDisplay)] #[diesel(table_name = business_profile, primary_key(profile_id), check_for_backend(diesel::pg::Pg))] pub struct BusinessProfile { - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub merchant_id: common_utils::id_type::MerchantId, pub profile_name: String, pub created_at: time::PrimitiveDateTime, @@ -283,7 +283,7 @@ pub struct BusinessProfile { #[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)] #[diesel(table_name = business_profile, primary_key(profile_id))] pub struct BusinessProfileNew { - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub merchant_id: common_utils::id_type::MerchantId, pub profile_name: String, pub created_at: time::PrimitiveDateTime, diff --git a/crates/diesel_models/src/dispute.rs b/crates/diesel_models/src/dispute.rs index 704b1781e2..14fe16c982 100644 --- a/crates/diesel_models/src/dispute.rs +++ b/crates/diesel_models/src/dispute.rs @@ -27,7 +27,7 @@ pub struct DisputeNew { pub connector_updated_at: Option, pub connector: String, pub evidence: Option>, - pub profile_id: Option, + pub profile_id: Option, pub merchant_connector_id: Option, pub dispute_amount: i64, } @@ -56,7 +56,7 @@ pub struct Dispute { pub modified_at: PrimitiveDateTime, pub connector: String, pub evidence: Secret, - pub profile_id: Option, + pub profile_id: Option, pub merchant_connector_id: Option, pub dispute_amount: i64, } diff --git a/crates/diesel_models/src/events.rs b/crates/diesel_models/src/events.rs index 20c811654a..2cc2bfff3b 100644 --- a/crates/diesel_models/src/events.rs +++ b/crates/diesel_models/src/events.rs @@ -22,7 +22,7 @@ pub struct EventNew { pub primary_object_type: storage_enums::EventObjectType, pub created_at: PrimitiveDateTime, pub merchant_id: Option, - pub business_profile_id: Option, + pub business_profile_id: Option, pub primary_object_created_at: Option, pub idempotent_event_id: Option, pub initial_attempt_id: Option, @@ -51,7 +51,7 @@ pub struct Event { #[serde(with = "custom_serde::iso8601")] pub created_at: PrimitiveDateTime, pub merchant_id: Option, - pub business_profile_id: Option, + pub business_profile_id: Option, // This column can be used to partition the database table, so that all events related to a // single object would reside in the same partition pub primary_object_created_at: Option, diff --git a/crates/diesel_models/src/file.rs b/crates/diesel_models/src/file.rs index e5ad3568d7..523bb1f26e 100644 --- a/crates/diesel_models/src/file.rs +++ b/crates/diesel_models/src/file.rs @@ -17,7 +17,7 @@ pub struct FileMetadataNew { pub file_upload_provider: Option, pub available: bool, pub connector_label: Option, - pub profile_id: Option, + pub profile_id: Option, pub merchant_connector_id: Option, } @@ -36,7 +36,7 @@ pub struct FileMetadata { #[serde(with = "custom_serde::iso8601")] pub created_at: time::PrimitiveDateTime, pub connector_label: Option, - pub profile_id: Option, + pub profile_id: Option, pub merchant_connector_id: Option, } @@ -46,7 +46,7 @@ pub enum FileMetadataUpdate { provider_file_id: Option, file_upload_provider: Option, available: bool, - profile_id: Option, + profile_id: Option, merchant_connector_id: Option, }, } @@ -57,7 +57,7 @@ pub struct FileMetadataUpdateInternal { provider_file_id: Option, file_upload_provider: Option, available: bool, - profile_id: Option, + profile_id: Option, merchant_connector_id: Option, } diff --git a/crates/diesel_models/src/merchant_account.rs b/crates/diesel_models/src/merchant_account.rs index b3ef64b3e3..ac7635e88c 100644 --- a/crates/diesel_models/src/merchant_account.rs +++ b/crates/diesel_models/src/merchant_account.rs @@ -52,7 +52,7 @@ pub struct MerchantAccount { pub payout_routing_algorithm: Option, pub organization_id: common_utils::id_type::OrganizationId, pub is_recon_enabled: bool, - pub default_profile: Option, + pub default_profile: Option, pub recon_status: storage_enums::ReconStatus, pub payment_link_config: Option, pub pm_collect_link_config: Option, @@ -87,7 +87,7 @@ pub struct MerchantAccountSetter { pub payout_routing_algorithm: Option, pub organization_id: common_utils::id_type::OrganizationId, pub is_recon_enabled: bool, - pub default_profile: Option, + pub default_profile: Option, pub recon_status: storage_enums::ReconStatus, pub payment_link_config: Option, pub pm_collect_link_config: Option, @@ -241,7 +241,7 @@ pub struct MerchantAccountNew { pub payout_routing_algorithm: Option, pub organization_id: common_utils::id_type::OrganizationId, pub is_recon_enabled: bool, - pub default_profile: Option, + pub default_profile: Option, pub recon_status: storage_enums::ReconStatus, pub payment_link_config: Option, pub pm_collect_link_config: Option, @@ -306,7 +306,7 @@ pub struct MerchantAccountUpdateInternal { pub payout_routing_algorithm: Option, pub organization_id: Option, pub is_recon_enabled: Option, - pub default_profile: Option>, + pub default_profile: Option>, pub recon_status: Option, pub payment_link_config: Option, pub pm_collect_link_config: Option, diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rs index 876240f44a..61f2af238e 100644 --- a/crates/diesel_models/src/merchant_connector_account.rs +++ b/crates/diesel_models/src/merchant_connector_account.rs @@ -48,7 +48,7 @@ pub struct MerchantConnectorAccount { pub connector_webhook_details: Option, #[diesel(deserialize_as = super::OptionalDieselArray)] pub frm_config: Option>, - pub profile_id: Option, + pub profile_id: Option, #[diesel(deserialize_as = super::OptionalDieselArray)] pub applepay_verified_domains: Option>, pub pm_auth_config: Option, @@ -95,7 +95,7 @@ pub struct MerchantConnectorAccount { pub connector_webhook_details: Option, #[diesel(deserialize_as = super::OptionalDieselArray)] pub frm_config: Option>, - pub profile_id: String, + pub profile_id: id_type::ProfileId, #[diesel(deserialize_as = super::OptionalDieselArray)] pub applepay_verified_domains: Option>, pub pm_auth_config: Option, @@ -139,7 +139,7 @@ pub struct MerchantConnectorAccountNew { pub connector_webhook_details: Option, #[diesel(deserialize_as = super::OptionalDieselArray)] pub frm_config: Option>, - pub profile_id: Option, + pub profile_id: Option, #[diesel(deserialize_as = super::OptionalDieselArray)] pub applepay_verified_domains: Option>, pub pm_auth_config: Option, @@ -166,7 +166,7 @@ pub struct MerchantConnectorAccountNew { pub connector_webhook_details: Option, #[diesel(deserialize_as = super::OptionalDieselArray)] pub frm_config: Option>, - pub profile_id: String, + pub profile_id: id_type::ProfileId, #[diesel(deserialize_as = super::OptionalDieselArray)] pub applepay_verified_domains: Option>, pub pm_auth_config: Option, diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs index bdea1fe52a..7bd1652ab5 100644 --- a/crates/diesel_models/src/payment_intent.rs +++ b/crates/diesel_models/src/payment_intent.rs @@ -47,7 +47,7 @@ pub struct PaymentIntent { pub connector_metadata: Option, pub feature_metadata: Option, pub attempt_count: i16, - pub profile_id: Option, + pub profile_id: Option, // Denotes the action(approve or reject) taken by merchant in case of manual review. // Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment pub merchant_decision: Option, @@ -108,7 +108,7 @@ pub struct PaymentIntent { pub connector_metadata: Option, pub feature_metadata: Option, pub attempt_count: i16, - pub profile_id: Option, + pub profile_id: Option, // Denotes the action(approve or reject) taken by merchant in case of manual review. // Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment pub merchant_decision: Option, @@ -170,7 +170,7 @@ pub struct PaymentIntentNew { pub connector_metadata: Option, pub feature_metadata: Option, pub attempt_count: i16, - pub profile_id: Option, + pub profile_id: Option, pub merchant_decision: Option, pub payment_link_id: Option, pub payment_confirm_source: Option, diff --git a/crates/diesel_models/src/payment_link.rs b/crates/diesel_models/src/payment_link.rs index 347a730eb6..51e3b89d60 100644 --- a/crates/diesel_models/src/payment_link.rs +++ b/crates/diesel_models/src/payment_link.rs @@ -23,7 +23,7 @@ pub struct PaymentLink { pub custom_merchant_name: Option, pub payment_link_config: Option, pub description: Option, - pub profile_id: Option, + pub profile_id: Option, pub secure_link: Option, } @@ -54,6 +54,6 @@ pub struct PaymentLinkNew { pub custom_merchant_name: Option, pub payment_link_config: Option, pub description: Option, - pub profile_id: Option, + pub profile_id: Option, pub secure_link: Option, } diff --git a/crates/diesel_models/src/payout_attempt.rs b/crates/diesel_models/src/payout_attempt.rs index 17600e0cd7..7e9b2ec4e1 100644 --- a/crates/diesel_models/src/payout_attempt.rs +++ b/crates/diesel_models/src/payout_attempt.rs @@ -27,7 +27,7 @@ pub struct PayoutAttempt { pub created_at: PrimitiveDateTime, #[serde(with = "common_utils::custom_serde::iso8601")] pub last_modified_at: PrimitiveDateTime, - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub merchant_connector_id: Option, pub routing_info: Option, } @@ -59,11 +59,11 @@ pub struct PayoutAttemptNew { pub error_code: Option, pub business_country: Option, pub business_label: Option, - #[serde(default, with = "common_utils::custom_serde::iso8601::option")] - pub created_at: Option, - #[serde(default, with = "common_utils::custom_serde::iso8601::option")] - pub last_modified_at: Option, - pub profile_id: String, + #[serde(with = "common_utils::custom_serde::iso8601")] + pub created_at: PrimitiveDateTime, + #[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 routing_info: Option, } diff --git a/crates/diesel_models/src/payouts.rs b/crates/diesel_models/src/payouts.rs index cb8f6f9a88..8acdc4a0a5 100644 --- a/crates/diesel_models/src/payouts.rs +++ b/crates/diesel_models/src/payouts.rs @@ -31,7 +31,7 @@ pub struct Payouts { #[serde(with = "common_utils::custom_serde::iso8601")] pub last_modified_at: PrimitiveDateTime, pub attempt_count: i16, - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub status: storage_enums::PayoutStatus, pub confirm: Option, pub payout_link_id: Option, @@ -72,7 +72,7 @@ pub struct PayoutsNew { #[serde(with = "common_utils::custom_serde::iso8601")] pub last_modified_at: PrimitiveDateTime, pub attempt_count: i16, - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub status: storage_enums::PayoutStatus, pub confirm: Option, pub payout_link_id: Option, @@ -92,7 +92,7 @@ pub enum PayoutsUpdate { return_url: Option, entity_type: storage_enums::PayoutEntityType, metadata: Option, - profile_id: Option, + profile_id: Option, status: Option, confirm: Option, payout_type: Option, @@ -126,7 +126,7 @@ pub struct PayoutsUpdateInternal { pub entity_type: Option, pub metadata: Option, pub payout_method_id: Option, - pub profile_id: Option, + pub profile_id: Option, pub status: Option, pub last_modified_at: PrimitiveDateTime, pub attempt_count: Option, diff --git a/crates/diesel_models/src/query/business_profile.rs b/crates/diesel_models/src/query/business_profile.rs index fb80449cdc..807648b5dc 100644 --- a/crates/diesel_models/src/query/business_profile.rs +++ b/crates/diesel_models/src/query/business_profile.rs @@ -40,7 +40,10 @@ impl BusinessProfile { } } - pub async fn find_by_profile_id(conn: &PgPooledConn, profile_id: &str) -> StorageResult { + pub async fn find_by_profile_id( + conn: &PgPooledConn, + profile_id: &common_utils::id_type::ProfileId, + ) -> StorageResult { generics::generic_find_one::<::Table, _, _>( conn, dsl::profile_id.eq(profile_id.to_owned()), @@ -51,7 +54,7 @@ impl BusinessProfile { pub async fn find_by_merchant_id_profile_id( conn: &PgPooledConn, merchant_id: &common_utils::id_type::MerchantId, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, ) -> StorageResult { generics::generic_find_one::<::Table, _, _>( conn, @@ -97,7 +100,7 @@ impl BusinessProfile { pub async fn delete_by_profile_id_merchant_id( conn: &PgPooledConn, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, merchant_id: &common_utils::id_type::MerchantId, ) -> StorageResult { generics::generic_delete::<::Table, _>( diff --git a/crates/diesel_models/src/query/events.rs b/crates/diesel_models/src/query/events.rs index 8b2a1a001f..34222e6e7d 100644 --- a/crates/diesel_models/src/query/events.rs +++ b/crates/diesel_models/src/query/events.rs @@ -118,7 +118,7 @@ impl Event { pub async fn list_initial_attempts_by_profile_id_primary_object_id( conn: &PgPooledConn, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, primary_object_id: &str, ) -> StorageResult> { generics::generic_filter::<::Table, _, _, _>( @@ -137,7 +137,7 @@ impl Event { pub async fn list_initial_attempts_by_profile_id_constraints( conn: &PgPooledConn, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, created_after: Option, created_before: Option, limit: Option, @@ -187,7 +187,7 @@ impl Event { pub async fn list_by_profile_id_initial_attempt_id( conn: &PgPooledConn, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, initial_attempt_id: &str, ) -> StorageResult> { generics::generic_filter::<::Table, _, _, _>( diff --git a/crates/diesel_models/src/query/merchant_connector_account.rs b/crates/diesel_models/src/query/merchant_connector_account.rs index e4dcdba597..7eeddd5d59 100644 --- a/crates/diesel_models/src/query/merchant_connector_account.rs +++ b/crates/diesel_models/src/query/merchant_connector_account.rs @@ -78,7 +78,7 @@ impl MerchantConnectorAccount { pub async fn find_by_profile_id_connector_name( conn: &PgPooledConn, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, connector_name: &str, ) -> StorageResult { generics::generic_find_one::<::Table, _, _>( diff --git a/crates/diesel_models/src/query/routing_algorithm.rs b/crates/diesel_models/src/query/routing_algorithm.rs index 0f3b709d26..f0fc75430e 100644 --- a/crates/diesel_models/src/query/routing_algorithm.rs +++ b/crates/diesel_models/src/query/routing_algorithm.rs @@ -34,7 +34,7 @@ impl RoutingAlgorithm { pub async fn find_by_algorithm_id_profile_id( conn: &PgPooledConn, algorithm_id: &str, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, ) -> StorageResult { generics::generic_find_one::<::Table, _, _>( conn, @@ -48,7 +48,7 @@ impl RoutingAlgorithm { pub async fn find_metadata_by_algorithm_id_profile_id( conn: &PgPooledConn, algorithm_id: &str, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, ) -> StorageResult { Self::table() .select(( @@ -68,7 +68,7 @@ impl RoutingAlgorithm { ) .limit(1) .load_async::<( - String, + common_utils::id_type::ProfileId, String, String, Option, @@ -109,7 +109,7 @@ impl RoutingAlgorithm { pub async fn list_metadata_by_profile_id( conn: &PgPooledConn, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, limit: i64, offset: i64, ) -> StorageResult> { @@ -129,7 +129,7 @@ impl RoutingAlgorithm { .offset(offset) .load_async::<( String, - String, + common_utils::id_type::ProfileId, String, Option, enums::RoutingAlgorithmKind, @@ -188,7 +188,7 @@ impl RoutingAlgorithm { .offset(offset) .order(dsl::modified_at.desc()) .load_async::<( - String, + common_utils::id_type::ProfileId, String, String, Option, @@ -250,7 +250,7 @@ impl RoutingAlgorithm { .offset(offset) .order(dsl::modified_at.desc()) .load_async::<( - String, + common_utils::id_type::ProfileId, String, String, Option, diff --git a/crates/diesel_models/src/query/user_role.rs b/crates/diesel_models/src/query/user_role.rs index b4789b3c16..7904d3c264 100644 --- a/crates/diesel_models/src/query/user_role.rs +++ b/crates/diesel_models/src/query/user_role.rs @@ -83,7 +83,7 @@ impl UserRole { user_id: String, org_id: id_type::OrganizationId, merchant_id: id_type::MerchantId, - profile_id: Option, + profile_id: Option, version: UserRoleVersion, ) -> StorageResult { // Checking in user roles, for a user in token hierarchy, only one of the relation will be true, either org level, merchant level or profile level @@ -116,7 +116,7 @@ impl UserRole { user_id: String, org_id: id_type::OrganizationId, merchant_id: id_type::MerchantId, - profile_id: Option, + profile_id: Option, update: UserRoleUpdate, version: UserRoleVersion, ) -> StorageResult { @@ -156,7 +156,7 @@ impl UserRole { user_id: String, org_id: id_type::OrganizationId, merchant_id: id_type::MerchantId, - profile_id: Option, + profile_id: Option, version: UserRoleVersion, ) -> StorageResult { // Checking in user roles, for a user in token hierarchy, only one of the relation will be true, either org level, merchant level or profile level @@ -190,7 +190,7 @@ impl UserRole { user_id: String, org_id: Option, merchant_id: Option, - profile_id: Option, + profile_id: Option, entity_id: Option, version: Option, ) -> StorageResult> { diff --git a/crates/diesel_models/src/refund.rs b/crates/diesel_models/src/refund.rs index e4a74a6d66..3b73a60367 100644 --- a/crates/diesel_models/src/refund.rs +++ b/crates/diesel_models/src/refund.rs @@ -46,7 +46,7 @@ pub struct Refund { pub attempt_id: String, pub refund_reason: Option, pub refund_error_code: Option, - pub profile_id: Option, + pub profile_id: Option, pub updated_by: String, pub merchant_connector_id: Option, pub charges: Option, @@ -88,7 +88,7 @@ pub struct RefundNew { pub description: Option, pub attempt_id: String, pub refund_reason: Option, - pub profile_id: Option, + pub profile_id: Option, pub updated_by: String, pub merchant_connector_id: Option, pub charges: Option, diff --git a/crates/diesel_models/src/routing_algorithm.rs b/crates/diesel_models/src/routing_algorithm.rs index e2566783e9..6be0be3d5e 100644 --- a/crates/diesel_models/src/routing_algorithm.rs +++ b/crates/diesel_models/src/routing_algorithm.rs @@ -7,7 +7,7 @@ use crate::{enums, schema::routing_algorithm}; #[diesel(table_name = routing_algorithm, primary_key(algorithm_id), check_for_backend(diesel::pg::Pg))] pub struct RoutingAlgorithm { pub algorithm_id: String, - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub merchant_id: common_utils::id_type::MerchantId, pub name: String, pub description: Option, @@ -29,7 +29,7 @@ pub struct RoutingAlgorithmMetadata { } pub struct RoutingProfileMetadata { - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub algorithm_id: String, pub name: String, pub description: Option, diff --git a/crates/diesel_models/src/user_role.rs b/crates/diesel_models/src/user_role.rs index 1a006f2a4a..b508c86211 100644 --- a/crates/diesel_models/src/user_role.rs +++ b/crates/diesel_models/src/user_role.rs @@ -18,7 +18,7 @@ pub struct UserRole { pub last_modified_by: String, pub created_at: PrimitiveDateTime, pub last_modified: PrimitiveDateTime, - pub profile_id: Option, + pub profile_id: Option, pub entity_id: Option, pub entity_type: Option, pub version: enums::UserRoleVersion, @@ -36,7 +36,7 @@ pub struct UserRoleNew { pub last_modified_by: String, pub created_at: PrimitiveDateTime, pub last_modified: PrimitiveDateTime, - pub profile_id: Option, + pub profile_id: Option, pub entity_id: Option, pub entity_type: Option, pub version: enums::UserRoleVersion, diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rs index ec072521d9..9a6edc50e7 100644 --- a/crates/hyperswitch_domain_models/src/business_profile.rs +++ b/crates/hyperswitch_domain_models/src/business_profile.rs @@ -23,7 +23,7 @@ use crate::type_encryption::{crypto_operation, AsyncLift, CryptoOperation}; ))] #[derive(Clone, Debug)] pub struct BusinessProfile { - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub merchant_id: common_utils::id_type::MerchantId, pub profile_name: String, pub created_at: time::PrimitiveDateTime, @@ -453,7 +453,7 @@ impl super::behaviour::Conversion for BusinessProfile { #[cfg(all(feature = "v2", feature = "business_profile_v2"))] #[derive(Clone, Debug)] pub struct BusinessProfile { - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub merchant_id: common_utils::id_type::MerchantId, pub profile_name: String, pub created_at: time::PrimitiveDateTime, diff --git a/crates/hyperswitch_domain_models/src/merchant_account.rs b/crates/hyperswitch_domain_models/src/merchant_account.rs index c86dff60ea..50b1effd27 100644 --- a/crates/hyperswitch_domain_models/src/merchant_account.rs +++ b/crates/hyperswitch_domain_models/src/merchant_account.rs @@ -45,7 +45,7 @@ pub struct MerchantAccount { pub payout_routing_algorithm: Option, pub organization_id: common_utils::id_type::OrganizationId, pub is_recon_enabled: bool, - pub default_profile: Option, + pub default_profile: Option, pub recon_status: diesel_models::enums::ReconStatus, pub payment_link_config: Option, pub pm_collect_link_config: Option, @@ -82,7 +82,7 @@ pub struct MerchantAccountSetter { pub payout_routing_algorithm: Option, pub organization_id: common_utils::id_type::OrganizationId, pub is_recon_enabled: bool, - pub default_profile: Option, + pub default_profile: Option, pub recon_status: diesel_models::enums::ReconStatus, pub payment_link_config: Option, pub pm_collect_link_config: Option, @@ -231,7 +231,7 @@ pub enum MerchantAccountUpdate { intent_fulfillment_time: Option, frm_routing_algorithm: Option, payout_routing_algorithm: Option, - default_profile: Option>, + default_profile: Option>, payment_link_config: Option, pm_collect_link_config: Option, }, diff --git a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs b/crates/hyperswitch_domain_models/src/merchant_connector_account.rs index 9e2f6918b4..76b7cd4a85 100644 --- a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs +++ b/crates/hyperswitch_domain_models/src/merchant_connector_account.rs @@ -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: String, + pub profile_id: common_utils::id_type::ProfileId, pub applepay_verified_domains: Option>, pub pm_auth_config: Option, pub status: enums::ConnectorStatus, @@ -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: String, + pub profile_id: common_utils::id_type::ProfileId, pub applepay_verified_domains: Option>, pub pm_auth_config: Option, pub status: enums::ConnectorStatus, diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs index 3f7cfde2f7..11a2c3c316 100644 --- a/crates/hyperswitch_domain_models/src/payments.rs +++ b/crates/hyperswitch_domain_models/src/payments.rs @@ -44,7 +44,7 @@ pub struct PaymentIntent { pub connector_metadata: Option, pub feature_metadata: Option, pub attempt_count: i16, - pub profile_id: Option, + pub profile_id: Option, pub payment_link_id: Option, // Denotes the action(approve or reject) taken by merchant in case of manual review. // Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs index c129e83d55..4c59a90ba1 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs @@ -133,7 +133,7 @@ pub struct PaymentIntentNew { pub connector_metadata: Option, pub feature_metadata: Option, pub attempt_count: i16, - pub profile_id: Option, + pub profile_id: Option, pub merchant_decision: Option, pub payment_link_id: Option, pub payment_confirm_source: Option, @@ -746,7 +746,7 @@ pub struct PaymentIntentListParams { pub payment_method_type: Option>, pub authentication_type: Option>, pub merchant_connector_id: Option>, - pub profile_id: Option, + pub profile_id: Option, pub customer_id: Option, pub starting_after_id: Option, pub ending_before_id: Option, diff --git a/crates/hyperswitch_domain_models/src/payouts.rs b/crates/hyperswitch_domain_models/src/payouts.rs index bb636d2dc4..952028fab3 100644 --- a/crates/hyperswitch_domain_models/src/payouts.rs +++ b/crates/hyperswitch_domain_models/src/payouts.rs @@ -19,7 +19,7 @@ pub struct PayoutListParams { pub currency: Option>, pub status: Option>, pub payout_method: Option>, - pub profile_id: Option, + pub profile_id: Option, pub customer_id: Option, pub starting_after_id: Option, pub ending_before_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 a1f08610f9..8182ed35ba 100644 --- a/crates/hyperswitch_domain_models/src/payouts/payout_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payouts/payout_attempt.rs @@ -75,7 +75,7 @@ pub struct PayoutAttempt { pub created_at: PrimitiveDateTime, #[serde(with = "common_utils::custom_serde::iso8601")] pub last_modified_at: PrimitiveDateTime, - pub profile_id: String, + pub profile_id: id_type::ProfileId, pub merchant_connector_id: Option, pub routing_info: Option, } @@ -96,41 +96,13 @@ pub struct PayoutAttemptNew { pub error_code: Option, pub business_country: Option, pub business_label: Option, - pub created_at: Option, - pub last_modified_at: Option, - pub profile_id: String, + pub created_at: PrimitiveDateTime, + pub last_modified_at: PrimitiveDateTime, + pub profile_id: id_type::ProfileId, pub merchant_connector_id: Option, pub routing_info: Option, } -impl Default for PayoutAttemptNew { - fn default() -> Self { - let now = common_utils::date_time::now(); - - Self { - payout_attempt_id: String::default(), - payout_id: String::default(), - customer_id: None, - merchant_id: id_type::MerchantId::default(), - address_id: None, - connector: None, - connector_payout_id: None, - payout_token: None, - status: storage_enums::PayoutStatus::default(), - is_eligible: None, - error_message: None, - error_code: None, - business_country: None, - business_label: None, - created_at: Some(now), - last_modified_at: Some(now), - profile_id: String::default(), - merchant_connector_id: None, - routing_info: None, - } - } -} - #[derive(Debug, Clone)] pub enum PayoutAttemptUpdate { StatusUpdate { diff --git a/crates/hyperswitch_domain_models/src/payouts/payouts.rs b/crates/hyperswitch_domain_models/src/payouts/payouts.rs index 834b6bb3f7..e514dbfb4c 100644 --- a/crates/hyperswitch_domain_models/src/payouts/payouts.rs +++ b/crates/hyperswitch_domain_models/src/payouts/payouts.rs @@ -106,7 +106,7 @@ pub struct Payouts { pub created_at: PrimitiveDateTime, pub last_modified_at: PrimitiveDateTime, pub attempt_count: i16, - pub profile_id: String, + pub profile_id: id_type::ProfileId, pub status: storage_enums::PayoutStatus, pub confirm: Option, pub payout_link_id: Option, @@ -131,10 +131,10 @@ pub struct PayoutsNew { pub return_url: Option, pub entity_type: storage_enums::PayoutEntityType, pub metadata: Option, - pub created_at: Option, - pub last_modified_at: Option, + pub created_at: PrimitiveDateTime, + pub last_modified_at: PrimitiveDateTime, pub attempt_count: i16, - pub profile_id: String, + pub profile_id: id_type::ProfileId, pub status: storage_enums::PayoutStatus, pub confirm: Option, pub payout_link_id: Option, @@ -142,39 +142,6 @@ pub struct PayoutsNew { pub priority: Option, } -impl Default for PayoutsNew { - fn default() -> Self { - let now = common_utils::date_time::now(); - - Self { - payout_id: String::default(), - merchant_id: id_type::MerchantId::default(), - customer_id: None, - address_id: None, - payout_type: None, - payout_method_id: None, - amount: MinorUnit::new(i64::default()), - destination_currency: storage_enums::Currency::default(), - source_currency: storage_enums::Currency::default(), - description: None, - recurring: bool::default(), - auto_fulfill: bool::default(), - return_url: None, - entity_type: storage_enums::PayoutEntityType::default(), - metadata: None, - created_at: Some(now), - last_modified_at: Some(now), - attempt_count: 1, - profile_id: String::default(), - status: storage_enums::PayoutStatus::default(), - confirm: None, - payout_link_id: None, - client_secret: None, - priority: None, - } - } -} - #[derive(Debug, Serialize, Deserialize)] pub enum PayoutsUpdate { Update { @@ -187,7 +154,7 @@ pub enum PayoutsUpdate { return_url: Option, entity_type: storage_enums::PayoutEntityType, metadata: Option, - profile_id: Option, + profile_id: Option, status: Option, confirm: Option, payout_type: Option, @@ -220,7 +187,7 @@ pub struct PayoutsUpdateInternal { pub entity_type: Option, pub metadata: Option, pub payout_method_id: Option, - pub profile_id: Option, + pub profile_id: Option, pub status: Option, pub attempt_count: Option, pub confirm: Option, diff --git a/crates/kgraph_utils/benches/evaluation.rs b/crates/kgraph_utils/benches/evaluation.rs index ab2e8c80ca..5a078de1d7 100644 --- a/crates/kgraph_utils/benches/evaluation.rs +++ b/crates/kgraph_utils/benches/evaluation.rs @@ -52,6 +52,8 @@ fn build_test_data( }); } + let profile_id = common_utils::generate_profile_id_of_default_length(); + #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))] let stripe_account = MerchantConnectorResponse { connector_type: api_enums::ConnectorType::FizOperations, @@ -64,7 +66,7 @@ fn build_test_data( connector_label: Some("something".to_string()), frm_configs: None, connector_webhook_details: None, - profile_id: "profile_id".to_string(), + profile_id, applepay_verified_domains: None, pm_auth_config: None, status: api_enums::ConnectorStatus::Inactive, @@ -90,7 +92,7 @@ fn build_test_data( business_sub_label: Some("something".to_string()), frm_configs: None, connector_webhook_details: None, - profile_id: "profile_id".to_string(), + profile_id, applepay_verified_domains: None, pm_auth_config: None, status: api_enums::ConnectorStatus::Inactive, diff --git a/crates/kgraph_utils/src/mca.rs b/crates/kgraph_utils/src/mca.rs index d4e0466971..1e099589b0 100644 --- a/crates/kgraph_utils/src/mca.rs +++ b/crates/kgraph_utils/src/mca.rs @@ -704,6 +704,8 @@ mod tests { fn build_test_data() -> ConstraintGraph { use api_models::{admin::*, payment_methods::*}; + let profile_id = common_utils::generate_profile_id_of_default_length(); + #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))] let stripe_account = MerchantConnectorResponse { connector_type: api_enums::ConnectorType::FizOperations, @@ -752,7 +754,7 @@ mod tests { }]), frm_configs: None, connector_webhook_details: None, - profile_id: "profile_id".to_string(), + profile_id, applepay_verified_domains: None, pm_auth_config: None, status: api_enums::ConnectorStatus::Inactive, @@ -813,7 +815,7 @@ mod tests { }]), frm_configs: None, connector_webhook_details: None, - profile_id: "profile_id".to_string(), + profile_id, applepay_verified_domains: None, pm_auth_config: None, status: api_enums::ConnectorStatus::Inactive, diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index e90924a593..f78d5dca2e 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -721,7 +721,7 @@ pub async fn list_merchant_account( pub async fn get_merchant_account( state: SessionState, req: api::MerchantId, - _profile_id: Option, + _profile_id: Option, ) -> RouterResponse { let db = state.store.as_ref(); let key_manager_state = &(&state).into(); @@ -842,8 +842,6 @@ impl MerchantAccountUpdateBridge for api::MerchantAccountUpdate { merchant_id: &id_type::MerchantId, key_store: &domain::MerchantKeyStore, ) -> RouterResult { - use common_utils::ext_traits::ConfigExt; - let key_manager_state = &state.into(); let key = key_store.key.get_inner().peek(); @@ -885,21 +883,16 @@ impl MerchantAccountUpdateBridge for api::MerchantAccountUpdate { // This supports changing the business profile by passing in the profile_id let business_profile_id_update = if let Some(ref profile_id) = self.default_profile { - if !profile_id.is_empty_after_trim() { - // Validate whether profile_id passed in request is valid and is linked to the merchant - core_utils::validate_and_get_business_profile( - state.store.as_ref(), - key_manager_state, - key_store, - Some(profile_id), - merchant_id, - ) - .await? - .map(|business_profile| Some(business_profile.profile_id)) - } else { - // If empty, Update profile_id to None in the database - Some(None) - } + // Validate whether profile_id passed in request is valid and is linked to the merchant + core_utils::validate_and_get_business_profile( + state.store.as_ref(), + key_manager_state, + key_store, + Some(profile_id), + merchant_id, + ) + .await? + .map(|business_profile| Some(business_profile.profile_id)) } else { None }; @@ -1047,7 +1040,7 @@ impl MerchantAccountUpdateBridge for api::MerchantAccountUpdate { pub async fn merchant_account_update( state: SessionState, merchant_id: &id_type::MerchantId, - _profile_id: Option, + _profile_id: Option, req: api::MerchantAccountUpdate, ) -> RouterResponse { let db = state.store.as_ref(); @@ -1765,7 +1758,7 @@ struct PMAuthConfigValidation<'a> { pm_auth_config: &'a Option, db: &'a dyn StorageInterface, merchant_id: &'a id_type::MerchantId, - profile_id: &'a String, + profile_id: &'a id_type::ProfileId, key_store: &'a domain::MerchantKeyStore, key_manager_state: &'a KeyManagerState, } @@ -1877,7 +1870,7 @@ struct MerchantDefaultConfigUpdate<'a> { merchant_connector_id: &'a String, store: &'a dyn StorageInterface, merchant_id: &'a id_type::MerchantId, - profile_id: &'a String, + profile_id: &'a id_type::ProfileId, transaction_type: &'a api_enums::TransactionType, } #[cfg(all( @@ -1897,7 +1890,7 @@ impl<'a> MerchantDefaultConfigUpdate<'a> { let mut default_routing_config_for_profile = routing::helpers::get_merchant_default_config( self.store, - self.profile_id, + self.profile_id.get_string_repr(), self.transaction_type, ) .await?; @@ -1922,7 +1915,7 @@ impl<'a> MerchantDefaultConfigUpdate<'a> { default_routing_config_for_profile.push(choice); routing::helpers::update_merchant_default_config( self.store, - self.profile_id, + self.profile_id.get_string_repr(), default_routing_config_for_profile.clone(), self.transaction_type, ) @@ -1969,7 +1962,7 @@ impl<'a> DefaultFallbackRoutingConfigUpdate<'a> { profile_wrapper .update_default_fallback_routing_of_connectors_under_profile( self.store, - &default_routing_config_for_profile, + default_routing_config_for_profile, self.key_manager_state, &self.key_store, ) @@ -2438,7 +2431,9 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate { ) .await? .get_required_value("BusinessProfile") - .change_context(errors::ApiErrorResponse::BusinessProfileNotFound { id: profile_id })?; + .change_context(errors::ApiErrorResponse::BusinessProfileNotFound { + id: profile_id.get_string_repr().to_owned(), + })?; Ok(business_profile) } @@ -2614,7 +2609,9 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate { .await? .get_required_value("BusinessProfile") .change_context( - errors::ApiErrorResponse::BusinessProfileNotFound { id: profile_id }, + errors::ApiErrorResponse::BusinessProfileNotFound { + id: profile_id.get_string_repr().to_owned(), + }, )?; Ok(business_profile) @@ -2746,7 +2743,7 @@ pub async fn create_connector( .await .to_duplicate_response( errors::ApiErrorResponse::DuplicateMerchantConnectorAccount { - profile_id: business_profile.profile_id.clone(), + profile_id: business_profile.profile_id.get_string_repr().to_owned(), connector_label: merchant_connector_account .connector_label .unwrap_or_default(), @@ -2809,7 +2806,7 @@ async fn validate_pm_auth( merchant_id: &id_type::MerchantId, key_store: &domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, - profile_id: &String, + profile_id: &id_type::ProfileId, ) -> RouterResponse<()> { let config = serde_json::from_value::(val.expose()) @@ -2858,7 +2855,7 @@ async fn validate_pm_auth( pub async fn retrieve_connector( state: SessionState, merchant_id: id_type::MerchantId, - profile_id: Option, + profile_id: Option, merchant_connector_id: String, ) -> RouterResponse { let store = state.store.as_ref(); @@ -2939,7 +2936,7 @@ pub async fn retrieve_connector( pub async fn list_payment_connectors( state: SessionState, merchant_id: id_type::MerchantId, - profile_id_list: Option>, + profile_id_list: Option>, ) -> RouterResponse> { let store = state.store.as_ref(); let key_manager_state = &(&state).into(); @@ -2984,7 +2981,7 @@ pub async fn list_payment_connectors( pub async fn update_connector( state: SessionState, merchant_id: &id_type::MerchantId, - profile_id: Option, + profile_id: Option, merchant_connector_id: &str, req: api_models::admin::MerchantConnectorUpdate, ) -> RouterResponse { @@ -3042,7 +3039,7 @@ pub async fn update_connector( .await .change_context( errors::ApiErrorResponse::DuplicateMerchantConnectorAccount { - profile_id, + profile_id: profile_id.get_string_repr().to_owned(), connector_label: request_connector_label.unwrap_or_default(), }, ) @@ -3409,7 +3406,7 @@ impl BusinessProfileCreateBridge for api::BusinessProfileCreate { } // Generate a unique profile id - let profile_id = common_utils::generate_id_with_default_len("pro"); + let profile_id = common_utils::generate_profile_id_of_default_length(); let profile_name = self.profile_name.unwrap_or("default".to_string()); let current_time = date_time::now(); @@ -3523,7 +3520,7 @@ impl BusinessProfileCreateBridge for api::BusinessProfileCreate { // Generate a unique profile id // TODO: the profile_id should be generated from the profile_name - let profile_id = common_utils::generate_id_with_default_len("pro"); + let profile_id = common_utils::generate_profile_id_of_default_length(); let profile_name = self.profile_name; let current_time = date_time::now(); @@ -3656,7 +3653,10 @@ pub async fn create_business_profile( .insert_business_profile(key_manager_state, &key_store, business_profile) .await .to_duplicate_response(errors::ApiErrorResponse::GenericDuplicateError { - message: format!("Business Profile with the profile_id {profile_id} already exists"), + message: format!( + "Business Profile with the profile_id {} already exists", + profile_id.get_string_repr() + ), }) .attach_printable("Failed to insert Business profile because of duplication error")?; @@ -3715,7 +3715,7 @@ pub async fn list_business_profile( pub async fn retrieve_business_profile( state: SessionState, - profile_id: String, + profile_id: id_type::ProfileId, merchant_id: id_type::MerchantId, ) -> RouterResponse { let db = state.store.as_ref(); @@ -3731,7 +3731,7 @@ pub async fn retrieve_business_profile( .find_business_profile_by_profile_id(&(&state).into(), &key_store, &profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id, + id: profile_id.get_string_repr().to_owned(), })?; Ok(service_api::ApplicationResponse::Json( @@ -3743,7 +3743,7 @@ pub async fn retrieve_business_profile( pub async fn delete_business_profile( state: SessionState, - profile_id: String, + profile_id: id_type::ProfileId, merchant_id: &id_type::MerchantId, ) -> RouterResponse { let db = state.store.as_ref(); @@ -3751,7 +3751,7 @@ pub async fn delete_business_profile( .delete_business_profile_by_profile_id_merchant_id(&profile_id, merchant_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id, + id: profile_id.get_string_repr().to_owned(), })?; Ok(service_api::ApplicationResponse::Json(delete_result)) @@ -3977,7 +3977,7 @@ impl BusinessProfileUpdateBridge for api::BusinessProfileUpdate { #[cfg(feature = "olap")] pub async fn update_business_profile( state: SessionState, - profile_id: &str, + profile_id: &id_type::ProfileId, merchant_id: &id_type::MerchantId, request: api::BusinessProfileUpdate, ) -> RouterResponse { @@ -3997,12 +3997,12 @@ pub async fn update_business_profile( .find_business_profile_by_profile_id(key_manager_state, &key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_owned(), + id: profile_id.get_string_repr().to_owned(), })?; if business_profile.merchant_id != *merchant_id { Err(errors::ApiErrorResponse::AccessForbidden { - resource: profile_id.to_string(), + resource: profile_id.get_string_repr().to_owned(), })? } @@ -4019,7 +4019,7 @@ pub async fn update_business_profile( ) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_owned(), + id: profile_id.get_string_repr().to_owned(), })?; Ok(service_api::ApplicationResponse::Json( @@ -4055,8 +4055,9 @@ impl BusinessProfileWrapper { storage_impl::redis::cache::CacheKind::Routing( format!( - "routing_config_{}_{profile_id}", - merchant_id.get_string_repr() + "routing_config_{}_{}", + merchant_id.get_string_repr(), + profile_id.get_string_repr() ) .into(), ) @@ -4177,7 +4178,7 @@ impl BusinessProfileWrapper { pub async fn extended_card_info_toggle( state: SessionState, merchant_id: &id_type::MerchantId, - profile_id: &str, + profile_id: &id_type::ProfileId, ext_card_info_choice: admin_types::ExtendedCardInfoChoice, ) -> RouterResponse { let db = state.store.as_ref(); @@ -4197,7 +4198,7 @@ pub async fn extended_card_info_toggle( .find_business_profile_by_profile_id(key_manager_state, &key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; if business_profile.is_extended_card_info_enabled.is_none() @@ -4217,7 +4218,7 @@ pub async fn extended_card_info_toggle( ) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_owned(), + id: profile_id.get_string_repr().to_owned(), })?; } @@ -4227,7 +4228,7 @@ pub async fn extended_card_info_toggle( pub async fn connector_agnostic_mit_toggle( state: SessionState, merchant_id: &id_type::MerchantId, - profile_id: &str, + profile_id: &id_type::ProfileId, connector_agnostic_mit_choice: admin_types::ConnectorAgnosticMitChoice, ) -> RouterResponse { let db = state.store.as_ref(); @@ -4247,12 +4248,12 @@ pub async fn connector_agnostic_mit_toggle( .find_business_profile_by_profile_id(key_manager_state, &key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; if business_profile.merchant_id != *merchant_id { Err(errors::ApiErrorResponse::AccessForbidden { - resource: profile_id.to_string(), + resource: profile_id.get_string_repr().to_owned(), })? } @@ -4271,7 +4272,7 @@ pub async fn connector_agnostic_mit_toggle( ) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_owned(), + id: profile_id.get_string_repr().to_owned(), })?; } diff --git a/crates/router/src/core/authentication/utils.rs b/crates/router/src/core/authentication/utils.rs index 87235582c0..58862d1890 100644 --- a/crates/router/src/core/authentication/utils.rs +++ b/crates/router/src/core/authentication/utils.rs @@ -178,7 +178,7 @@ pub async fn create_new_authentication( merchant_id: common_utils::id_type::MerchantId, authentication_connector: String, token: String, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, payment_id: Option, merchant_connector_id: String, ) -> RouterResult { @@ -285,7 +285,7 @@ pub async fn get_authentication_connector_data( .ok_or(errors::ApiErrorResponse::UnprocessableEntity { message: format!( "No authentication_connector found for profile_id {}", - business_profile.profile_id + business_profile.profile_id.get_string_repr() ), }) .attach_printable( diff --git a/crates/router/src/core/customers.rs b/crates/router/src/core/customers.rs index 71e982031e..1044ca7822 100644 --- a/crates/router/src/core/customers.rs +++ b/crates/router/src/core/customers.rs @@ -433,7 +433,7 @@ impl<'a> MerchantReferenceIdForCustomer<'a> { pub async fn retrieve_customer( state: SessionState, merchant_account: domain::MerchantAccount, - _profile_id: Option, + _profile_id: Option, key_store: domain::MerchantKeyStore, req: customers::CustomerId, ) -> errors::CustomerResponse { @@ -494,7 +494,7 @@ pub async fn retrieve_customer( pub async fn list_customers( state: SessionState, merchant_id: id_type::MerchantId, - _profile_id_list: Option>, + _profile_id_list: Option>, key_store: domain::MerchantKeyStore, ) -> errors::CustomerResponse> { let db = state.store.as_ref(); diff --git a/crates/router/src/core/disputes.rs b/crates/router/src/core/disputes.rs index 7321595930..24c6c0f8be 100644 --- a/crates/router/src/core/disputes.rs +++ b/crates/router/src/core/disputes.rs @@ -26,7 +26,7 @@ use crate::{ pub async fn retrieve_dispute( state: SessionState, merchant_account: domain::MerchantAccount, - profile_id: Option, + profile_id: Option, req: disputes::DisputeId, ) -> RouterResponse { let dispute = state @@ -45,7 +45,7 @@ pub async fn retrieve_dispute( pub async fn retrieve_disputes_list( state: SessionState, merchant_account: domain::MerchantAccount, - _profile_id_list: Option>, + _profile_id_list: Option>, constraints: api_models::disputes::DisputeListConstraints, ) -> RouterResponse> { let disputes = state @@ -65,7 +65,7 @@ pub async fn retrieve_disputes_list( pub async fn accept_dispute( state: SessionState, merchant_account: domain::MerchantAccount, - profile_id: Option, + profile_id: Option, key_store: domain::MerchantKeyStore, req: disputes::DisputeId, ) -> RouterResponse { @@ -169,7 +169,7 @@ pub async fn accept_dispute( pub async fn submit_evidence( state: SessionState, merchant_account: domain::MerchantAccount, - profile_id: Option, + profile_id: Option, key_store: domain::MerchantKeyStore, req: dispute_models::SubmitEvidenceRequest, ) -> RouterResponse { @@ -336,7 +336,7 @@ pub async fn submit_evidence( pub async fn attach_evidence( state: SessionState, merchant_account: domain::MerchantAccount, - profile_id: Option, + profile_id: Option, key_store: domain::MerchantKeyStore, attach_evidence_request: api::AttachEvidenceRequest, ) -> RouterResponse { @@ -415,7 +415,7 @@ pub async fn attach_evidence( pub async fn retrieve_dispute_evidence( state: SessionState, merchant_account: domain::MerchantAccount, - profile_id: Option, + profile_id: Option, req: disputes::DisputeId, ) -> RouterResponse> { let dispute = state diff --git a/crates/router/src/core/files/helpers.rs b/crates/router/src/core/files/helpers.rs index b479d13156..14e404e88a 100644 --- a/crates/router/src/core/files/helpers.rs +++ b/crates/router/src/core/files/helpers.rs @@ -245,7 +245,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/fraud_check.rs b/crates/router/src/core/fraud_check.rs index a5d78377a8..d185e3545b 100644 --- a/crates/router/src/core/fraud_check.rs +++ b/crates/router/src/core/fraud_check.rs @@ -128,7 +128,7 @@ pub async fn should_call_frm( ) -> RouterResult<( bool, Option, - Option, + Option, Option, )> { // Frm routing algorithm is not present in the merchant account @@ -145,7 +145,7 @@ pub async fn should_call_frm( ) -> RouterResult<( bool, Option, - Option, + Option, Option, )> { use common_utils::ext_traits::OptionExt; @@ -327,7 +327,7 @@ pub async fn should_call_frm( Ok(( is_frm_enabled, Some(frm_routing_algorithm_struct), - Some(profile_id.to_string()), + Some(profile_id), Some(frm_configs_object), )) } @@ -354,7 +354,7 @@ pub async fn make_frm_data_and_fraud_check_operation<'a, F>( merchant_account: &domain::MerchantAccount, payment_data: payments::PaymentData, frm_routing_algorithm: FrmRoutingAlgorithm, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, frm_configs: FrmConfigsObject, _customer: &Option, ) -> RouterResult> diff --git a/crates/router/src/core/fraud_check/types.rs b/crates/router/src/core/fraud_check/types.rs index d35e3227e6..7f9d21216b 100644 --- a/crates/router/src/core/fraud_check/types.rs +++ b/crates/router/src/core/fraud_check/types.rs @@ -69,7 +69,7 @@ pub struct FrmInfo { #[derive(Clone, Debug)] pub struct ConnectorDetailsCore { pub connector_name: String, - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, } #[derive(Clone)] pub struct PaymentToFrmData { diff --git a/crates/router/src/core/mandate/helpers.rs b/crates/router/src/core/mandate/helpers.rs index 9899d85fc7..e5fa762aeb 100644 --- a/crates/router/src/core/mandate/helpers.rs +++ b/crates/router/src/core/mandate/helpers.rs @@ -16,7 +16,7 @@ pub async fn get_profile_id_for_mandate( merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, mandate: Mandate, -) -> CustomResult { +) -> CustomResult { let profile_id = if let Some(ref payment_id) = mandate.original_payment_id { let pi = state .store @@ -35,6 +35,7 @@ pub async fn get_profile_id_for_mandate( .ok_or(errors::ApiErrorResponse::BusinessProfileNotFound { id: pi .profile_id + .map(|profile_id| profile_id.get_string_repr().to_owned()) .unwrap_or_else(|| "Profile id is Null".to_string()), })?; Ok(profile_id) diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rs index e7f21ae0fd..bb39bede2d 100644 --- a/crates/router/src/core/payment_link.rs +++ b/crates/router/src/core/payment_link.rs @@ -129,7 +129,7 @@ pub async fn form_payment_link_data( .find_business_profile_by_profile_id(key_manager_state, &key_store, &profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let return_url = if let Some(payment_create_return_url) = payment_intent.return_url.clone() { @@ -754,7 +754,7 @@ pub async fn get_payment_link_status( .find_business_profile_by_profile_id(key_manager_state, &key_store, &profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let return_url = if let Some(payment_create_return_url) = payment_intent.return_url.clone() { diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 274ef3c096..586e93a0fe 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -2734,7 +2734,7 @@ pub async fn list_payment_methods( format!( "pm_filters_cgraph_{}_{}", merchant_account.get_id().get_string_repr(), - profile_id + profile_id.get_string_repr() ) }; @@ -4909,7 +4909,7 @@ async fn generate_saved_pm_response( pub async fn get_mca_status( state: &routes::SessionState, key_store: &domain::MerchantKeyStore, - profile_id: Option, + profile_id: Option, merchant_id: &id_type::MerchantId, is_connector_agnostic_mit_enabled: bool, connector_mandate_details: Option, @@ -5789,7 +5789,7 @@ where pub async fn list_countries_currencies_for_connector_payment_method( state: routes::SessionState, req: ListCountriesCurrenciesRequest, - _profile_id: Option, + _profile_id: Option, ) -> errors::RouterResponse { Ok(services::ApplicationResponse::Json( list_countries_currencies_for_connector_payment_method_util( diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 6938d3c407..72a188a47e 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -106,7 +106,7 @@ pub async fn payments_operation_core( state: &SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, - profile_id_from_auth_layer: Option, + profile_id_from_auth_layer: Option, key_store: domain::MerchantKeyStore, operation: Op, req: Req, @@ -828,7 +828,7 @@ pub async fn payments_core( state: SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, - profile_id: Option, + profile_id: Option, key_store: domain::MerchantKeyStore, operation: Op, req: Req, @@ -1067,7 +1067,7 @@ impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize { .find_business_profile_by_profile_id(key_manager_state, &merchant_key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; Ok(router_types::RedirectPaymentFlowResponse { payments_response, @@ -1201,7 +1201,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync { .find_business_profile_by_profile_id(key_manager_state, &merchant_key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; Ok(router_types::RedirectPaymentFlowResponse { payments_response, @@ -1432,7 +1432,7 @@ impl PaymentRedirectFlow for PaymentAuthenticateCompleteAuthorize { .find_business_profile_by_profile_id(key_manager_state, &merchant_key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; Ok(router_types::AuthenticatePaymentFlowResponse { payments_response, @@ -2019,10 +2019,9 @@ where .as_ref() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("profile_id is not set in payment_intent")? - .clone(); + .attach_printable("profile_id is not set in payment_intent")?; - format!("{connector_name}_{profile_id}") + format!("{connector_name}_{}", profile_id.get_string_repr()) }; let (should_call_connector, existing_connector_customer_id) = @@ -2912,7 +2911,7 @@ pub fn is_operation_complete_authorize(operation: &Op) -> bool { pub async fn list_payments( state: SessionState, merchant: domain::MerchantAccount, - profile_id_list: Option>, + profile_id_list: Option>, key_store: domain::MerchantKeyStore, constraints: api::PaymentListConstraints, ) -> RouterResponse { @@ -2987,7 +2986,7 @@ pub async fn list_payments( pub async fn apply_filters_on_payments( state: SessionState, merchant: domain::MerchantAccount, - profile_id_list: Option>, + profile_id_list: Option>, merchant_key_store: domain::MerchantKeyStore, constraints: api::PaymentListFilterConstraints, ) -> RouterResponse { @@ -3085,7 +3084,7 @@ pub async fn get_filters_for_payments( pub async fn get_payment_filters( state: SessionState, merchant: domain::MerchantAccount, - profile_id_list: Option>, + profile_id_list: Option>, ) -> RouterResponse { let merchant_connector_accounts = if let services::ApplicationResponse::Json(data) = super::admin::list_payment_connectors(state, merchant.get_id().to_owned(), profile_id_list) @@ -4329,7 +4328,7 @@ pub async fn payment_external_authentication( .find_business_profile_by_profile_id(key_manager_state, &key_store, profile_id) .await .change_context(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let authentication_details = business_profile diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 068a66a248..98d680197b 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -136,7 +136,7 @@ pub fn create_certificate( pub fn filter_mca_based_on_profile_and_connector_type( merchant_connector_accounts: Vec, - profile_id: &String, + profile_id: &id_type::ProfileId, connector_type: ConnectorType, ) -> Vec { merchant_connector_accounts @@ -3272,7 +3272,7 @@ pub async fn get_merchant_connector_account( merchant_id: &id_type::MerchantId, creds_identifier: Option, key_store: &domain::MerchantKeyStore, - profile_id: &String, + profile_id: &id_type::ProfileId, connector_name: &str, merchant_connector_id: Option<&String>, ) -> RouterResult { @@ -3397,7 +3397,8 @@ pub async fn get_merchant_connector_account( .to_not_found_response( errors::ApiErrorResponse::MerchantConnectorAccountNotFound { id: format!( - "profile id {profile_id} and connector name {connector_name}" + "profile id {} and connector name {connector_name}", + profile_id.get_string_repr() ), }, ) @@ -3838,7 +3839,7 @@ mod test { pub async fn get_additional_payment_data( pm_data: &domain::PaymentMethodData, db: &dyn StorageInterface, - profile_id: &str, + profile_id: &id_type::ProfileId, ) -> Option { match pm_data { domain::PaymentMethodData::Card(card_data) => { @@ -3846,7 +3847,7 @@ pub async fn get_additional_payment_data( let card_isin = Some(card_data.card_number.get_card_isin()); let enable_extended_bin =db .find_config_by_key_unwrap_or( - format!("{}_enable_extended_card_bin", profile_id).as_str(), + format!("{}_enable_extended_card_bin", profile_id.get_string_repr()).as_str(), Some("false".to_string())) .await.map_err(|err| services::logger::error!(message="Failed to fetch the config", extended_card_bin_error=?err)).ok(); @@ -4347,7 +4348,7 @@ where ))] let fallback_connetors_list = crate::core::routing::helpers::get_merchant_default_config( &*state.clone().store, - profile_id, + profile_id.get_string_repr(), &api_enums::TransactionType::Payment, ) .await diff --git a/crates/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rs index 401e1c2c7a..7034cfab2f 100644 --- a/crates/router/src/core/payments/operations/payment_approve.rs +++ b/crates/router/src/core/payments/operations/payment_approve.rs @@ -81,7 +81,7 @@ impl GetTracker, api::PaymentsCaptureRequest> .find_business_profile_by_profile_id(key_manager_state, key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let attempt_id = payment_intent.active_attempt.get_id().clone(); diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rs index 84eaf97bfa..4a26e53344 100644 --- a/crates/router/src/core/payments/operations/payment_cancel.rs +++ b/crates/router/src/core/payments/operations/payment_cancel.rs @@ -150,7 +150,7 @@ impl GetTracker, api::PaymentsCancelRequest> .find_business_profile_by_profile_id(key_manager_state, key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let payment_data = PaymentData { diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs index 0d096e1d3a..de7ee99619 100644 --- a/crates/router/src/core/payments/operations/payment_capture.rs +++ b/crates/router/src/core/payments/operations/payment_capture.rs @@ -196,7 +196,7 @@ impl GetTracker, api::PaymentsCaptu .find_business_profile_by_profile_id(key_manager_state, key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let payment_data = payments::PaymentData { diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs index 8d4e6f7a5f..c7a2686724 100644 --- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs +++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs @@ -290,7 +290,7 @@ impl GetTracker, api::PaymentsRequest> for Co .find_business_profile_by_profile_id(key_manager_state, key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let payment_data = PaymentData { diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 2e7131edce..273773a80b 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -164,7 +164,7 @@ impl GetTracker, api::PaymentsRequest> for Pa .map(|business_profile_result| { business_profile_result.to_not_found_response( errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), }, ) }) @@ -476,7 +476,7 @@ impl GetTracker, api::PaymentsRequest> for Pa helpers::get_additional_payment_data( &payment_method_data.into(), store.as_ref(), - profile_id.as_ref(), + &profile_id, ) .await }) diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 2b80598adf..a455f1d4c5 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -140,7 +140,7 @@ impl GetTracker, api::PaymentsRequest> for Pa .await .to_not_found_response( errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), }, )? }; @@ -883,7 +883,7 @@ impl PaymentCreate { payment_method_billing_address_id: Option, payment_method_info: &Option, key_store: &domain::MerchantKeyStore, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, customer_acceptance: &Option, ) -> RouterResult<( storage::PaymentAttemptNew, @@ -1083,7 +1083,7 @@ impl PaymentCreate { payment_link_data: Option, billing_address_id: Option, active_attempt_id: String, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, session_expiry: PrimitiveDateTime, ) -> RouterResult { let created_at @ modified_at @ last_synced = common_utils::date_time::now(); @@ -1293,7 +1293,7 @@ async fn create_payment_link( db: &dyn StorageInterface, amount: api::Amount, description: Option, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, domain_name: String, session_expiry: PrimitiveDateTime, locale: Option, diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs index a5d0b95a67..b148d5bbcc 100644 --- a/crates/router/src/core/payments/operations/payment_reject.rs +++ b/crates/router/src/core/payments/operations/payment_reject.rs @@ -134,7 +134,7 @@ impl GetTracker, PaymentsCancelRequest> for P .find_business_profile_by_profile_id(key_manager_state, key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let payment_data = PaymentData { diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs index af5f234e2c..6b101b6bd1 100644 --- a/crates/router/src/core/payments/operations/payment_session.rs +++ b/crates/router/src/core/payments/operations/payment_session.rs @@ -159,7 +159,7 @@ impl GetTracker, api::PaymentsSessionRequest> .find_business_profile_by_profile_id(key_manager_state, key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let payment_data = PaymentData { diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rs index ae9397aa8e..9a29b36b55 100644 --- a/crates/router/src/core/payments/operations/payment_start.rs +++ b/crates/router/src/core/payments/operations/payment_start.rs @@ -144,7 +144,7 @@ impl GetTracker, api::PaymentsStartRequest> f .find_business_profile_by_profile_id(key_manager_state, key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let payment_data = PaymentData { diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs index 587bdc8ef0..f2453e52c8 100644 --- a/crates/router/src/core/payments/operations/payment_status.rs +++ b/crates/router/src/core/payments/operations/payment_status.rs @@ -376,7 +376,7 @@ async fn get_tracker_for_sync< .find_business_profile_by_profile_id(key_manager_state, key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let payment_method_info = diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index e7045116f2..32d7b32059 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -419,7 +419,7 @@ impl GetTracker, api::PaymentsRequest> for Pa .find_business_profile_by_profile_id(key_manager_state, key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let surcharge_details = request.surcharge_details.map(|request_surcharge_details| { diff --git a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs index 31883042ec..e3e3bf4260 100644 --- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs +++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs @@ -112,7 +112,7 @@ impl .find_business_profile_by_profile_id(key_manager_state, key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; let payment_data = payments::PaymentData { diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs index 30c1edb6e0..692a5924a0 100644 --- a/crates/router/src/core/payments/routing.rs +++ b/crates/router/src/core/payments/routing.rs @@ -81,7 +81,7 @@ pub struct SessionRoutingPmTypeInput<'a> { routing_algorithm: &'a MerchantAccountRoutingAlgorithm, backend_input: dsl_inputs::BackendInput, allowed_connectors: FxHashMap, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, } type RoutingResult = oss_errors::CustomResult; @@ -291,7 +291,7 @@ pub async fn perform_static_routing_v1( ))] let fallback_config = routing::helpers::get_merchant_default_config( &*state.clone().store, - &business_profile.profile_id, + business_profile.profile_id.get_string_repr(), &api_enums::TransactionType::from(transaction_data), ) .await @@ -342,22 +342,24 @@ async fn ensure_algorithm_cached_v1( state: &SessionState, merchant_id: &common_utils::id_type::MerchantId, algorithm_id: &str, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, transaction_type: &api_enums::TransactionType, ) -> RoutingResult> { let key = { match transaction_type { common_enums::TransactionType::Payment => { format!( - "routing_config_{}_{profile_id}", - merchant_id.get_string_repr() + "routing_config_{}_{}", + merchant_id.get_string_repr(), + profile_id.get_string_repr(), ) } #[cfg(feature = "payouts")] common_enums::TransactionType::Payout => { format!( - "routing_config_po_{}_{profile_id}", - merchant_id.get_string_repr() + "routing_config_po_{}_{}", + merchant_id.get_string_repr(), + profile_id.get_string_repr() ) } } @@ -425,7 +427,7 @@ pub async fn refresh_routing_cache_v1( state: &SessionState, key: String, algorithm_id: &str, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, ) -> RoutingResult> { let algorithm = { let algorithm = state @@ -507,7 +509,7 @@ pub fn perform_volume_split( pub async fn get_merchant_cgraph<'a>( state: &SessionState, key_store: &domain::MerchantKeyStore, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, transaction_type: &api_enums::TransactionType, ) -> RoutingResult>> { let merchant_id = &key_store.merchant_id; @@ -515,11 +517,19 @@ pub async fn get_merchant_cgraph<'a>( let key = { match transaction_type { api_enums::TransactionType::Payment => { - format!("cgraph_{}_{}", merchant_id.get_string_repr(), profile_id) + format!( + "cgraph_{}_{}", + merchant_id.get_string_repr(), + profile_id.get_string_repr() + ) } #[cfg(feature = "payouts")] api_enums::TransactionType::Payout => { - format!("cgraph_po_{}_{}", merchant_id.get_string_repr(), profile_id) + format!( + "cgraph_po_{}_{}", + merchant_id.get_string_repr(), + profile_id.get_string_repr() + ) } } }; @@ -546,7 +556,7 @@ pub async fn refresh_cgraph_cache<'a>( state: &SessionState, key_store: &domain::MerchantKeyStore, key: String, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, transaction_type: &api_enums::TransactionType, ) -> RoutingResult>> { let mut merchant_connector_accounts = state @@ -645,7 +655,7 @@ async fn perform_cgraph_filtering( chosen: Vec, backend_input: dsl_inputs::BackendInput, eligible_connectors: Option<&Vec>, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, transaction_type: &api_enums::TransactionType, ) -> RoutingResult> { let context = euclid_graph::AnalysisContext::from_dir_values( @@ -689,7 +699,7 @@ pub async fn perform_eligibility_analysis( chosen: Vec, transaction_data: &routing::TransactionData<'_, F>, eligible_connectors: Option<&Vec>, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, ) -> RoutingResult> { let backend_input = match transaction_data { routing::TransactionData::Payment(payment_data) => make_dsl_input(payment_data)?, @@ -728,9 +738,12 @@ pub async fn perform_fallback_routing( .profile_id .as_ref() .get_required_value("profile_id") - .change_context(errors::RoutingError::ProfileIdMissing)?, + .change_context(errors::RoutingError::ProfileIdMissing)? + .get_string_repr(), #[cfg(feature = "payouts")] - routing::TransactionData::Payout(payout_data) => &payout_data.payout_attempt.profile_id, + routing::TransactionData::Payout(payout_data) => { + payout_data.payout_attempt.profile_id.get_string_repr() + } }, &api_enums::TransactionType::from(transaction_data), ) @@ -1015,7 +1028,7 @@ async fn perform_session_routing_for_pm_type( } else { routing::helpers::get_merchant_default_config( &*session_pm_input.state.clone().store, - &session_pm_input.profile_id, + session_pm_input.profile_id.get_string_repr(), transaction_type, ) .await @@ -1036,7 +1049,7 @@ async fn perform_session_routing_for_pm_type( if final_selection.is_empty() { let fallback = routing::helpers::get_merchant_default_config( &*session_pm_input.state.clone().store, - &session_pm_input.profile_id, + session_pm_input.profile_id.get_string_repr(), transaction_type, ) .await diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs index f331639be5..ed847526a3 100644 --- a/crates/router/src/core/payouts.rs +++ b/crates/router/src/core/payouts.rs @@ -66,7 +66,7 @@ pub struct PayoutData { pub payouts: storage::Payouts, pub payout_attempt: storage::PayoutAttempt, pub payout_method_data: Option, - pub profile_id: String, + pub profile_id: common_utils::id_type::ProfileId, pub should_terminate: bool, pub payout_link: Option, } @@ -514,7 +514,7 @@ pub async fn payouts_update_core( pub async fn payouts_retrieve_core( state: SessionState, merchant_account: domain::MerchantAccount, - profile_id: Option, + profile_id: Option, key_store: domain::MerchantKeyStore, req: payouts::PayoutRetrieveRequest, ) -> RouterResponse { @@ -740,7 +740,7 @@ pub async fn payouts_fulfill_core( pub async fn payouts_list_core( _state: SessionState, _merchant_account: domain::MerchantAccount, - _profile_id_list: Option>, + _profile_id_list: Option>, _key_store: domain::MerchantKeyStore, _constraints: payouts::PayoutListConstraints, ) -> RouterResponse { @@ -755,7 +755,7 @@ pub async fn payouts_list_core( pub async fn payouts_list_core( state: SessionState, merchant_account: domain::MerchantAccount, - profile_id_list: Option>, + profile_id_list: Option>, key_store: domain::MerchantKeyStore, constraints: payouts::PayoutListConstraints, ) -> RouterResponse { @@ -864,7 +864,7 @@ pub async fn payouts_list_core( pub async fn payouts_filtered_list_core( state: SessionState, merchant_account: domain::MerchantAccount, - profile_id_list: Option>, + profile_id_list: Option>, key_store: domain::MerchantKeyStore, filters: payouts::PayoutListFilterConstraints, ) -> RouterResponse { @@ -1143,7 +1143,11 @@ pub async fn create_recipient( let connector_name = connector_data.connector_name.to_string(); // Create the connector label using {profile_id}_{connector_name} - let connector_label = format!("{}_{}", payout_data.profile_id, connector_name); + let connector_label = format!( + "{}_{}", + payout_data.profile_id.get_string_repr(), + connector_name + ); let (should_call_connector, _connector_customer_id) = helpers::should_call_payout_connector_create_customer( state, @@ -2217,7 +2221,7 @@ pub async fn payout_create_db_entries( key_store: &domain::MerchantKeyStore, req: &payouts::PayoutCreateRequest, payout_id: &String, - profile_id: &String, + profile_id: &common_utils::id_type::ProfileId, stored_payout_method_data: Option<&payouts::PayoutMethodData>, locale: &String, customer: Option<&domain::Customer>, @@ -2291,7 +2295,7 @@ pub async fn payout_create_db_entries( let payouts_req = storage::PayoutsNew { payout_id: payout_id.to_string(), merchant_id: merchant_id.to_owned(), - customer_id, + customer_id: customer_id.to_owned(), address_id: address_id.to_owned(), payout_type, amount, @@ -2303,7 +2307,7 @@ pub async fn payout_create_db_entries( return_url: req.return_url.to_owned(), entity_type: req.entity_type.unwrap_or_default(), payout_method_id, - profile_id: profile_id.to_string(), + profile_id: profile_id.to_owned(), attempt_count: 1, metadata: req.metadata.clone(), confirm: req.confirm, @@ -2313,7 +2317,8 @@ pub async fn payout_create_db_entries( client_secret: Some(client_secret), priority: req.priority, status, - ..Default::default() + created_at: common_utils::date_time::now(), + last_modified_at: common_utils::date_time::now(), }; let payouts = db .insert_payout(payouts_req, merchant_account.storage_scheme) @@ -2333,8 +2338,18 @@ pub async fn payout_create_db_entries( business_country: req.business_country.to_owned(), business_label: req.business_label.to_owned(), payout_token: req.payout_token.to_owned(), - profile_id: profile_id.to_string(), - ..Default::default() + profile_id: profile_id.to_owned(), + customer_id, + address_id, + connector: None, + connector_payout_id: None, + is_eligible: None, + error_message: None, + error_code: None, + created_at: common_utils::date_time::now(), + last_modified_at: common_utils::date_time::now(), + merchant_connector_id: None, + routing_info: None, }; let payout_attempt = db .insert_payout_attempt( @@ -2371,7 +2386,7 @@ pub async fn payout_create_db_entries( pub async fn make_payout_data( _state: &SessionState, _merchant_account: &domain::MerchantAccount, - _auth_profile_id: Option, + _auth_profile_id: Option, _key_store: &domain::MerchantKeyStore, _req: &payouts::PayoutRequest, ) -> RouterResult { @@ -2382,7 +2397,7 @@ pub async fn make_payout_data( pub async fn make_payout_data( state: &SessionState, merchant_account: &domain::MerchantAccount, - auth_profile_id: Option, + auth_profile_id: Option, key_store: &domain::MerchantKeyStore, req: &payouts::PayoutRequest, ) -> RouterResult { @@ -2567,7 +2582,7 @@ pub async fn add_external_account_addition_task( async fn validate_and_get_business_profile( state: &SessionState, merchant_key_store: &domain::MerchantKeyStore, - profile_id: &String, + profile_id: &common_utils::id_type::ProfileId, merchant_id: &common_utils::id_type::MerchantId, ) -> RouterResult { let db = &*state.store; @@ -2587,7 +2602,7 @@ async fn validate_and_get_business_profile( db.find_business_profile_by_profile_id(key_manager_state, merchant_key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), }) } } @@ -2726,7 +2741,7 @@ pub async fn create_payout_link_db_entry( pub async fn get_mca_from_profile_id( state: &SessionState, merchant_account: &domain::MerchantAccount, - profile_id: &String, + profile_id: &common_utils::id_type::ProfileId, connector_name: &str, merchant_connector_id: Option<&String>, key_store: &domain::MerchantKeyStore, diff --git a/crates/router/src/core/payouts/retry.rs b/crates/router/src/core/payouts/retry.rs index 284f81a170..08fef69988 100644 --- a/crates/router/src/core/payouts/retry.rs +++ b/crates/router/src/core/payouts/retry.rs @@ -285,8 +285,16 @@ pub async fn modify_trackers( business_country: payout_data.payout_attempt.business_country.to_owned(), business_label: payout_data.payout_attempt.business_label.to_owned(), payout_token: payout_data.payout_attempt.payout_token.to_owned(), - profile_id: payout_data.payout_attempt.profile_id.to_string(), - ..Default::default() + profile_id: payout_data.payout_attempt.profile_id.to_owned(), + connector_payout_id: None, + status: common_enums::PayoutStatus::default(), + is_eligible: None, + error_message: None, + error_code: None, + created_at: common_utils::date_time::now(), + last_modified_at: common_utils::date_time::now(), + merchant_connector_id: None, + routing_info: None, }; payout_data.payout_attempt = db .insert_payout_attempt( diff --git a/crates/router/src/core/payouts/validator.rs b/crates/router/src/core/payouts/validator.rs index d425725645..bde753a90e 100644 --- a/crates/router/src/core/payouts/validator.rs +++ b/crates/router/src/core/payouts/validator.rs @@ -56,7 +56,7 @@ pub async fn validate_create_request( ) -> RouterResult<( String, Option, - String, + common_utils::id_type::ProfileId, Option, )> { let merchant_id = merchant_account.get_id(); diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs index 878ec24185..8945034740 100644 --- a/crates/router/src/core/refunds.rs +++ b/crates/router/src/core/refunds.rs @@ -47,7 +47,7 @@ use crate::{ pub async fn refund_create_core( state: SessionState, merchant_account: domain::MerchantAccount, - _profile_id: Option, + _profile_id: Option, key_store: domain::MerchantKeyStore, req: refunds::RefundRequest, ) -> RouterResponse { @@ -374,7 +374,7 @@ where pub async fn refund_response_wrapper<'a, F, Fut, T, Req>( state: SessionState, merchant_account: domain::MerchantAccount, - profile_id: Option, + profile_id: Option, key_store: domain::MerchantKeyStore, request: Req, f: F, @@ -383,7 +383,7 @@ where F: Fn( SessionState, domain::MerchantAccount, - Option, + Option, domain::MerchantKeyStore, Req, ) -> Fut, @@ -401,7 +401,7 @@ where pub async fn refund_retrieve_core( state: SessionState, merchant_account: domain::MerchantAccount, - profile_id: Option, + profile_id: Option, key_store: domain::MerchantKeyStore, request: refunds::RefundsRetrieveRequest, ) -> RouterResult { @@ -865,7 +865,7 @@ pub async fn validate_and_create_refund( pub async fn refund_list( state: SessionState, merchant_account: domain::MerchantAccount, - _profile_id_list: Option>, + _profile_id_list: Option>, req: api_models::refunds::RefundListRequest, ) -> RouterResponse { let db = state.store; @@ -987,7 +987,7 @@ pub async fn refund_manual_update( pub async fn get_filters_for_refunds( state: SessionState, merchant_account: domain::MerchantAccount, - profile_id_list: Option>, + profile_id_list: Option>, ) -> RouterResponse { let merchant_connector_accounts = if let services::ApplicationResponse::Json(data) = super::admin::list_payment_connectors( diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rs index 640b12c52c..267a3d55ce 100644 --- a/crates/router/src/core/routing.rs +++ b/crates/router/src/core/routing.rs @@ -50,7 +50,7 @@ impl RoutingAlgorithmUpdate { pub fn create_new_routing_algorithm( request: &routing_types::RoutingConfigRequest, merchant_id: &common_utils::id_type::MerchantId, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, transaction_type: &enums::TransactionType, ) -> Self { let algorithm_id = common_utils::generate_id( @@ -279,7 +279,7 @@ pub async fn link_routing_config_under_profile( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, algorithm_id: String, transaction_type: &enums::TransactionType, ) -> RouterResponse { @@ -377,7 +377,7 @@ pub async fn link_routing_config( .await? .get_required_value("BusinessProfile") .change_context(errors::ApiErrorResponse::BusinessProfileNotFound { - id: routing_algorithm.profile_id.clone(), + id: routing_algorithm.profile_id.get_string_repr().to_owned(), })?; let mut routing_ref: routing_types::RoutingAlgorithmRef = business_profile @@ -506,7 +506,7 @@ pub async fn unlink_routing_config_under_profile( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, transaction_type: &enums::TransactionType, ) -> RouterResponse { metrics::ROUTING_UNLINK_CONFIG.add(&metrics::CONTEXT, 1, &[]); @@ -652,7 +652,7 @@ pub async fn update_default_fallback_routing( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, updated_list_of_connectors: Vec, ) -> RouterResponse> { metrics::ROUTING_UPDATE_CONFIG.add(&metrics::CONTEXT, 1, &[]); @@ -788,7 +788,7 @@ pub async fn retrieve_default_fallback_algorithm_for_profile( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, ) -> RouterResponse> { metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG.add(&metrics::CONTEXT, 1, &[]); let db = state.store.as_ref(); @@ -844,7 +844,7 @@ pub async fn retrieve_routing_config_under_profile( merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, query_params: RoutingRetrieveQuery, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, transaction_type: &enums::TransactionType, ) -> RouterResponse { metrics::ROUTING_RETRIEVE_LINK_CONFIG.add(&metrics::CONTEXT, 1, &[]); @@ -908,7 +908,9 @@ pub async fn retrieve_linked_routing_config( .await? .map(|profile| vec![profile]) .get_required_value("BusinessProfile") - .change_context(errors::ApiErrorResponse::BusinessProfileNotFound { id: profile_id })? + .change_context(errors::ApiErrorResponse::BusinessProfileNotFound { + id: profile_id.get_string_repr().to_owned(), + })? } else { db.list_business_profile_by_merchant_id( key_manager_state, @@ -975,7 +977,13 @@ pub async fn retrieve_default_routing_config_for_profiles( let retrieve_config_futures = all_profiles .iter() - .map(|prof| helpers::get_merchant_default_config(db, &prof.profile_id, transaction_type)) + .map(|prof| { + helpers::get_merchant_default_config( + db, + prof.profile_id.get_string_repr(), + transaction_type, + ) + }) .collect::>(); let configs = futures::future::join_all(retrieve_config_futures) @@ -1003,7 +1011,7 @@ pub async fn update_default_routing_config_for_profile( merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, updated_config: Vec, - profile_id: String, + profile_id: common_utils::id_type::ProfileId, transaction_type: &enums::TransactionType, ) -> RouterResponse { metrics::ROUTING_UPDATE_CONFIG_FOR_PROFILE.add(&metrics::CONTEXT, 1, &[]); @@ -1019,10 +1027,15 @@ pub async fn update_default_routing_config_for_profile( ) .await? .get_required_value("BusinessProfile") - .change_context(errors::ApiErrorResponse::BusinessProfileNotFound { id: profile_id })?; - let default_config = - helpers::get_merchant_default_config(db, &business_profile.profile_id, transaction_type) - .await?; + .change_context(errors::ApiErrorResponse::BusinessProfileNotFound { + id: profile_id.get_string_repr().to_owned(), + })?; + let default_config = helpers::get_merchant_default_config( + db, + business_profile.profile_id.get_string_repr(), + transaction_type, + ) + .await?; utils::when(default_config.len() != updated_config.len(), || { Err(errors::ApiErrorResponse::PreconditionFailed { @@ -1061,7 +1074,7 @@ pub async fn update_default_routing_config_for_profile( helpers::update_merchant_default_config( db, - &business_profile.profile_id, + business_profile.profile_id.get_string_repr(), updated_config.clone(), transaction_type, ) diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rs index 43da2bb2bd..5cbb1e9fdf 100644 --- a/crates/router/src/core/routing/helpers.rs +++ b/crates/router/src/core/routing/helpers.rs @@ -207,8 +207,9 @@ pub async fn update_business_profile_active_algorithm_ref( let routing_cache_key = cache::CacheKind::Routing( format!( - "routing_config_{}_{profile_id}", - merchant_id.get_string_repr() + "routing_config_{}_{}", + merchant_id.get_string_repr(), + profile_id.get_string_repr(), ) .into(), ); @@ -300,13 +301,13 @@ impl MerchantConnectorAccounts { pub fn filter_by_profile<'a, T>( &'a self, - profile_id: &'a str, + profile_id: &'a common_utils::id_type::ProfileId, func: impl Fn(&'a MerchantConnectorAccount) -> T, ) -> FxHashSet where T: std::hash::Hash + Eq, { - self.filter_and_map(|mca| mca.profile_id == profile_id, func) + self.filter_and_map(|mca| mca.profile_id == *profile_id, func) } } @@ -396,7 +397,7 @@ pub async fn validate_connectors_in_routing_config( state: &SessionState, key_store: &domain::MerchantKeyStore, merchant_id: &common_utils::id_type::MerchantId, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, routing_algorithm: &routing_types::RoutingAlgorithm, ) -> RouterResult<()> { let all_mcas = &*state @@ -413,13 +414,13 @@ pub async fn validate_connectors_in_routing_config( })?; let name_mca_id_set = all_mcas .iter() - .filter(|mca| mca.profile_id == profile_id) + .filter(|mca| mca.profile_id == *profile_id) .map(|mca| (&mca.connector_name, mca.get_id())) .collect::>(); let name_set = all_mcas .iter() - .filter(|mca| mca.profile_id == profile_id) + .filter(|mca| mca.profile_id == *profile_id) .map(|mca| &mca.connector_name) .collect::>(); diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index 02a10252cd..c46fac1322 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -94,7 +94,11 @@ pub async fn construct_payout_router_data<'a, F>( let payouts = &payout_data.payouts; let payout_attempt = &payout_data.payout_attempt; let customer_details = &payout_data.customer_details; - let connector_label = format!("{}_{}", payout_data.profile_id, connector_name); + let connector_label = format!( + "{}_{}", + payout_data.profile_id.get_string_repr(), + connector_name + ); let connector_customer_id = customer_details .as_ref() .and_then(|c| c.connector_customer.as_ref()) @@ -394,6 +398,7 @@ pub fn validate_uuid(uuid: String, key: &str) -> Result, + profile_id: Option, } impl Object { - pub fn new(profile_id: &str) -> Self { + pub fn new(profile_id: &'static str) -> Self { Self { - profile_id: Some(profile_id.to_string()), + profile_id: Some( + common_utils::id_type::ProfileId::try_from(std::borrow::Cow::from( + profile_id, + )) + .expect("invalid profile ID"), + ), } } } impl GetProfileId for Object { - fn get_profile_id(&self) -> Option<&String> { + fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> { self.profile_id.as_ref() } } + fn new_profile_id(profile_id: &'static str) -> common_utils::id_type::ProfileId { + common_utils::id_type::ProfileId::try_from(std::borrow::Cow::from(profile_id)) + .expect("invalid profile ID") + } + // non empty object_list and profile_id_list let object_list = vec![ Object::new("p1"), @@ -450,7 +465,11 @@ mod tests { Object::new("p4"), Object::new("p5"), ]; - let profile_id_list = vec!["p1".to_string(), "p2".to_string(), "p3".to_string()]; + let profile_id_list = vec![ + new_profile_id("p1"), + new_profile_id("p2"), + new_profile_id("p3"), + ]; let filtered_list = filter_objects_based_on_profile_id_list(Some(profile_id_list), object_list.clone()); let expected_result = vec![Object::new("p1"), Object::new("p2"), Object::new("p2")]; @@ -1040,7 +1059,7 @@ pub async fn validate_and_get_business_profile( db: &dyn StorageInterface, key_manager_state: &common_utils::types::keymanager::KeyManagerState, merchant_key_store: &domain::MerchantKeyStore, - profile_id: Option<&String>, + profile_id: Option<&common_utils::id_type::ProfileId>, merchant_id: &common_utils::id_type::MerchantId, ) -> RouterResult> { profile_id @@ -1052,7 +1071,7 @@ pub async fn validate_and_get_business_profile( ) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_owned(), + id: profile_id.get_string_repr().to_owned(), }) }) .await @@ -1061,7 +1080,7 @@ pub async fn validate_and_get_business_profile( // Check if the merchant_id of business profile is same as the current merchant_id if business_profile.merchant_id.ne(merchant_id) { Err(errors::ApiErrorResponse::AccessForbidden { - resource: business_profile.profile_id, + resource: business_profile.profile_id.get_string_repr().to_owned(), } .into()) } else { @@ -1123,10 +1142,10 @@ pub async fn get_profile_id_from_business_details( business_country: Option, business_label: Option<&String>, merchant_account: &domain::MerchantAccount, - request_profile_id: Option<&String>, + request_profile_id: Option<&common_utils::id_type::ProfileId>, db: &dyn StorageInterface, should_validate: bool, -) -> RouterResult { +) -> RouterResult { match request_profile_id.or(merchant_account.default_profile.as_ref()) { Some(profile_id) => { // Check whether this business profile belongs to the merchant @@ -1297,55 +1316,55 @@ pub fn get_incremental_authorization_allowed_value( } pub(super) trait GetProfileId { - fn get_profile_id(&self) -> Option<&String>; + fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId>; } impl GetProfileId for MerchantConnectorAccount { - fn get_profile_id(&self) -> Option<&String> { + fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> { Some(&self.profile_id) } } impl GetProfileId for storage::PaymentIntent { - fn get_profile_id(&self) -> Option<&String> { + fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> { self.profile_id.as_ref() } } impl GetProfileId for (storage::PaymentIntent, A) { - fn get_profile_id(&self) -> Option<&String> { + fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> { self.0.get_profile_id() } } impl GetProfileId for diesel_models::Dispute { - fn get_profile_id(&self) -> Option<&String> { + fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> { self.profile_id.as_ref() } } impl GetProfileId for diesel_models::Refund { - fn get_profile_id(&self) -> Option<&String> { + fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> { self.profile_id.as_ref() } } #[cfg(feature = "payouts")] impl GetProfileId for storage::Payouts { - fn get_profile_id(&self) -> Option<&String> { + fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> { Some(&self.profile_id) } } #[cfg(feature = "payouts")] impl GetProfileId for (storage::Payouts, T, F) { - fn get_profile_id(&self) -> Option<&String> { + fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> { self.0.get_profile_id() } } /// Filter Objects based on profile ids pub(super) fn filter_objects_based_on_profile_id_list( - profile_id_list_auth_layer: Option>, + profile_id_list_auth_layer: Option>, object_list: Vec, ) -> Vec { if let Some(profile_id_list) = profile_id_list_auth_layer { @@ -1369,7 +1388,7 @@ pub(super) fn filter_objects_based_on_profile_id_list( } pub(super) fn validate_profile_id_from_auth_layer( - profile_id_auth_layer: Option, + profile_id_auth_layer: Option, object: &T, ) -> RouterResult<()> { match (profile_id_auth_layer, object.get_profile_id()) { diff --git a/crates/router/src/core/verification.rs b/crates/router/src/core/verification.rs index 795e188c8a..44bb67d0ba 100644 --- a/crates/router/src/core/verification.rs +++ b/crates/router/src/core/verification.rs @@ -12,7 +12,7 @@ pub async fn verify_merchant_creds_for_applepay( state: SessionState, body: verifications::ApplepayMerchantVerificationRequest, merchant_id: common_utils::id_type::MerchantId, - profile_id: Option, + profile_id: Option, ) -> CustomResult, errors::ApiErrorResponse> { let applepay_merchant_configs = state.conf.applepay_merchant_configs.get_inner(); diff --git a/crates/router/src/core/verification/utils.rs b/crates/router/src/core/verification/utils.rs index dd0aa3edef..4b8e0ac074 100644 --- a/crates/router/src/core/verification/utils.rs +++ b/crates/router/src/core/verification/utils.rs @@ -15,7 +15,7 @@ use crate::{ 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, + profile_id_from_auth_layer: Option, merchant_connector_id: String, domain_from_req: Vec, ) -> CustomResult, errors::ApiErrorResponse> { diff --git a/crates/router/src/core/verify_connector.rs b/crates/router/src/core/verify_connector.rs index b6f03c27ab..f7fa06dee5 100644 --- a/crates/router/src/core/verify_connector.rs +++ b/crates/router/src/core/verify_connector.rs @@ -19,7 +19,7 @@ use crate::{ pub async fn verify_connector_credentials( state: SessionState, req: VerifyConnectorRequest, - _profile_id: Option, + _profile_id: Option, ) -> errors::RouterResponse<()> { let boxed_connector = api::ConnectorData::get_connector_by_name( &state.conf.connectors, diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs index d3e5873e9e..01a1046be3 100644 --- a/crates/router/src/core/webhooks/incoming.rs +++ b/crates/router/src/core/webhooks/incoming.rs @@ -347,14 +347,14 @@ async fn incoming_webhooks_core( )?, }; - let profile_id = merchant_connector_account.profile_id.as_ref(); + let profile_id = &merchant_connector_account.profile_id; let business_profile = state .store .find_business_profile_by_profile_id(key_manager_state, &key_store, profile_id) .await .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), })?; match flow_type { diff --git a/crates/router/src/core/webhooks/outgoing.rs b/crates/router/src/core/webhooks/outgoing.rs index b075b15e7f..276d296a4c 100644 --- a/crates/router/src/core/webhooks/outgoing.rs +++ b/crates/router/src/core/webhooks/outgoing.rs @@ -71,7 +71,7 @@ pub(crate) async fn create_event_and_trigger_outgoing_webhook( || webhook_url_result.as_ref().is_ok_and(String::is_empty) { logger::debug!( - business_profile_id=%business_profile.profile_id, + business_profile_id=?business_profile.profile_id, %idempotent_event_id, "Outgoing webhooks are disabled in application configuration, or merchant webhook URL \ could not be obtained; skipping outgoing webhooks for event" diff --git a/crates/router/src/core/webhooks/types.rs b/crates/router/src/core/webhooks/types.rs index d9eed529e8..d9094bff00 100644 --- a/crates/router/src/core/webhooks/types.rs +++ b/crates/router/src/core/webhooks/types.rs @@ -59,7 +59,7 @@ impl OutgoingWebhookType for webhooks::OutgoingWebhook { #[derive(Debug, serde::Serialize, serde::Deserialize)] pub(crate) struct OutgoingWebhookTrackingData { pub(crate) merchant_id: common_utils::id_type::MerchantId, - pub(crate) business_profile_id: String, + pub(crate) business_profile_id: common_utils::id_type::ProfileId, pub(crate) event_type: enums::EventType, pub(crate) event_class: enums::EventClass, pub(crate) primary_object_id: String, diff --git a/crates/router/src/core/webhooks/webhook_events.rs b/crates/router/src/core/webhooks/webhook_events.rs index cf4a8d8726..13f1e95fc2 100644 --- a/crates/router/src/core/webhooks/webhook_events.rs +++ b/crates/router/src/core/webhooks/webhook_events.rs @@ -265,7 +265,7 @@ pub async fn retry_delivery_attempt( async fn get_account_and_key_store( state: SessionState, merchant_id: common_utils::id_type::MerchantId, - profile_id: Option, + profile_id: Option, ) -> errors::RouterResult<(MerchantAccountOrBusinessProfile, domain::MerchantKeyStore)> { let store = state.store.as_ref(); let key_manager_state = &(&state).into(); @@ -292,13 +292,13 @@ async fn get_account_and_key_store( .await .attach_printable_lazy(|| { format!( - "Failed to find business profile by merchant_id `{merchant_id:?}` and profile_id `{profile_id}`. \ - The merchant_id associated with the business profile `{profile_id}` may be \ + "Failed to find business profile by merchant_id `{merchant_id:?}` and profile_id `{profile_id:?}`. \ + The merchant_id associated with the business profile `{profile_id:?}` may be \ different than the merchant_id specified (`{merchant_id:?}`)." ) }) .to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id, + id: profile_id.get_string_repr().to_owned(), })?; Ok(( diff --git a/crates/router/src/db/business_profile.rs b/crates/router/src/db/business_profile.rs index ed178f275f..8c81b0c3df 100644 --- a/crates/router/src/db/business_profile.rs +++ b/crates/router/src/db/business_profile.rs @@ -33,7 +33,7 @@ where &self, key_manager_state: &KeyManagerState, merchant_key_store: &domain::MerchantKeyStore, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, ) -> CustomResult; async fn find_business_profile_by_merchant_id_profile_id( @@ -41,7 +41,7 @@ where key_manager_state: &KeyManagerState, merchant_key_store: &domain::MerchantKeyStore, merchant_id: &common_utils::id_type::MerchantId, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, ) -> CustomResult; async fn find_business_profile_by_profile_name_merchant_id( @@ -62,7 +62,7 @@ where async fn delete_business_profile_by_profile_id_merchant_id( &self, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, merchant_id: &common_utils::id_type::MerchantId, ) -> CustomResult; @@ -105,7 +105,7 @@ impl BusinessProfileInterface for Store { &self, key_manager_state: &KeyManagerState, merchant_key_store: &domain::MerchantKeyStore, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, ) -> CustomResult { let conn = connection::pg_connection_read(self).await?; storage::BusinessProfile::find_by_profile_id(&conn, profile_id) @@ -125,7 +125,7 @@ impl BusinessProfileInterface for Store { key_manager_state: &KeyManagerState, merchant_key_store: &domain::MerchantKeyStore, merchant_id: &common_utils::id_type::MerchantId, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, ) -> CustomResult { let conn = connection::pg_connection_read(self).await?; storage::BusinessProfile::find_by_merchant_id_profile_id(&conn, merchant_id, profile_id) @@ -191,7 +191,7 @@ impl BusinessProfileInterface for Store { #[instrument(skip_all)] async fn delete_business_profile_by_profile_id_merchant_id( &self, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, merchant_id: &common_utils::id_type::MerchantId, ) -> CustomResult { let conn = connection::pg_connection_write(self).await?; @@ -262,13 +262,13 @@ impl BusinessProfileInterface for MockDb { &self, key_manager_state: &KeyManagerState, merchant_key_store: &domain::MerchantKeyStore, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, ) -> CustomResult { self.business_profiles .lock() .await .iter() - .find(|business_profile| business_profile.profile_id == profile_id) + .find(|business_profile| business_profile.profile_id == *profile_id) .cloned() .async_map(|business_profile| async { business_profile @@ -284,7 +284,7 @@ impl BusinessProfileInterface for MockDb { .transpose()? .ok_or( errors::StorageError::ValueNotFound(format!( - "No business profile found for profile_id = {profile_id}" + "No business profile found for profile_id = {profile_id:?}" )) .into(), ) @@ -295,7 +295,7 @@ impl BusinessProfileInterface for MockDb { key_manager_state: &KeyManagerState, merchant_key_store: &domain::MerchantKeyStore, merchant_id: &common_utils::id_type::MerchantId, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, ) -> CustomResult { self.business_profiles .lock() @@ -303,7 +303,7 @@ impl BusinessProfileInterface for MockDb { .iter() .find(|business_profile| { business_profile.merchant_id == *merchant_id - && business_profile.profile_id == profile_id + && business_profile.profile_id == *profile_id }) .cloned() .async_map(|business_profile| async { @@ -320,7 +320,7 @@ impl BusinessProfileInterface for MockDb { .transpose()? .ok_or( errors::StorageError::ValueNotFound(format!( - "No business profile found for merchant_id = {merchant_id:?} and profile_id = {profile_id}" + "No business profile found for merchant_id = {merchant_id:?} and profile_id = {profile_id:?}" )) .into(), ) @@ -362,7 +362,7 @@ impl BusinessProfileInterface for MockDb { .transpose()? .ok_or( errors::StorageError::ValueNotFound(format!( - "No business profile found for profile_id = {profile_id}" + "No business profile found for profile_id = {profile_id:?}" )) .into(), ) @@ -370,18 +370,18 @@ impl BusinessProfileInterface for MockDb { async fn delete_business_profile_by_profile_id_merchant_id( &self, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, merchant_id: &common_utils::id_type::MerchantId, ) -> CustomResult { let mut business_profiles = self.business_profiles.lock().await; let index = business_profiles .iter() .position(|business_profile| { - business_profile.profile_id == profile_id + business_profile.profile_id == *profile_id && business_profile.merchant_id == *merchant_id }) .ok_or::(errors::StorageError::ValueNotFound(format!( - "No business profile found for profile_id = {profile_id} and merchant_id = {merchant_id:?}" + "No business profile found for profile_id = {profile_id:?} and merchant_id = {merchant_id:?}" )))?; business_profiles.remove(index); Ok(true) diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rs index edd1eecff9..6aae49f1bd 100644 --- a/crates/router/src/db/events.rs +++ b/crates/router/src/db/events.rs @@ -67,7 +67,7 @@ where async fn list_initial_events_by_profile_id_primary_object_id( &self, state: &KeyManagerState, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, primary_object_id: &str, merchant_key_store: &domain::MerchantKeyStore, ) -> CustomResult, errors::StorageError>; @@ -76,7 +76,7 @@ where async fn list_initial_events_by_profile_id_constraints( &self, state: &KeyManagerState, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, created_after: Option, created_before: Option, limit: Option, @@ -256,7 +256,7 @@ impl EventInterface for Store { async fn list_initial_events_by_profile_id_primary_object_id( &self, state: &KeyManagerState, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, primary_object_id: &str, merchant_key_store: &domain::MerchantKeyStore, ) -> CustomResult, errors::StorageError> { @@ -291,7 +291,7 @@ impl EventInterface for Store { async fn list_initial_events_by_profile_id_constraints( &self, state: &KeyManagerState, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, created_after: Option, created_before: Option, limit: Option, @@ -554,7 +554,7 @@ impl EventInterface for MockDb { async fn list_initial_events_by_profile_id_primary_object_id( &self, state: &KeyManagerState, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, primary_object_id: &str, merchant_key_store: &domain::MerchantKeyStore, ) -> CustomResult, errors::StorageError> { @@ -589,7 +589,7 @@ impl EventInterface for MockDb { async fn list_initial_events_by_profile_id_constraints( &self, state: &KeyManagerState, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, created_after: Option, created_before: Option, limit: Option, @@ -737,7 +737,8 @@ mod tests { let merchant_id = common_utils::id_type::MerchantId::try_from(std::borrow::Cow::from("merchant_1")) .unwrap(); - let business_profile_id = "profile1"; + let business_profile_id = + common_utils::id_type::ProfileId::try_from(std::borrow::Cow::from("profile1")).unwrap(); let payment_id = "test_payment_id"; let key_manager_state = &state.into(); let master_key = mockdb.get_master_key(); diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs index c02304c7b4..37613d5961 100644 --- a/crates/router/src/db/kafka_store.rs +++ b/crates/router/src/db/kafka_store.rs @@ -714,7 +714,7 @@ impl EventInterface for KafkaStore { async fn list_initial_events_by_profile_id_primary_object_id( &self, state: &KeyManagerState, - profile_id: &str, + profile_id: &id_type::ProfileId, primary_object_id: &str, merchant_key_store: &domain::MerchantKeyStore, ) -> CustomResult, errors::StorageError> { @@ -731,7 +731,7 @@ impl EventInterface for KafkaStore { async fn list_initial_events_by_profile_id_constraints( &self, state: &KeyManagerState, - profile_id: &str, + profile_id: &id_type::ProfileId, created_after: Option, created_before: Option, limit: Option, @@ -1129,7 +1129,7 @@ impl MerchantConnectorAccountInterface for KafkaStore { async fn find_merchant_connector_account_by_profile_id_connector_name( &self, state: &KeyManagerState, - profile_id: &str, + profile_id: &id_type::ProfileId, connector_name: &str, key_store: &domain::MerchantKeyStore, ) -> CustomResult { @@ -2373,7 +2373,7 @@ impl BusinessProfileInterface for KafkaStore { &self, key_manager_state: &KeyManagerState, merchant_key_store: &domain::MerchantKeyStore, - profile_id: &str, + profile_id: &id_type::ProfileId, ) -> CustomResult { self.diesel_store .find_business_profile_by_profile_id(key_manager_state, merchant_key_store, profile_id) @@ -2385,7 +2385,7 @@ impl BusinessProfileInterface for KafkaStore { key_manager_state: &KeyManagerState, merchant_key_store: &domain::MerchantKeyStore, merchant_id: &id_type::MerchantId, - profile_id: &str, + profile_id: &id_type::ProfileId, ) -> CustomResult { self.diesel_store .find_business_profile_by_merchant_id_profile_id( @@ -2416,7 +2416,7 @@ impl BusinessProfileInterface for KafkaStore { async fn delete_business_profile_by_profile_id_merchant_id( &self, - profile_id: &str, + profile_id: &id_type::ProfileId, merchant_id: &id_type::MerchantId, ) -> CustomResult { self.diesel_store @@ -2493,7 +2493,7 @@ impl RoutingAlgorithmInterface for KafkaStore { async fn find_routing_algorithm_by_profile_id_algorithm_id( &self, - profile_id: &str, + profile_id: &id_type::ProfileId, algorithm_id: &str, ) -> CustomResult { self.diesel_store @@ -2514,7 +2514,7 @@ impl RoutingAlgorithmInterface for KafkaStore { async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id( &self, algorithm_id: &str, - profile_id: &str, + profile_id: &id_type::ProfileId, ) -> CustomResult { self.diesel_store .find_routing_algorithm_metadata_by_algorithm_id_profile_id(algorithm_id, profile_id) @@ -2523,7 +2523,7 @@ impl RoutingAlgorithmInterface for KafkaStore { async fn list_routing_algorithm_metadata_by_profile_id( &self, - profile_id: &str, + profile_id: &id_type::ProfileId, limit: i64, offset: i64, ) -> CustomResult, errors::StorageError> { @@ -2807,7 +2807,7 @@ impl UserRoleInterface for KafkaStore { user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, version: enums::UserRoleVersion, ) -> CustomResult { self.diesel_store @@ -2826,7 +2826,7 @@ impl UserRoleInterface for KafkaStore { user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, update: user_storage::UserRoleUpdate, version: enums::UserRoleVersion, ) -> CustomResult { @@ -2847,7 +2847,7 @@ impl UserRoleInterface for KafkaStore { user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, version: enums::UserRoleVersion, ) -> CustomResult { self.diesel_store @@ -2876,7 +2876,7 @@ impl UserRoleInterface for KafkaStore { user_id: &str, org_id: Option<&id_type::OrganizationId>, merchant_id: Option<&id_type::MerchantId>, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, entity_id: Option<&String>, version: Option, ) -> CustomResult, errors::StorageError> { diff --git a/crates/router/src/db/merchant_account.rs b/crates/router/src/db/merchant_account.rs index 5a828ebb0c..8aa013ab08 100644 --- a/crates/router/src/db/merchant_account.rs +++ b/crates/router/src/db/merchant_account.rs @@ -589,7 +589,7 @@ async fn publish_and_redact_merchant_account_cache( format!( "cgraph_{}_{}", merchant_account.get_id().get_string_repr(), - profile_id, + profile_id.get_string_repr(), ) .into(), ) diff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rs index f039728de4..1908e01e94 100644 --- a/crates/router/src/db/merchant_connector_account.rs +++ b/crates/router/src/db/merchant_connector_account.rs @@ -141,7 +141,7 @@ where async fn find_merchant_connector_account_by_profile_id_connector_name( &self, state: &KeyManagerState, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, connector_name: &str, key_store: &domain::MerchantKeyStore, ) -> CustomResult; @@ -290,7 +290,7 @@ impl MerchantConnectorAccountInterface for Store { async fn find_merchant_connector_account_by_profile_id_connector_name( &self, state: &KeyManagerState, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, connector_name: &str, key_store: &domain::MerchantKeyStore, ) -> CustomResult { @@ -322,7 +322,7 @@ impl MerchantConnectorAccountInterface for Store { { cache::get_or_populate_in_memory( self, - &format!("{}_{}", profile_id, connector_name), + &format!("{}_{}", profile_id.get_string_repr(), connector_name), find_call, &cache::ACCOUNTS_CACHE, ) @@ -587,7 +587,7 @@ impl MerchantConnectorAccountInterface for Store { self, [ cache::CacheKind::Accounts( - format!("{}_{}", _profile_id, _connector_name).into(), + format!("{}_{}", _profile_id.get_string_repr(), _connector_name).into(), ), cache::CacheKind::Accounts( format!( @@ -598,8 +598,12 @@ impl MerchantConnectorAccountInterface for Store { .into(), ), cache::CacheKind::CGraph( - format!("cgraph_{}_{_profile_id}", _merchant_id.get_string_repr()) - .into(), + format!( + "cgraph_{}_{}", + _merchant_id.get_string_repr(), + _profile_id.get_string_repr() + ) + .into(), ), ], || update, @@ -683,7 +687,7 @@ impl MerchantConnectorAccountInterface for Store { self, [ cache::CacheKind::Accounts( - format!("{}_{}", _profile_id, _connector_name).into(), + format!("{}_{}", _profile_id.get_string_repr(), _connector_name).into(), ), cache::CacheKind::Accounts( format!( @@ -694,12 +698,18 @@ impl MerchantConnectorAccountInterface for Store { .into(), ), cache::CacheKind::CGraph( - format!("cgraph_{}_{_profile_id}", _merchant_id.get_string_repr()).into(), + format!( + "cgraph_{}_{}", + _merchant_id.get_string_repr(), + _profile_id.get_string_repr() + ) + .into(), ), cache::CacheKind::PmFiltersCGraph( format!( - "pm_filters_cgraph_{}_{_profile_id}", - _merchant_id.get_string_repr() + "pm_filters_cgraph_{}_{}", + _merchant_id.get_string_repr(), + _profile_id.get_string_repr(), ) .into(), ), @@ -759,7 +769,7 @@ impl MerchantConnectorAccountInterface for Store { self, [ cache::CacheKind::Accounts( - format!("{}_{}", _profile_id, _connector_name).into(), + format!("{}_{}", _profile_id.get_string_repr(), _connector_name).into(), ), cache::CacheKind::Accounts( format!( @@ -770,12 +780,18 @@ impl MerchantConnectorAccountInterface for Store { .into(), ), cache::CacheKind::CGraph( - format!("cgraph_{}_{_profile_id}", _merchant_id.get_string_repr()).into(), + format!( + "cgraph_{}_{}", + _merchant_id.get_string_repr(), + _profile_id.get_string_repr() + ) + .into(), ), cache::CacheKind::PmFiltersCGraph( format!( - "pm_filters_cgraph_{}_{_profile_id}", - _merchant_id.get_string_repr() + "pm_filters_cgraph_{}_{}", + _merchant_id.get_string_repr(), + _profile_id.get_string_repr() ) .into(), ), @@ -835,16 +851,26 @@ impl MerchantConnectorAccountInterface for Store { self, [ cache::CacheKind::Accounts( - format!("{}_{}", mca.merchant_id.get_string_repr(), _profile_id).into(), + format!( + "{}_{}", + mca.merchant_id.get_string_repr(), + _profile_id.get_string_repr() + ) + .into(), ), cache::CacheKind::CGraph( - format!("cgraph_{}_{_profile_id}", mca.merchant_id.get_string_repr()) - .into(), + format!( + "cgraph_{}_{}", + mca.merchant_id.get_string_repr(), + _profile_id.get_string_repr() + ) + .into(), ), cache::CacheKind::PmFiltersCGraph( format!( - "pm_filters_cgraph_{}_{_profile_id}", - mca.merchant_id.get_string_repr() + "pm_filters_cgraph_{}_{}", + mca.merchant_id.get_string_repr(), + _profile_id.get_string_repr() ) .into(), ), @@ -890,16 +916,26 @@ impl MerchantConnectorAccountInterface for Store { self, [ cache::CacheKind::Accounts( - format!("{}_{}", mca.merchant_id.get_string_repr(), _profile_id).into(), + format!( + "{}_{}", + mca.merchant_id.get_string_repr(), + _profile_id.get_string_repr() + ) + .into(), ), cache::CacheKind::CGraph( - format!("cgraph_{}_{_profile_id}", mca.merchant_id.get_string_repr()) - .into(), + format!( + "cgraph_{}_{}", + mca.merchant_id.get_string_repr(), + _profile_id.get_string_repr() + ) + .into(), ), cache::CacheKind::PmFiltersCGraph( format!( - "pm_filters_cgraph_{}_{_profile_id}", - mca.merchant_id.get_string_repr() + "pm_filters_cgraph_{}_{}", + mca.merchant_id.get_string_repr(), + _profile_id.get_string_repr() ) .into(), ), @@ -1016,7 +1052,7 @@ impl MerchantConnectorAccountInterface for MockDb { async fn find_merchant_connector_account_by_profile_id_connector_name( &self, state: &KeyManagerState, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, connector_name: &str, key_store: &domain::MerchantKeyStore, ) -> CustomResult { @@ -1475,7 +1511,9 @@ mod merchant_connector_account_cache_tests { let connector_label = "stripe_USA"; let merchant_connector_id = "simple_merchant_connector_id"; - let profile_id = "pro_max_ultra"; + let profile_id = + common_utils::id_type::ProfileId::try_from(std::borrow::Cow::from("pro_max_ultra")) + .unwrap(); let key_manager_state = &state.into(); db.insert_merchant_key_store( key_manager_state, @@ -1536,7 +1574,7 @@ mod merchant_connector_account_cache_tests { created_at: date_time::now(), modified_at: date_time::now(), connector_webhook_details: None, - profile_id: profile_id.to_string(), + profile_id: profile_id.to_owned(), applepay_verified_domains: None, pm_auth_config: None, status: common_enums::ConnectorStatus::Inactive, @@ -1564,7 +1602,7 @@ mod merchant_connector_account_cache_tests { Conversion::convert( db.find_merchant_connector_account_by_profile_id_connector_name( key_manager_state, - profile_id, + &profile_id, &mca.connector_name, &merchant_key, ) @@ -1576,7 +1614,11 @@ mod merchant_connector_account_cache_tests { }; let _: storage::MerchantConnectorAccount = cache::get_or_populate_in_memory( &db, - &format!("{}_{}", merchant_id.get_string_repr(), profile_id), + &format!( + "{}_{}", + merchant_id.get_string_repr(), + profile_id.get_string_repr(), + ), find_call, &ACCOUNTS_CACHE, ) @@ -1644,7 +1686,9 @@ mod merchant_connector_account_cache_tests { .unwrap(); let connector_label = "stripe_USA"; let id = "simple_id"; - let profile_id = "pro_max_ultra"; + let profile_id = + common_utils::id_type::ProfileId::try_from(std::borrow::Cow::from("pro_max_ultra")) + .unwrap(); let key_manager_state = &state.into(); db.insert_merchant_key_store( key_manager_state, @@ -1701,7 +1745,7 @@ mod merchant_connector_account_cache_tests { created_at: date_time::now(), modified_at: date_time::now(), connector_webhook_details: None, - profile_id: profile_id.to_string(), + profile_id: profile_id.to_owned(), applepay_verified_domains: None, pm_auth_config: None, status: common_enums::ConnectorStatus::Inactive, @@ -1748,7 +1792,11 @@ mod merchant_connector_account_cache_tests { let _: storage::MerchantConnectorAccount = cache::get_or_populate_in_memory( &db, - &format!("{}_{}", merchant_id.clone().get_string_repr(), profile_id), + &format!( + "{}_{}", + merchant_id.clone().get_string_repr(), + profile_id.get_string_repr() + ), find_call, &ACCOUNTS_CACHE, ) diff --git a/crates/router/src/db/routing_algorithm.rs b/crates/router/src/db/routing_algorithm.rs index ad4b3bd919..5672777bfa 100644 --- a/crates/router/src/db/routing_algorithm.rs +++ b/crates/router/src/db/routing_algorithm.rs @@ -20,7 +20,7 @@ pub trait RoutingAlgorithmInterface { async fn find_routing_algorithm_by_profile_id_algorithm_id( &self, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, algorithm_id: &str, ) -> StorageResult; @@ -33,12 +33,12 @@ pub trait RoutingAlgorithmInterface { async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id( &self, algorithm_id: &str, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, ) -> StorageResult; async fn list_routing_algorithm_metadata_by_profile_id( &self, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, limit: i64, offset: i64, ) -> StorageResult>; @@ -76,7 +76,7 @@ impl RoutingAlgorithmInterface for Store { #[instrument(skip_all)] async fn find_routing_algorithm_by_profile_id_algorithm_id( &self, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, algorithm_id: &str, ) -> StorageResult { let conn = connection::pg_connection_write(self).await?; @@ -109,7 +109,7 @@ impl RoutingAlgorithmInterface for Store { async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id( &self, algorithm_id: &str, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, ) -> StorageResult { let conn = connection::pg_connection_write(self).await?; routing_storage::RoutingAlgorithm::find_metadata_by_algorithm_id_profile_id( @@ -124,7 +124,7 @@ impl RoutingAlgorithmInterface for Store { #[instrument(skip_all)] async fn list_routing_algorithm_metadata_by_profile_id( &self, - profile_id: &str, + profile_id: &common_utils::id_type::ProfileId, limit: i64, offset: i64, ) -> StorageResult> { @@ -185,7 +185,7 @@ impl RoutingAlgorithmInterface for MockDb { async fn find_routing_algorithm_by_profile_id_algorithm_id( &self, - _profile_id: &str, + _profile_id: &common_utils::id_type::ProfileId, _algorithm_id: &str, ) -> StorageResult { Err(errors::StorageError::MockDbError)? @@ -202,14 +202,14 @@ impl RoutingAlgorithmInterface for MockDb { async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id( &self, _algorithm_id: &str, - _profile_id: &str, + _profile_id: &common_utils::id_type::ProfileId, ) -> StorageResult { Err(errors::StorageError::MockDbError)? } async fn list_routing_algorithm_metadata_by_profile_id( &self, - _profile_id: &str, + _profile_id: &common_utils::id_type::ProfileId, _limit: i64, _offset: i64, ) -> StorageResult> { diff --git a/crates/router/src/db/user_role.rs b/crates/router/src/db/user_role.rs index f028437b34..524eaaaab7 100644 --- a/crates/router/src/db/user_role.rs +++ b/crates/router/src/db/user_role.rs @@ -47,7 +47,7 @@ pub trait UserRoleInterface { user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, version: enums::UserRoleVersion, ) -> CustomResult; @@ -56,7 +56,7 @@ pub trait UserRoleInterface { user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, update: storage::UserRoleUpdate, version: enums::UserRoleVersion, ) -> CustomResult; @@ -66,7 +66,7 @@ pub trait UserRoleInterface { user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, version: enums::UserRoleVersion, ) -> CustomResult; @@ -75,7 +75,7 @@ pub trait UserRoleInterface { user_id: &str, org_id: Option<&id_type::OrganizationId>, merchant_id: Option<&id_type::MerchantId>, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, entity_id: Option<&String>, version: Option, ) -> CustomResult, errors::StorageError>; @@ -155,7 +155,7 @@ impl UserRoleInterface for Store { user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, version: enums::UserRoleVersion, ) -> CustomResult { let conn = connection::pg_connection_write(self).await?; @@ -177,7 +177,7 @@ impl UserRoleInterface for Store { user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, update: storage::UserRoleUpdate, version: enums::UserRoleVersion, ) -> CustomResult { @@ -201,7 +201,7 @@ impl UserRoleInterface for Store { user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, version: enums::UserRoleVersion, ) -> CustomResult { let conn = connection::pg_connection_write(self).await?; @@ -222,7 +222,7 @@ impl UserRoleInterface for Store { user_id: &str, org_id: Option<&id_type::OrganizationId>, merchant_id: Option<&id_type::MerchantId>, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, entity_id: Option<&String>, version: Option, ) -> CustomResult, errors::StorageError> { @@ -377,7 +377,7 @@ impl UserRoleInterface for MockDb { user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, version: enums::UserRoleVersion, ) -> CustomResult { let user_roles = self.user_roles.lock().await; @@ -416,7 +416,7 @@ impl UserRoleInterface for MockDb { user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, update: storage::UserRoleUpdate, version: enums::UserRoleVersion, ) -> CustomResult { @@ -470,7 +470,7 @@ impl UserRoleInterface for MockDb { user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, version: enums::UserRoleVersion, ) -> CustomResult { let mut user_roles = self.user_roles.lock().await; @@ -510,7 +510,7 @@ impl UserRoleInterface for MockDb { user_id: &str, org_id: Option<&id_type::OrganizationId>, merchant_id: Option<&id_type::MerchantId>, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, entity_id: Option<&String>, version: Option, ) -> CustomResult, errors::StorageError> { diff --git a/crates/router/src/routes/admin.rs b/crates/router/src/routes/admin.rs index 80ee049484..343246e31a 100644 --- a/crates/router/src/routes/admin.rs +++ b/crates/router/src/routes/admin.rs @@ -946,7 +946,10 @@ pub async fn business_profile_create( pub async fn business_profile_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::ProfileId, + )>, ) -> HttpResponse { let flow = Flow::BusinessProfileRetrieve; let (merchant_id, profile_id) = path.into_inner(); @@ -975,7 +978,7 @@ pub async fn business_profile_retrieve( pub async fn business_profile_retrieve( state: web::Data, req: HttpRequest, - path: web::Path, + path: web::Path, ) -> HttpResponse { let flow = Flow::BusinessProfileRetrieve; let profile_id = path.into_inner(); @@ -1015,7 +1018,10 @@ pub async fn business_profile_retrieve( pub async fn business_profile_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::ProfileId, + )>, json_payload: web::Json, ) -> HttpResponse { let flow = Flow::BusinessProfileUpdate; @@ -1045,7 +1051,7 @@ pub async fn business_profile_update( pub async fn business_profile_update( state: web::Data, req: HttpRequest, - path: web::Path, + path: web::Path, json_payload: web::Json, ) -> HttpResponse { let flow = Flow::BusinessProfileUpdate; @@ -1081,7 +1087,10 @@ pub async fn business_profile_update( pub async fn business_profile_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::ProfileId, + )>, ) -> HttpResponse { let flow = Flow::BusinessProfileDelete; let (merchant_id, profile_id) = path.into_inner(); @@ -1129,7 +1138,10 @@ pub async fn business_profiles_list( pub async fn toggle_connector_agnostic_mit( 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::ProfileId, + )>, json_payload: web::Json, ) -> HttpResponse { let flow = Flow::ToggleConnectorAgnosticMit; @@ -1200,7 +1212,10 @@ pub async fn merchant_account_transfer_keys( pub async fn toggle_extended_card_info( 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::ProfileId, + )>, json_payload: web::Json, ) -> HttpResponse { let flow = Flow::ToggleExtendedCardInfo; diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs index 11cdf4eb7e..63c40580e5 100644 --- a/crates/router/src/routes/payments.rs +++ b/crates/router/src/routes/payments.rs @@ -1327,7 +1327,7 @@ async fn authorize_verify_select( state: app::SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, - profile_id: Option, + profile_id: Option, key_store: domain::MerchantKeyStore, header_payload: HeaderPayload, req: api_models::payments::PaymentsRequest, diff --git a/crates/router/src/routes/routing.rs b/crates/router/src/routes/routing.rs index 79e8ec11f2..61d89e5e77 100644 --- a/crates/router/src/routes/routing.rs +++ b/crates/router/src/routes/routing.rs @@ -96,7 +96,7 @@ pub async fn routing_link_config( pub async fn routing_link_config( state: web::Data, req: HttpRequest, - path: web::Path, + path: web::Path, json_payload: web::Json, transaction_type: &enums::TransactionType, ) -> impl Responder { @@ -209,7 +209,7 @@ pub async fn list_routing_configs( pub async fn routing_unlink_config( state: web::Data, req: HttpRequest, - path: web::Path, + path: web::Path, transaction_type: &enums::TransactionType, ) -> impl Responder { let flow = Flow::RoutingUnlinkConfig; @@ -290,7 +290,7 @@ pub async fn routing_unlink_config( pub async fn routing_update_default_config( state: web::Data, req: HttpRequest, - path: web::Path, + path: web::Path, json_payload: web::Json>, ) -> impl Responder { let wrapper = routing_types::ProfileDefaultRoutingConfig { @@ -372,7 +372,7 @@ pub async fn routing_update_default_config( pub async fn routing_retrieve_default_config( state: web::Data, req: HttpRequest, - path: web::Path, + path: web::Path, ) -> impl Responder { Box::pin(oss_api::server_wrap( Flow::RoutingRetrieveDefaultConfig, @@ -674,7 +674,7 @@ pub async fn routing_retrieve_linked_config( state: web::Data, req: HttpRequest, query: web::Query, - path: web::Path, + path: web::Path, transaction_type: &enums::TransactionType, ) -> impl Responder { use crate::services::authentication::AuthenticationData; @@ -753,7 +753,7 @@ pub async fn routing_retrieve_default_config_for_profiles( pub async fn routing_update_default_config_for_profile( state: web::Data, req: HttpRequest, - path: web::Path, + path: web::Path, json_payload: web::Json>, transaction_type: &enums::TransactionType, ) -> impl Responder { diff --git a/crates/router/src/services/authentication.rs b/crates/router/src/services/authentication.rs index 9ab2e2e3b0..f1de552822 100644 --- a/crates/router/src/services/authentication.rs +++ b/crates/router/src/services/authentication.rs @@ -59,14 +59,14 @@ mod detached; pub struct AuthenticationData { pub merchant_account: domain::MerchantAccount, pub key_store: domain::MerchantKeyStore, - pub profile_id: Option, + pub profile_id: Option, } #[derive(Clone, Debug)] pub struct AuthenticationDataWithMultipleProfiles { pub merchant_account: domain::MerchantAccount, pub key_store: domain::MerchantKeyStore, - pub profile_id_list: Option>, + pub profile_id_list: Option>, } #[derive(Clone, Debug, Eq, PartialEq, Serialize)] @@ -195,7 +195,7 @@ pub struct AuthToken { pub role_id: String, pub exp: u64, pub org_id: id_type::OrganizationId, - pub profile_id: Option, + pub profile_id: Option, } #[cfg(feature = "olap")] @@ -206,7 +206,7 @@ impl AuthToken { role_id: String, settings: &Settings, org_id: id_type::OrganizationId, - profile_id: Option, + profile_id: Option, ) -> UserResult { let exp_duration = std::time::Duration::from_secs(consts::JWT_TOKEN_TIME_IN_SECS); let exp = jwt::generate_exp(exp_duration)?.as_secs(); @@ -228,7 +228,7 @@ pub struct UserFromToken { pub merchant_id: id_type::MerchantId, pub role_id: String, pub org_id: id_type::OrganizationId, - pub profile_id: Option, + pub profile_id: Option, } pub struct UserIdFromAuth { diff --git a/crates/router/src/services/kafka/authentication.rs b/crates/router/src/services/kafka/authentication.rs index be3e093334..42079525d8 100644 --- a/crates/router/src/services/kafka/authentication.rs +++ b/crates/router/src/services/kafka/authentication.rs @@ -35,7 +35,7 @@ pub struct KafkaAuthentication<'a> { pub acs_reference_number: Option<&'a String>, pub acs_trans_id: Option<&'a String>, pub acs_signed_content: Option<&'a String>, - pub profile_id: &'a String, + pub profile_id: &'a common_utils::id_type::ProfileId, pub payment_id: Option<&'a String>, pub merchant_connector_id: &'a String, pub ds_trans_id: Option<&'a String>, diff --git a/crates/router/src/services/kafka/authentication_event.rs b/crates/router/src/services/kafka/authentication_event.rs index 3f10c7596a..6213488a6d 100644 --- a/crates/router/src/services/kafka/authentication_event.rs +++ b/crates/router/src/services/kafka/authentication_event.rs @@ -36,7 +36,7 @@ pub struct KafkaAuthenticationEvent<'a> { pub acs_reference_number: Option<&'a String>, pub acs_trans_id: Option<&'a String>, pub acs_signed_content: Option<&'a String>, - pub profile_id: &'a String, + pub profile_id: &'a common_utils::id_type::ProfileId, pub payment_id: Option<&'a String>, pub merchant_connector_id: &'a String, pub ds_trans_id: Option<&'a String>, diff --git a/crates/router/src/services/kafka/dispute.rs b/crates/router/src/services/kafka/dispute.rs index b4b493a79d..6f789cbe94 100644 --- a/crates/router/src/services/kafka/dispute.rs +++ b/crates/router/src/services/kafka/dispute.rs @@ -30,7 +30,7 @@ pub struct KafkaDispute<'a> { pub modified_at: OffsetDateTime, pub connector: &'a String, pub evidence: &'a Secret, - pub profile_id: Option<&'a String>, + pub profile_id: Option<&'a common_utils::id_type::ProfileId>, pub merchant_connector_id: Option<&'a String>, } diff --git a/crates/router/src/services/kafka/dispute_event.rs b/crates/router/src/services/kafka/dispute_event.rs index d6cb5d5849..e425491259 100644 --- a/crates/router/src/services/kafka/dispute_event.rs +++ b/crates/router/src/services/kafka/dispute_event.rs @@ -31,7 +31,7 @@ pub struct KafkaDisputeEvent<'a> { pub modified_at: OffsetDateTime, pub connector: &'a String, pub evidence: &'a Secret, - pub profile_id: Option<&'a String>, + pub profile_id: Option<&'a common_utils::id_type::ProfileId>, pub merchant_connector_id: Option<&'a String>, } diff --git a/crates/router/src/services/kafka/payment_intent.rs b/crates/router/src/services/kafka/payment_intent.rs index 3296956797..29aa563283 100644 --- a/crates/router/src/services/kafka/payment_intent.rs +++ b/crates/router/src/services/kafka/payment_intent.rs @@ -33,7 +33,7 @@ pub struct KafkaPaymentIntent<'a> { pub business_country: Option, pub business_label: Option<&'a String>, pub attempt_count: i16, - pub profile_id: Option<&'a String>, + pub profile_id: Option<&'a id_type::ProfileId>, pub payment_confirm_source: Option, pub billing_details: Option>>, pub shipping_details: Option>>, diff --git a/crates/router/src/services/kafka/payment_intent_event.rs b/crates/router/src/services/kafka/payment_intent_event.rs index f5186a0b2b..50d2c48a4b 100644 --- a/crates/router/src/services/kafka/payment_intent_event.rs +++ b/crates/router/src/services/kafka/payment_intent_event.rs @@ -34,7 +34,7 @@ pub struct KafkaPaymentIntentEvent<'a> { pub business_country: Option, pub business_label: Option<&'a String>, pub attempt_count: i16, - pub profile_id: Option<&'a String>, + pub profile_id: Option<&'a id_type::ProfileId>, pub payment_confirm_source: Option, pub billing_details: Option>>, pub shipping_details: Option>>, diff --git a/crates/router/src/services/kafka/payout.rs b/crates/router/src/services/kafka/payout.rs index ca89a34f18..08733c4600 100644 --- a/crates/router/src/services/kafka/payout.rs +++ b/crates/router/src/services/kafka/payout.rs @@ -10,7 +10,7 @@ pub struct KafkaPayout<'a> { pub merchant_id: &'a id_type::MerchantId, pub customer_id: Option<&'a id_type::CustomerId>, pub address_id: Option<&'a String>, - pub profile_id: &'a String, + pub profile_id: &'a id_type::ProfileId, pub payout_method_id: Option<&'a String>, pub payout_type: Option, pub amount: MinorUnit, diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rs index 912cc1c1fa..c959c59bad 100644 --- a/crates/router/src/types/api/admin.rs +++ b/crates/router/src/types/api/admin.rs @@ -250,7 +250,7 @@ pub async fn create_business_profile_from_merchant_account( use crate::core; // Generate a unique profile id - let profile_id = common_utils::generate_id_with_default_len("pro"); + let profile_id = common_utils::generate_profile_id_of_default_length(); let merchant_id = merchant_account.get_id().to_owned(); let current_time = common_utils::date_time::now(); diff --git a/crates/router/src/types/domain/event.rs b/crates/router/src/types/domain/event.rs index 872eb30390..badbb9df7b 100644 --- a/crates/router/src/types/domain/event.rs +++ b/crates/router/src/types/domain/event.rs @@ -26,7 +26,7 @@ pub struct Event { pub primary_object_type: EventObjectType, pub created_at: time::PrimitiveDateTime, pub merchant_id: Option, - pub business_profile_id: Option, + pub business_profile_id: Option, pub primary_object_created_at: Option, pub idempotent_event_id: Option, pub initial_attempt_id: Option, diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rs index ef07ab6a84..7e5f857134 100644 --- a/crates/router/src/utils.rs +++ b/crates/router/src/utils.rs @@ -467,7 +467,10 @@ pub async fn get_mca_from_payment_intent( .await .to_not_found_response( errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: format!("profile_id {profile_id} and connector_name {connector_name}"), + id: format!( + "profile_id {} and connector_name {connector_name}", + profile_id.get_string_repr() + ), }, ) } @@ -556,7 +559,8 @@ pub async fn get_mca_from_payout_attempt( errors::ApiErrorResponse::MerchantConnectorAccountNotFound { id: format!( "profile_id {} and connector_name {}", - payout.profile_id, connector_name + payout.profile_id.get_string_repr(), + connector_name ), }, ) @@ -603,7 +607,10 @@ pub async fn get_mca_from_object_reference_id( .await .to_not_found_response( errors::ApiErrorResponse::MerchantConnectorAccountNotFound { - id: format!("profile_id {profile_id} and connector_name {connector_name}"), + id: format!( + "profile_id {} and connector_name {connector_name}", + profile_id.get_string_repr() + ), }, ) } diff --git a/crates/router/src/utils/user.rs b/crates/router/src/utils/user.rs index 1de45b7436..30a0e1ca78 100644 --- a/crates/router/src/utils/user.rs +++ b/crates/router/src/utils/user.rs @@ -114,7 +114,7 @@ pub async fn generate_jwt_auth_token_with_custom_role_attributes( merchant_id: id_type::MerchantId, org_id: id_type::OrganizationId, role_id: String, - profile_id: Option, + profile_id: Option, ) -> UserResult> { let token = AuthToken::new_token( user.get_user_id().to_string(), diff --git a/crates/router/src/utils/user_role.rs b/crates/router/src/utils/user_role.rs index 7aebbe1bbc..792a79c91e 100644 --- a/crates/router/src/utils/user_role.rs +++ b/crates/router/src/utils/user_role.rs @@ -182,7 +182,7 @@ pub async fn update_v1_and_v2_user_roles_in_db( user_id: &str, org_id: &id_type::OrganizationId, merchant_id: &id_type::MerchantId, - profile_id: Option<&String>, + profile_id: Option<&id_type::ProfileId>, update: UserRoleUpdate, ) -> ( Result>, diff --git a/crates/router/src/workflows/payment_sync.rs b/crates/router/src/workflows/payment_sync.rs index c536ec7e4e..207af2ea4b 100644 --- a/crates/router/src/workflows/payment_sync.rs +++ b/crates/router/src/workflows/payment_sync.rs @@ -177,7 +177,7 @@ impl ProcessTrackerWorkflow for PaymentsSyncWorkflow { .await .to_not_found_response( errors::ApiErrorResponse::BusinessProfileNotFound { - id: profile_id.to_string(), + id: profile_id.get_string_repr().to_owned(), }, )?; diff --git a/crates/storage_impl/src/payouts/payout_attempt.rs b/crates/storage_impl/src/payouts/payout_attempt.rs index aba6f2016b..08843a060a 100644 --- a/crates/storage_impl/src/payouts/payout_attempt.rs +++ b/crates/storage_impl/src/payouts/payout_attempt.rs @@ -60,7 +60,6 @@ impl PayoutAttemptInterface for KVRouterStore { payout_attempt_id: &payout_attempt_id, }; let key_str = key.to_string(); - let now = common_utils::date_time::now(); let created_attempt = PayoutAttempt { payout_attempt_id: new_payout_attempt.payout_attempt_id.clone(), payout_id: new_payout_attempt.payout_id.clone(), @@ -76,8 +75,8 @@ impl PayoutAttemptInterface for KVRouterStore { error_code: new_payout_attempt.error_code.clone(), business_country: new_payout_attempt.business_country, business_label: new_payout_attempt.business_label.clone(), - created_at: new_payout_attempt.created_at.unwrap_or(now), - last_modified_at: new_payout_attempt.last_modified_at.unwrap_or(now), + created_at: new_payout_attempt.created_at, + last_modified_at: new_payout_attempt.last_modified_at, profile_id: new_payout_attempt.profile_id.clone(), merchant_connector_id: new_payout_attempt.merchant_connector_id.clone(), routing_info: new_payout_attempt.routing_info.clone(), diff --git a/crates/storage_impl/src/payouts/payouts.rs b/crates/storage_impl/src/payouts/payouts.rs index aee21771db..320aee2006 100644 --- a/crates/storage_impl/src/payouts/payouts.rs +++ b/crates/storage_impl/src/payouts/payouts.rs @@ -91,7 +91,6 @@ impl PayoutsInterface for KVRouterStore { }; let key_str = key.to_string(); let field = format!("po_{}", new.payout_id); - let now = common_utils::date_time::now(); let created_payout = Payouts { payout_id: new.payout_id.clone(), merchant_id: new.merchant_id.clone(), @@ -108,8 +107,8 @@ impl PayoutsInterface for KVRouterStore { return_url: new.return_url.clone(), entity_type: new.entity_type, metadata: new.metadata.clone(), - created_at: new.created_at.unwrap_or(now), - last_modified_at: new.last_modified_at.unwrap_or(now), + created_at: new.created_at, + last_modified_at: new.last_modified_at, profile_id: new.profile_id.clone(), status: new.status, attempt_count: new.attempt_count, @@ -936,10 +935,8 @@ impl DataModelExt for PayoutsNew { return_url: self.return_url, entity_type: self.entity_type, metadata: self.metadata, - created_at: self.created_at.unwrap_or_else(common_utils::date_time::now), - last_modified_at: self - .last_modified_at - .unwrap_or_else(common_utils::date_time::now), + created_at: self.created_at, + last_modified_at: self.last_modified_at, profile_id: self.profile_id, status: self.status, attempt_count: self.attempt_count, @@ -967,8 +964,8 @@ impl DataModelExt for PayoutsNew { return_url: storage_model.return_url, entity_type: storage_model.entity_type, metadata: storage_model.metadata, - created_at: Some(storage_model.created_at), - last_modified_at: Some(storage_model.last_modified_at), + created_at: storage_model.created_at, + last_modified_at: storage_model.last_modified_at, profile_id: storage_model.profile_id, status: storage_model.status, attempt_count: storage_model.attempt_count, diff --git a/scripts/ci-checks-v2.sh b/scripts/ci-checks-v2.sh index 151e5a382d..93bd2921a3 100755 --- a/scripts/ci-checks-v2.sh +++ b/scripts/ci-checks-v2.sh @@ -1,8 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -crates_to_check=\ -'api_models +crates_to_check='api_models diesel_models hyperswitch_domain_models storage_impl' @@ -38,7 +37,7 @@ if [[ "${GITHUB_EVENT_NAME:-}" == 'pull_request' ]]; then # A package must be checked if it has been modified if grep --quiet --extended-regexp "^crates/${package_name}" <<< "${files_modified}"; then if [[ "${package_name}" == "storage_impl" ]]; then - all_commands+=("cargo hack clippy --features 'v2,payment_v2,customer_v2,payment_methods_v2' -p storage_impl") + all_commands+=("cargo hack clippy --features 'v2,payment_v2,customer_v2' -p storage_impl") else valid_features="$(features_to_run "$package_name")" all_commands+=("cargo hack clippy --feature-powerset --depth 2 --ignore-unknown-features --at-least-one-of 'v2 ' --include-features '${valid_features}' --package '${package_name}'") @@ -54,7 +53,7 @@ if [[ "${GITHUB_EVENT_NAME:-}" == 'pull_request' ]]; then else # If we are doing this locally or on merge queue, then check for all the V2 crates - all_commands+=("cargo hack clippy --features 'v2,payment_v2' -p storage_impl") + all_commands+=("cargo hack clippy --features 'v2,payment_v2,customer_v2' -p storage_impl") common_command="cargo hack clippy --feature-powerset --depth 2 --ignore-unknown-features --at-least-one-of 'v2 '" while IFS= read -r crate; do if [[ "${crate}" != "storage_impl" ]]; then