mirror of
https://github.com/plutov/paypal.git
synced 2025-02-02 15:10:36 +01:00
Reset after reading (#118)
This commit is contained in:
parent
cd72fd3aec
commit
06a298ef76
18
webhooks.go
18
webhooks.go
|
@ -1,6 +1,7 @@
|
||||||
package paypal
|
package paypal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -19,15 +20,14 @@ func (c *Client) VerifyWebhookSignature(httpReq *http.Request, webhookID string)
|
||||||
WebhookID string `json:"webhook_id,omitempty"`
|
WebhookID string `json:"webhook_id,omitempty"`
|
||||||
WebhookEvent json.RawMessage `json:"webhook_event"`
|
WebhookEvent json.RawMessage `json:"webhook_event"`
|
||||||
}
|
}
|
||||||
getBody := httpReq.GetBody
|
|
||||||
bodyReadCloser, err := getBody()
|
// Read the content
|
||||||
if err != nil {
|
var bodyBytes []byte
|
||||||
return nil, err
|
if httpReq.Body != nil {
|
||||||
}
|
bodyBytes, _ = ioutil.ReadAll(httpReq.Body)
|
||||||
body, err := ioutil.ReadAll(bodyReadCloser)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
// Restore the io.ReadCloser to its original state
|
||||||
|
httpReq.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||||
|
|
||||||
verifyRequest := verifyWebhookSignatureRequest{
|
verifyRequest := verifyWebhookSignatureRequest{
|
||||||
AuthAlgo: httpReq.Header.Get("PAYPAL-AUTH-ALGO"),
|
AuthAlgo: httpReq.Header.Get("PAYPAL-AUTH-ALGO"),
|
||||||
|
@ -36,7 +36,7 @@ func (c *Client) VerifyWebhookSignature(httpReq *http.Request, webhookID string)
|
||||||
TransmissionSig: httpReq.Header.Get("PAYPAL-TRANSMISSION-SIG"),
|
TransmissionSig: httpReq.Header.Get("PAYPAL-TRANSMISSION-SIG"),
|
||||||
TransmissionTime: httpReq.Header.Get("PAYPAL-TRANSMISSION-TIME"),
|
TransmissionTime: httpReq.Header.Get("PAYPAL-TRANSMISSION-TIME"),
|
||||||
WebhookID: webhookID,
|
WebhookID: webhookID,
|
||||||
WebhookEvent: json.RawMessage(body),
|
WebhookEvent: json.RawMessage(bodyBytes),
|
||||||
}
|
}
|
||||||
|
|
||||||
response := &VerifyWebhookResponse{}
|
response := &VerifyWebhookResponse{}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user