From 8b2889a5242cf893a353be1b813ff8dbf6e6ea0b Mon Sep 17 00:00:00 2001 From: marcus06 Date: Thu, 28 May 2026 11:53:54 +0200 Subject: [PATCH] fix(sca): re-fetch payment intent when error response omits next_action (#18) --- api/handlers/cart.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/handlers/cart.go b/api/handlers/cart.go index c1620e3..227e7de 100644 --- a/api/handlers/cart.go +++ b/api/handlers/cart.go @@ -506,6 +506,16 @@ func (h *CartHandler) ConvertCart(w http.ResponseWriter, r *http.Request) { func (h *CartHandler) respondRequiresAction(w http.ResponseWriter, order *models.Order, pi *stripe.PaymentIntent) { db := database.GetDB() + // PaymentIntents returned inside a *stripe.Error are partial — next_action + // is often nil. Re-fetch from Stripe to get the canonical PI with the 3DS + // challenge URL populated. + if pi.NextAction == nil || pi.NextAction.RedirectToURL == nil || pi.NextAction.RedirectToURL.URL == "" { + fresh, ferr := paymentintent.Get(pi.ID, nil) + if ferr == nil && fresh != nil { + pi = fresh + } + } + if pi.NextAction == nil || pi.NextAction.RedirectToURL == nil || pi.NextAction.RedirectToURL.URL == "" { middleware.RecordCartConversion("sca_missing_next_action") db.Model(order).Update("status", models.OrderStatusFailed)