forked from Fakerr/go-paddle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhooks.go
78 lines (67 loc) · 2.76 KB
/
webhooks.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
package paddle
import (
"context"
"net/http"
)
// WebhooksService handles communication with the webhooks related
// methods of the Paddle API.
//
// Paddle API docs: https://developer.paddle.com/api-reference/alert-api/webhooks/
type WebhooksService service
// WebhookEvent represents a Paddle plan.
type WebhookEvent struct {
CurrentPage *int `json:"current_page,omitempty"`
TotalPages *int `json:"total_pages,omitempty"`
AlertsPerPage *int `json:"alerts_per_page,omitempty"`
TotalAlerts *int `json:"total_alerts,omitempty"`
QueryHead *string `json:"query_head,omitempty"`
QueryTail *string `json:"query_tail,omitempty"`
Data []*EventData `json:"data,omitempty"`
}
type EventData struct {
ID *int `json:"id,omitempty"`
AlertName *string `json:"alert_name,omitempty"`
Status *string `json:"status,omitempty"`
CreatedAt *string `json:"created_at,omitempty"`
UpdatedAt *string `json:"updated_at,omitempty"`
Attempts *int `json:"attempts,omitempty"`
Fields *EventField `json:"fields,omitempty"`
}
type EventField struct {
OrderID *int `json:"order_id,omitempty"`
Amount *string `json:"amount,omitempty"`
Currency *string `json:"currency,omitempty"`
Email *string `json:"email,omitempty"`
MarketingConsent *int `json:"marketing_consent,omitempty"`
}
type WebhookEventResponse struct {
Success bool `json:"success"`
Response *WebhookEvent `json:"response"`
}
// WebhookEventOptions specifies the optional parameters to the
// WebhooksService.Get method.
type WebhookEventOptions struct {
// Number of webhook alerts to return per page. Returns 10 alerts by default.
AlertsPerPage string `url:"alerts_per_page,omitempty"`
// The date and time (UTC - Coordinated Universal Time) at which the webhook occurred before (end date). In the format: YYYY-MM-DD HH:MM:SS
QueryHead string `url:"query_head,omitempty"`
// The date and time (UTC - Coordinated Universal Time) at which the webhook occurred after (start date). In the format: YYYY-MM-DD HH:MM:SS
QueryTail string `url:"query_tail,omitempty"`
ListOptions
}
// Retrieve past events and alerts that Paddle has sent to webhooks on your account
//
// Paddle API docs: https://developer.paddle.com/api-reference/alert-api/webhooks/webhooks
func (s *WebhooksService) Get(ctx context.Context, options *WebhookEventOptions) (*WebhookEvent, *http.Response, error) {
u := "2.0/alert/webhooks"
req, err := s.client.NewRequest("POST", u, options)
if err != nil {
return nil, nil, err
}
eventResponse := new(WebhookEventResponse)
response, err := s.client.Do(ctx, req, eventResponse)
if err != nil {
return nil, response, err
}
return eventResponse.Response, response, nil
}