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 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
// ====================================== // This file was automatically generated. // ====================================== use crate::config::{Client, Response}; use crate::ids::SkuId; use crate::params::{Deleted, Expand, Expandable, IdOrCreate, List, Metadata, Object, Timestamp}; use crate::resources::{CreateProduct, Currency, PackageDimensions, Product}; use serde_derive::{Deserialize, Serialize}; /// The resource representing a Stripe "Sku". /// /// For more details see [https://stripe.com/docs/api/skus/object](https://stripe.com/docs/api/skus/object). #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Sku { /// Unique identifier for the object. pub id: SkuId, /// Whether the SKU is available for purchase. #[serde(skip_serializing_if = "Option::is_none")] pub active: Option<bool>, /// A dictionary of attributes and values for the attributes defined by the product. /// /// If, for example, a product's attributes are `["size", "gender"]`, a valid SKU has the following dictionary of attributes: `{"size": "Medium", "gender": "Unisex"}`. #[serde(skip_serializing_if = "Option::is_none")] pub attributes: Option<Metadata>, /// Time at which the object was created. /// /// Measured in seconds since the Unix epoch. #[serde(skip_serializing_if = "Option::is_none")] pub created: Option<Timestamp>, /// 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). #[serde(skip_serializing_if = "Option::is_none")] pub currency: Option<Currency>, // Always true for a deleted object #[serde(default)] pub deleted: bool, /// The URL of an image for this SKU, meant to be displayable to the customer. #[serde(skip_serializing_if = "Option::is_none")] pub image: Option<String>, #[serde(skip_serializing_if = "Option::is_none")] pub inventory: Option<Inventory>, /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. #[serde(skip_serializing_if = "Option::is_none")] pub livemode: Option<bool>, /// 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. #[serde(default)] pub metadata: Metadata, /// The dimensions of this SKU for shipping purposes. #[serde(skip_serializing_if = "Option::is_none")] pub package_dimensions: Option<PackageDimensions>, /// The cost of the item as a positive integer in the smallest currency unit (that is, 100 cents to charge $1.00, or 100 to charge ¥100, Japanese Yen being a zero-decimal currency). #[serde(skip_serializing_if = "Option::is_none")] pub price: Option<i64>, /// The ID of the product this SKU is associated with. /// /// The product must be currently active. #[serde(skip_serializing_if = "Option::is_none")] pub product: Option<Expandable<Product>>, /// Time at which the object was last updated. /// /// Measured in seconds since the Unix epoch. #[serde(skip_serializing_if = "Option::is_none")] pub updated: Option<Timestamp>, } impl Sku { /// Returns a list of your SKUs. /// /// The SKUs are returned sorted by creation date, with the most recently created SKUs appearing first. pub fn list(client: &Client, params: ListSkus<'_>) -> Response<List<Sku>> { client.get_query("/skus", ¶ms) } /// Creates a new SKU associated with a product. pub fn create(client: &Client, params: CreateSku<'_>) -> Response<Sku> { client.post_form("/skus", ¶ms) } /// Retrieves the details of an existing SKU. /// /// Supply the unique SKU identifier from either a SKU creation request or from the product, and Stripe will return the corresponding SKU information. pub fn retrieve(client: &Client, id: &SkuId, expand: &[&str]) -> Response<Sku> { client.get_query(&format!("/skus/{}", id), &Expand { expand }) } /// Updates the specific SKU by setting the values of the parameters passed. /// /// Any parameters not provided will be left unchanged. Note that a SKU’s `attributes` are not editable. /// Instead, you would need to deactivate the existing SKU and create a new one with the new attribute values. pub fn update(client: &Client, id: &SkuId, params: UpdateSku<'_>) -> Response<Sku> { client.post_form(&format!("/skus/{}", id), ¶ms) } /// Delete a SKU. /// /// Deleting a SKU is only possible until it has been used in an order. pub fn delete(client: &Client, id: &SkuId) -> Response<Deleted<SkuId>> { client.delete(&format!("/skus/{}", id)) } } impl Object for Sku { type Id = SkuId; fn id(&self) -> Self::Id { self.id.clone() } fn object(&self) -> &'static str { "sku" } } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Inventory { /// The count of inventory available. /// /// Will be present if and only if `type` is `finite`. #[serde(skip_serializing_if = "Option::is_none")] pub quantity: Option<u64>, /// Inventory type. /// /// Possible values are `finite`, `bucket` (not quantified), and `infinite`. #[serde(rename = "type")] pub type_: String, /// An indicator of the inventory available. /// /// Possible values are `in_stock`, `limited`, and `out_of_stock`. /// Will be present if and only if `type` is `bucket`. #[serde(skip_serializing_if = "Option::is_none")] pub value: Option<String>, } /// The parameters for `Sku::create`. #[derive(Clone, Debug, Serialize)] pub struct CreateSku<'a> { /// Whether the SKU is available for purchase. /// /// Default to `true`. #[serde(skip_serializing_if = "Option::is_none")] pub active: Option<bool>, /// A dictionary of attributes and values for the attributes defined by the product. /// /// If, for example, a product's attributes are `["size", "gender"]`, a valid SKU has the following dictionary of attributes: `{"size": "Medium", "gender": "Unisex"}`. #[serde(skip_serializing_if = "Option::is_none")] pub attributes: Option<Metadata>, /// 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). pub currency: Currency, /// Specifies which fields in the response should be expanded. #[serde(skip_serializing_if = "Expand::is_empty")] pub expand: &'a [&'a str], /// The identifier for the SKU. /// /// Must be unique. /// If not provided, an identifier will be randomly generated. #[serde(skip_serializing_if = "Option::is_none")] pub id: Option<&'a str>, /// The URL of an image for this SKU, meant to be displayable to the customer. #[serde(skip_serializing_if = "Option::is_none")] pub image: Option<&'a str>, /// Description of the SKU's inventory. #[serde(skip_serializing_if = "Option::is_none")] pub inventory: Option<Inventory>, /// 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`. #[serde(skip_serializing_if = "Option::is_none")] pub metadata: Option<Metadata>, /// The dimensions of this SKU for shipping purposes. #[serde(skip_serializing_if = "Option::is_none")] pub package_dimensions: Option<PackageDimensions>, /// The cost of the item as a nonnegative integer in the smallest currency unit (that is, 100 cents to charge $1.00, or 100 to charge ¥100, Japanese Yen being a zero-decimal currency). pub price: i64, /// The ID of the product this SKU is associated with. /// /// Must be a product with type `good`. pub product: IdOrCreate<'a, CreateProduct<'a>>, } impl<'a> CreateSku<'a> { pub fn new( currency: Currency, inventory: Option<Inventory>, price: i64, product: IdOrCreate<'a, CreateProduct<'a>>, ) -> Self { CreateSku { active: Default::default(), attributes: Default::default(), currency, expand: Default::default(), id: Default::default(), image: Default::default(), inventory, metadata: Default::default(), package_dimensions: Default::default(), price, product, } } } /// The parameters for `Sku::list`. #[derive(Clone, Debug, Serialize, Default)] pub struct ListSkus<'a> { /// Only return SKUs that are active or inactive (e.g., pass `false` to list all inactive products). #[serde(skip_serializing_if = "Option::is_none")] pub active: Option<bool>, /// Only return SKUs that have the specified key-value pairs in this partially constructed dictionary. /// /// Can be specified only if `product` is also supplied. /// For instance, if the associated product has attributes `["color", "size"]`, passing in `attributes[color]=red` returns all the SKUs for this product that have `color` set to `red`. #[serde(skip_serializing_if = "Option::is_none")] pub attributes: Option<Metadata>, /// A cursor for use in pagination. /// /// `ending_before` is an object ID that defines your place in the list. /// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list. #[serde(skip_serializing_if = "Option::is_none")] pub ending_before: Option<SkuId>, /// Specifies which fields in the response should be expanded. #[serde(skip_serializing_if = "Expand::is_empty")] pub expand: &'a [&'a str], /// Only return SKUs with the given IDs. #[serde(skip_serializing_if = "Option::is_none")] pub ids: Option<Vec<String>>, /// Only return SKUs that are either in stock or out of stock (e.g., pass `false` to list all SKUs that are out of stock). /// /// If no value is provided, all SKUs are returned. #[serde(skip_serializing_if = "Option::is_none")] pub in_stock: Option<bool>, /// A limit on the number of objects to be returned. /// /// Limit can range between 1 and 100, and the default is 10. #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option<u64>, /// The ID of the product whose SKUs will be retrieved. /// /// Must be a product with type `good`. #[serde(skip_serializing_if = "Option::is_none")] pub product: Option<IdOrCreate<'a, CreateProduct<'a>>>, /// A cursor for use in pagination. /// /// `starting_after` is an object ID that defines your place in the list. /// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list. #[serde(skip_serializing_if = "Option::is_none")] pub starting_after: Option<SkuId>, } impl<'a> ListSkus<'a> { pub fn new() -> Self { ListSkus { active: Default::default(), attributes: Default::default(), ending_before: Default::default(), expand: Default::default(), ids: Default::default(), in_stock: Default::default(), limit: Default::default(), product: Default::default(), starting_after: Default::default(), } } } /// The parameters for `Sku::update`. #[derive(Clone, Debug, Serialize, Default)] pub struct UpdateSku<'a> { /// Whether this SKU is available for purchase. #[serde(skip_serializing_if = "Option::is_none")] pub active: Option<bool>, /// A dictionary of attributes and values for the attributes defined by the product. /// /// When specified, `attributes` will partially update the existing attributes dictionary on the product, with the postcondition that a value must be present for each attribute key on the product. #[serde(skip_serializing_if = "Option::is_none")] pub attributes: Option<Metadata>, /// 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). #[serde(skip_serializing_if = "Option::is_none")] pub currency: Option<Currency>, /// Specifies which fields in the response should be expanded. #[serde(skip_serializing_if = "Expand::is_empty")] pub expand: &'a [&'a str], /// The URL of an image for this SKU, meant to be displayable to the customer. #[serde(skip_serializing_if = "Option::is_none")] pub image: Option<&'a str>, /// Description of the SKU's inventory. #[serde(skip_serializing_if = "Option::is_none")] pub inventory: Option<Inventory>, /// 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`. #[serde(skip_serializing_if = "Option::is_none")] pub metadata: Option<Metadata>, /// The dimensions of this SKU for shipping purposes. #[serde(skip_serializing_if = "Option::is_none")] pub package_dimensions: Option<PackageDimensions>, /// The cost of the item as a positive integer in the smallest currency unit (that is, 100 cents to charge $1.00, or 100 to charge ¥100, Japanese Yen being a zero-decimal currency). #[serde(skip_serializing_if = "Option::is_none")] pub price: Option<i64>, /// The ID of the product that this SKU should belong to. /// /// The product must exist, have the same set of attribute names as the SKU's current product, and be of type `good`. #[serde(skip_serializing_if = "Option::is_none")] pub product: Option<IdOrCreate<'a, CreateProduct<'a>>>, } impl<'a> UpdateSku<'a> { pub fn new() -> Self { UpdateSku { active: Default::default(), attributes: Default::default(), currency: Default::default(), expand: Default::default(), image: Default::default(), inventory: Default::default(), metadata: Default::default(), package_dimensions: Default::default(), price: Default::default(), product: Default::default(), } } }