-
Notifications
You must be signed in to change notification settings - Fork 2
/
discounts.go
217 lines (185 loc) · 11.4 KB
/
discounts.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
// Code generated by the Paddle SDK Generator; DO NOT EDIT.
package paddle
import (
"context"
paddleerr "github.com/PaddleHQ/paddle-go-sdk/v3/pkg/paddleerr"
)
// ErrDiscountExpired represents a `discount_expired` error.
// See https://developer.paddle.com/errors/discounts/discount_expired for more information.
var ErrDiscountExpired = &paddleerr.Error{
Code: "discount_expired",
Type: paddleerr.ErrorTypeRequestError,
}
// ErrDiscountUsageLimitExceeded represents a `discount_usage_limit_exceeded` error.
// See https://developer.paddle.com/errors/discounts/discount_usage_limit_exceeded for more information.
var ErrDiscountUsageLimitExceeded = &paddleerr.Error{
Code: "discount_usage_limit_exceeded",
Type: paddleerr.ErrorTypeRequestError,
}
// ErrDiscountCodeConflict represents a `discount_code_conflict` error.
// See https://developer.paddle.com/errors/discounts/discount_code_conflict for more information.
var ErrDiscountCodeConflict = &paddleerr.Error{
Code: "discount_code_conflict",
Type: paddleerr.ErrorTypeRequestError,
}
// ErrDiscountRestrictedProductNotActive represents a `discount_restricted_product_not_active` error.
// See https://developer.paddle.com/errors/discounts/discount_restricted_product_not_active for more information.
var ErrDiscountRestrictedProductNotActive = &paddleerr.Error{
Code: "discount_restricted_product_not_active",
Type: paddleerr.ErrorTypeRequestError,
}
// ErrDiscountRestrictedProductPriceNotActive represents a `discount_restricted_product_price_not_active` error.
// See https://developer.paddle.com/errors/discounts/discount_restricted_product_price_not_active for more information.
var ErrDiscountRestrictedProductPriceNotActive = &paddleerr.Error{
Code: "discount_restricted_product_price_not_active",
Type: paddleerr.ErrorTypeRequestError,
}
// ErrDiscountUsageLimitLessThanTimesUsed represents a `discount_usage_limit_less_than_times_used` error.
// See https://developer.paddle.com/errors/discounts/discount_usage_limit_less_than_times_used for more information.
var ErrDiscountUsageLimitLessThanTimesUsed = &paddleerr.Error{
Code: "discount_usage_limit_less_than_times_used",
Type: paddleerr.ErrorTypeRequestError,
}
// DiscountsClient is a client for the Discounts resource.
type DiscountsClient struct {
doer Doer
}
// ListDiscountsRequest is given as an input to ListDiscounts.
type ListDiscountsRequest 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:"-"`
// Code is a query parameter.
// Return entities that match the discount code. Use a comma-separated list to specify multiple discount codes.
Code []string `in:"query=code;omitempty" json:"-"`
// ID is a query parameter.
// Return only the IDs specified. Use a comma-separated list to get multiple entities.
ID []string `in:"query=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: `created_at` and `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:"-"`
// 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:"-"`
}
// ListDiscounts performs the GET operation on a Discounts resource.
func (c *DiscountsClient) ListDiscounts(ctx context.Context, req *ListDiscountsRequest) (res *Collection[*Discount], err error) {
if err := c.doer.Do(ctx, "GET", "/discounts", req, &res); err != nil {
return nil, err
}
return res, nil
}
// CreateDiscountRequest is given as an input to CreateDiscount.
type CreateDiscountRequest struct {
// Amount: Amount to discount by. For `percentage` discounts, must be an amount between `0.01` and `100`. For `flat` and `flat_per_seat` discounts, amount in the lowest denomination for a currency.
Amount string `json:"amount,omitempty"`
// Description: Short description for this discount for your reference. Not shown to customers.
Description string `json:"description,omitempty"`
// Type: Type of discount. Determines how this discount impacts the checkout or transaction total.
Type DiscountType `json:"type,omitempty"`
// EnabledForCheckout: Whether this discount can be redeemed by customers at checkout (`true`) or not (`false`).
EnabledForCheckout *bool `json:"enabled_for_checkout,omitempty"`
/*
Code: Unique code that customers can use to redeem this discount at checkout. Use letters and numbers only, up to 16 characters. Not case-sensitive.
If omitted and `enabled_for_checkout` is `true`, Paddle generates a random 10-character code.
*/
Code *string `json:"code,omitempty"`
// CurrencyCode: Supported three-letter ISO 4217 currency code. Required where discount type is `flat` or `flat_per_seat`.
CurrencyCode *CurrencyCode `json:"currency_code,omitempty"`
// Recur: Whether this discount applies for multiple subscription billing periods (`true`) or not (`false`). If omitted, defaults to `false`.
Recur *bool `json:"recur,omitempty"`
/*
MaximumRecurringIntervals: Number of subscription billing periods that this discount recurs for. Requires `recur`. `null` if this discount recurs forever.
Subscription renewals, midcycle changes, and one-time charges billed to a subscription aren't considered a redemption. `times_used` is not incremented in these cases.
*/
MaximumRecurringIntervals *int `json:"maximum_recurring_intervals,omitempty"`
/*
UsageLimit: Maximum number of times this discount can be redeemed. This is an overall limit for this discount, rather than a per-customer limit. `null` if this discount can be redeemed an unlimited amount of times.
Paddle counts a usage as a redemption on a checkout, transaction, or the initial application against a subscription. Transactions created for subscription renewals, midcycle changes, and one-time charges aren't considered a redemption.
*/
UsageLimit *int `json:"usage_limit,omitempty"`
// RestrictTo: Product or price IDs that this discount is for. When including a product ID, all prices for that product can be discounted. `null` if this discount applies to all products and prices.
RestrictTo []string `json:"restrict_to,omitempty"`
/*
ExpiresAt: RFC 3339 datetime string of when this discount expires. Discount can no longer be redeemed after this date has elapsed. `null` if this discount can be redeemed forever.
Expired discounts can't be redeemed against transactions or checkouts, but can be applied when updating subscriptions.
*/
ExpiresAt *string `json:"expires_at,omitempty"`
// CustomData: Your own structured key-value data.
CustomData CustomData `json:"custom_data,omitempty"`
}
// CreateDiscount performs the POST operation on a Discounts resource.
func (c *DiscountsClient) CreateDiscount(ctx context.Context, req *CreateDiscountRequest) (res *Discount, err error) {
if err := c.doer.Do(ctx, "POST", "/discounts", req, &res); err != nil {
return nil, err
}
return res, nil
}
// GetDiscountRequest is given as an input to GetDiscount.
type GetDiscountRequest struct {
// URL path parameters.
DiscountID string `in:"path=discount_id" json:"-"`
}
// GetDiscount performs the GET operation on a Discounts resource.
func (c *DiscountsClient) GetDiscount(ctx context.Context, req *GetDiscountRequest) (res *Discount, err error) {
if err := c.doer.Do(ctx, "GET", "/discounts/{discount_id}", req, &res); err != nil {
return nil, err
}
return res, nil
}
// UpdateDiscountRequest is given as an input to UpdateDiscount.
type UpdateDiscountRequest struct {
// URL path parameters.
DiscountID string `in:"path=discount_id" json:"-"`
// Status: Whether this entity can be used in Paddle.
Status *PatchField[DiscountStatus] `json:"status,omitempty"`
// Description: Short description for this discount for your reference. Not shown to customers.
Description *PatchField[string] `json:"description,omitempty"`
// EnabledForCheckout: Whether this discount can be redeemed by customers at checkout (`true`) or not (`false`).
EnabledForCheckout *PatchField[bool] `json:"enabled_for_checkout,omitempty"`
// Code: Unique code that customers can use to redeem this discount at checkout. Not case-sensitive.
Code *PatchField[*string] `json:"code,omitempty"`
// Type: Type of discount. Determines how this discount impacts the checkout or transaction total.
Type *PatchField[DiscountType] `json:"type,omitempty"`
// Amount: Amount to discount by. For `percentage` discounts, must be an amount between `0.01` and `100`. For `flat` and `flat_per_seat` discounts, amount in the lowest denomination for a currency.
Amount *PatchField[string] `json:"amount,omitempty"`
// CurrencyCode: Supported three-letter ISO 4217 currency code. Required where discount type is `flat` or `flat_per_seat`.
CurrencyCode *PatchField[*CurrencyCode] `json:"currency_code,omitempty"`
// Recur: Whether this discount applies for multiple subscription billing periods (`true`) or not (`false`).
Recur *PatchField[bool] `json:"recur,omitempty"`
/*
MaximumRecurringIntervals: Number of subscription billing periods that this discount recurs for. Requires `recur`. `null` if this discount recurs forever.
Subscription renewals, midcycle changes, and one-time charges billed to a subscription aren't considered a redemption. `times_used` is not incremented in these cases.
*/
MaximumRecurringIntervals *PatchField[*int] `json:"maximum_recurring_intervals,omitempty"`
/*
UsageLimit: Maximum number of times this discount can be redeemed. This is an overall limit for this discount, rather than a per-customer limit. `null` if this discount can be redeemed an unlimited amount of times.
Paddle counts a usage as a redemption on a checkout, transaction, or the initial application against a subscription. Transactions created for subscription renewals, midcycle changes, and one-time charges aren't considered a redemption.
*/
UsageLimit *PatchField[*int] `json:"usage_limit,omitempty"`
// RestrictTo: Product or price IDs that this discount is for. When including a product ID, all prices for that product can be discounted. `null` if this discount applies to all products and prices.
RestrictTo *PatchField[[]string] `json:"restrict_to,omitempty"`
/*
ExpiresAt: RFC 3339 datetime string of when this discount expires. Discount can no longer be redeemed after this date has elapsed. `null` if this discount can be redeemed forever.
Expired discounts can't be redeemed against transactions or checkouts, but can be applied when updating subscriptions.
*/
ExpiresAt *PatchField[*string] `json:"expires_at,omitempty"`
// CustomData: Your own structured key-value data.
CustomData *PatchField[CustomData] `json:"custom_data,omitempty"`
}
// UpdateDiscount performs the PATCH operation on a Discounts resource.
func (c *DiscountsClient) UpdateDiscount(ctx context.Context, req *UpdateDiscountRequest) (res *Discount, err error) {
if err := c.doer.Do(ctx, "PATCH", "/discounts/{discount_id}", req, &res); err != nil {
return nil, err
}
return res, nil
}