Skip to content

Commit

Permalink
v.1.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
fareskato committed Mar 3, 2024
1 parent e12cc99 commit 15692dd
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
"io"

"github.com/fareskato/fkshopify/fkutils"
)
Expand All @@ -21,22 +20,19 @@ func (s Shopify) verifyWebHook(data []byte) bool {
}
return hmac.Equal(expectedHMAC, decodedHMAC)
}
func WebHookCreateEntity[T any](s Shopify, t T, reqBody io.Reader) (*T, error) {
func WebHookCreateEntity[T any](s Shopify, t T, reqBody []byte) (*T, error) {
var whPayload T
if s.storeWebHookKey == "" {
return nil, fkutils.ErrWebHookMissed
}
if s.hmacHeader == "" {
return nil, fkutils.ErrHmacHeaderMissed
}
data, err := io.ReadAll(reqBody)
if err != nil {
return nil, err
}
if !s.verifyWebHook(data) {

if !s.verifyWebHook(reqBody) {
return nil, fkutils.ErrInvalidWebHookKey
}
err = json.Unmarshal(data, &whPayload)
err := json.Unmarshal(reqBody, &whPayload)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 15692dd

Please sign in to comment.