github.com/stripe/stripe-go/v76@v76.25.0/promotioncode.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 package stripe 8 9 import "encoding/json" 10 11 // Returns a list of your promotion codes. 12 type PromotionCodeListParams struct { 13 ListParams `form:"*"` 14 // Filter promotion codes by whether they are active. 15 Active *bool `form:"active"` 16 // Only return promotion codes that have this case-insensitive code. 17 Code *string `form:"code"` 18 // Only return promotion codes for this coupon. 19 Coupon *string `form:"coupon"` 20 // 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. 21 Created *int64 `form:"created"` 22 // 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. 23 CreatedRange *RangeQueryParams `form:"created"` 24 // Only return promotion codes that are restricted to this customer. 25 Customer *string `form:"customer"` 26 // Specifies which fields in the response should be expanded. 27 Expand []*string `form:"expand"` 28 } 29 30 // AddExpand appends a new field to expand. 31 func (p *PromotionCodeListParams) AddExpand(f string) { 32 p.Expand = append(p.Expand, &f) 33 } 34 35 // 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). 36 type PromotionCodeRestrictionsCurrencyOptionsParams struct { 37 // Minimum amount required to redeem this Promotion Code into a Coupon (e.g., a purchase must be $100 or more to work). 38 MinimumAmount *int64 `form:"minimum_amount"` 39 } 40 41 // Settings that restrict the redemption of the promotion code. 42 type PromotionCodeRestrictionsParams struct { 43 // 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). 44 CurrencyOptions map[string]*PromotionCodeRestrictionsCurrencyOptionsParams `form:"currency_options"` 45 // A Boolean indicating if the Promotion Code should only be redeemed for Customers without any successful payments or invoices 46 FirstTimeTransaction *bool `form:"first_time_transaction"` 47 // Minimum amount required to redeem this Promotion Code into a Coupon (e.g., a purchase must be $100 or more to work). 48 MinimumAmount *int64 `form:"minimum_amount"` 49 // Three-letter [ISO code](https://stripe.com/docs/currencies) for minimum_amount 50 MinimumAmountCurrency *string `form:"minimum_amount_currency"` 51 } 52 53 // A promotion code points to a coupon. You can optionally restrict the code to a specific customer, redemption limit, and expiration date. 54 type PromotionCodeParams struct { 55 Params `form:"*"` 56 // Whether the promotion code is currently active. A promotion code can only be reactivated when the coupon is still valid and the promotion code is otherwise redeemable. 57 Active *bool `form:"active"` 58 // 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. 59 Code *string `form:"code"` 60 // The coupon for this promotion code. 61 Coupon *string `form:"coupon"` 62 // The customer that this promotion code can be used by. If not set, the promotion code can be used by all customers. 63 Customer *string `form:"customer"` 64 // Specifies which fields in the response should be expanded. 65 Expand []*string `form:"expand"` 66 // 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`. 67 ExpiresAt *int64 `form:"expires_at"` 68 // 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`. 69 MaxRedemptions *int64 `form:"max_redemptions"` 70 // 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. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. 71 Metadata map[string]string `form:"metadata"` 72 // Settings that restrict the redemption of the promotion code. 73 Restrictions *PromotionCodeRestrictionsParams `form:"restrictions"` 74 } 75 76 // AddExpand appends a new field to expand. 77 func (p *PromotionCodeParams) AddExpand(f string) { 78 p.Expand = append(p.Expand, &f) 79 } 80 81 // AddMetadata adds a new key-value pair to the Metadata. 82 func (p *PromotionCodeParams) AddMetadata(key string, value string) { 83 if p.Metadata == nil { 84 p.Metadata = make(map[string]string) 85 } 86 87 p.Metadata[key] = value 88 } 89 90 // 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). 91 type PromotionCodeRestrictionsCurrencyOptions struct { 92 // Minimum amount required to redeem this Promotion Code into a Coupon (e.g., a purchase must be $100 or more to work). 93 MinimumAmount int64 `json:"minimum_amount"` 94 } 95 type PromotionCodeRestrictions struct { 96 // 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). 97 CurrencyOptions map[string]*PromotionCodeRestrictionsCurrencyOptions `json:"currency_options"` 98 // A Boolean indicating if the Promotion Code should only be redeemed for Customers without any successful payments or invoices 99 FirstTimeTransaction bool `json:"first_time_transaction"` 100 // Minimum amount required to redeem this Promotion Code into a Coupon (e.g., a purchase must be $100 or more to work). 101 MinimumAmount int64 `json:"minimum_amount"` 102 // Three-letter [ISO code](https://stripe.com/docs/currencies) for minimum_amount 103 MinimumAmountCurrency Currency `json:"minimum_amount_currency"` 104 } 105 106 // A Promotion Code represents a customer-redeemable code for a [coupon](https://stripe.com/docs/api#coupons). It can be used to 107 // create multiple codes for a single coupon. 108 type PromotionCode struct { 109 APIResource 110 // Whether the promotion code is currently active. A promotion code is only active if the coupon is also valid. 111 Active bool `json:"active"` 112 // The customer-facing code. Regardless of case, this code must be unique across all active promotion codes for each customer. 113 Code string `json:"code"` 114 // A coupon contains information about a percent-off or amount-off discount you 115 // 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), 116 // [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). 117 Coupon *Coupon `json:"coupon"` 118 // Time at which the object was created. Measured in seconds since the Unix epoch. 119 Created int64 `json:"created"` 120 // The customer that this promotion code can be used by. 121 Customer *Customer `json:"customer"` 122 // Date at which the promotion code can no longer be redeemed. 123 ExpiresAt int64 `json:"expires_at"` 124 // Unique identifier for the object. 125 ID string `json:"id"` 126 // Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. 127 Livemode bool `json:"livemode"` 128 // Maximum number of times this promotion code can be redeemed. 129 MaxRedemptions int64 `json:"max_redemptions"` 130 // 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. 131 Metadata map[string]string `json:"metadata"` 132 // String representing the object's type. Objects of the same type share the same value. 133 Object string `json:"object"` 134 Restrictions *PromotionCodeRestrictions `json:"restrictions"` 135 // Number of times this promotion code has been used. 136 TimesRedeemed int64 `json:"times_redeemed"` 137 } 138 139 // PromotionCodeList is a list of PromotionCodes as retrieved from a list endpoint. 140 type PromotionCodeList struct { 141 APIResource 142 ListMeta 143 Data []*PromotionCode `json:"data"` 144 } 145 146 // UnmarshalJSON handles deserialization of a PromotionCode. 147 // This custom unmarshaling is needed because the resulting 148 // property may be an id or the full struct if it was expanded. 149 func (p *PromotionCode) UnmarshalJSON(data []byte) error { 150 if id, ok := ParseID(data); ok { 151 p.ID = id 152 return nil 153 } 154 155 type promotionCode PromotionCode 156 var v promotionCode 157 if err := json.Unmarshal(data, &v); err != nil { 158 return err 159 } 160 161 *p = PromotionCode(v) 162 return nil 163 }