fix(sca): re-fetch payment intent when error response omits next_action (#18)

This commit is contained in:
2026-05-28 11:53:54 +02:00
committed by GitHub
parent c2b2b6e834
commit 8b2889a524

View File

@@ -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)