clear cookie if failing
This commit is contained in:
@@ -210,7 +210,14 @@ func (s *CheckoutPoolServer) StartCheckoutHandler(w http.ResponseWriter, r *http
|
||||
}
|
||||
|
||||
// Create checkout with same ID as cart
|
||||
checkoutId := checkout.CheckoutId(cartId)
|
||||
var checkoutId checkout.CheckoutId = cart.MustNewCartId()
|
||||
cookie, err := r.Cookie(checkoutCookieName)
|
||||
if err == nil {
|
||||
parsed, ok := cart.ParseCartId(cookie.Value)
|
||||
if ok {
|
||||
checkoutId = parsed
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize checkout with cart state wrapped in Any
|
||||
cartStateAny := &messages.InitializeCheckout{
|
||||
@@ -225,13 +232,14 @@ func (s *CheckoutPoolServer) StartCheckoutHandler(w http.ResponseWriter, r *http
|
||||
|
||||
result, err := s.ApplyLocal(r.Context(), checkoutId, cartStateAny)
|
||||
if err != nil {
|
||||
setCheckoutCookie(w, 0, r.TLS != nil)
|
||||
logger.Error("failed to initialize checkout", "error", err)
|
||||
http.Error(w, "failed to initialize checkout", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Set checkout cookie
|
||||
setCheckoutCookie(w, result.Result.Id, r.TLS != nil)
|
||||
setCheckoutCookie(w, checkoutId, r.TLS != nil)
|
||||
|
||||
if err := s.WriteResult(w, result.Result); err != nil {
|
||||
logger.Error("failed to write result", "error", err)
|
||||
|
||||
Reference in New Issue
Block a user