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
fix(router): allow refund after a failed void post capture and block multiple void post capture attempts (#13853)
Akshaya Shankara9dacb2ed9d2
diff --git a/crates/common_types/src/payments.rs b/crates/common_types/src/payments.rsindex 045ca3b28b..9e8d0c545b 100644--- a/crates/common_types/src/payments.rs+++ b/crates/common_types/src/payments.rs@@ -1126,7 +1126,7 @@ impl PaymentIntentStateMetadata {/// Check if post capture void is issued for the payment intentpub fn is_post_capture_void_issued(&self) -> bool {- self.post_capture_void.is_some()+ self.is_post_capture_void_pending() || self.is_post_capture_void_successful()}/// Check if post capture void is applied for the payment intentdiff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rsindex 5a1095e254..9541928578 100644--- a/crates/hyperswitch_domain_models/src/payments.rs+++ b/crates/hyperswitch_domain_models/src/payments.rs@@ -316,6 +316,14 @@ impl PaymentIntent {.unwrap_or(false)}+ #[cfg(feature = "v1")]+ pub fn is_post_capture_void_attempted(&self) -> bool {+ self.state_metadata+ .as_ref()+ .map(|state_metadata| state_metadata.post_capture_void.is_some())+ .unwrap_or(false)+ }+#[cfg(feature = "v2")]/// This is the url to which the customer will be redirected to, after completing the redirection flowpub fn create_finish_redirection_url(diff --git a/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs b/crates/router/src/core/payments/operations/payment_cancel_post_capture.rsindex 8372a9e0e5..bfbcad236e 100644--- a/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs+++ b/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs@@ -225,6 +225,19 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCancelPopayment_data: &mut PaymentData<F>,_business_profile: &domain::Profile,) -> RouterResult<()> {+ crate::utils::when(+ payment_data.payment_intent.is_post_capture_void_attempted(),+ || {+ Err(error_stack::report!(+ errors::ApiErrorResponse::PreconditionFailed {+ message:+ "Multiple post capture void requests are not allowed for a payment"+ .into()+ }+ ))+ },+ )?;+// Validates that no refunds have been issued against the payment before allowing post-capture voidlet is_refund_issued = payment_data.refunds