Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(mandates): refactor mandates to check for misleading error codes in mandates (#1377)
BallaNitesha899c9738941
diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rsindex a9368b2a0e..bd203170f3 100644--- a/crates/router/src/compatibility/stripe/errors.rs+++ b/crates/router/src/compatibility/stripe/errors.rs@@ -421,6 +421,8 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {errors::ApiErrorResponse::RefundFailed { data } => Self::RefundFailed, // Nothing at stripe to maperrors::ApiErrorResponse::MandateUpdateFailed+ | errors::ApiErrorResponse::MandateSerializationFailed+ | errors::ApiErrorResponse::MandateDeserializationFailed| errors::ApiErrorResponse::InternalServerError => Self::InternalServerError, // not a stripe codeerrors::ApiErrorResponse::ExternalConnectorError {code,diff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rsindex e77f3ed690..19d1561d98 100644--- a/crates/router/src/core/errors/api_error_response.rs+++ b/crates/router/src/core/errors/api_error_response.rs@@ -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::ApiErrorResponSelf::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)),diff --git a/crates/router/src/core/mandate.rs b/crates/router/src/core/mandate.rsindex e7518e0e37..f58da04eaa 100644--- a/crates/router/src/core/mandate.rs+++ b/crates/router/src/core/mandate.rs@@ -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 @@ wherelet 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(diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex f595818823..2ea7fa1e12 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -160,7 +160,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Palet 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,diff --git a/crates/router/src/types/api/mandates.rs b/crates/router/src/types/api/mandates.rsindex 22a96acf2b..dfd9ba124b 100644--- a/crates/router/src/types/api/mandates.rs+++ b/crates/router/src/types/api/mandates.rs@@ -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")?;