stripe/resources/generated/quote.rs
1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::client::{Client, Response};
6use crate::ids::{CustomerId, QuoteId};
7use crate::params::{Expand, Expandable, List, Metadata, Object, Paginable, Timestamp};
8use crate::resources::{
9 Account, Application, CheckoutSessionItem, ConnectAccountReference, Currency, Customer,
10 Discount, Invoice, QuotesResourceTotalDetails, Subscription, SubscriptionSchedule, TaxRate,
11 TestHelpersTestClock,
12};
13use serde::{Deserialize, Serialize};
14
15/// The resource representing a Stripe "Quote".
16///
17/// For more details see <https://stripe.com/docs/api/quotes/object>
18#[derive(Clone, Debug, Default, Deserialize, Serialize)]
19pub struct Quote {
20 /// Unique identifier for the object.
21 pub id: QuoteId,
22
23 /// Total before any discounts or taxes are applied.
24 pub amount_subtotal: i64,
25
26 /// Total after discounts and taxes are applied.
27 pub amount_total: i64,
28
29 /// ID of the Connect Application that created the quote.
30 pub application: Option<Expandable<Application>>,
31
32 /// The amount of the application fee (if any) that will be requested to be applied to the payment and transferred to the application owner's Stripe account.
33 ///
34 /// Only applicable if there are no line items with recurring prices on the quote.
35 pub application_fee_amount: Option<i64>,
36
37 /// A non-negative decimal between 0 and 100, with at most two decimal places.
38 ///
39 /// This represents the percentage of the subscription invoice total that will be transferred to the application owner's Stripe account.
40 /// Only applicable if there are line items with recurring prices on the quote.
41 pub application_fee_percent: Option<f64>,
42
43 pub automatic_tax: QuotesResourceAutomaticTax,
44
45 /// Either `charge_automatically`, or `send_invoice`.
46 ///
47 /// When charging automatically, Stripe will attempt to pay invoices at the end of the subscription cycle or on finalization using the default payment method attached to the subscription or customer.
48 /// When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as `active`.
49 /// Defaults to `charge_automatically`.
50 pub collection_method: QuoteCollectionMethod,
51
52 pub computed: QuotesResourceComputed,
53
54 /// Time at which the object was created.
55 ///
56 /// Measured in seconds since the Unix epoch.
57 pub created: Timestamp,
58
59 /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
60 ///
61 /// Must be a [supported currency](https://stripe.com/docs/currencies).
62 pub currency: Option<Currency>,
63
64 /// The customer which this quote belongs to.
65 ///
66 /// A customer is required before finalizing the quote.
67 /// Once specified, it cannot be changed.
68 pub customer: Option<Expandable<Customer>>,
69
70 /// The tax rates applied to this quote.
71 #[serde(skip_serializing_if = "Option::is_none")]
72 pub default_tax_rates: Option<Vec<Expandable<TaxRate>>>,
73
74 /// A description that will be displayed on the quote PDF.
75 pub description: Option<String>,
76
77 /// The discounts applied to this quote.
78 pub discounts: Vec<Expandable<Discount>>,
79
80 /// The date on which the quote will be canceled if in `open` or `draft` status.
81 ///
82 /// Measured in seconds since the Unix epoch.
83 pub expires_at: Timestamp,
84
85 /// A footer that will be displayed on the quote PDF.
86 pub footer: Option<String>,
87
88 /// Details of the quote that was cloned.
89 ///
90 /// See the [cloning documentation](https://stripe.com/docs/quotes/clone) for more details.
91 pub from_quote: Option<QuotesResourceFromQuote>,
92
93 /// A header that will be displayed on the quote PDF.
94 pub header: Option<String>,
95
96 /// The invoice that was created from this quote.
97 pub invoice: Option<Expandable<Invoice>>,
98
99 pub invoice_settings: InvoiceSettingQuoteSetting,
100
101 /// A list of items the customer is being quoted for.
102 #[serde(skip_serializing_if = "Option::is_none")]
103 pub line_items: Option<List<CheckoutSessionItem>>,
104
105 /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
106 pub livemode: bool,
107
108 /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
109 ///
110 /// This can be useful for storing additional information about the object in a structured format.
111 pub metadata: Metadata,
112
113 /// A unique number that identifies this particular quote.
114 ///
115 /// This number is assigned once the quote is [finalized](https://stripe.com/docs/quotes/overview#finalize).
116 pub number: Option<String>,
117
118 /// The account on behalf of which to charge.
119 ///
120 /// See the [Connect documentation](https://support.stripe.com/questions/sending-invoices-on-behalf-of-connected-accounts) for details.
121 pub on_behalf_of: Option<Expandable<Account>>,
122
123 /// The status of the quote.
124 pub status: QuoteStatus,
125
126 pub status_transitions: QuotesResourceStatusTransitions,
127
128 /// The subscription that was created or updated from this quote.
129 pub subscription: Option<Expandable<Subscription>>,
130
131 pub subscription_data: QuotesResourceSubscriptionDataSubscriptionData,
132
133 /// The subscription schedule that was created or updated from this quote.
134 pub subscription_schedule: Option<Expandable<SubscriptionSchedule>>,
135
136 /// ID of the test clock this quote belongs to.
137 pub test_clock: Option<Expandable<TestHelpersTestClock>>,
138
139 pub total_details: QuotesResourceTotalDetails,
140
141 /// The account (if any) the payments will be attributed to for tax reporting, and where funds from each payment will be transferred to for each of the invoices.
142 pub transfer_data: Option<QuotesResourceTransferData>,
143}
144
145impl Quote {
146 /// Returns a list of your quotes.
147 pub fn list(client: &Client, params: &ListQuotes<'_>) -> Response<List<Quote>> {
148 client.get_query("/quotes", params)
149 }
150
151 /// Retrieves the quote with the given ID.
152 pub fn retrieve(client: &Client, id: &QuoteId, expand: &[&str]) -> Response<Quote> {
153 client.get_query(&format!("/quotes/{}", id), Expand { expand })
154 }
155}
156
157impl Object for Quote {
158 type Id = QuoteId;
159 fn id(&self) -> Self::Id {
160 self.id.clone()
161 }
162 fn object(&self) -> &'static str {
163 "quote"
164 }
165}
166
167#[derive(Clone, Debug, Default, Deserialize, Serialize)]
168pub struct InvoiceSettingQuoteSetting {
169 /// Number of days within which a customer must pay invoices generated by this quote.
170 ///
171 /// This value will be `null` for quotes where `collection_method=charge_automatically`.
172 pub days_until_due: Option<u32>,
173
174 pub issuer: ConnectAccountReference,
175}
176
177#[derive(Clone, Debug, Default, Deserialize, Serialize)]
178pub struct QuotesResourceAutomaticTax {
179 /// Automatically calculate taxes.
180 pub enabled: bool,
181
182 /// The account that's liable for tax.
183 ///
184 /// If set, the business address and tax registrations required to perform the tax calculation are loaded from this account.
185 /// The tax transaction is returned in the report of the connected account.
186 pub liability: Option<ConnectAccountReference>,
187
188 /// The status of the most recent automated tax calculation for this quote.
189 pub status: Option<QuotesResourceAutomaticTaxStatus>,
190}
191
192#[derive(Clone, Debug, Default, Deserialize, Serialize)]
193pub struct QuotesResourceComputed {
194 /// The definitive totals and line items the customer will be charged on a recurring basis.
195 ///
196 /// Takes into account the line items with recurring prices and discounts with `duration=forever` coupons only.
197 /// Defaults to `null` if no inputted line items with recurring prices.
198 pub recurring: Option<QuotesResourceRecurring>,
199
200 pub upfront: QuotesResourceUpfront,
201}
202
203#[derive(Clone, Debug, Default, Deserialize, Serialize)]
204pub struct QuotesResourceFromQuote {
205 /// Whether this quote is a revision of a different quote.
206 pub is_revision: bool,
207
208 /// The quote that was cloned.
209 pub quote: Expandable<Quote>,
210}
211
212#[derive(Clone, Debug, Default, Deserialize, Serialize)]
213pub struct QuotesResourceRecurring {
214 /// Total before any discounts or taxes are applied.
215 pub amount_subtotal: i64,
216
217 /// Total after discounts and taxes are applied.
218 pub amount_total: i64,
219
220 /// The frequency at which a subscription is billed.
221 ///
222 /// One of `day`, `week`, `month` or `year`.
223 pub interval: QuotesResourceRecurringInterval,
224
225 /// The number of intervals (specified in the `interval` attribute) between subscription billings.
226 ///
227 /// For example, `interval=month` and `interval_count=3` bills every 3 months.
228 pub interval_count: u64,
229
230 pub total_details: QuotesResourceTotalDetails,
231}
232
233#[derive(Clone, Debug, Default, Deserialize, Serialize)]
234pub struct QuotesResourceStatusTransitions {
235 /// The time that the quote was accepted.
236 ///
237 /// Measured in seconds since Unix epoch.
238 pub accepted_at: Option<Timestamp>,
239
240 /// The time that the quote was canceled.
241 ///
242 /// Measured in seconds since Unix epoch.
243 pub canceled_at: Option<Timestamp>,
244
245 /// The time that the quote was finalized.
246 ///
247 /// Measured in seconds since Unix epoch.
248 pub finalized_at: Option<Timestamp>,
249}
250
251#[derive(Clone, Debug, Default, Deserialize, Serialize)]
252pub struct QuotesResourceSubscriptionDataSubscriptionData {
253 /// The subscription's description, meant to be displayable to the customer.
254 ///
255 /// Use this field to optionally store an explanation of the subscription for rendering in Stripe surfaces and certain local payment methods UIs.
256 pub description: Option<String>,
257
258 /// When creating a new subscription, the date of which the subscription schedule will start after the quote is accepted.
259 ///
260 /// This date is ignored if it is in the past when the quote is accepted.
261 /// Measured in seconds since the Unix epoch.
262 pub effective_date: Option<Timestamp>,
263
264 /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that will set metadata on the subscription or subscription schedule when the quote is accepted.
265 ///
266 /// If a recurring price is included in `line_items`, this field will be passed to the resulting subscription's `metadata` field.
267 /// If `subscription_data.effective_date` is used, this field will be passed to the resulting subscription schedule's `phases.metadata` field.
268 /// Unlike object-level metadata, this field is declarative.
269 /// Updates will clear prior values.
270 pub metadata: Option<Metadata>,
271
272 /// Integer representing the number of trial period days before the customer is charged for the first time.
273 pub trial_period_days: Option<u32>,
274}
275
276#[derive(Clone, Debug, Default, Deserialize, Serialize)]
277pub struct QuotesResourceTransferData {
278 /// The amount in cents (or local equivalent) that will be transferred to the destination account when the invoice is paid.
279 ///
280 /// By default, the entire amount is transferred to the destination.
281 pub amount: Option<i64>,
282
283 /// A non-negative decimal between 0 and 100, with at most two decimal places.
284 ///
285 /// This represents the percentage of the subscription invoice total that will be transferred to the destination account.
286 /// By default, the entire amount will be transferred to the destination.
287 pub amount_percent: Option<f64>,
288
289 /// The account where funds from the payment will be transferred to upon payment success.
290 pub destination: Expandable<Account>,
291}
292
293#[derive(Clone, Debug, Default, Deserialize, Serialize)]
294pub struct QuotesResourceUpfront {
295 /// Total before any discounts or taxes are applied.
296 pub amount_subtotal: i64,
297
298 /// Total after discounts and taxes are applied.
299 pub amount_total: i64,
300
301 /// The line items that will appear on the next invoice after this quote is accepted.
302 ///
303 /// This does not include pending invoice items that exist on the customer but may still be included in the next invoice.
304 #[serde(skip_serializing_if = "Option::is_none")]
305 pub line_items: Option<List<CheckoutSessionItem>>,
306
307 pub total_details: QuotesResourceTotalDetails,
308}
309
310/// The parameters for `Quote::list`.
311#[derive(Clone, Debug, Serialize, Default)]
312pub struct ListQuotes<'a> {
313 /// The ID of the customer whose quotes will be retrieved.
314 #[serde(skip_serializing_if = "Option::is_none")]
315 pub customer: Option<CustomerId>,
316
317 /// A cursor for use in pagination.
318 ///
319 /// `ending_before` is an object ID that defines your place in the list.
320 /// 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.
321 #[serde(skip_serializing_if = "Option::is_none")]
322 pub ending_before: Option<QuoteId>,
323
324 /// Specifies which fields in the response should be expanded.
325 #[serde(skip_serializing_if = "Expand::is_empty")]
326 pub expand: &'a [&'a str],
327
328 /// A limit on the number of objects to be returned.
329 ///
330 /// Limit can range between 1 and 100, and the default is 10.
331 #[serde(skip_serializing_if = "Option::is_none")]
332 pub limit: Option<u64>,
333
334 /// A cursor for use in pagination.
335 ///
336 /// `starting_after` is an object ID that defines your place in the list.
337 /// 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.
338 #[serde(skip_serializing_if = "Option::is_none")]
339 pub starting_after: Option<QuoteId>,
340
341 /// The status of the quote.
342 #[serde(skip_serializing_if = "Option::is_none")]
343 pub status: Option<QuoteStatus>,
344
345 /// Provides a list of quotes that are associated with the specified test clock.
346 ///
347 /// The response will not include quotes with test clocks if this and the customer parameter is not set.
348 #[serde(skip_serializing_if = "Option::is_none")]
349 pub test_clock: Option<&'a str>,
350}
351
352impl<'a> ListQuotes<'a> {
353 pub fn new() -> Self {
354 ListQuotes {
355 customer: Default::default(),
356 ending_before: Default::default(),
357 expand: Default::default(),
358 limit: Default::default(),
359 starting_after: Default::default(),
360 status: Default::default(),
361 test_clock: Default::default(),
362 }
363 }
364}
365impl Paginable for ListQuotes<'_> {
366 type O = Quote;
367 fn set_last(&mut self, item: Self::O) {
368 self.starting_after = Some(item.id());
369 }
370}
371/// An enum representing the possible values of an `Quote`'s `collection_method` field.
372#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
373#[serde(rename_all = "snake_case")]
374pub enum QuoteCollectionMethod {
375 ChargeAutomatically,
376 SendInvoice,
377}
378
379impl QuoteCollectionMethod {
380 pub fn as_str(self) -> &'static str {
381 match self {
382 QuoteCollectionMethod::ChargeAutomatically => "charge_automatically",
383 QuoteCollectionMethod::SendInvoice => "send_invoice",
384 }
385 }
386}
387
388impl AsRef<str> for QuoteCollectionMethod {
389 fn as_ref(&self) -> &str {
390 self.as_str()
391 }
392}
393
394impl std::fmt::Display for QuoteCollectionMethod {
395 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
396 self.as_str().fmt(f)
397 }
398}
399impl std::default::Default for QuoteCollectionMethod {
400 fn default() -> Self {
401 Self::ChargeAutomatically
402 }
403}
404
405/// An enum representing the possible values of an `Quote`'s `status` field.
406#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
407#[serde(rename_all = "snake_case")]
408pub enum QuoteStatus {
409 Accepted,
410 Canceled,
411 Draft,
412 Open,
413}
414
415impl QuoteStatus {
416 pub fn as_str(self) -> &'static str {
417 match self {
418 QuoteStatus::Accepted => "accepted",
419 QuoteStatus::Canceled => "canceled",
420 QuoteStatus::Draft => "draft",
421 QuoteStatus::Open => "open",
422 }
423 }
424}
425
426impl AsRef<str> for QuoteStatus {
427 fn as_ref(&self) -> &str {
428 self.as_str()
429 }
430}
431
432impl std::fmt::Display for QuoteStatus {
433 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
434 self.as_str().fmt(f)
435 }
436}
437impl std::default::Default for QuoteStatus {
438 fn default() -> Self {
439 Self::Accepted
440 }
441}
442
443/// An enum representing the possible values of an `QuotesResourceAutomaticTax`'s `status` field.
444#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
445#[serde(rename_all = "snake_case")]
446pub enum QuotesResourceAutomaticTaxStatus {
447 Complete,
448 Failed,
449 RequiresLocationInputs,
450}
451
452impl QuotesResourceAutomaticTaxStatus {
453 pub fn as_str(self) -> &'static str {
454 match self {
455 QuotesResourceAutomaticTaxStatus::Complete => "complete",
456 QuotesResourceAutomaticTaxStatus::Failed => "failed",
457 QuotesResourceAutomaticTaxStatus::RequiresLocationInputs => "requires_location_inputs",
458 }
459 }
460}
461
462impl AsRef<str> for QuotesResourceAutomaticTaxStatus {
463 fn as_ref(&self) -> &str {
464 self.as_str()
465 }
466}
467
468impl std::fmt::Display for QuotesResourceAutomaticTaxStatus {
469 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
470 self.as_str().fmt(f)
471 }
472}
473impl std::default::Default for QuotesResourceAutomaticTaxStatus {
474 fn default() -> Self {
475 Self::Complete
476 }
477}
478
479/// An enum representing the possible values of an `QuotesResourceRecurring`'s `interval` field.
480#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
481#[serde(rename_all = "snake_case")]
482pub enum QuotesResourceRecurringInterval {
483 Day,
484 Month,
485 Week,
486 Year,
487}
488
489impl QuotesResourceRecurringInterval {
490 pub fn as_str(self) -> &'static str {
491 match self {
492 QuotesResourceRecurringInterval::Day => "day",
493 QuotesResourceRecurringInterval::Month => "month",
494 QuotesResourceRecurringInterval::Week => "week",
495 QuotesResourceRecurringInterval::Year => "year",
496 }
497 }
498}
499
500impl AsRef<str> for QuotesResourceRecurringInterval {
501 fn as_ref(&self) -> &str {
502 self.as_str()
503 }
504}
505
506impl std::fmt::Display for QuotesResourceRecurringInterval {
507 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
508 self.as_str().fmt(f)
509 }
510}
511impl std::default::Default for QuotesResourceRecurringInterval {
512 fn default() -> Self {
513 Self::Day
514 }
515}