handle checkout resume
This commit is contained in:
73
main.go
73
main.go
@@ -199,37 +199,48 @@ func main() {
|
|||||||
w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/checkout", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/checkout", func(w http.ResponseWriter, r *http.Request) {
|
||||||
cookie, err := r.Cookie("cartid")
|
orderId := r.URL.Query().Get("order_id")
|
||||||
if err != nil {
|
order := &CheckoutOrder{}
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
if orderId == "" {
|
||||||
w.Write([]byte(err.Error()))
|
cookie, err := r.Cookie("cartid")
|
||||||
return
|
if err != nil {
|
||||||
}
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
if cookie.Value == "" {
|
w.Write([]byte(err.Error()))
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
return
|
||||||
w.Write([]byte("no cart id to checkout is empty"))
|
}
|
||||||
return
|
if cookie.Value == "" {
|
||||||
}
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
cartId := ToCartId(cookie.Value)
|
w.Write([]byte("no cart id to checkout is empty"))
|
||||||
reply, err := syncedServer.pool.Process(cartId, Message{
|
return
|
||||||
Type: CreateCheckoutOrderType,
|
}
|
||||||
Content: &messages.CreateCheckoutOrder{
|
cartId := ToCartId(cookie.Value)
|
||||||
Terms: "https://slask-finder.tornberg.me/terms",
|
reply, err := syncedServer.pool.Process(cartId, Message{
|
||||||
Checkout: "https://slask-finder.tornberg.me/checkout?order_id={checkout.order.id}",
|
Type: CreateCheckoutOrderType,
|
||||||
Confirmation: "https://slask-finder.tornberg.me/confirmation/{checkout.order.id}",
|
Content: &messages.CreateCheckoutOrder{
|
||||||
Push: "https://cart.tornberg.me/push?order_id={checkout.order.id}",
|
Terms: "https://slask-finder.tornberg.me/terms",
|
||||||
},
|
Checkout: "https://slask-finder.tornberg.me/checkout?order_id={checkout.order.id}",
|
||||||
})
|
Confirmation: "https://slask-finder.tornberg.me/confirmation/{checkout.order.id}",
|
||||||
if err != nil {
|
Push: "https://cart.tornberg.me/push?order_id={checkout.order.id}",
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
},
|
||||||
w.Write([]byte(err.Error()))
|
})
|
||||||
}
|
if err != nil {
|
||||||
order := CheckoutOrder{}
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
err = json.Unmarshal(reply.Payload, &order)
|
w.Write([]byte(err.Error()))
|
||||||
if err != nil {
|
}
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
err = json.Unmarshal(reply.Payload, &order)
|
||||||
w.Write([]byte(err.Error()))
|
if err != nil {
|
||||||
return
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
w.Write([]byte(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
prevOrder, err := KlarnaInstance.GetOrder(orderId)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
w.Write([]byte(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
order = prevOrder
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|||||||
Reference in New Issue
Block a user