mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +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:
		| @ -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
	 Narayan Bhat
					Narayan Bhat