more refactor

This commit is contained in:
matst80
2025-12-03 09:14:17 +01:00
parent a0142c2698
commit 976d44ed54
4 changed files with 122 additions and 77 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
@@ -61,6 +62,14 @@ func (s *CheckoutPoolServer) AdyenSessionHandler(w http.ResponseWriter, r *http.
}
func getCheckoutIdFromNotificationItem(item webhook.NotificationRequestItem) (uint64, error) {
cartId, ok := cart.ParseCartId(item.MerchantReference)
if !ok {
return 0, errors.New("invalid cart id")
}
return uint64(cartId), nil
}
func (s *CheckoutPoolServer) AdyenHookHandler(w http.ResponseWriter, r *http.Request) {
var notificationRequest webhook.Webhook
service := s.adyenClient.Checkout()
@@ -91,10 +100,9 @@ func (s *CheckoutPoolServer) AdyenHookHandler(w http.ResponseWriter, r *http.Req
//s.ApplyAnywhere(r.Context(),0, &messages.PaymentEvent{PaymentId: item.PspReference, Success: item.Success, Name: item.EventCode, Data: &pbany.Any{Value: dataBytes}})
case "AUTHORISATION":
cartId, ok := cart.ParseCartId(item.MerchantReference)
if !ok {
log.Printf("invalid cart id %s", item.MerchantReference)
http.Error(w, "Invalid cart id", http.StatusBadRequest)
cartId, err := getCheckoutIdFromNotificationItem(item)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
//s.Apply()