From fa7f5396c343b21b0462f4c8fd3e9fb4d6c055d5 Mon Sep 17 00:00:00 2001 From: Jerry Phillips Date: Sat, 16 May 2026 21:54:30 -0400 Subject: [PATCH] fix(api): [AB#288] catch StripeException in RefundPaymentAsync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit StripePaymentProcessor.RefundPaymentAsync previously let StripeException propagate to ErrorHandlingMiddleware, which converted every Stripe error into a generic STRIPE_UNAVAILABLE 503. Now the processor catches StripeException and returns a PaymentOperationResult failure with the actual Stripe error message, which the controller surfaces as a 400 BadRequest. Changes: [1] Wrapped refundService.CreateAsync in try/catch(StripeException) — returns failure result with ex.StripeError?.Message References: [1] [JobFlow.Infrastructure/PaymentGateways/Stripe/StripePaymentProcessor.cs:155](https://github.com/Katharix/JobFlow.API/blob/feature/288-fix-stripe-refund-exception-handling/JobFlow.Infrastructure/PaymentGateways/Stripe/StripePaymentProcessor.cs#L155) --- .../Stripe/StripePaymentProcessor.cs | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/JobFlow.Infrastructure/PaymentGateways/Stripe/StripePaymentProcessor.cs b/JobFlow.Infrastructure/PaymentGateways/Stripe/StripePaymentProcessor.cs index 0529490..49719e2 100644 --- a/JobFlow.Infrastructure/PaymentGateways/Stripe/StripePaymentProcessor.cs +++ b/JobFlow.Infrastructure/PaymentGateways/Stripe/StripePaymentProcessor.cs @@ -151,16 +151,28 @@ public async Task RefundPaymentAsync(PaymentRefundReques requestOptions = new RequestOptions { StripeAccount = request.ConnectedAccountId }; } - var refund = await refundService.CreateAsync(options, requestOptions); - - return new PaymentOperationResult + try { - Success = refund.Status == "succeeded", - ProviderPaymentId = refund.Id, - Amount = request.Amount, - Currency = request.Currency, - Message = refund.Status - }; + var refund = await refundService.CreateAsync(options, requestOptions); + return new PaymentOperationResult + { + Success = refund.Status == "succeeded", + ProviderPaymentId = refund.Id, + Amount = request.Amount, + Currency = request.Currency, + Message = refund.Status + }; + } + catch (StripeException ex) + { + return new PaymentOperationResult + { + Success = false, + Amount = request.Amount, + Currency = request.Currency, + Message = ex.StripeError?.Message ?? ex.Message + }; + } } public async Task AdjustPaymentAsync(PaymentAdjustmentRequest request)