diff --git a/cmd/cart/pool-server.go b/cmd/cart/pool-server.go index eb411f6..e15b01a 100644 --- a/cmd/cart/pool-server.go +++ b/cmd/cart/pool-server.go @@ -756,16 +756,6 @@ func (s *PoolServer) AdyenHookHandler(w http.ResponseWriter, r *http.Request) { for _, notificationItem := range *notificationRequest.NotificationItems { item := notificationItem.NotificationRequestItem log.Printf("Recieved notification event code: %s, %v", item.EventCode, item) - cartId, ok := cart.ParseCartId(item.MerchantReference) - if !ok { - log.Printf("invalid cart id %s", item.MerchantReference) - http.Error(w, "Invalid cart id", http.StatusBadRequest) - return - } - if host, ok := s.OwnerHost(uint64(cartId)); ok { - cartHostMap[host] = append(cartHostMap[host], notificationItem) - continue - } isValid := hmacvalidator.ValidateHmac(item, hmacKey) if !isValid { @@ -774,8 +764,21 @@ func (s *PoolServer) AdyenHookHandler(w http.ResponseWriter, r *http.Request) { return } else { switch item.EventCode { + case "CAPTURE": + log.Printf("Capture status: %v", item.Success) 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) + return + } + if host, ok := s.OwnerHost(uint64(cartId)); ok { + cartHostMap[host] = append(cartHostMap[host], notificationItem) + continue + } + grain, err := s.Get(r.Context(), uint64(cartId)) if err != nil { log.Printf("Error getting cart: %v", err) @@ -804,6 +807,8 @@ func (s *PoolServer) AdyenHookHandler(w http.ResponseWriter, r *http.Request) { Status: item.EventCode, }) } + default: + log.Printf("Unknown event code: %s", item.EventCode) } } }