Skip to content

Commit 5b29c25

Browse files
refactor(core): use profile id to find connector (#2020)
1 parent 60c5fdb commit 5b29c25

File tree

37 files changed

+776
-363
lines changed

37 files changed

+776
-363
lines changed

crates/api_models/src/admin.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl From<StraightThroughAlgorithm> for StraightThroughAlgorithmSerde {
488488
}
489489
}
490490

491-
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
491+
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize, PartialEq)]
492492
#[serde(deny_unknown_fields)]
493493
pub struct PrimaryBusinessDetails {
494494
#[schema(value_type = CountryAlpha2)]
@@ -615,10 +615,10 @@ pub struct MerchantConnectorCreate {
615615
#[schema(example = json!(common_utils::consts::FRM_CONFIGS_EG))]
616616
pub frm_configs: Option<Vec<FrmConfigs>>,
617617

618-
#[schema(value_type = CountryAlpha2, example = "US")]
619-
pub business_country: api_enums::CountryAlpha2,
618+
#[schema(value_type = Option<CountryAlpha2>, example = "US")]
619+
pub business_country: Option<api_enums::CountryAlpha2>,
620620

621-
pub business_label: String,
621+
pub business_label: Option<String>,
622622

623623
/// Business Sub label of the merchant
624624
#[schema(example = "chase")]
@@ -658,7 +658,7 @@ pub struct MerchantConnectorResponse {
658658
// /// Connector label for specific country and Business
659659
#[serde(skip_deserializing)]
660660
#[schema(example = "stripe_US_travel")]
661-
pub connector_label: String,
661+
pub connector_label: Option<String>,
662662

663663
/// Unique ID of the connector
664664
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
@@ -708,12 +708,12 @@ pub struct MerchantConnectorResponse {
708708
pub metadata: Option<pii::SecretSerdeValue>,
709709

710710
/// Business Country of the connector
711-
#[schema(value_type = CountryAlpha2, example = "US")]
712-
pub business_country: api_enums::CountryAlpha2,
711+
#[schema(value_type = Option<CountryAlpha2>, example = "US")]
712+
pub business_country: Option<api_enums::CountryAlpha2>,
713713

714714
///Business Type of the merchant
715715
#[schema(example = "travel")]
716-
pub business_label: String,
716+
pub business_label: Option<String>,
717717

718718
/// Business Sub label of the merchant
719719
#[schema(example = "chase")]

crates/api_models/src/payments.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,11 +1866,11 @@ pub struct PaymentsResponse {
18661866
pub connector_label: Option<String>,
18671867

18681868
/// The business country of merchant for this payment
1869-
#[schema(value_type = CountryAlpha2, example = "US")]
1870-
pub business_country: api_enums::CountryAlpha2,
1869+
#[schema(value_type = Option<CountryAlpha2>, example = "US")]
1870+
pub business_country: Option<api_enums::CountryAlpha2>,
18711871

18721872
/// The business label of merchant for this payment
1873-
pub business_label: String,
1873+
pub business_label: Option<String>,
18741874

18751875
/// The business_sub_label for this payment
18761876
pub business_sub_label: Option<String>,

crates/data_models/src/payments/payment_intent.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ pub struct PaymentIntent {
9393
pub off_session: Option<bool>,
9494
pub client_secret: Option<String>,
9595
pub active_attempt_id: String,
96-
pub business_country: storage_enums::CountryAlpha2,
97-
pub business_label: String,
96+
pub business_country: Option<storage_enums::CountryAlpha2>,
97+
pub business_label: Option<String>,
9898
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
9999
pub allowed_payment_method_types: Option<serde_json::Value>,
100100
pub connector_metadata: Option<serde_json::Value>,
@@ -134,8 +134,8 @@ pub struct PaymentIntentNew {
134134
pub off_session: Option<bool>,
135135
pub client_secret: Option<String>,
136136
pub active_attempt_id: String,
137-
pub business_country: storage_enums::CountryAlpha2,
138-
pub business_label: String,
137+
pub business_country: Option<storage_enums::CountryAlpha2>,
138+
pub business_label: Option<String>,
139139
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
140140
pub allowed_payment_method_types: Option<serde_json::Value>,
141141
pub connector_metadata: Option<serde_json::Value>,

crates/diesel_models/src/file.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct FileMetadataNew {
1717
pub file_upload_provider: Option<common_enums::FileUploadProvider>,
1818
pub available: bool,
1919
pub connector_label: Option<String>,
20+
pub profile_id: Option<String>,
2021
}
2122

2223
#[derive(Clone, Debug, Deserialize, Serialize, Identifiable, Queryable)]
@@ -34,6 +35,7 @@ pub struct FileMetadata {
3435
#[serde(with = "custom_serde::iso8601")]
3536
pub created_at: time::PrimitiveDateTime,
3637
pub connector_label: Option<String>,
38+
pub profile_id: Option<String>,
3739
}
3840

3941
#[derive(Debug)]

crates/diesel_models/src/merchant_connector_account.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ pub struct MerchantConnectorAccount {
2828
pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
2929
pub connector_type: storage_enums::ConnectorType,
3030
pub metadata: Option<pii::SecretSerdeValue>,
31-
pub connector_label: String,
32-
pub business_country: storage_enums::CountryAlpha2,
33-
pub business_label: String,
31+
pub connector_label: Option<String>,
32+
pub business_country: Option<storage_enums::CountryAlpha2>,
33+
pub business_label: Option<String>,
3434
pub business_sub_label: Option<String>,
3535
pub frm_configs: Option<Secret<serde_json::Value>>,
3636
pub created_at: time::PrimitiveDateTime,
@@ -53,9 +53,9 @@ pub struct MerchantConnectorAccountNew {
5353
pub merchant_connector_id: String,
5454
pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
5555
pub metadata: Option<pii::SecretSerdeValue>,
56-
pub connector_label: String,
57-
pub business_country: storage_enums::CountryAlpha2,
58-
pub business_label: String,
56+
pub connector_label: Option<String>,
57+
pub business_country: Option<storage_enums::CountryAlpha2>,
58+
pub business_label: Option<String>,
5959
pub business_sub_label: Option<String>,
6060
pub frm_configs: Option<Secret<serde_json::Value>>,
6161
pub created_at: time::PrimitiveDateTime,

crates/diesel_models/src/payment_intent.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ pub struct PaymentIntent {
3434
pub off_session: Option<bool>,
3535
pub client_secret: Option<String>,
3636
pub active_attempt_id: String,
37-
pub business_country: storage_enums::CountryAlpha2,
38-
pub business_label: String,
37+
pub business_country: Option<storage_enums::CountryAlpha2>,
38+
pub business_label: Option<String>,
3939
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
4040
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
4141
pub allowed_payment_method_types: Option<serde_json::Value>,
@@ -87,8 +87,8 @@ pub struct PaymentIntentNew {
8787
pub off_session: Option<bool>,
8888
pub client_secret: Option<String>,
8989
pub active_attempt_id: String,
90-
pub business_country: storage_enums::CountryAlpha2,
91-
pub business_label: String,
90+
pub business_country: Option<storage_enums::CountryAlpha2>,
91+
pub business_label: Option<String>,
9292
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
9393
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
9494
pub allowed_payment_method_types: Option<serde_json::Value>,
@@ -186,6 +186,7 @@ pub struct PaymentIntentUpdateInternal {
186186
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
187187
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
188188
pub attempt_count: Option<i16>,
189+
pub profile_id: Option<String>,
189190
merchant_decision: Option<String>,
190191
payment_confirm_source: Option<storage_enums::PaymentSource>,
191192
}

crates/diesel_models/src/query/business_profile.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ impl BusinessProfile {
4747
.await
4848
}
4949

50+
#[instrument(skip(conn))]
51+
pub async fn find_by_profile_name_merchant_id(
52+
conn: &PgPooledConn,
53+
profile_name: &str,
54+
merchant_id: &str,
55+
) -> StorageResult<Self> {
56+
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
57+
conn,
58+
dsl::profile_name
59+
.eq(profile_name.to_owned())
60+
.and(dsl::merchant_id.eq(merchant_id.to_owned())),
61+
)
62+
.await
63+
}
64+
5065
pub async fn list_business_profile_by_merchant_id(
5166
conn: &PgPooledConn,
5267
merchant_id: &str,

crates/diesel_models/src/query/merchant_connector_account.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ impl MerchantConnectorAccount {
7070
.await
7171
}
7272

73+
#[instrument(skip(conn))]
74+
pub async fn find_by_profile_id_connector_name(
75+
conn: &PgPooledConn,
76+
profile_id: &str,
77+
connector_name: &str,
78+
) -> StorageResult<Self> {
79+
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
80+
conn,
81+
dsl::profile_id
82+
.eq(profile_id.to_owned())
83+
.and(dsl::connector_name.eq(connector_name.to_owned())),
84+
)
85+
.await
86+
}
87+
7388
#[instrument(skip(conn))]
7489
pub async fn find_by_merchant_id_connector_name(
7590
conn: &PgPooledConn,

crates/diesel_models/src/schema.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ diesel::table! {
282282
created_at -> Timestamp,
283283
#[max_length = 255]
284284
connector_label -> Nullable<Varchar>,
285+
#[max_length = 64]
286+
profile_id -> Nullable<Varchar>,
285287
}
286288
}
287289

@@ -455,10 +457,10 @@ diesel::table! {
455457
connector_type -> ConnectorType,
456458
metadata -> Nullable<Jsonb>,
457459
#[max_length = 255]
458-
connector_label -> Varchar,
459-
business_country -> CountryAlpha2,
460+
connector_label -> Nullable<Varchar>,
461+
business_country -> Nullable<CountryAlpha2>,
460462
#[max_length = 255]
461-
business_label -> Varchar,
463+
business_label -> Nullable<Varchar>,
462464
#[max_length = 64]
463465
business_sub_label -> Nullable<Varchar>,
464466
frm_configs -> Nullable<Jsonb>,
@@ -585,9 +587,9 @@ diesel::table! {
585587
client_secret -> Nullable<Varchar>,
586588
#[max_length = 64]
587589
active_attempt_id -> Varchar,
588-
business_country -> CountryAlpha2,
590+
business_country -> Nullable<CountryAlpha2>,
589591
#[max_length = 64]
590-
business_label -> Varchar,
592+
business_label -> Nullable<Varchar>,
591593
order_details -> Nullable<Array<Nullable<Jsonb>>>,
592594
allowed_payment_method_types -> Nullable<Json>,
593595
connector_metadata -> Nullable<Json>,

crates/router/src/compatibility/stripe/errors.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ pub enum StripeErrorCode {
124124
#[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "duplicate merchant account")]
125125
DuplicateMerchantAccount,
126126

127-
#[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "The merchant connector account with the specified connector_label '{connector_label}' already exists in our records")]
128-
DuplicateMerchantConnectorAccount { connector_label: String },
127+
#[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "The merchant connector account with the specified profile_id '{profile_id}' and connector_name '{connector_name}' already exists in our records")]
128+
DuplicateMerchantConnectorAccount {
129+
profile_id: String,
130+
connector_name: String,
131+
},
129132

130133
#[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "duplicate payment method")]
131134
DuplicatePaymentMethod,
@@ -391,7 +394,7 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
391394
errors::ApiErrorResponse::Unauthorized
392395
| errors::ApiErrorResponse::InvalidJwtToken
393396
| errors::ApiErrorResponse::GenericUnauthorized { .. }
394-
| errors::ApiErrorResponse::AccessForbidden
397+
| errors::ApiErrorResponse::AccessForbidden { .. }
395398
| errors::ApiErrorResponse::InvalidEphemeralKey => Self::Unauthorized,
396399
errors::ApiErrorResponse::InvalidRequestUrl
397400
| errors::ApiErrorResponse::InvalidHttpMethod
@@ -495,9 +498,13 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
495498
}
496499
errors::ApiErrorResponse::ReturnUrlUnavailable => Self::ReturnUrlUnavailable,
497500
errors::ApiErrorResponse::DuplicateMerchantAccount => Self::DuplicateMerchantAccount,
498-
errors::ApiErrorResponse::DuplicateMerchantConnectorAccount { connector_label } => {
499-
Self::DuplicateMerchantConnectorAccount { connector_label }
500-
}
501+
errors::ApiErrorResponse::DuplicateMerchantConnectorAccount {
502+
profile_id,
503+
connector_name,
504+
} => Self::DuplicateMerchantConnectorAccount {
505+
profile_id,
506+
connector_name,
507+
},
501508
errors::ApiErrorResponse::DuplicatePaymentMethod => Self::DuplicatePaymentMethod,
502509
errors::ApiErrorResponse::ClientSecretInvalid => Self::PaymentIntentInvalidParameter {
503510
param: "client_secret".to_owned(),

0 commit comments

Comments
 (0)