-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook_type.go
97 lines (82 loc) · 2.73 KB
/
webhook_type.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package paypal
type ResourceType string
const (
EventResourceTypeInvoices ResourceType = "invoices"
EventResourceTypeSale ResourceType = "sale"
EventResourceTypeRefund ResourceType = "refund"
EventResourceTypeDispute ResourceType = "dispute"
)
// https://developer.paypal.com/docs/integration/direct/webhooks/event-names/
const (
EventTypePaymentSaleCompleted = "PAYMENT.SALE.COMPLETED"
EventTypePaymentSaleDenied = "PAYMENT.SALE.DENIED"
EventTypePaymentSalePending = "PAYMENT.SALE.PENDING"
// 退款成功
EventTypePaymentSaleRefunded = "PAYMENT.SALE.REFUNDED"
EventTypePaymentSaleReversed = "PAYMENT.SALE.REVERSED"
// 用户从 paypal 网站申请退款
EventTypeCustomerDisputeCreated = "CUSTOMER.DISPUTE.CREATED"
EventTypeCustomerDisputeResolved = "CUSTOMER.DISPUTE.RESOLVED"
EventTypeCustomerDisputeUpdated = "CUSTOMER.DISPUTE.UPDATED"
)
type EventType struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Status string `json:"status,omitempty"`
}
type Webhook struct {
Id string `json:"id,omitempty"`
URL string `json:"url"`
EventTypes []*EventType `json:"event_types,omitempty"`
Links []*Link `json:"links,omitempty"`
}
type WebhookList struct {
Webhooks []*Webhook `json:"webhooks,omitempty"`
}
type Event struct {
Id string `json:"id"`
CreateTime string `json:"create_time,omitempty"`
ResourceType ResourceType `json:"resource_type,omitempty"`
EventVersion string `json:"event_version,omitempty"`
EventType string `json:"event_type,omitempty"`
Summary string `json:"summary,omitempty"`
Resource interface{} `json:"resource,omitempty"`
Status string `json:"status,omitempty"`
Links []*Link `json:"links,omitempty"`
}
func (this *Event) Sale() *Sale {
if s, ok := this.Resource.(*Sale); ok {
return s
}
return nil
}
func (this *Event) Invoice() *Invoice {
if s, ok := this.Resource.(*Invoice); ok {
return s
}
return nil
}
func (this *Event) Dispute() *Dispute {
if s, ok := this.Resource.(*Dispute); ok {
return s
}
return nil
}
func (this *Event) Refund() *Refund {
if s, ok := this.Resource.(*Refund); ok {
return s
}
return nil
}
type verifyWebhookSignatureParam struct {
AuthAlgo string `json:"auth_algo"`
CertURL string `json:"cert_url"`
TransmissionId string `json:"transmission_id"`
TransmissionSig string `json:"transmission_sig"`
TransmissionTime string `json:"transmission_time"`
WebhookId string `json:"webhook_id"`
WebhookEvent interface{} `json:"webhook_event"`
}
type verifyWebhookSignatureResponse struct {
VerificationStatus string `json:"verification_status"`
}