/
webhook.go
47 lines (41 loc) · 1.55 KB
/
webhook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package paypal
import (
"context"
"net/http"
"time"
)
type Webhook struct {
ID string `json:"id,omitempty"`
CreateTime time.Time `json:"create_time,omitempty"`
ResourceType string `json:"resource_type,omitempty"`
EventType EventType `json:"event_type,omitempty"`
Summary string `json:"summary,omitempty"`
Resource map[string]any `json:"resource,omitempty"`
Links []Link `json:"links,omitempty"`
}
type VerifyWSReq struct {
AuthAlgo string `json:"auth_algo,omitempty"`
CertURL string `json:"cert_url,omitempty"`
TransmissionID string `json:"transmission_id,omitempty"`
TransmissionTime time.Time `json:"transmission_time,omitempty"`
TransmissionSig string `json:"transmission_sig,omitempty"`
// WebhookID is the ID of webhook as configured in your Developer Portal account.
WebhookID string `json:"webhook_id,omitempty"`
WebhookEvent any `json:"webhook_event,omitempty"`
}
type WebhookVerification struct {
VerificationStatus string `json:"verification_status,omitempty"`
}
// VerifyWebhookSign verifies a webhook signature.
//
// See https://developer.paypal.com/docs/api/webhooks/v1/#verify-webhook-signature_post
func (c *Client) VerifyWebhookSign(ctx context.Context, req *VerifyWSReq,
) (ok bool, err error) {
ctx = WithOperation(ctx, "VerifyWebhookSign")
r, err := JSON[WebhookVerification](ctx, c,
http.MethodPost, "/v1/notifications/verify-webhook-signature", req)
if err != nil {
return
}
return r.VerificationStatus == "SUCCESS", nil
}