-
Notifications
You must be signed in to change notification settings - Fork 2
/
notifications.go
275 lines (247 loc) · 11 KB
/
notifications.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// Code generated by the Paddle SDK Generator; DO NOT EDIT.
package paddle
import (
"context"
"encoding/json"
paddleerr "github.com/PaddleHQ/paddle-go-sdk/v3/pkg/paddleerr"
paddlenotification "github.com/PaddleHQ/paddle-go-sdk/v3/pkg/paddlenotification"
)
// ErrNotificationMaximumActiveSettingsReached represents a `notification_maximum_active_settings_reached` error.
// See https://developer.paddle.com/errors/notifications/notification_maximum_active_settings_reached for more information.
var ErrNotificationMaximumActiveSettingsReached = &paddleerr.Error{
Code: "notification_maximum_active_settings_reached",
Type: paddleerr.ErrorTypeRequestError,
}
// ErrNotificationCannotReplay represents a `notification_cannot_replay` error.
// See https://developer.paddle.com/errors/notifications/notification_cannot_replay for more information.
var ErrNotificationCannotReplay = &paddleerr.Error{
Code: "notification_cannot_replay",
Type: paddleerr.ErrorTypeRequestError,
}
// ErrURLNotificationSettingIncorrect represents a `url_notification_setting_incorrect` error.
// See https://developer.paddle.com/errors/notifications/url_notification_setting_incorrect for more information.
var ErrURLNotificationSettingIncorrect = &paddleerr.Error{
Code: "url_notification_setting_incorrect",
Type: paddleerr.ErrorTypeRequestError,
}
// ErrEmailNotificationSettingIncorrect represents a `email_notification_setting_incorrect` error.
// See https://developer.paddle.com/errors/notifications/email_notification_setting_incorrect for more information.
var ErrEmailNotificationSettingIncorrect = &paddleerr.Error{
Code: "email_notification_setting_incorrect",
Type: paddleerr.ErrorTypeRequestError,
}
// ErrNotificationReplayInvalidOriginType represents a `notification_replay_invalid_origin_type` error.
// See https://developer.paddle.com/errors/notifications/notification_replay_invalid_origin_type for more information.
var ErrNotificationReplayInvalidOriginType = &paddleerr.Error{
Code: "notification_replay_invalid_origin_type",
Type: paddleerr.ErrorTypeRequestError,
}
// NotificationStatus: Status of this notification..
type NotificationStatus string
const (
NotificationStatusNotAttempted NotificationStatus = "not_attempted"
NotificationStatusNeedsRetry NotificationStatus = "needs_retry"
NotificationStatusDelivered NotificationStatus = "delivered"
NotificationStatusFailed NotificationStatus = "failed"
)
// NotificationOrigin: Describes how this notification was created..
type NotificationOrigin string
const (
NotificationOriginEvent NotificationOrigin = "event"
NotificationOriginReplay NotificationOrigin = "replay"
)
// Notification: Represents a notification entity.
type Notification struct {
// ID: Unique Paddle ID for this notification, prefixed with `ntf_`.
ID string `json:"id,omitempty"`
// Type: Type of event sent by Paddle, in the format `entity.event_type`.
Type EventTypeName `json:"type,omitempty"`
// Status: Status of this notification.
Status NotificationStatus `json:"status,omitempty"`
// Payload: Notification payload. Includes the new or changed event.
Payload paddlenotification.NotificationEvent `json:"payload,omitempty"`
// OccurredAt: RFC 3339 datetime string of when this notification occurred.
OccurredAt string `json:"occurred_at,omitempty"`
// DeliveredAt: RFC 3339 datetime string of when this notification was delivered. `null` if not yet delivered successfully.
DeliveredAt *string `json:"delivered_at,omitempty"`
// ReplayedAt: RFC 3339 datetime string of when this notification was replayed. `null` if not replayed.
ReplayedAt *string `json:"replayed_at,omitempty"`
// Origin: Describes how this notification was created.
Origin NotificationOrigin `json:"origin,omitempty"`
// LastAttemptAt: RFC 3339 datetime string of when this notification was last attempted.
LastAttemptAt *string `json:"last_attempt_at,omitempty"`
// RetryAt: RFC 3339 datetime string of when this notification is scheduled to be retried.
RetryAt *string `json:"retry_at,omitempty"`
// TimesAttempted: How many times delivery of this notification has been attempted. Automatically incremented by Paddle after an attempt.
TimesAttempted int `json:"times_attempted,omitempty"`
// NotificationSettingID: Unique Paddle ID for this notification setting, prefixed with `ntfset_`.
NotificationSettingID string `json:"notification_setting_id,omitempty"`
}
// UnmarshalJSON implements the json.Unmarshaler interface for Notification
func (n *Notification) UnmarshalJSON(data []byte) error {
type alias Notification
if err := json.Unmarshal(data, (*alias)(n)); err != nil {
return err
}
var t paddlenotification.NotificationEvent
switch n.Type {
case "address.created":
t = &paddlenotification.AddressCreated{}
case "address.imported":
t = &paddlenotification.AddressImported{}
case "address.updated":
t = &paddlenotification.AddressUpdated{}
case "adjustment.created":
t = &paddlenotification.AdjustmentCreated{}
case "adjustment.updated":
t = &paddlenotification.AdjustmentUpdated{}
case "business.created":
t = &paddlenotification.BusinessCreated{}
case "business.imported":
t = &paddlenotification.BusinessImported{}
case "business.updated":
t = &paddlenotification.BusinessUpdated{}
case "customer.created":
t = &paddlenotification.CustomerCreated{}
case "customer.imported":
t = &paddlenotification.CustomerImported{}
case "customer.updated":
t = &paddlenotification.CustomerUpdated{}
case "discount.created":
t = &paddlenotification.DiscountCreated{}
case "discount.imported":
t = &paddlenotification.DiscountImported{}
case "discount.updated":
t = &paddlenotification.DiscountUpdated{}
case "payment_method.saved":
t = &paddlenotification.PaymentMethodSaved{}
case "payment_method.deleted":
t = &paddlenotification.PaymentMethodDeleted{}
case "payout.created":
t = &paddlenotification.PayoutCreated{}
case "payout.paid":
t = &paddlenotification.PayoutPaid{}
case "price.created":
t = &paddlenotification.PriceCreated{}
case "price.imported":
t = &paddlenotification.PriceImported{}
case "price.updated":
t = &paddlenotification.PriceUpdated{}
case "product.created":
t = &paddlenotification.ProductCreated{}
case "product.imported":
t = &paddlenotification.ProductImported{}
case "product.updated":
t = &paddlenotification.ProductUpdated{}
case "report.created":
t = &paddlenotification.ReportCreated{}
case "report.updated":
t = &paddlenotification.ReportUpdated{}
case "subscription.activated":
t = &paddlenotification.SubscriptionActivated{}
case "subscription.canceled":
t = &paddlenotification.SubscriptionCanceled{}
case "subscription.created":
t = &paddlenotification.SubscriptionCreated{}
case "subscription.past_due":
t = &paddlenotification.SubscriptionPastDue{}
case "subscription.imported":
t = &paddlenotification.SubscriptionImported{}
case "subscription.paused":
t = &paddlenotification.SubscriptionPaused{}
case "subscription.resumed":
t = &paddlenotification.SubscriptionResumed{}
case "subscription.trialing":
t = &paddlenotification.SubscriptionTrialing{}
case "subscription.updated":
t = &paddlenotification.SubscriptionUpdated{}
case "transaction.billed":
t = &paddlenotification.TransactionBilled{}
case "transaction.canceled":
t = &paddlenotification.TransactionCanceled{}
case "transaction.completed":
t = &paddlenotification.TransactionCompleted{}
case "transaction.created":
t = &paddlenotification.TransactionCreated{}
case "transaction.paid":
t = &paddlenotification.TransactionPaid{}
case "transaction.past_due":
t = &paddlenotification.TransactionPastDue{}
case "transaction.payment_failed":
t = &paddlenotification.TransactionPaymentFailed{}
case "transaction.ready":
t = &paddlenotification.TransactionReady{}
case "transaction.updated":
t = &paddlenotification.TransactionUpdated{}
default:
t = &paddlenotification.GenericNotificationEvent{}
}
rawT, err := json.Marshal(n.Payload)
if err != nil {
return err
}
if err := json.Unmarshal(rawT, t); err != nil {
return err
}
n.Payload = t
return nil
}
// NotificationsClient is a client for the Notifications resource.
type NotificationsClient struct {
doer Doer
}
// ListNotificationsRequest is given as an input to ListNotifications.
type ListNotificationsRequest struct {
// After is a query parameter.
// Return entities after the specified Paddle ID when working with paginated endpoints. Used in the `meta.pagination.next` URL in responses for list operations.
After *string `in:"query=after;omitempty" json:"-"`
// NotificationSettingID is a query parameter.
// Return entities related to the specified notification destination. Use a comma-separated list to specify multiple notification destination IDs.
NotificationSettingID []string `in:"query=notification_setting_id;omitempty" json:"-"`
// OrderBy is a query parameter.
/*
Order returned entities by the specified field and direction (`[ASC]` or `[DESC]`). For example, `?order_by=id[ASC]`.
Valid fields for ordering: `id`.
*/
OrderBy *string `in:"query=order_by;omitempty" json:"-"`
// PerPage is a query parameter.
/*
Set how many entities are returned per page. Paddle returns the maximum number of results if a number greater than the maximum is requested. Check `meta.pagination.per_page` in the response to see how many were returned.
Default: `50`; Maximum: `200`.
*/
PerPage *int `in:"query=per_page;omitempty" json:"-"`
// Search is a query parameter.
// Return entities that match a search query. Searches `id` and `type` fields.
Search *string `in:"query=search;omitempty" json:"-"`
// Status is a query parameter.
// Return entities that match the specified status. Use a comma-separated list to specify multiple status values.
Status []string `in:"query=status;omitempty" json:"-"`
// Filter is a query parameter.
// Return entities that contain the Paddle ID specified. Pass a transaction, customer, or subscription ID.
Filter *string `in:"query=filter;omitempty" json:"-"`
// To is a query parameter.
// Return entities up to a specific time.
To *string `in:"query=to;omitempty" json:"-"`
// From is a query parameter.
// Return entities from a specific time.
From *string `in:"query=from;omitempty" json:"-"`
}
// ListNotifications performs the GET operation on a Notifications resource.
func (c *NotificationsClient) ListNotifications(ctx context.Context, req *ListNotificationsRequest) (res *Collection[*Notification], err error) {
if err := c.doer.Do(ctx, "GET", "/notifications", req, &res); err != nil {
return nil, err
}
return res, nil
}
// GetNotificationRequest is given as an input to GetNotification.
type GetNotificationRequest struct {
// URL path parameters.
NotificationID string `in:"path=notification_id" json:"-"`
}
// GetNotification performs the GET operation on a Notifications resource.
func (c *NotificationsClient) GetNotification(ctx context.Context, req *GetNotificationRequest) (res *Notification, err error) {
if err := c.doer.Do(ctx, "GET", "/notifications/{notification_id}", req, &res); err != nil {
return nil, err
}
return res, nil
}