-
Notifications
You must be signed in to change notification settings - Fork 463
/
Copy pathpromotioncode.go
138 lines (126 loc) · 7.89 KB
/
promotioncode.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
//
//
// File generated from our OpenAPI spec
//
//
package stripe
import "encoding/json"
// Retrieves the promotion code with the given ID. In order to retrieve a promotion code by the customer-facing code use [list](https://stripe.com/docs/api/promotion_codes/list) with the desired code.
type PromotionCodeParams struct {
Params `form:"*"`
// Whether the promotion code is currently active.
Active *bool `form:"active"`
// The customer-facing code. Regardless of case, this code must be unique across all active promotion codes for a specific customer. If left blank, we will generate one automatically.
Code *string `form:"code"`
// The coupon for this promotion code.
Coupon *string `form:"coupon"`
// The customer that this promotion code can be used by. If not set, the promotion code can be used by all customers.
Customer *string `form:"customer"`
// The timestamp at which this promotion code will expire. If the coupon has specified a `redeems_by`, then this value cannot be after the coupon's `redeems_by`.
ExpiresAt *int64 `form:"expires_at"`
// A positive integer specifying the number of times the promotion code can be redeemed. If the coupon has specified a `max_redemptions`, then this value cannot be greater than the coupon's `max_redemptions`.
MaxRedemptions *int64 `form:"max_redemptions"`
// Settings that restrict the redemption of the promotion code.
Restrictions *PromotionCodeRestrictionsParams `form:"restrictions"`
}
// Promotion codes defined in each available currency option. Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
type PromotionCodeRestrictionsCurrencyOptionsParams struct {
// Minimum amount required to redeem this Promotion Code into a Coupon (e.g., a purchase must be $100 or more to work).
MinimumAmount *int64 `form:"minimum_amount"`
}
// Settings that restrict the redemption of the promotion code.
type PromotionCodeRestrictionsParams struct {
// Promotion codes defined in each available currency option. Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
CurrencyOptions map[string]*PromotionCodeRestrictionsCurrencyOptionsParams `form:"currency_options"`
// A Boolean indicating if the Promotion Code should only be redeemed for Customers without any successful payments or invoices
FirstTimeTransaction *bool `form:"first_time_transaction"`
// Minimum amount required to redeem this Promotion Code into a Coupon (e.g., a purchase must be $100 or more to work).
MinimumAmount *int64 `form:"minimum_amount"`
// Three-letter [ISO code](https://stripe.com/docs/currencies) for minimum_amount
MinimumAmountCurrency *string `form:"minimum_amount_currency"`
}
// Returns a list of your promotion codes.
type PromotionCodeListParams struct {
ListParams `form:"*"`
// Filter promotion codes by whether they are active.
Active *bool `form:"active"`
// Only return promotion codes that have this case-insensitive code.
Code *string `form:"code"`
// Only return promotion codes for this coupon.
Coupon *string `form:"coupon"`
// A filter on the list, based on the object `created` field. The value can be a string with an integer Unix timestamp, or it can be a dictionary with a number of different query options.
Created *int64 `form:"created"`
// A filter on the list, based on the object `created` field. The value can be a string with an integer Unix timestamp, or it can be a dictionary with a number of different query options.
CreatedRange *RangeQueryParams `form:"created"`
// Only return promotion codes that are restricted to this customer.
Customer *string `form:"customer"`
}
// Promotion code restrictions defined in each available currency option. Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
type PromotionCodeRestrictionsCurrencyOptions struct {
// Minimum amount required to redeem this Promotion Code into a Coupon (e.g., a purchase must be $100 or more to work).
MinimumAmount int64 `json:"minimum_amount"`
}
type PromotionCodeRestrictions struct {
// Promotion code restrictions defined in each available currency option. Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
CurrencyOptions map[string]*PromotionCodeRestrictionsCurrencyOptions `json:"currency_options"`
// A Boolean indicating if the Promotion Code should only be redeemed for Customers without any successful payments or invoices
FirstTimeTransaction bool `json:"first_time_transaction"`
// Minimum amount required to redeem this Promotion Code into a Coupon (e.g., a purchase must be $100 or more to work).
MinimumAmount int64 `json:"minimum_amount"`
// Three-letter [ISO code](https://stripe.com/docs/currencies) for minimum_amount
MinimumAmountCurrency Currency `json:"minimum_amount_currency"`
}
// A Promotion Code represents a customer-redeemable code for a [coupon](https://stripe.com/docs/api#coupons). It can be used to
// create multiple codes for a single coupon.
type PromotionCode struct {
APIResource
// Whether the promotion code is currently active. A promotion code is only active if the coupon is also valid.
Active bool `json:"active"`
// The customer-facing code. Regardless of case, this code must be unique across all active promotion codes for each customer.
Code string `json:"code"`
// A coupon contains information about a percent-off or amount-off discount you
// might want to apply to a customer. Coupons may be applied to [subscriptions](https://stripe.com/docs/api#subscriptions), [invoices](https://stripe.com/docs/api#invoices),
// [checkout sessions](https://stripe.com/docs/api/checkout/sessions), [quotes](https://stripe.com/docs/api#quotes), and more. Coupons do not work with conventional one-off [charges](https://stripe.com/docs/api#create_charge) or [payment intents](https://stripe.com/docs/api/payment_intents).
Coupon *Coupon `json:"coupon"`
// Time at which the object was created. Measured in seconds since the Unix epoch.
Created int64 `json:"created"`
// The customer that this promotion code can be used by.
Customer *Customer `json:"customer"`
// Date at which the promotion code can no longer be redeemed.
ExpiresAt int64 `json:"expires_at"`
// Unique identifier for the object.
ID string `json:"id"`
// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
Livemode bool `json:"livemode"`
// Maximum number of times this promotion code can be redeemed.
MaxRedemptions int64 `json:"max_redemptions"`
// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
Metadata map[string]string `json:"metadata"`
// String representing the object's type. Objects of the same type share the same value.
Object string `json:"object"`
Restrictions *PromotionCodeRestrictions `json:"restrictions"`
// Number of times this promotion code has been used.
TimesRedeemed int64 `json:"times_redeemed"`
}
// PromotionCodeList is a list of PromotionCodes as retrieved from a list endpoint.
type PromotionCodeList struct {
APIResource
ListMeta
Data []*PromotionCode `json:"data"`
}
// UnmarshalJSON handles deserialization of a PromotionCode.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (p *PromotionCode) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
p.ID = id
return nil
}
type promotionCode PromotionCode
var v promotionCode
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*p = PromotionCode(v)
return nil
}