Skip to content

Commit

Permalink
refactor(router): add domain type for merchant_connector_account id (#…
Browse files Browse the repository at this point in the history
…5685)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sanchith Hegde <sanchith.hegde@juspay.in>
  • Loading branch information
3 people authored Aug 28, 2024
1 parent f33e1bb commit 771f48c
Show file tree
Hide file tree
Showing 69 changed files with 388 additions and 271 deletions.
6 changes: 0 additions & 6 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -8537,12 +8537,6 @@
"example": "\n[{\"gateway\":\"stripe\",\"payment_methods\":[{\"payment_method\":\"card\",\"payment_method_types\":[{\"payment_method_type\":\"credit\",\"card_networks\":[\"Visa\"],\"flow\":\"pre\",\"action\":\"cancel_txn\"},{\"payment_method_type\":\"debit\",\"card_networks\":[\"Visa\"],\"flow\":\"pre\"}]}]}]\n",
"nullable": true
},
"merchant_connector_id": {
"type": "string",
"description": "Unique ID of the connector",
"example": "mca_5apGeP94tMts6rg3U3kR",
"nullable": true
},
"pm_auth_config": {
"type": "object",
"description": "pm_auth_config will relate MCA records to their respective chosen auth services, based on payment_method and pmt",
Expand Down
50 changes: 26 additions & 24 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,16 +670,18 @@ pub struct MerchantId {
any(feature = "v1", feature = "v2"),
not(feature = "merchant_connector_account_v2")
))]
#[derive(Default, Debug, Deserialize, ToSchema, Serialize)]
#[derive(Debug, Deserialize, ToSchema, Serialize)]
pub struct MerchantConnectorId {
#[schema(value_type = String)]
pub merchant_id: id_type::MerchantId,
pub merchant_connector_id: String,
#[schema(value_type = String)]
pub merchant_connector_id: id_type::MerchantConnectorAccountId,
}
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
#[derive(Default, Debug, Deserialize, ToSchema, Serialize)]
#[derive(Debug, Deserialize, ToSchema, Serialize)]
pub struct MerchantConnectorId {
pub id: String,
#[schema(value_type = String)]
pub id: id_type::MerchantConnectorAccountId,
}

#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
Expand Down Expand Up @@ -757,10 +759,6 @@ pub struct MerchantConnectorCreate {
#[schema(example = json!(consts::FRM_CONFIGS_EG))]
pub frm_configs: Option<Vec<FrmConfigs>>,

/// Unique ID of the connector
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
pub merchant_connector_id: Option<String>,

/// pm_auth_config will relate MCA records to their respective chosen auth services, based on payment_method and pmt
#[schema(value_type = Option<Object>)]
pub pm_auth_config: Option<pii::SecretSerdeValue>,
Expand Down Expand Up @@ -904,8 +902,8 @@ pub struct MerchantConnectorCreate {
pub business_sub_label: Option<String>,

/// Unique ID of the connector
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
pub merchant_connector_id: Option<String>,
#[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = Option<String>)]
pub merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,

#[schema(value_type = Option<Object>)]
pub pm_auth_config: Option<pii::SecretSerdeValue>,
Expand Down Expand Up @@ -1031,11 +1029,15 @@ pub struct MerchantConnectorWebhookDetails {
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, ToSchema)]
pub struct MerchantConnectorInfo {
pub connector_label: String,
pub merchant_connector_id: String,
#[schema(value_type = String)]
pub merchant_connector_id: id_type::MerchantConnectorAccountId,
}

impl MerchantConnectorInfo {
pub fn new(connector_label: String, merchant_connector_id: String) -> Self {
pub fn new(
connector_label: String,
merchant_connector_id: id_type::MerchantConnectorAccountId,
) -> Self {
Self {
connector_label,
merchant_connector_id,
Expand All @@ -1060,8 +1062,8 @@ pub struct MerchantConnectorResponse {
pub connector_label: Option<String>,

/// Unique ID of the merchant connector account
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
pub id: String,
#[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)]
pub id: id_type::MerchantConnectorAccountId,

/// Identifier for the business profile, if not provided default will be chosen from merchant account
#[schema(max_length = 64, value_type = String)]
Expand Down Expand Up @@ -1167,8 +1169,8 @@ pub struct MerchantConnectorResponse {
pub connector_label: Option<String>,

/// Unique ID of the merchant connector account
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
pub merchant_connector_id: String,
#[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)]
pub merchant_connector_id: id_type::MerchantConnectorAccountId,

/// Identifier for the business profile, if not provided default will be chosen from merchant account
#[schema(max_length = 64, value_type = String)]
Expand Down Expand Up @@ -1291,8 +1293,8 @@ pub struct MerchantConnectorListResponse {
pub connector_label: Option<String>,

/// Unique ID of the merchant connector account
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
pub merchant_connector_id: String,
#[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)]
pub merchant_connector_id: id_type::MerchantConnectorAccountId,

/// Identifier for the business profile, if not provided default will be chosen from merchant account
#[schema(max_length = 64, value_type = String)]
Expand Down Expand Up @@ -1400,8 +1402,8 @@ pub struct MerchantConnectorListResponse {
pub connector_label: Option<String>,

/// Unique ID of the merchant connector account
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
pub id: String,
#[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)]
pub id: id_type::MerchantConnectorAccountId,

/// Identifier for the business profile, if not provided default will be chosen from merchant account
#[schema(max_length = 64, value_type = String)]
Expand Down Expand Up @@ -1760,8 +1762,8 @@ pub struct MerchantConnectorDeleteResponse {
#[schema(max_length = 255, example = "y3oqhf46pyzuxjbcn2giaqnb44", value_type = String)]
pub merchant_id: id_type::MerchantId,
/// Unique ID of the connector
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
pub merchant_connector_id: String,
#[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)]
pub merchant_connector_id: id_type::MerchantConnectorAccountId,
/// If the connector is deleted or not
#[schema(example = false)]
pub deleted: bool,
Expand All @@ -1774,8 +1776,8 @@ pub struct MerchantConnectorDeleteResponse {
#[schema(max_length = 255, example = "y3oqhf46pyzuxjbcn2giaqnb44", value_type = String)]
pub merchant_id: id_type::MerchantId,
/// Unique ID of the connector
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
pub id: String,
#[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)]
pub id: id_type::MerchantConnectorAccountId,
/// If the connector is deleted or not
#[schema(example = false)]
pub deleted: bool,
Expand Down
12 changes: 7 additions & 5 deletions crates/api_models/src/connector_onboarding.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use common_utils::id_type;

use super::{admin, enums};

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
pub struct ActionUrlRequest {
pub connector: enums::Connector,
pub connector_id: String,
pub connector_id: id_type::MerchantConnectorAccountId,
pub return_url: String,
}

Expand All @@ -15,8 +17,8 @@ pub enum ActionUrlResponse {

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
pub struct OnboardingSyncRequest {
pub profile_id: common_utils::id_type::ProfileId,
pub connector_id: String,
pub profile_id: id_type::ProfileId,
pub connector_id: id_type::MerchantConnectorAccountId,
pub connector: enums::Connector,
}

Expand Down Expand Up @@ -45,7 +47,7 @@ pub enum PayPalOnboardingStatus {

#[derive(serde::Serialize, Debug, Clone)]
pub struct PayPalOnboardingDone {
pub payer_id: common_utils::id_type::MerchantId,
pub payer_id: id_type::MerchantId,
}

#[derive(serde::Serialize, Debug, Clone)]
Expand All @@ -55,6 +57,6 @@ pub struct PayPalIntegrationDone {

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
pub struct ResetTrackingIdRequest {
pub connector_id: String,
pub connector_id: id_type::MerchantConnectorAccountId,
pub connector: enums::Connector,
}
3 changes: 2 additions & 1 deletion crates/api_models/src/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ pub struct DisputeResponse {
#[schema(value_type = Option<String>)]
pub profile_id: Option<common_utils::id_type::ProfileId>,
/// The `merchant_connector_id` of the connector / processor through which the dispute was processed
pub merchant_connector_id: Option<String>,
#[schema(value_type = Option<String>)]
pub merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
}

#[derive(Clone, Debug, Serialize, ToSchema, Eq, PartialEq)]
Expand Down
3 changes: 2 additions & 1 deletion crates/api_models/src/mandates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,6 @@ pub struct ProcessorPaymentToken {
pub processor_payment_token: String,
#[schema(value_type = Connector, example = "stripe")]
pub connector: api_enums::Connector,
pub merchant_connector_id: String,
#[schema(value_type = String)]
pub merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
}
8 changes: 5 additions & 3 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ pub struct PaymentMethodMigrate {
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PaymentsMandateReference(pub HashMap<String, PaymentsMandateReferenceRecord>);
pub struct PaymentsMandateReference(
pub HashMap<id_type::MerchantConnectorAccountId, PaymentsMandateReferenceRecord>,
);

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PaymentsMandateReferenceRecord {
Expand Down Expand Up @@ -733,7 +735,7 @@ pub struct BankAccountTokenData {
pub struct BankAccountConnectorDetails {
pub connector: String,
pub account_id: masking::Secret<String>,
pub mca_id: String,
pub mca_id: id_type::MerchantConnectorAccountId,
pub access_token: BankAccountAccessCreds,
}

Expand Down Expand Up @@ -1983,7 +1985,7 @@ pub struct PaymentMethodRecord {
pub billing_address_line2: Option<masking::Secret<String>>,
pub billing_address_line3: Option<masking::Secret<String>>,
pub raw_card_number: Option<masking::Secret<String>>,
pub merchant_connector_id: String,
pub merchant_connector_id: id_type::MerchantConnectorAccountId,
pub original_transaction_amount: Option<i64>,
pub original_transaction_currency: Option<common_enums::Currency>,
pub line_number: Option<i64>,
Expand Down
5 changes: 3 additions & 2 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3829,7 +3829,8 @@ pub struct PaymentsResponse {
pub merchant_decision: Option<String>,

/// Identifier of the connector ( merchant connector account ) which was chosen to make the payment
pub merchant_connector_id: Option<String>,
#[schema(value_type = Option<String>)]
pub merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,

/// If true, incremental authorization can be performed on this payment, in case the funds authorized initially fall short.
pub incremental_authorization_allowed: Option<bool>,
Expand Down Expand Up @@ -4059,7 +4060,7 @@ pub struct PaymentListFilterConstraints {
/// The list of authentication types to filter payments list
pub authentication_type: Option<Vec<enums::AuthenticationType>>,
/// The list of merchant connector ids to filter payments list for selected label
pub merchant_connector_id: Option<Vec<String>>,
pub merchant_connector_id: Option<Vec<id_type::MerchantConnectorAccountId>>,
/// The order in which payments list should be sorted
#[serde(default)]
pub order: Order,
Expand Down
2 changes: 1 addition & 1 deletion crates/api_models/src/payouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ pub struct PayoutCreateResponse {

/// Unique identifier of the merchant connector account
#[schema(value_type = Option<String>, example = "mca_sAD3OZLATetvjLOYhUSy")]
pub merchant_connector_id: Option<String>,
pub merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,

/// Current status of the Payout
#[schema(value_type = PayoutStatus, example = RequiresConfirmation)]
Expand Down
4 changes: 2 additions & 2 deletions crates/api_models/src/pm_auth.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use common_enums::{PaymentMethod, PaymentMethodType};
use common_utils::{
events::{ApiEventMetric, ApiEventsType},
impl_api_event_type,
id_type, impl_api_event_type,
};

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -46,7 +46,7 @@ pub struct PaymentMethodAuthConnectorChoice {
pub payment_method: PaymentMethod,
pub payment_method_type: PaymentMethodType,
pub connector_name: String,
pub mca_id: String,
pub mca_id: id_type::MerchantConnectorAccountId,
}

impl_api_event_type!(
Expand Down
6 changes: 4 additions & 2 deletions crates/api_models/src/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ pub struct RefundResponse {
#[schema(value_type = Option<String>)]
pub profile_id: Option<common_utils::id_type::ProfileId>,
/// The merchant_connector_id of the processor through which this payment went through
pub merchant_connector_id: Option<String>,
#[schema(value_type = Option<String>)]
pub merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
/// Charge specific fields for controlling the revert of funds from either platform or connected account
#[schema(value_type = Option<ChargeRefunds>)]
pub charges: Option<ChargeRefunds>,
Expand All @@ -186,7 +187,8 @@ pub struct RefundListRequest {
/// The list of connectors to filter refunds list
pub connector: Option<Vec<String>>,
/// The list of merchant connector ids to filter the refunds list for selected label
pub merchant_connector_id: Option<Vec<String>>,
#[schema(value_type = Option<Vec<String>>)]
pub merchant_connector_id: Option<Vec<common_utils::id_type::MerchantConnectorAccountId>>,
/// The list of currencies to filter refunds list
#[schema(value_type = Option<Vec<Currency>>)]
pub currency: Option<Vec<enums::Currency>>,
Expand Down
5 changes: 3 additions & 2 deletions crates/api_models/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ pub struct RoutableConnectorChoice {
#[serde(skip)]
pub choice_kind: RoutableChoiceKind,
pub connector: RoutableConnectors,
pub merchant_connector_id: Option<String>,
#[schema(value_type = Option<String>)]
pub merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
}

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
Expand All @@ -188,7 +189,7 @@ pub enum RoutableChoiceSerde {
OnlyConnector(Box<RoutableConnectors>),
FullStruct {
connector: RoutableConnectors,
merchant_connector_id: Option<String>,
merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
},
}

Expand Down
4 changes: 2 additions & 2 deletions crates/api_models/src/user/dashboard_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use common_enums::CountryAlpha2;
use common_utils::pii;
use common_utils::{id_type, pii};
use masking::Secret;
use strum::EnumString;

Expand Down Expand Up @@ -43,7 +43,7 @@ pub struct SetupProcessor {

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct ProcessorConnected {
pub processor_id: String,
pub processor_id: id_type::MerchantConnectorAccountId,
pub processor_name: String,
}

Expand Down
8 changes: 5 additions & 3 deletions crates/api_models/src/verifications.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use common_utils::id_type;

/// The request body for verification of merchant (everything except domain_names are prefilled)
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -13,7 +15,7 @@ pub struct ApplepayMerchantVerificationConfigs {
#[serde(rename_all = "snake_case")]
pub struct ApplepayMerchantVerificationRequest {
pub domain_names: Vec<String>,
pub merchant_connector_account_id: String,
pub merchant_connector_account_id: id_type::MerchantConnectorAccountId,
}

/// Response to be sent for the verify/applepay api
Expand All @@ -27,8 +29,8 @@ pub struct ApplepayMerchantResponse {
#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct ApplepayGetVerifiedDomainsParam {
pub merchant_id: common_utils::id_type::MerchantId,
pub merchant_connector_account_id: String,
pub merchant_id: id_type::MerchantId,
pub merchant_connector_account_id: id_type::MerchantConnectorAccountId,
}
/// Response to be sent for derivation of the already verified domains
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions crates/common_utils/src/id_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{borrow::Cow, fmt::Debug};

mod customer;
mod merchant;
mod merchant_connector_account;
mod organization;
mod profile;

Expand All @@ -19,6 +20,7 @@ use diesel::{
sql_types,
};
pub use merchant::MerchantId;
pub use merchant_connector_account::MerchantConnectorAccountId;
pub use organization::OrganizationId;
pub use profile::ProfileId;
use serde::{Deserialize, Serialize};
Expand Down
23 changes: 23 additions & 0 deletions crates/common_utils/src/id_type/merchant_connector_account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::errors::{CustomResult, ValidationError};

crate::id_type!(
MerchantConnectorAccountId,
"A type for merchant_connector_id that can be used for merchant_connector_account ids"
);
crate::impl_id_type_methods!(MerchantConnectorAccountId, "merchant_connector_id");

// This is to display the `MerchantConnectorAccountId` as MerchantConnectorAccountId(abcd)
crate::impl_debug_id_type!(MerchantConnectorAccountId);
crate::impl_generate_id_id_type!(MerchantConnectorAccountId, "mca");
crate::impl_try_from_cow_str_id_type!(MerchantConnectorAccountId, "merchant_connector_id");

crate::impl_serializable_secret_id_type!(MerchantConnectorAccountId);
crate::impl_queryable_id_type!(MerchantConnectorAccountId);
crate::impl_to_sql_from_sql_id_type!(MerchantConnectorAccountId);

impl MerchantConnectorAccountId {
/// Get a merchant connector account id from String
pub fn wrap(merchant_connector_account_id: String) -> CustomResult<Self, ValidationError> {
Self::try_from(std::borrow::Cow::from(merchant_connector_account_id))
}
}
Loading

0 comments on commit 771f48c

Please sign in to comment.