mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
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>
This commit is contained in:
@ -71,7 +71,7 @@ pub struct MerchantAccountCreate {
|
||||
/// 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.
|
||||
pub payment_response_hash_key: Option<String>,
|
||||
|
||||
/// A boolean value to indicate if redirect to merchant with http post needs to be enabled
|
||||
/// A boolean value to indicate if redirect to merchant with http post needs to be enabled.
|
||||
#[schema(default = false, example = true)]
|
||||
pub redirect_to_merchant_with_http_post: Option<bool>,
|
||||
|
||||
@ -79,7 +79,8 @@ pub struct MerchantAccountCreate {
|
||||
#[schema(value_type = Option<Object>, example = r#"{ "city": "NY", "unit": "245" }"#)]
|
||||
pub metadata: Option<MerchantAccountMetadata>,
|
||||
|
||||
/// API key that will be used for server side API access
|
||||
/// API key that will be used for client side API access. A publishable key has to be always paired with a `client_secret`.
|
||||
/// A `client_secret` can be obtained by creating a payment with `confirm` set to false
|
||||
#[schema(example = "AH3423bkjbkjdsfbkj")]
|
||||
pub publishable_key: Option<String>,
|
||||
|
||||
@ -195,7 +196,7 @@ pub struct MerchantAccountResponse {
|
||||
#[schema(value_type = Option<String>,example = "NewAge Retailer")]
|
||||
pub merchant_name: OptionalEncryptableName,
|
||||
|
||||
/// The URL to redirect after the completion of the operation
|
||||
/// The URL to redirect after completion of the payment
|
||||
#[schema(max_length = 255, example = "https://www.example.com/success")]
|
||||
pub return_url: Option<String>,
|
||||
|
||||
|
||||
@ -129,10 +129,10 @@ pub enum StripeErrorCode {
|
||||
#[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "duplicate merchant account")]
|
||||
DuplicateMerchantAccount,
|
||||
|
||||
#[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")]
|
||||
#[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")]
|
||||
DuplicateMerchantConnectorAccount {
|
||||
profile_id: String,
|
||||
connector_name: String,
|
||||
connector_label: String,
|
||||
},
|
||||
|
||||
#[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "duplicate payment method")]
|
||||
@ -523,10 +523,10 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
|
||||
errors::ApiErrorResponse::DuplicateMerchantAccount => Self::DuplicateMerchantAccount,
|
||||
errors::ApiErrorResponse::DuplicateMerchantConnectorAccount {
|
||||
profile_id,
|
||||
connector_name,
|
||||
connector_label,
|
||||
} => Self::DuplicateMerchantConnectorAccount {
|
||||
profile_id,
|
||||
connector_name,
|
||||
connector_label,
|
||||
},
|
||||
errors::ApiErrorResponse::DuplicatePaymentMethod => Self::DuplicatePaymentMethod,
|
||||
errors::ApiErrorResponse::PaymentBlockedError {
|
||||
|
||||
@ -923,7 +923,7 @@ pub async fn create_payment_connector(
|
||||
disabled,
|
||||
metadata: req.metadata,
|
||||
frm_configs,
|
||||
connector_label: Some(connector_label),
|
||||
connector_label: Some(connector_label.clone()),
|
||||
business_country: req.business_country,
|
||||
business_label: req.business_label.clone(),
|
||||
business_sub_label: req.business_sub_label.clone(),
|
||||
@ -960,7 +960,7 @@ pub async fn create_payment_connector(
|
||||
.to_duplicate_response(
|
||||
errors::ApiErrorResponse::DuplicateMerchantConnectorAccount {
|
||||
profile_id: profile_id.clone(),
|
||||
connector_name: req.connector_name.to_string(),
|
||||
connector_label,
|
||||
},
|
||||
)?;
|
||||
|
||||
@ -1277,7 +1277,7 @@ pub async fn update_payment_connector(
|
||||
.change_context(
|
||||
errors::ApiErrorResponse::DuplicateMerchantConnectorAccount {
|
||||
profile_id,
|
||||
connector_name: request_connector_label.unwrap_or_default(),
|
||||
connector_label: request_connector_label.unwrap_or_default(),
|
||||
},
|
||||
)
|
||||
.attach_printable_lazy(|| {
|
||||
|
||||
@ -133,10 +133,10 @@ pub enum ApiErrorResponse {
|
||||
DuplicateMandate,
|
||||
#[error(error_type = ErrorType::DuplicateRequest, code = "HE_01", message = "The merchant account with the specified details already exists in our records")]
|
||||
DuplicateMerchantAccount,
|
||||
#[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")]
|
||||
#[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")]
|
||||
DuplicateMerchantConnectorAccount {
|
||||
profile_id: String,
|
||||
connector_name: String,
|
||||
connector_label: String,
|
||||
},
|
||||
#[error(error_type = ErrorType::DuplicateRequest, code = "HE_01", message = "The payment method with the specified details already exists in our records")]
|
||||
DuplicatePaymentMethod,
|
||||
|
||||
@ -102,7 +102,7 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
|
||||
connector,
|
||||
reason,
|
||||
status_code,
|
||||
} => 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)),
|
||||
} => 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)),
|
||||
Self::PaymentAuthorizationFailed { data } => {
|
||||
AER::BadRequest(ApiError::new("CE", 1, "Payment failed during authorization with connector. Retry payment", Some(Extra { data: data.clone(), ..Default::default()})))
|
||||
}
|
||||
@ -133,8 +133,8 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
|
||||
Self::DuplicateRefundRequest => AER::BadRequest(ApiError::new("HE", 1, "Duplicate refund request. Refund already attempted with the refund ID", None)),
|
||||
Self::DuplicateMandate => AER::BadRequest(ApiError::new("HE", 1, "Duplicate mandate request. Mandate already attempted with the Mandate ID", None)),
|
||||
Self::DuplicateMerchantAccount => AER::BadRequest(ApiError::new("HE", 1, "The merchant account with the specified details already exists in our records", None)),
|
||||
Self::DuplicateMerchantConnectorAccount { profile_id, connector_name } => {
|
||||
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))
|
||||
Self::DuplicateMerchantConnectorAccount { profile_id, connector_label: connector_name } => {
|
||||
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))
|
||||
}
|
||||
Self::DuplicatePaymentMethod => AER::BadRequest(ApiError::new("HE", 1, "The payment method with the specified details already exists in our records", None)),
|
||||
Self::DuplicatePayment { payment_id } => {
|
||||
@ -187,7 +187,7 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
|
||||
AER::BadRequest(ApiError::new("HE", 3, format!("This refund is not possible through Hyperswitch. Please raise the refund through {connector} dashboard"), None))
|
||||
}
|
||||
Self::MandateValidationFailed { reason } => {
|
||||
AER::BadRequest(ApiError::new("HE", 3, "Mandate Validation Failed", Some(Extra { reason: Some(reason.clone()), ..Default::default() })))
|
||||
AER::BadRequest(ApiError::new("HE", 3, "Mandate Validation Failed", Some(Extra { reason: Some(reason.to_owned()), ..Default::default() })))
|
||||
}
|
||||
Self::PaymentNotSucceeded => AER::BadRequest(ApiError::new("HE", 3, "The payment has not succeeded yet. Please pass a successful payment to initiate refund", None)),
|
||||
Self::PaymentBlockedError {
|
||||
|
||||
@ -779,7 +779,7 @@ pub fn validate_mandate(
|
||||
let req: api::MandateValidationFields = req.into();
|
||||
match req.validate_and_get_mandate_type().change_context(
|
||||
errors::ApiErrorResponse::MandateValidationFailed {
|
||||
reason: "Expected one out of mandate_id and mandate_data but got both".to_string(),
|
||||
reason: "Expected one out of mandate_id and mandate_data but got both".into(),
|
||||
},
|
||||
)? {
|
||||
Some(api::MandateTransactionType::NewMandateTransaction) => {
|
||||
@ -950,7 +950,7 @@ pub fn verify_mandate_details(
|
||||
.unwrap_or(true),
|
||||
|| {
|
||||
Err(report!(errors::ApiErrorResponse::MandateValidationFailed {
|
||||
reason: "request amount is greater than mandate amount".to_string()
|
||||
reason: "request amount is greater than mandate amount".into()
|
||||
}))
|
||||
},
|
||||
),
|
||||
@ -963,7 +963,7 @@ pub fn verify_mandate_details(
|
||||
.unwrap_or(false),
|
||||
|| {
|
||||
Err(report!(errors::ApiErrorResponse::MandateValidationFailed {
|
||||
reason: "request amount is greater than mandate amount".to_string()
|
||||
reason: "request amount is greater than mandate amount".into()
|
||||
}))
|
||||
},
|
||||
),
|
||||
@ -975,7 +975,7 @@ pub fn verify_mandate_details(
|
||||
.unwrap_or(false),
|
||||
|| {
|
||||
Err(report!(errors::ApiErrorResponse::MandateValidationFailed {
|
||||
reason: "cross currency mandates not supported".to_string()
|
||||
reason: "cross currency mandates not supported".into()
|
||||
}))
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user