Skip to content

Commit 073310c

Browse files
refactor(merchant_connector_account): change unique constraint to connector label (#3091)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent f123479 commit 073310c

File tree

17 files changed

+381
-23
lines changed

17 files changed

+381
-23
lines changed

crates/api_models/src/admin.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,16 @@ pub struct MerchantAccountCreate {
7171
/// Refers to the hash key used for calculating the signature for webhooks and redirect response. If the value is not provided, a default value is used.
7272
pub payment_response_hash_key: Option<String>,
7373

74-
/// A boolean value to indicate if redirect to merchant with http post needs to be enabled
74+
/// A boolean value to indicate if redirect to merchant with http post needs to be enabled.
7575
#[schema(default = false, example = true)]
7676
pub redirect_to_merchant_with_http_post: Option<bool>,
7777

7878
/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
7979
#[schema(value_type = Option<Object>, example = r#"{ "city": "NY", "unit": "245" }"#)]
8080
pub metadata: Option<MerchantAccountMetadata>,
8181

82-
/// API key that will be used for server side API access
82+
/// API key that will be used for client side API access. A publishable key has to be always paired with a `client_secret`.
83+
/// A `client_secret` can be obtained by creating a payment with `confirm` set to false
8384
#[schema(example = "AH3423bkjbkjdsfbkj")]
8485
pub publishable_key: Option<String>,
8586

@@ -195,7 +196,7 @@ pub struct MerchantAccountResponse {
195196
#[schema(value_type = Option<String>,example = "NewAge Retailer")]
196197
pub merchant_name: OptionalEncryptableName,
197198

198-
/// The URL to redirect after the completion of the operation
199+
/// The URL to redirect after completion of the payment
199200
#[schema(max_length = 255, example = "https://www.example.com/success")]
200201
pub return_url: Option<String>,
201202

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ pub enum StripeErrorCode {
129129
#[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "duplicate merchant account")]
130130
DuplicateMerchantAccount,
131131

132-
#[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")]
132+
#[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "The merchant connector account with the specified profile_id '{profile_id}' and connector_label '{connector_label}' already exists in our records")]
133133
DuplicateMerchantConnectorAccount {
134134
profile_id: String,
135-
connector_name: String,
135+
connector_label: String,
136136
},
137137

138138
#[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "duplicate payment method")]
@@ -523,10 +523,10 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
523523
errors::ApiErrorResponse::DuplicateMerchantAccount => Self::DuplicateMerchantAccount,
524524
errors::ApiErrorResponse::DuplicateMerchantConnectorAccount {
525525
profile_id,
526-
connector_name,
526+
connector_label,
527527
} => Self::DuplicateMerchantConnectorAccount {
528528
profile_id,
529-
connector_name,
529+
connector_label,
530530
},
531531
errors::ApiErrorResponse::DuplicatePaymentMethod => Self::DuplicatePaymentMethod,
532532
errors::ApiErrorResponse::PaymentBlockedError {

crates/router/src/core/admin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ pub async fn create_payment_connector(
923923
disabled,
924924
metadata: req.metadata,
925925
frm_configs,
926-
connector_label: Some(connector_label),
926+
connector_label: Some(connector_label.clone()),
927927
business_country: req.business_country,
928928
business_label: req.business_label.clone(),
929929
business_sub_label: req.business_sub_label.clone(),
@@ -960,7 +960,7 @@ pub async fn create_payment_connector(
960960
.to_duplicate_response(
961961
errors::ApiErrorResponse::DuplicateMerchantConnectorAccount {
962962
profile_id: profile_id.clone(),
963-
connector_name: req.connector_name.to_string(),
963+
connector_label,
964964
},
965965
)?;
966966

@@ -1277,7 +1277,7 @@ pub async fn update_payment_connector(
12771277
.change_context(
12781278
errors::ApiErrorResponse::DuplicateMerchantConnectorAccount {
12791279
profile_id,
1280-
connector_name: request_connector_label.unwrap_or_default(),
1280+
connector_label: request_connector_label.unwrap_or_default(),
12811281
},
12821282
)
12831283
.attach_printable_lazy(|| {

crates/router/src/core/errors/api_error_response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ pub enum ApiErrorResponse {
133133
DuplicateMandate,
134134
#[error(error_type = ErrorType::DuplicateRequest, code = "HE_01", message = "The merchant account with the specified details already exists in our records")]
135135
DuplicateMerchantAccount,
136-
#[error(error_type = ErrorType::DuplicateRequest, code = "HE_01", message = "The merchant connector account with the specified profile_id '{profile_id}' and connector_name '{connector_name}' already exists in our records")]
136+
#[error(error_type = ErrorType::DuplicateRequest, code = "HE_01", message = "The merchant connector account with the specified profile_id '{profile_id}' and connector_label '{connector_label}' already exists in our records")]
137137
DuplicateMerchantConnectorAccount {
138138
profile_id: String,
139-
connector_name: String,
139+
connector_label: String,
140140
},
141141
#[error(error_type = ErrorType::DuplicateRequest, code = "HE_01", message = "The payment method with the specified details already exists in our records")]
142142
DuplicatePaymentMethod,

crates/router/src/core/errors/transformers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
102102
connector,
103103
reason,
104104
status_code,
105-
} => AER::ConnectorError(ApiError::new("CE", 0, format!("{code}: {message}"), Some(Extra {connector: Some(connector.clone()), reason: reason.clone(), ..Default::default()})), StatusCode::from_u16(*status_code).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR)),
105+
} => AER::ConnectorError(ApiError::new("CE", 0, format!("{code}: {message}"), Some(Extra {connector: Some(connector.clone()), reason: reason.to_owned().map(Into::into), ..Default::default()})), StatusCode::from_u16(*status_code).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR)),
106106
Self::PaymentAuthorizationFailed { data } => {
107107
AER::BadRequest(ApiError::new("CE", 1, "Payment failed during authorization with connector. Retry payment", Some(Extra { data: data.clone(), ..Default::default()})))
108108
}
@@ -133,8 +133,8 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
133133
Self::DuplicateRefundRequest => AER::BadRequest(ApiError::new("HE", 1, "Duplicate refund request. Refund already attempted with the refund ID", None)),
134134
Self::DuplicateMandate => AER::BadRequest(ApiError::new("HE", 1, "Duplicate mandate request. Mandate already attempted with the Mandate ID", None)),
135135
Self::DuplicateMerchantAccount => AER::BadRequest(ApiError::new("HE", 1, "The merchant account with the specified details already exists in our records", None)),
136-
Self::DuplicateMerchantConnectorAccount { profile_id, connector_name } => {
137-
AER::BadRequest(ApiError::new("HE", 1, format!("The merchant connector account with the specified profile_id '{profile_id}' and connector_name '{connector_name}' already exists in our records"), None))
136+
Self::DuplicateMerchantConnectorAccount { profile_id, connector_label: connector_name } => {
137+
AER::BadRequest(ApiError::new("HE", 1, format!("The merchant connector account with the specified profile_id '{profile_id}' and connector_label '{connector_name}' already exists in our records"), None))
138138
}
139139
Self::DuplicatePaymentMethod => AER::BadRequest(ApiError::new("HE", 1, "The payment method with the specified details already exists in our records", None)),
140140
Self::DuplicatePayment { payment_id } => {
@@ -187,7 +187,7 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
187187
AER::BadRequest(ApiError::new("HE", 3, format!("This refund is not possible through Hyperswitch. Please raise the refund through {connector} dashboard"), None))
188188
}
189189
Self::MandateValidationFailed { reason } => {
190-
AER::BadRequest(ApiError::new("HE", 3, "Mandate Validation Failed", Some(Extra { reason: Some(reason.clone()), ..Default::default() })))
190+
AER::BadRequest(ApiError::new("HE", 3, "Mandate Validation Failed", Some(Extra { reason: Some(reason.to_owned()), ..Default::default() })))
191191
}
192192
Self::PaymentNotSucceeded => AER::BadRequest(ApiError::new("HE", 3, "The payment has not succeeded yet. Please pass a successful payment to initiate refund", None)),
193193
Self::PaymentBlockedError {

crates/router/src/core/payments/helpers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ pub fn validate_mandate(
779779
let req: api::MandateValidationFields = req.into();
780780
match req.validate_and_get_mandate_type().change_context(
781781
errors::ApiErrorResponse::MandateValidationFailed {
782-
reason: "Expected one out of mandate_id and mandate_data but got both".to_string(),
782+
reason: "Expected one out of mandate_id and mandate_data but got both".into(),
783783
},
784784
)? {
785785
Some(api::MandateTransactionType::NewMandateTransaction) => {
@@ -950,7 +950,7 @@ pub fn verify_mandate_details(
950950
.unwrap_or(true),
951951
|| {
952952
Err(report!(errors::ApiErrorResponse::MandateValidationFailed {
953-
reason: "request amount is greater than mandate amount".to_string()
953+
reason: "request amount is greater than mandate amount".into()
954954
}))
955955
},
956956
),
@@ -963,7 +963,7 @@ pub fn verify_mandate_details(
963963
.unwrap_or(false),
964964
|| {
965965
Err(report!(errors::ApiErrorResponse::MandateValidationFailed {
966-
reason: "request amount is greater than mandate amount".to_string()
966+
reason: "request amount is greater than mandate amount".into()
967967
}))
968968
},
969969
),
@@ -975,7 +975,7 @@ pub fn verify_mandate_details(
975975
.unwrap_or(false),
976976
|| {
977977
Err(report!(errors::ApiErrorResponse::MandateValidationFailed {
978-
reason: "cross currency mandates not supported".to_string()
978+
reason: "cross currency mandates not supported".into()
979979
}))
980980
},
981981
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- This file should undo anything in `up.sql`
2+
CREATE UNIQUE INDEX IF NOT EXISTS "merchant_connector_account_profile_id_connector_id_index" ON merchant_connector_account (profile_id, connector_name);
3+
4+
ALTER TABLE merchant_connector_account DROP CONSTRAINT IF EXISTS "merchant_connector_account_profile_id_connector_label_key";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Your SQL goes here
2+
ALTER TABLE merchant_connector_account
3+
ADD UNIQUE (profile_id, connector_label);
4+
5+
DROP INDEX IF EXISTS "merchant_connector_account_profile_id_connector_id_index";

openapi/openapi_spec.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9392,7 +9392,7 @@
93929392
},
93939393
"redirect_to_merchant_with_http_post": {
93949394
"type": "boolean",
9395-
"description": "A boolean value to indicate if redirect to merchant with http post needs to be enabled",
9395+
"description": "A boolean value to indicate if redirect to merchant with http post needs to be enabled.",
93969396
"default": false,
93979397
"example": true,
93989398
"nullable": true
@@ -9404,7 +9404,7 @@
94049404
},
94059405
"publishable_key": {
94069406
"type": "string",
9407-
"description": "API key that will be used for server side API access",
9407+
"description": "API key that will be used for client side API access. A publishable key has to be always paired with a `client_secret`.\nA `client_secret` can be obtained by creating a payment with `confirm` set to false",
94089408
"example": "AH3423bkjbkjdsfbkj",
94099409
"nullable": true
94109410
},
@@ -9480,7 +9480,7 @@
94809480
},
94819481
"return_url": {
94829482
"type": "string",
9483-
"description": "The URL to redirect after the completion of the operation",
9483+
"description": "The URL to redirect after completion of the payment",
94849484
"example": "https://www.example.com/success",
94859485
"nullable": true,
94869486
"maxLength": 255
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"eventOrder": ["event.test.js"]
3+
}

0 commit comments

Comments
 (0)