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 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
// ====================================== // This file was automatically generated. // ====================================== use crate::config::{Client, Response}; use crate::ids::PlanId; use crate::params::{Deleted, Expand, Expandable, List, Metadata, Object, RangeQuery, Timestamp}; use crate::resources::{Currency, Product, UpTo}; use serde_derive::{Deserialize, Serialize}; /// The resource representing a Stripe "Plan". /// /// For more details see [https://stripe.com/docs/api/plans/object](https://stripe.com/docs/api/plans/object). #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Plan { /// Unique identifier for the object. pub id: PlanId, /// Whether the plan is currently available for new subscriptions. #[serde(skip_serializing_if = "Option::is_none")] pub active: Option<bool>, /// Specifies a usage aggregation strategy for plans of `usage_type=metered`. /// /// Allowed values are `sum` for summing up all usage during a period, `last_during_period` for picking the last usage record reported within a period, `last_ever` for picking the last usage record ever (across period bounds) or `max` which picks the usage record with the maximum reported usage during a period. /// Defaults to `sum`. #[serde(skip_serializing_if = "Option::is_none")] pub aggregate_usage: Option<PlanAggregateUsage>, /// The amount in %s to be charged on the interval specified. #[serde(skip_serializing_if = "Option::is_none")] pub amount: Option<i64>, /// Describes how to compute the price per period. /// /// Either `per_unit` or `tiered`. /// `per_unit` indicates that the fixed amount (specified in `amount`) will be charged per unit in `quantity` (for plans with `usage_type=licensed`), or per unit of total usage (for plans with `usage_type=metered`). /// `tiered` indicates that the unit pricing will be computed using a tiering strategy as defined using the `tiers` and `tiers_mode` attributes. #[serde(skip_serializing_if = "Option::is_none")] pub billing_scheme: Option<PlanBillingScheme>, /// 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, /// One of `day`, `week`, `month` or `year`. /// /// The frequency with which a subscription should be billed. #[serde(skip_serializing_if = "Option::is_none")] pub interval: Option<PlanInterval>, /// The number of intervals (specified in the `interval` property) between subscription billings. /// /// For example, `interval=month` and `interval_count=3` bills every 3 months. #[serde(skip_serializing_if = "Option::is_none")] pub interval_count: Option<u64>, /// 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 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, /// A brief description of the plan, hidden from customers. #[serde(skip_serializing_if = "Option::is_none")] pub nickname: Option<String>, /// The product whose pricing this plan determines. #[serde(skip_serializing_if = "Option::is_none")] pub product: Option<Expandable<Product>>, /// Each element represents a pricing tier. /// /// This parameter requires `billing_scheme` to be set to `tiered`. /// See also the documentation for `billing_scheme`. #[serde(skip_serializing_if = "Option::is_none")] pub tiers: Option<Vec<PlanTier>>, /// Defines if the tiering price should be `graduated` or `volume` based. /// /// In `volume`-based tiering, the maximum quantity within a period determines the per unit price, in `graduated` tiering pricing can successively change as the quantity grows. #[serde(skip_serializing_if = "Option::is_none")] pub tiers_mode: Option<PlanTiersMode>, /// Apply a transformation to the reported usage or set quantity before computing the billed price. /// /// Cannot be combined with `tiers`. #[serde(skip_serializing_if = "Option::is_none")] pub transform_usage: Option<TransformUsage>, /// Default number of trial days when subscribing a customer to this plan using [`trial_from_plan=true`](https://stripe.com/docs/api#create_subscription-trial_from_plan). #[serde(skip_serializing_if = "Option::is_none")] pub trial_period_days: Option<u32>, /// Configures how the quantity per period should be determined, can be either `metered` or `licensed`. /// /// `licensed` will automatically bill the `quantity` set for a plan when adding it to a subscription, `metered` will aggregate the total usage based on usage records. /// Defaults to `licensed`. #[serde(skip_serializing_if = "Option::is_none")] pub usage_type: Option<PlanUsageType>, } impl Plan { /// Returns a list of your plans. pub fn list(client: &Client, params: ListPlans<'_>) -> Response<List<Plan>> { client.get_query("/plans", ¶ms) } /// You can create plans using the API, or in the Stripe [Dashboard](https://dashboard.stripe.com/subscriptions/products). pub fn create(client: &Client, params: CreatePlan<'_>) -> Response<Plan> { client.post_form("/plans", ¶ms) } /// Retrieves the plan with the given ID. pub fn retrieve(client: &Client, id: &PlanId, expand: &[&str]) -> Response<Plan> { client.get_query(&format!("/plans/{}", id), &Expand { expand }) } /// Updates the specified plan by setting the values of the parameters passed. /// /// Any parameters not provided are left unchanged. /// By design, you cannot change a plan’s ID, amount, currency, or billing cycle. pub fn update(client: &Client, id: &PlanId, params: UpdatePlan<'_>) -> Response<Plan> { client.post_form(&format!("/plans/{}", id), ¶ms) } /// Deleting plans means new subscribers can’t be added. /// /// Existing subscribers aren’t affected. pub fn delete(client: &Client, id: &PlanId) -> Response<Deleted<PlanId>> { client.delete(&format!("/plans/{}", id)) } } impl Object for Plan { type Id = PlanId; fn id(&self) -> Self::Id { self.id.clone() } fn object(&self) -> &'static str { "plan" } } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct PlanTier { /// Price for the entire tier. #[serde(skip_serializing_if = "Option::is_none")] pub flat_amount: Option<i64>, /// Per unit price for units relevant to the tier. #[serde(skip_serializing_if = "Option::is_none")] pub unit_amount: Option<i64>, /// Up to and including to this quantity will be contained in the tier. #[serde(skip_serializing_if = "Option::is_none")] pub up_to: Option<i64>, } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct TransformUsage { /// Divide usage by this number. pub divide_by: i64, /// After division, either round the result `up` or `down`. pub round: TransformUsageRound, } /// The parameters for `Plan::create`. #[derive(Clone, Debug, Serialize)] pub struct CreatePlan<'a> { /// Whether the plan is currently available for new subscriptions. /// /// Defaults to `true`. #[serde(skip_serializing_if = "Option::is_none")] pub active: Option<bool>, /// Specifies a usage aggregation strategy for plans of `usage_type=metered`. /// /// Allowed values are `sum` for summing up all usage during a period, `last_during_period` for picking the last usage record reported within a period, `last_ever` for picking the last usage record ever (across period bounds) or `max` which picks the usage record with the maximum reported usage during a period. /// Defaults to `sum`. #[serde(skip_serializing_if = "Option::is_none")] pub aggregate_usage: Option<PlanAggregateUsage>, /// A positive integer in %s (or 0 for a free plan) representing how much to charge on a recurring basis. #[serde(skip_serializing_if = "Option::is_none")] pub amount: Option<i64>, /// Describes how to compute the price per period. /// /// Either `per_unit` or `tiered`. /// `per_unit` indicates that the fixed amount (specified in `amount`) will be charged per unit in `quantity` (for plans with `usage_type=licensed`), or per unit of total usage (for plans with `usage_type=metered`). /// `tiered` indicates that the unit pricing will be computed using a tiering strategy as defined using the `tiers` and `tiers_mode` attributes. #[serde(skip_serializing_if = "Option::is_none")] pub billing_scheme: Option<PlanBillingScheme>, /// 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], /// An identifier randomly generated by Stripe. /// /// Used to identify this plan when subscribing a customer. /// You can optionally override this ID, but the ID must be unique across all plans in your Stripe account. /// You can, however, use the same plan ID in both live and test modes. #[serde(skip_serializing_if = "Option::is_none")] pub id: Option<&'a str>, /// Specifies billing frequency. /// /// Either `day`, `week`, `month` or `year`. pub interval: PlanInterval, /// The number of intervals between subscription billings. /// /// For example, `interval=month` and `interval_count=3` bills every 3 months. /// Maximum of one year interval allowed (1 year, 12 months, or 52 weeks). #[serde(skip_serializing_if = "Option::is_none")] pub interval_count: Option<u64>, /// A set of key-value pairs that you can attach to a plan object. /// /// It can be useful for storing additional information about the plan in a structured format. #[serde(skip_serializing_if = "Option::is_none")] pub metadata: Option<Metadata>, /// A brief description of the plan, hidden from customers. #[serde(skip_serializing_if = "Option::is_none")] pub nickname: Option<&'a str>, /// Each element represents a pricing tier. /// /// This parameter requires `billing_scheme` to be set to `tiered`. /// See also the documentation for `billing_scheme`. #[serde(skip_serializing_if = "Option::is_none")] pub tiers: Option<Vec<CreatePlanTiers>>, /// Defines if the tiering price should be `graduated` or `volume` based. /// /// In `volume`-based tiering, the maximum quantity within a period determines the per unit price, in `graduated` tiering pricing can successively change as the quantity grows. #[serde(skip_serializing_if = "Option::is_none")] pub tiers_mode: Option<PlanTiersMode>, /// Apply a transformation to the reported usage or set quantity before computing the billed price. /// /// Cannot be combined with `tiers`. #[serde(skip_serializing_if = "Option::is_none")] pub transform_usage: Option<CreatePlanTransformUsage>, /// Default number of trial days when subscribing a customer to this plan using [`trial_from_plan=true`](https://stripe.com/docs/api#create_subscription-trial_from_plan). #[serde(skip_serializing_if = "Option::is_none")] pub trial_period_days: Option<u32>, /// Configures how the quantity per period should be determined, can be either `metered` or `licensed`. /// /// `licensed` will automatically bill the `quantity` set for a plan when adding it to a subscription, `metered` will aggregate the total usage based on usage records. /// Defaults to `licensed`. #[serde(skip_serializing_if = "Option::is_none")] pub usage_type: Option<PlanUsageType>, } impl<'a> CreatePlan<'a> { pub fn new(currency: Currency, interval: PlanInterval) -> Self { CreatePlan { active: Default::default(), aggregate_usage: Default::default(), amount: Default::default(), billing_scheme: Default::default(), currency, expand: Default::default(), id: Default::default(), interval, interval_count: Default::default(), metadata: Default::default(), nickname: Default::default(), tiers: Default::default(), tiers_mode: Default::default(), transform_usage: Default::default(), trial_period_days: Default::default(), usage_type: Default::default(), } } } /// The parameters for `Plan::list`. #[derive(Clone, Debug, Serialize, Default)] pub struct ListPlans<'a> { /// Only return plans 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>, /// 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. #[serde(skip_serializing_if = "Option::is_none")] pub created: Option<RangeQuery<Timestamp>>, /// 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<PlanId>, /// Specifies which fields in the response should be expanded. #[serde(skip_serializing_if = "Expand::is_empty")] pub expand: &'a [&'a str], /// 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>, /// 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<PlanId>, } impl<'a> ListPlans<'a> { pub fn new() -> Self { ListPlans { active: Default::default(), created: Default::default(), ending_before: Default::default(), expand: Default::default(), limit: Default::default(), starting_after: Default::default(), } } } /// The parameters for `Plan::update`. #[derive(Clone, Debug, Serialize, Default)] pub struct UpdatePlan<'a> { /// Whether the plan is currently available for new subscriptions. #[serde(skip_serializing_if = "Option::is_none")] pub active: Option<bool>, /// Specifies which fields in the response should be expanded. #[serde(skip_serializing_if = "Expand::is_empty")] pub expand: &'a [&'a str], /// A set of key-value pairs that you can attach to a plan object. /// /// It can be useful for storing additional information about the plan in a structured format. #[serde(skip_serializing_if = "Option::is_none")] pub metadata: Option<Metadata>, /// A brief description of the plan, hidden from customers. #[serde(skip_serializing_if = "Option::is_none")] pub nickname: Option<&'a str>, /// Default number of trial days when subscribing a customer to this plan using [`trial_from_plan=true`](https://stripe.com/docs/api#create_subscription-trial_from_plan). #[serde(skip_serializing_if = "Option::is_none")] pub trial_period_days: Option<u32>, } impl<'a> UpdatePlan<'a> { pub fn new() -> Self { UpdatePlan { active: Default::default(), expand: Default::default(), metadata: Default::default(), nickname: Default::default(), trial_period_days: Default::default(), } } } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct CreatePlanTiers { #[serde(skip_serializing_if = "Option::is_none")] pub flat_amount: Option<i64>, #[serde(skip_serializing_if = "Option::is_none")] pub unit_amount: Option<i64>, pub up_to: Option<UpTo>, } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct CreatePlanTransformUsage { pub divide_by: i64, pub round: CreatePlanTransformUsageRound, } /// An enum representing the possible values of an `CreatePlanTransformUsage`'s `round` field. #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum CreatePlanTransformUsageRound { Down, Up, } impl CreatePlanTransformUsageRound { pub fn as_str(self) -> &'static str { match self { CreatePlanTransformUsageRound::Down => "down", CreatePlanTransformUsageRound::Up => "up", } } } impl AsRef<str> for CreatePlanTransformUsageRound { fn as_ref(&self) -> &str { self.as_str() } } impl std::fmt::Display for CreatePlanTransformUsageRound { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.as_str().fmt(f) } } /// An enum representing the possible values of an `Plan`'s `aggregate_usage` field. #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum PlanAggregateUsage { LastDuringPeriod, LastEver, Max, Sum, } impl PlanAggregateUsage { pub fn as_str(self) -> &'static str { match self { PlanAggregateUsage::LastDuringPeriod => "last_during_period", PlanAggregateUsage::LastEver => "last_ever", PlanAggregateUsage::Max => "max", PlanAggregateUsage::Sum => "sum", } } } impl AsRef<str> for PlanAggregateUsage { fn as_ref(&self) -> &str { self.as_str() } } impl std::fmt::Display for PlanAggregateUsage { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.as_str().fmt(f) } } /// An enum representing the possible values of an `Plan`'s `billing_scheme` field. #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum PlanBillingScheme { PerUnit, Tiered, } impl PlanBillingScheme { pub fn as_str(self) -> &'static str { match self { PlanBillingScheme::PerUnit => "per_unit", PlanBillingScheme::Tiered => "tiered", } } } impl AsRef<str> for PlanBillingScheme { fn as_ref(&self) -> &str { self.as_str() } } impl std::fmt::Display for PlanBillingScheme { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.as_str().fmt(f) } } /// An enum representing the possible values of an `Plan`'s `interval` field. #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum PlanInterval { Day, Month, Week, Year, } impl PlanInterval { pub fn as_str(self) -> &'static str { match self { PlanInterval::Day => "day", PlanInterval::Month => "month", PlanInterval::Week => "week", PlanInterval::Year => "year", } } } impl AsRef<str> for PlanInterval { fn as_ref(&self) -> &str { self.as_str() } } impl std::fmt::Display for PlanInterval { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.as_str().fmt(f) } } /// An enum representing the possible values of an `Plan`'s `tiers_mode` field. #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum PlanTiersMode { Graduated, Volume, } impl PlanTiersMode { pub fn as_str(self) -> &'static str { match self { PlanTiersMode::Graduated => "graduated", PlanTiersMode::Volume => "volume", } } } impl AsRef<str> for PlanTiersMode { fn as_ref(&self) -> &str { self.as_str() } } impl std::fmt::Display for PlanTiersMode { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.as_str().fmt(f) } } /// An enum representing the possible values of an `Plan`'s `usage_type` field. #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum PlanUsageType { Licensed, Metered, } impl PlanUsageType { pub fn as_str(self) -> &'static str { match self { PlanUsageType::Licensed => "licensed", PlanUsageType::Metered => "metered", } } } impl AsRef<str> for PlanUsageType { fn as_ref(&self) -> &str { self.as_str() } } impl std::fmt::Display for PlanUsageType { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.as_str().fmt(f) } } /// An enum representing the possible values of an `TransformUsage`'s `round` field. #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum TransformUsageRound { Down, Up, } impl TransformUsageRound { pub fn as_str(self) -> &'static str { match self { TransformUsageRound::Down => "down", TransformUsageRound::Up => "up", } } } impl AsRef<str> for TransformUsageRound { fn as_ref(&self) -> &str { self.as_str() } } impl std::fmt::Display for TransformUsageRound { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.as_str().fmt(f) } }