github.com/stripe/stripe-go/v76@v76.25.0/shippingrate.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 package stripe 8 9 import "encoding/json" 10 11 // A unit of time. 12 type ShippingRateDeliveryEstimateMaximumUnit string 13 14 // List of values that ShippingRateDeliveryEstimateMaximumUnit can take 15 const ( 16 ShippingRateDeliveryEstimateMaximumUnitBusinessDay ShippingRateDeliveryEstimateMaximumUnit = "business_day" 17 ShippingRateDeliveryEstimateMaximumUnitDay ShippingRateDeliveryEstimateMaximumUnit = "day" 18 ShippingRateDeliveryEstimateMaximumUnitHour ShippingRateDeliveryEstimateMaximumUnit = "hour" 19 ShippingRateDeliveryEstimateMaximumUnitMonth ShippingRateDeliveryEstimateMaximumUnit = "month" 20 ShippingRateDeliveryEstimateMaximumUnitWeek ShippingRateDeliveryEstimateMaximumUnit = "week" 21 ) 22 23 // A unit of time. 24 type ShippingRateDeliveryEstimateMinimumUnit string 25 26 // List of values that ShippingRateDeliveryEstimateMinimumUnit can take 27 const ( 28 ShippingRateDeliveryEstimateMinimumUnitBusinessDay ShippingRateDeliveryEstimateMinimumUnit = "business_day" 29 ShippingRateDeliveryEstimateMinimumUnitDay ShippingRateDeliveryEstimateMinimumUnit = "day" 30 ShippingRateDeliveryEstimateMinimumUnitHour ShippingRateDeliveryEstimateMinimumUnit = "hour" 31 ShippingRateDeliveryEstimateMinimumUnitMonth ShippingRateDeliveryEstimateMinimumUnit = "month" 32 ShippingRateDeliveryEstimateMinimumUnitWeek ShippingRateDeliveryEstimateMinimumUnit = "week" 33 ) 34 35 // Specifies whether the rate is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. 36 type ShippingRateFixedAmountCurrencyOptionsTaxBehavior string 37 38 // List of values that ShippingRateFixedAmountCurrencyOptionsTaxBehavior can take 39 const ( 40 ShippingRateFixedAmountCurrencyOptionsTaxBehaviorExclusive ShippingRateFixedAmountCurrencyOptionsTaxBehavior = "exclusive" 41 ShippingRateFixedAmountCurrencyOptionsTaxBehaviorInclusive ShippingRateFixedAmountCurrencyOptionsTaxBehavior = "inclusive" 42 ShippingRateFixedAmountCurrencyOptionsTaxBehaviorUnspecified ShippingRateFixedAmountCurrencyOptionsTaxBehavior = "unspecified" 43 ) 44 45 // Specifies whether the rate is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. 46 type ShippingRateTaxBehavior string 47 48 // List of values that ShippingRateTaxBehavior can take 49 const ( 50 ShippingRateTaxBehaviorExclusive ShippingRateTaxBehavior = "exclusive" 51 ShippingRateTaxBehaviorInclusive ShippingRateTaxBehavior = "inclusive" 52 ShippingRateTaxBehaviorUnspecified ShippingRateTaxBehavior = "unspecified" 53 ) 54 55 // The type of calculation to use on the shipping rate. Can only be `fixed_amount` for now. 56 type ShippingRateType string 57 58 // List of values that ShippingRateType can take 59 const ( 60 ShippingRateTypeFixedAmount ShippingRateType = "fixed_amount" 61 ) 62 63 // Returns a list of your shipping rates. 64 type ShippingRateListParams struct { 65 ListParams `form:"*"` 66 // Only return shipping rates that are active or inactive. 67 Active *bool `form:"active"` 68 // 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. 69 Created *int64 `form:"created"` 70 // 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. 71 CreatedRange *RangeQueryParams `form:"created"` 72 // Only return shipping rates for the given currency. 73 Currency *string `form:"currency"` 74 // Specifies which fields in the response should be expanded. 75 Expand []*string `form:"expand"` 76 } 77 78 // AddExpand appends a new field to expand. 79 func (p *ShippingRateListParams) AddExpand(f string) { 80 p.Expand = append(p.Expand, &f) 81 } 82 83 // The upper bound of the estimated range. If empty, represents no upper bound i.e., infinite. 84 type ShippingRateDeliveryEstimateMaximumParams struct { 85 // A unit of time. 86 Unit *string `form:"unit"` 87 // Must be greater than 0. 88 Value *int64 `form:"value"` 89 } 90 91 // The lower bound of the estimated range. If empty, represents no lower bound. 92 type ShippingRateDeliveryEstimateMinimumParams struct { 93 // A unit of time. 94 Unit *string `form:"unit"` 95 // Must be greater than 0. 96 Value *int64 `form:"value"` 97 } 98 99 // The estimated range for how long shipping will take, meant to be displayable to the customer. This will appear on CheckoutSessions. 100 type ShippingRateDeliveryEstimateParams struct { 101 // The upper bound of the estimated range. If empty, represents no upper bound i.e., infinite. 102 Maximum *ShippingRateDeliveryEstimateMaximumParams `form:"maximum"` 103 // The lower bound of the estimated range. If empty, represents no lower bound. 104 Minimum *ShippingRateDeliveryEstimateMinimumParams `form:"minimum"` 105 } 106 107 // Shipping rates 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). 108 type ShippingRateFixedAmountCurrencyOptionsParams struct { 109 // A non-negative integer in cents representing how much to charge. 110 Amount *int64 `form:"amount"` 111 // Specifies whether the rate is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. 112 TaxBehavior *string `form:"tax_behavior"` 113 } 114 115 // Describes a fixed amount to charge for shipping. Must be present if type is `fixed_amount`. 116 type ShippingRateFixedAmountParams struct { 117 // A non-negative integer in cents representing how much to charge. 118 Amount *int64 `form:"amount"` 119 // Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies). 120 Currency *string `form:"currency"` 121 // Shipping rates 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). 122 CurrencyOptions map[string]*ShippingRateFixedAmountCurrencyOptionsParams `form:"currency_options"` 123 } 124 125 // Creates a new shipping rate object. 126 type ShippingRateParams struct { 127 Params `form:"*"` 128 // Whether the shipping rate can be used for new purchases. Defaults to `true`. 129 Active *bool `form:"active"` 130 // The estimated range for how long shipping will take, meant to be displayable to the customer. This will appear on CheckoutSessions. 131 DeliveryEstimate *ShippingRateDeliveryEstimateParams `form:"delivery_estimate"` 132 // The name of the shipping rate, meant to be displayable to the customer. This will appear on CheckoutSessions. 133 DisplayName *string `form:"display_name"` 134 // Specifies which fields in the response should be expanded. 135 Expand []*string `form:"expand"` 136 // Describes a fixed amount to charge for shipping. Must be present if type is `fixed_amount`. 137 FixedAmount *ShippingRateFixedAmountParams `form:"fixed_amount"` 138 // 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`. 139 Metadata map[string]string `form:"metadata"` 140 // Specifies whether the rate is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. 141 TaxBehavior *string `form:"tax_behavior"` 142 // A [tax code](https://stripe.com/docs/tax/tax-categories) ID. The Shipping tax code is `txcd_92010001`. 143 TaxCode *string `form:"tax_code"` 144 // The type of calculation to use on the shipping rate. Can only be `fixed_amount` for now. 145 Type *string `form:"type"` 146 } 147 148 // AddExpand appends a new field to expand. 149 func (p *ShippingRateParams) AddExpand(f string) { 150 p.Expand = append(p.Expand, &f) 151 } 152 153 // AddMetadata adds a new key-value pair to the Metadata. 154 func (p *ShippingRateParams) AddMetadata(key string, value string) { 155 if p.Metadata == nil { 156 p.Metadata = make(map[string]string) 157 } 158 159 p.Metadata[key] = value 160 } 161 162 // The upper bound of the estimated range. If empty, represents no upper bound i.e., infinite. 163 type ShippingRateDeliveryEstimateMaximum struct { 164 // A unit of time. 165 Unit ShippingRateDeliveryEstimateMaximumUnit `json:"unit"` 166 // Must be greater than 0. 167 Value int64 `json:"value"` 168 } 169 170 // The lower bound of the estimated range. If empty, represents no lower bound. 171 type ShippingRateDeliveryEstimateMinimum struct { 172 // A unit of time. 173 Unit ShippingRateDeliveryEstimateMinimumUnit `json:"unit"` 174 // Must be greater than 0. 175 Value int64 `json:"value"` 176 } 177 178 // The estimated range for how long shipping will take, meant to be displayable to the customer. This will appear on CheckoutSessions. 179 type ShippingRateDeliveryEstimate struct { 180 // The upper bound of the estimated range. If empty, represents no upper bound i.e., infinite. 181 Maximum *ShippingRateDeliveryEstimateMaximum `json:"maximum"` 182 // The lower bound of the estimated range. If empty, represents no lower bound. 183 Minimum *ShippingRateDeliveryEstimateMinimum `json:"minimum"` 184 } 185 186 // Shipping rates 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). 187 type ShippingRateFixedAmountCurrencyOptions struct { 188 // A non-negative integer in cents representing how much to charge. 189 Amount int64 `json:"amount"` 190 // Specifies whether the rate is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. 191 TaxBehavior ShippingRateFixedAmountCurrencyOptionsTaxBehavior `json:"tax_behavior"` 192 } 193 type ShippingRateFixedAmount struct { 194 // A non-negative integer in cents representing how much to charge. 195 Amount int64 `json:"amount"` 196 // Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies). 197 Currency Currency `json:"currency"` 198 // Shipping rates 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). 199 CurrencyOptions map[string]*ShippingRateFixedAmountCurrencyOptions `json:"currency_options"` 200 } 201 202 // Shipping rates describe the price of shipping presented to your customers and 203 // applied to a purchase. For more information, see [Charge for shipping](https://stripe.com/docs/payments/during-payment/charge-shipping). 204 type ShippingRate struct { 205 APIResource 206 // Whether the shipping rate can be used for new purchases. Defaults to `true`. 207 Active bool `json:"active"` 208 // Time at which the object was created. Measured in seconds since the Unix epoch. 209 Created int64 `json:"created"` 210 // The estimated range for how long shipping will take, meant to be displayable to the customer. This will appear on CheckoutSessions. 211 DeliveryEstimate *ShippingRateDeliveryEstimate `json:"delivery_estimate"` 212 // The name of the shipping rate, meant to be displayable to the customer. This will appear on CheckoutSessions. 213 DisplayName string `json:"display_name"` 214 FixedAmount *ShippingRateFixedAmount `json:"fixed_amount"` 215 // Unique identifier for the object. 216 ID string `json:"id"` 217 // Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. 218 Livemode bool `json:"livemode"` 219 // 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. 220 Metadata map[string]string `json:"metadata"` 221 // String representing the object's type. Objects of the same type share the same value. 222 Object string `json:"object"` 223 // Specifies whether the rate is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. 224 TaxBehavior ShippingRateTaxBehavior `json:"tax_behavior"` 225 // A [tax code](https://stripe.com/docs/tax/tax-categories) ID. The Shipping tax code is `txcd_92010001`. 226 TaxCode *TaxCode `json:"tax_code"` 227 // The type of calculation to use on the shipping rate. Can only be `fixed_amount` for now. 228 Type ShippingRateType `json:"type"` 229 } 230 231 // ShippingRateList is a list of ShippingRates as retrieved from a list endpoint. 232 type ShippingRateList struct { 233 APIResource 234 ListMeta 235 Data []*ShippingRate `json:"data"` 236 } 237 238 // UnmarshalJSON handles deserialization of a ShippingRate. 239 // This custom unmarshaling is needed because the resulting 240 // property may be an id or the full struct if it was expanded. 241 func (s *ShippingRate) UnmarshalJSON(data []byte) error { 242 if id, ok := ParseID(data); ok { 243 s.ID = id 244 return nil 245 } 246 247 type shippingRate ShippingRate 248 var v shippingRate 249 if err := json.Unmarshal(data, &v); err != nil { 250 return err 251 } 252 253 *s = ShippingRate(v) 254 return nil 255 }