From 5bd0bdb44c5221030cd1a19632a11bda926b8496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20T=C3=B6rnberg?= Date: Thu, 13 Nov 2025 18:14:43 +0100 Subject: [PATCH] notification url --- cmd/cart/checkout_builder.go | 2 ++ cmd/cart/checkout_server.go | 15 +++++++++++++++ cmd/cart/pool-server.go | 1 + 3 files changed, 18 insertions(+) diff --git a/cmd/cart/checkout_builder.go b/cmd/cart/checkout_builder.go index e4a152a..84db784 100644 --- a/cmd/cart/checkout_builder.go +++ b/cmd/cart/checkout_builder.go @@ -14,6 +14,7 @@ type CheckoutMeta struct { Terms string Checkout string Confirmation string + Notification string Validation string Push string Country string @@ -107,6 +108,7 @@ func BuildCheckoutOrderPayload(grain *cart.CartGrain, meta *CheckoutMeta) ([]byt Terms: meta.Terms, Checkout: meta.Checkout, Confirmation: meta.Confirmation, + Notification: meta.Notification, Validation: meta.Validation, Push: meta.Push, }, diff --git a/cmd/cart/checkout_server.go b/cmd/cart/checkout_server.go index 7d41e9a..6dd6f76 100644 --- a/cmd/cart/checkout_server.go +++ b/cmd/cart/checkout_server.go @@ -102,6 +102,21 @@ func (a *App) HandleCheckoutRequests(amqpUrl string, mux *http.ServeMux) { w.WriteHeader(http.StatusOK) fmt.Fprintf(w, tpl, order.HTMLSnippet) }) + mux.HandleFunc("/notification", func(w http.ResponseWriter, r *http.Request) { + log.Printf("Klarna order notification, method: %s", r.Method) + if r.Method != "POST" { + w.WriteHeader(http.StatusMethodNotAllowed) + return + } + order := &CheckoutOrder{} + err := json.NewDecoder(r.Body).Decode(order) + if err != nil { + w.WriteHeader(http.StatusBadRequest) + } + log.Printf("Klarna order notification: %s", order.ID) + + w.WriteHeader(http.StatusOK) + }) mux.HandleFunc("POST /validate", func(w http.ResponseWriter, r *http.Request) { log.Printf("Klarna order validation, method: %s", r.Method) if r.Method != "POST" { diff --git a/cmd/cart/pool-server.go b/cmd/cart/pool-server.go index 499c5b4..026b344 100644 --- a/cmd/cart/pool-server.go +++ b/cmd/cart/pool-server.go @@ -318,6 +318,7 @@ func (s *PoolServer) CreateOrUpdateCheckout(ctx context.Context, host string, id Confirmation: fmt.Sprintf("https://%s/confirmation/{checkout.order.id}", host), Validation: fmt.Sprintf("https://%s/validate", host), Push: fmt.Sprintf("https://%s/push?order_id={checkout.order.id}", host), + Notification: "https://cart.tornberg.me/notification", Country: country, Currency: getCurrency(country), Locale: getLocale(country),