mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 01:57:45 +08:00 
			
		
		
		
	refactor(mandates): refactor mandates to check for misleading error codes in mandates (#1377)
This commit is contained in:
		| @ -421,6 +421,8 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode { | ||||
|             errors::ApiErrorResponse::RefundFailed { data } => Self::RefundFailed, // Nothing at stripe to map | ||||
|  | ||||
|             errors::ApiErrorResponse::MandateUpdateFailed | ||||
|             | errors::ApiErrorResponse::MandateSerializationFailed | ||||
|             | errors::ApiErrorResponse::MandateDeserializationFailed | ||||
|             | errors::ApiErrorResponse::InternalServerError => Self::InternalServerError, // not a stripe code | ||||
|             errors::ApiErrorResponse::ExternalConnectorError { | ||||
|                 code, | ||||
|  | ||||
| @ -154,6 +154,10 @@ pub enum ApiErrorResponse { | ||||
|     MandateUpdateFailed, | ||||
|     #[error(error_type = ErrorType::ObjectNotFound, code = "HE_02", message = "API Key does not exist in our records")] | ||||
|     ApiKeyNotFound, | ||||
|     #[error(error_type = ErrorType::ValidationError, code = "HE_03", message = "Invalid mandate id passed from connector")] | ||||
|     MandateSerializationFailed, | ||||
|     #[error(error_type = ErrorType::ValidationError, code = "HE_03", message = "Unable to parse the mandate identifier passed from connector")] | ||||
|     MandateDeserializationFailed, | ||||
|     #[error(error_type = ErrorType::ValidationError, code = "HE_03", message = "Return URL is not configured and not passed in payments request")] | ||||
|     ReturnUrlUnavailable, | ||||
|     #[error(error_type = ErrorType::ValidationError, code = "HE_03", message = "This refund is not possible through Hyperswitch. Please raise the refund through {connector} dashboard")] | ||||
| @ -369,7 +373,7 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon | ||||
|             Self::VerificationFailed { data } => { | ||||
|                 AER::BadRequest(ApiError::new("CE", 7, "Verification failed while processing with connector. Retry operation", Some(Extra { data: data.clone(), ..Default::default()}))) | ||||
|             }, | ||||
|             Self::MandateUpdateFailed | Self::InternalServerError => { | ||||
|             Self::MandateUpdateFailed | Self::MandateSerializationFailed | Self::MandateDeserializationFailed | Self::InternalServerError => { | ||||
|                 AER::InternalServerError(ApiError::new("HE", 0, "Something went wrong", None)) | ||||
|             } | ||||
|             Self::DuplicateRefundRequest => AER::BadRequest(ApiError::new("HE", 1, "Duplicate refund request. Refund already attempted with the refund ID", None)), | ||||
|  | ||||
| @ -144,7 +144,7 @@ where | ||||
|                     .store | ||||
|                     .find_mandate_by_merchant_id_mandate_id(resp.merchant_id.as_ref(), mandate_id) | ||||
|                     .await | ||||
|                     .change_context(errors::ApiErrorResponse::MandateNotFound)?; | ||||
|                     .to_not_found_response(errors::ApiErrorResponse::MandateNotFound)?; | ||||
|                 let mandate = match mandate.mandate_type { | ||||
|                     storage_enums::MandateType::SingleUse => state | ||||
|                         .store | ||||
| @ -197,7 +197,9 @@ where | ||||
|                     let mandate_ids = mandate_reference | ||||
|                         .map(|md| { | ||||
|                             Encode::<types::MandateReference>::encode_to_value(&md) | ||||
|                                 .change_context(errors::ApiErrorResponse::MandateNotFound) | ||||
|                                 .change_context( | ||||
|                                     errors::ApiErrorResponse::MandateSerializationFailed, | ||||
|                                 ) | ||||
|                                 .map(masking::Secret::new) | ||||
|                         }) | ||||
|                         .transpose()?; | ||||
| @ -224,7 +226,7 @@ where | ||||
|                                     .parse_value::<api_models::payments::ConnectorMandateReferenceId>( | ||||
|                                         "ConnectorMandateId", | ||||
|                                     ) | ||||
|                                     .change_context(errors::ApiErrorResponse::MandateNotFound) | ||||
|                                     .change_context(errors::ApiErrorResponse::MandateDeserializationFailed) | ||||
|                             }) | ||||
|                             .transpose()? | ||||
|                             .map_or( | ||||
|  | ||||
| @ -160,7 +160,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa | ||||
|                 let mandate = db | ||||
|                     .find_mandate_by_merchant_id_mandate_id(merchant_id, mandate_id) | ||||
|                     .await | ||||
|                     .change_context(errors::ApiErrorResponse::MandateNotFound); | ||||
|                     .to_not_found_response(errors::ApiErrorResponse::MandateNotFound); | ||||
|                 Some(mandate.and_then(|mandate_obj| { | ||||
|                     match ( | ||||
|                         mandate_obj.network_transaction_id, | ||||
|  | ||||
| @ -52,9 +52,7 @@ impl MandateResponseExt for MandateResponse { | ||||
|                 &payment_method.payment_method_id, | ||||
|                 merchant_account.locker_id.clone(), | ||||
|             ) | ||||
|             .await | ||||
|             .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|             .attach_printable("Error getting card from card vault")?; | ||||
|             .await?; | ||||
|             let card_detail = payment_methods::transformers::get_card_detail(&payment_method, card) | ||||
|                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|                 .attach_printable("Failed while getting card details")?; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 BallaNitesh
					BallaNitesh