ack
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/google/uuid"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -107,8 +108,20 @@ func (k *KlarnaClient) AbortOrder(orderId string) error {
|
|||||||
req.SetBasicAuth(k.UserName, k.Password)
|
req.SetBasicAuth(k.UserName, k.Password)
|
||||||
|
|
||||||
_, err = http.DefaultClient.Do(req)
|
_, err = http.DefaultClient.Do(req)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ordermanagement/v1/orders/{order_id}/acknowledge
|
||||||
|
func (k *KlarnaClient) AcknowledgeOrder(orderId string) error {
|
||||||
|
req, err := http.NewRequest("POST", fmt.Sprintf("%s/ordermanagement/v1/orders/%s/acknowledge", k.Url, orderId), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
id := uuid.New()
|
||||||
|
|
||||||
|
req.SetBasicAuth(k.UserName, k.Password)
|
||||||
|
req.Header.Add("Klarna-Idempotency-Key", id.String())
|
||||||
|
|
||||||
|
_, err = http.DefaultClient.Do(req)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
30
main.go
30
main.go
@@ -284,19 +284,19 @@ func main() {
|
|||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
log.Printf("Klarna order validation: %s", order.ID)
|
log.Printf("Klarna order validation: %s", order.ID)
|
||||||
err = confirmOrder(order, orderHandler)
|
//err = confirmOrder(order, orderHandler)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
log.Printf("Error validating order: %v\n", err)
|
// log.Printf("Error validating order: %v\n", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
// w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
err = triggerOrderCompleted(err, syncedServer, order)
|
//err = triggerOrderCompleted(err, syncedServer, order)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
log.Printf("Error processing cart message: %v\n", err)
|
// log.Printf("Error processing cart message: %v\n", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
// w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/push", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/push", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -329,6 +329,10 @@ func main() {
|
|||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
err := KlarnaInstance.AcknowledgeOrder(orderId)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error acknowledging order: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user