polar_rs/models.rs
1use std::collections::HashMap;
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6use url::Url;
7use uuid::Uuid;
8
9use crate::enums::*;
10
11#[derive(Deserialize)]
12pub struct AttachedCustomField {
13 /// ID of the custom field.
14 pub custom_field_id: Uuid,
15 /// Schema for a custom field of type text.
16 pub custom_field: CustomField,
17 /// Order of the custom field in the resource.
18 pub order: usize,
19 /// Whether the value is required for this custom field.
20 pub required: bool,
21}
22
23#[derive(Deserialize, Serialize)]
24pub struct AttachedCustomFieldParams {
25 /// ID of the custom field.
26 pub custom_field_id: Uuid,
27 /// Whether the value is required for this custom field.
28 pub required: bool,
29}
30
31#[derive(Deserialize)]
32pub struct Benefit {
33 /// The ID of the benefit.
34 pub id: Uuid,
35 /// Creation timestamp of the object.
36 pub created_at: DateTime<Utc>,
37 /// Last modification timestamp of the object.
38 pub modified_at: Option<DateTime<Utc>>,
39 /// The type of the benefit.
40 pub r#type: BenefitType,
41 /// The description of the benefit.
42 pub description: String,
43 /// Whether the benefit is selectable when creating a product.
44 pub selectable: bool,
45 /// Whether the benefit is deletable.
46 pub deletable: bool,
47 /// The ID of the organization owning the benefit.
48 pub organization_id: Uuid,
49}
50
51#[derive(Deserialize)]
52pub struct BillingAddressFields {
53 pub country: BillingAddressField,
54 pub state: BillingAddressField,
55 pub city: BillingAddressField,
56 pub postal_code: BillingAddressField,
57 pub line1: BillingAddressField,
58 pub line2: BillingAddressField,
59}
60
61#[derive(Deserialize)]
62pub struct CheckoutProduct {
63 /// Creation timestamp of the object.
64 pub created_at: DateTime<Utc>,
65 /// Last modification timestamp of the object.
66 pub modified_at: Option<DateTime<Utc>>,
67 /// The ID of the product.
68 pub id: Uuid,
69 /// The name of the product.
70 pub name: String,
71 /// The description of the product.
72 pub description: Option<String>,
73 /// The recurring interval of the product. If `None`, the product is a one-time purchase.
74 pub recurring_interval: Option<RecurringInterval>,
75 /// Whether the product is a subscription.
76 pub is_recurring: bool,
77 /// Whether the product is archived and no longer available.
78 pub is_archived: bool,
79 /// The ID of the organization owning the product.
80 pub organization_id: Uuid,
81 /// List of prices for this product.
82 pub prices: Vec<Price>,
83 /// List of benefits granted by the product.
84 pub benefits: Vec<Benefit>,
85 /// List of medias associated to the product.
86 pub medias: Vec<Media>,
87}
88
89#[derive(Deserialize)]
90pub struct CheckoutSession {
91 /// Creation timestamp of the object.
92 pub created_at: DateTime<Utc>,
93 /// Last modification timestamp of the object.
94 pub modified_at: Option<DateTime<Utc>>,
95 /// The ID of the object.
96 pub id: Uuid,
97 /// Payment processor used.
98 pub payment_processor: PaymentProcessor,
99 /// Status of the checkout session.
100 pub status: CheckoutSessionStatus,
101 /// Client secret used to update and complete the checkout session from the client.
102 pub client_secret: String,
103 /// URL where the customer can access the checkout session.
104 pub url: Url,
105 /// Expiration date and time of the checkout session.
106 pub expires_at: DateTime<Utc>,
107 // URL where the customer will be redirected after a successful payment.
108 pub success_url: Url,
109 /// When checkout is embedded, represents the Origin of the page embedding the checkout. Used as a security measure to send messages only to the embedding page.
110 pub embed_origin: Option<String>,
111 /// Amount in cents, before discounts and taxes.
112 pub amount: u32,
113 /// Discount amount in cents.
114 pub discount_amount: u32,
115 /// Amount in cents, after discounts but before taxes.
116 pub net_amount: u32,
117 /// Sales tax amount in cents. If `null`, it means there is no enough information yet to calculate it.
118 pub tax_amount: Option<u32>,
119 /// Amount in cents, after discounts and taxes.
120 pub total_amount: u32,
121 /// Currency code of the checkout session.
122 pub currency: String,
123 /// ID of the product to checkout.
124 pub product_id: Uuid,
125 /// ID of the product price to checkout.
126 pub product_price_id: Uuid,
127 /// ID of the discount applied to the checkout.
128 pub discount_id: Option<Uuid>,
129 /// Whether to allow the customer to apply discount codes. If you apply a discount through `discount_id`, it'll still be applied, but the customer won't be able to change it.
130 pub allow_discount_codes: bool,
131 /// Whether to require the customer to fill their full billing address, instead of just the country. Customers in the US will always be required to fill their full address, regardless of this setting. If you preset the billing address, this setting will be automatically set to `true`.
132 pub require_billing_address: bool,
133 /// Whether the discount is applicable to the checkout. Typically, free and custom prices are not discountable.
134 pub is_discount_applicable: bool,
135 /// Whether the product price is free, regardless of discounts.
136 pub is_free_product_price: bool,
137 /// Whether the checkout requires payment, e.g. in case of free products or discounts that cover the total amount.
138 pub is_payment_required: bool,
139 /// Whether the checkout requires setting up a payment method, regardless of the amount, e.g. subscriptions that have first free cycles.
140 pub is_payment_setup_required: bool,
141 /// Whether the checkout requires a payment form, whether because of a payment or payment method setup.
142 pub is_payment_form_required: bool,
143 pub customer_id: Option<Uuid>,
144 /// Whether the customer is a business or an individual. If `true`, the customer will be required to fill their full billing address and billing name.
145 pub is_business_customer: bool,
146 /// Name of the customer.
147 pub customer_name: Option<String>,
148 /// Email address of the customer.
149 pub customer_email: Option<String>,
150 pub customer_ip_address: Option<String>,
151 pub customer_billing_name: Option<String>,
152 /// Billing address of the customer.
153 pub customer_billing_address: Option<CustomerBillingAddress>,
154 pub customer_tax_id: Option<String>,
155 pub payment_processor_metadata: HashMap<String, String>,
156 /// Determine which billing address fields should be disabled, optional or required in the checkout form.
157 pub billing_address_fields: BillingAddressFields,
158 pub metadata: HashMap<String, String>,
159 pub external_customer_id: Option<String>,
160 /// List of products available to select.
161 pub products: Vec<CheckoutProduct>,
162 /// Product selected to checkout.
163 pub product: CheckoutProduct,
164 /// Price of the selected product.
165 pub product_price: Price,
166 /// Schema for a percentage discount that is applied on every invoice for a certain number of months.
167 pub discount: Option<Discount>,
168 pub subscription_id: Option<Uuid>,
169 pub attached_custom_fields: Vec<AttachedCustomField>,
170 pub customer_metadata: HashMap<String, String>,
171 pub custom_field_data: HashMap<String, Option<String>>,
172}
173
174#[derive(Default, Deserialize, Serialize)]
175pub struct CheckoutSessionParams {
176 /// List of product IDs available to select at that checkout. The first one will be selected by default.
177 pub products: Vec<Uuid>,
178 /// Key-value object allowing you to store additional information.
179 pub metadata: HashMap<String, String>,
180 /// Key-value object storing custom field values.
181 pub custom_field_data: HashMap<String, String>,
182 /// ID of the discount to apply to the checkout.
183 pub discount_id: Option<Uuid>,
184 /// Whether to allow the customer to apply discount codes. If you apply a discount through `discount_id`, it'll still be applied, but the customer won't be able to change it.
185 pub allow_discount_codes: bool,
186 /// Whether to require the customer to fill their full billing address, instead of just the country. Customers in the US will always be required to fill their full address, regardless of this setting. If you preset the billing address, this setting will be automatically set to `true`.
187 pub require_billing_address: bool,
188 /// Amount in cents, before discounts and taxes. Only useful for custom prices, it'll be ignored for fixed and free prices.
189 pub amount: Option<u32>,
190 /// ID of an existing customer in the organization. The customer data will be pre-filled in the checkout form. The resulting order will be linked to this customer.
191 pub customer_id: Option<Uuid>,
192 /// Whether the customer is a business or an individual. If `true`, the customer will be required to fill their full billing address and billing name.
193 pub is_business_customer: bool,
194 /// ID of the customer in your system. If a matching customer exists on Polar, the resulting order will be linked to this customer. Otherwise, a new customer will be created with this external ID set.
195 pub external_customer_id: Option<String>,
196 /// Name of the customer.
197 pub customer_name: Option<String>,
198 /// Email address of the customer.
199 pub customer_email: Option<String>,
200 pub customer_ip_address: Option<String>,
201 pub customer_billing_name: Option<String>,
202 /// Billing address of the customer.
203 pub customer_billing_address: Option<CustomerBillingAddressParams>,
204 pub customer_tax_id: Option<String>,
205 /// Key-value object allowing you to store additional information that'll be copied to the created customer.
206 pub customer_metadata: HashMap<String, String>,
207 /// ID of a subscription to upgrade. It must be on a free pricing. If checkout is successful, metadata set on this checkout will be copied to the subscription, and existing keys will be overwritten.
208 pub subscription_id: Option<Uuid>,
209 ///URL where the customer will be redirected after a successful payment.You can add the `checkout_id={CHECKOUT_ID}` query parameter to retrieve the checkout session id.
210 pub success_url: Option<Url>,
211 /// If you plan to embed the checkout session, set this to the Origin of the embedding page. It'll allow the Polar iframe to communicate with the parent page.
212 pub embed_origin: Option<String>,
213}
214
215#[derive(Deserialize)]
216pub struct CustomField {
217 /// Creation timestamp of the object.
218 pub created_at: DateTime<Utc>,
219 /// Last modification timestamp of the object.
220 pub modified_at: Option<DateTime<Utc>>,
221 /// The ID of the object.
222 pub id: Uuid,
223 pub metadata: HashMap<String, String>,
224 pub r#type: CustomFieldType,
225 /// Identifier of the custom field. It'll be used as key when storing the value.
226 pub slug: String,
227 /// Name of the custom field.
228 pub name: String,
229 /// The ID of the organization owning the custom field.
230 pub organization_id: Uuid,
231 pub properties: CustomFieldProperties,
232}
233
234#[derive(Deserialize)]
235pub struct CustomFieldOption {
236 /// Minimum length: `1`
237 pub value: String,
238 /// Minimum length: `1`
239 pub label: String,
240}
241
242#[derive(Deserialize)]
243pub struct CustomFieldProperties {
244 /// Minimum length: `1`
245 pub form_label: String,
246 /// Minimum length: `1`
247 pub form_help_text: String,
248 /// Minimum length: `1`
249 pub form_placeholder: String,
250 pub textarea: Option<bool>,
251 /// Required range: `x >= 0`
252 pub min_length: Option<usize>,
253 /// Required range: `x >= 0`
254 pub max_length: Option<usize>,
255 pub ge: Option<usize>,
256 pub le: Option<usize>,
257 pub options: Option<Vec<CustomFieldOption>>,
258}
259
260#[derive(Deserialize)]
261pub struct Customer {
262 /// The ID of the customer.
263 pub id: Uuid,
264 /// Creation timestamp of the object.
265 pub created_at: DateTime<Utc>,
266 /// Last modification timestamp of the object.
267 pub modified_at: Option<DateTime<Utc>>,
268 pub metadata: HashMap<String, String>,
269 /// The ID of the customer in your system. This must be unique within the organization. Once set, it can't be updated.
270 pub external_id: Option<String>,
271 /// The email address of the customer. This must be unique within the organization.
272 pub email: String,
273 /// Whether the customer email address is verified. The address is automatically verified when the customer accesses the customer portal using their email address.
274 pub email_verified: bool,
275 /// The name of the customer.
276 pub name: Option<String>,
277 pub billing_address: Option<CustomerBillingAddress>,
278 /// Required array length: 2 elements
279 pub tax_id: Option<Vec<String>>,
280 /// The ID of the organization owning the customer.
281 pub organization_id: Uuid,
282 /// Timestamp for when the customer was soft deleted.
283 pub deleted_at: Option<DateTime<Utc>>,
284 pub avatar_url: String,
285}
286
287#[derive(Deserialize, Serialize)]
288pub struct CustomerBillingAddress {
289 /// Examples: `"US"` `"SE"` `"FR"`
290 country: String,
291 line1: Option<String>,
292 line2: Option<String>,
293 postal_code: Option<String>,
294 city: Option<String>,
295 state: Option<String>,
296}
297
298pub type CustomerBillingAddressParams = CustomerBillingAddress;
299
300#[derive(Deserialize)]
301pub struct Discount {
302 pub duration: DiscountDuration,
303 pub duration_in_months: Option<usize>,
304 pub r#type: DiscountType,
305 pub amount: Option<u32>,
306 pub currency: Option<String>,
307 pub basis_points: Option<usize>,
308 /// The ID of the object.
309 pub id: Uuid,
310 pub name: String,
311 pub code: Option<String>,
312}
313
314#[derive(Deserialize)]
315pub struct Event {
316 // The ID of the object.
317 pub id: Uuid,
318 // The timestamp of the event.
319 pub timestamp: DateTime<Utc>,
320 // The ID of the organization owning the event.
321 pub organization_id: Uuid,
322 // ID of the customer in your Polar organization associated with the event.
323 pub customer_id: Option<Uuid>,
324 // The customer associated with the event. A customer in an organization.
325 pub customer: Option<Customer>,
326 // ID of the customer in your system associated with the event.
327 pub external_customer_id: Option<String>,
328 // The source of the event. `system` events are created by Polar. `user` events are the one you create through our ingestion API.
329 pub source: String,
330 // The name of the event.
331 pub name: String,
332 pub metadata: HashMap<String, Value>,
333}
334
335#[derive(Serialize)]
336pub struct EventParams {
337 /// The name of the event.
338 pub name: String,
339 /// ID of the customer in your Polar organization associated with the event.
340 pub customer_id: Option<Uuid>,
341 /// Key-value object allowing you to store additional information.
342 pub metadata: HashMap<String, String>,
343 /// The timestamp of the event.
344 pub timestamp: DateTime<Utc>,
345 /// The ID of the organization owning the event. **Required unless you use an organization token.**
346 pub organization_id: Option<Uuid>,
347}
348
349#[derive(Default, Serialize)]
350pub struct ListCheckoutSessionsParams {
351 /// Filter by organization ID.
352 pub organization_id: Option<Vec<Uuid>>,
353 /// Filter by product ID.
354 pub product_id: Option<Vec<Uuid>>,
355 /// Filter by customer ID.
356 pub customer_id: Option<Vec<Uuid>>,
357 /// Filter by checkout session status.
358 pub status: Option<CheckoutSessionStatus>,
359 /// Filter by customer email.
360 pub query: Option<String>,
361 /// Page number, defaults to 1.
362 ///
363 /// Required range: `x > 0`
364 pub page: Option<usize>,
365 /// Size of a page, defaults to 10. Maximum is 100.
366 ///
367 /// Required range: `x > 0`
368 pub limit: Option<u8>,
369 /// Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign - before the criteria name to sort by descending order.
370 pub sorting: Option<Vec<CheckoutSessionsSorting>>,
371}
372
373#[derive(Default, Serialize)]
374pub struct ListMetersParams {
375 /// Filter by organization ID.
376 pub organization_id: Option<Vec<Uuid>>,
377 /// Filter by name.
378 pub query: Option<String>,
379 /// Page number, defaults to 1.
380 ///
381 /// Required range: `x > 0`
382 pub page: Option<usize>,
383 /// Size of a page, defaults to 10. Maximum is 100.
384 ///
385 /// Required range: `x > 0`
386 pub limit: Option<u8>,
387 /// Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign - before the criteria name to sort by descending order.
388 pub sorting: Option<Vec<MetersSorting>>,
389 /// Filter by metadata key-value pairs.
390 pub metadata: Option<HashMap<String, String>>,
391}
392
393#[derive(Default, Serialize)]
394pub struct ListProductsParams {
395 /// Filter by product ID.
396 pub id: Option<Vec<Uuid>>,
397 /// Filter by organization ID.
398 pub organization_id: Option<Vec<Uuid>>,
399 /// Filter by product name.
400 pub query: Option<String>,
401 /// Filter on archived products.
402 pub is_archived: Option<bool>,
403 /// Filter on recurring products. If `true`, only subscriptions tiers are returned. If `false`, only one-time purchase products are returned.
404 pub is_recurring: Option<bool>,
405 /// Filter products granting specific benefit.
406 pub benefit_id: Option<Vec<Uuid>>,
407 /// Page number, defaults to 1.
408 ///
409 /// Required range: `x > 0`
410 pub page: Option<usize>,
411 /// Size of a page, defaults to 10. Maximum is 100.
412 ///
413 /// Required range: `x > 0`
414 pub limit: Option<u8>,
415 /// Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign - before the criteria name to sort by descending order.
416 pub sorting: Option<Vec<ProductsSorting>>,
417 /// Filter by metadata key-value pairs.
418 pub metadata: Option<HashMap<String, String>>,
419}
420
421#[derive(Default, Serialize)]
422pub struct ListSubscriptionsParams {
423 /// Filter by organization ID.
424 pub organization_id: Option<Vec<Uuid>>,
425 /// Filter by product ID.
426 pub product_id: Option<Vec<Uuid>>,
427 /// Filter by customer ID.
428 pub customer_id: Option<Vec<Uuid>>,
429 /// Filter by customer external ID.
430 pub external_customer_id: Option<Vec<String>>,
431 /// Filter by discount ID.
432 pub discount_id: Option<Vec<Uuid>>,
433 /// Filter by active or inactive subscription.
434 pub active: Option<bool>,
435 /// Page number, defaults to 1.
436 ///
437 /// Required range: `x > 0`
438 pub page: Option<usize>,
439 /// Size of a page, defaults to 10. Maximum is 100.
440 ///
441 /// Required range: `x > 0`
442 pub limit: Option<u8>,
443 /// Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign - before the criteria name to sort by descending order.
444 pub sorting: Option<Vec<SubscriptionsSorting>>,
445 /// Filter by metadata key-value pairs.
446 pub metadata: Option<HashMap<String, String>>,
447}
448
449#[derive(Deserialize)]
450pub struct Media {
451 /// The ID of the object.
452 pub id: Uuid,
453 pub organization_id: Uuid,
454 pub name: String,
455 pub path: String,
456 pub mime_type: String,
457 pub size: u64,
458 pub storage_version: Option<String>,
459 pub checksum_etag: Option<String>,
460 pub checksum_sha256_base64: Option<String>,
461 pub checksum_sha256_hex: Option<String>,
462 pub last_modified_at: Option<DateTime<Utc>>,
463 pub version: Option<String>,
464 pub service: String,
465 pub is_uploaded: bool,
466 pub created_at: DateTime<Utc>,
467 pub size_readable: String,
468 pub public_url: Url,
469}
470
471#[derive(Deserialize)]
472pub struct Meter {
473 pub metadata: HashMap<String, String>,
474 /// Creation timestamp of the object.
475 pub created_at: DateTime<Utc>,
476 /// Last modification timestamp of the object.
477 pub modified_at: Option<DateTime<Utc>>,
478 /// The ID of the object.
479 pub id: Uuid,
480 /// The name of the meter. Will be shown on customer's invoices and usage.
481 pub name: String,
482 /// The filter to apply on events that'll be used to calculate the meter.
483 pub filter: MeterFilter,
484 /// The aggregation to apply on the filtered events to calculate the meter.
485 pub aggregation: MeterAggregation,
486 /// The ID of the organization owning the meter.
487 pub organization_id: Uuid,
488}
489
490#[derive(Deserialize, Serialize)]
491pub struct MeterAggregation {
492 pub func: MeterAggregationFunc,
493 pub property: Option<String>,
494}
495
496#[derive(Deserialize, Serialize)]
497pub struct MeterFilter {
498 pub conjunction: MeterFilterConjunction,
499 pub clauses: Vec<MeterFilterClause>,
500}
501
502#[derive(Deserialize, Serialize)]
503pub struct MeterFilterClause {
504 pub property: Option<String>,
505 pub operator: Option<MeterFilterOperator>,
506 pub value: Option<String>,
507 pub conjunction: Option<MeterFilterConjunction>,
508 pub clauses: Option<Vec<MeterFilterClause>>,
509}
510
511#[derive(Deserialize, Serialize)]
512pub struct MeterParams {
513 /// The name of the meter. Will be shown on customer's invoices and usage.
514 ///
515 /// Minimum length: `3`
516 pub name: String,
517 /// The filter to apply on events that'll be used to calculate the meter.
518 pub filter: MeterFilter,
519 /// The aggregation to apply on the filtered events to calculate the meter.
520 pub aggregation: MeterAggregation,
521 /// Key-value object allowing you to store additional information.
522 pub metadata: HashMap<String, String>,
523 /// The ID of the organization owning the meter. **Required unless you use an organization token**.
524 pub organization_id: Option<Uuid>,
525}
526
527#[derive(Deserialize)]
528pub struct MeterQuantities {
529 pub quantities: Vec<MeterQuantity>,
530 /// The total quantity for the period.
531 pub total: usize,
532}
533
534#[derive(Default, Serialize)]
535pub struct MeterQuantitiesParams {
536 /// Start timestamp.
537 pub start_timestamp: Option<DateTime<Utc>>,
538 /// End timestamp.
539 pub end_timestamp: Option<DateTime<Utc>>,
540 //// Interval between two timestamps.
541 pub interval: Option<Interval>,
542 /// Filter by customer ID.
543 pub customer_id: Option<Vec<Uuid>>,
544 /// Filter by external customer ID.
545 pub external_customer_id: Option<Vec<String>>,
546 /// Filter by metadata key-value pairs.
547 pub metadata: Option<HashMap<String, String>>,
548}
549
550#[derive(Deserialize)]
551pub struct MeterQuantity {
552 /// The timestamp for the current period.
553 pub timestamp: DateTime<Utc>,
554 /// The quantity for the current period.
555 pub quantity: usize,
556}
557
558#[derive(Deserialize)]
559pub struct Page<T> {
560 pub items: Vec<T>,
561 pub pagination: Pagination,
562}
563
564#[derive(Deserialize)]
565pub struct Pagination {
566 pub total_count: usize,
567 pub max_page: usize,
568}
569
570#[derive(Deserialize)]
571pub struct Price {
572 /// Creation timestamp of the object.
573 pub created_at: DateTime<Utc>,
574 /// Last modification timestamp of the object.
575 pub modified_at: Option<DateTime<Utc>>,
576 /// The ID of the price.
577 pub id: Uuid,
578 pub amount_type: AmountType,
579 /// Whether the price is archived and no longer available.
580 pub is_archived: bool,
581 /// The ID of the product owning the price.
582 pub product_id: Uuid,
583 pub r#type: PriceType,
584 /// The currency. Not required for `amount_type: Free`.
585 pub price_currency: Option<String>,
586 /// The price in cents. Only for `amount_type: Fixed`.
587 pub price_amount: Option<u32>,
588 /// The minimum amount the customer can pay. Only for `amount_type: Custom`.
589 pub minimum_amount: Option<u32>,
590 /// The maximum amount the customer can pay. Only for `amount_type: Custom`.
591 pub maximum_amount: Option<u32>,
592 /// The initial amount shown to the customer. Only for `amount_type: Custom`.
593 pub preset_amount: Option<u32>,
594 /// The price per unit in cents. Only for `amount_type: MeteredUnit`.
595 pub unit_amount: Option<String>,
596 /// The maximum amount in cents that can be charged, regardless of the number of units consumed. Only for `amount_type: MeteredUnit`.
597 pub cap_amount: Option<u32>,
598 /// The ID of the meter associated to the price. Only for `amount_type: MeteredUnit`.
599 pub meter_id: Option<Uuid>,
600 /// The meter associated to the price. Only for `amount_type: MeteredUnit`.
601 pub meter: Option<PriceMeter>,
602}
603
604#[derive(Deserialize)]
605pub struct PriceMeter {
606 /// The ID of the object.
607 pub id: Uuid,
608 /// The name of the meter.
609 pub name: String,
610}
611
612#[derive(Default, Deserialize, Serialize)]
613pub struct PriceParams {
614 pub amount_type: AmountType,
615 /// The currency. Not required for `amount_type: Free`.
616 pub price_currency: Option<String>,
617 /// The price in cents. Only for `amount_type: Fixed`.
618 pub price_amount: Option<u32>,
619 /// The minimum amount the customer can pay. Only for `amount_type: Custom`.
620 pub minimum_amount: Option<u32>,
621 /// The maximum amount the customer can pay. Only for `amount_type: Custom`.
622 pub maximum_amount: Option<u32>,
623 /// The initial amount shown to the customer. Only for `amount_type: Custom`.
624 pub preset_amount: Option<u32>,
625 /// The ID of the meter associated to the price. Only for `amount_type: MeteredUnit`.
626 pub meter_id: Option<Uuid>,
627 /// The price per unit in cents. Only for `amount_type: MeteredUnit`.
628 pub unit_amount: Option<String>,
629 /// The maximum amount in cents that can be charged, regardless of the number of units consumed. Only for `amount_type: MeteredUnit`.
630 pub cap_amount: Option<u32>,
631}
632
633#[derive(Deserialize)]
634pub struct Product {
635 /// Creation timestamp of the object.
636 pub created_at: DateTime<Utc>,
637 /// Last modification timestamp of the object.
638 pub modified_at: Option<DateTime<Utc>>,
639 /// The ID of the product.
640 pub id: Uuid,
641 /// The name of the product.
642 pub name: String,
643 /// The description of the product.
644 pub description: Option<String>,
645 /// The recurring interval of the product. If `None`, the product is a one-time purchase.
646 pub recurring_interval: Option<RecurringInterval>,
647 /// Whether the product is a subscription.
648 pub is_recurring: bool,
649 /// Whether the product is archived and no longer available.
650 pub is_archived: bool,
651 /// The ID of the organization owning the product.
652 pub organization_id: Uuid,
653 pub metadata: HashMap<String, String>,
654 /// List of prices for this product.
655 pub prices: Vec<Price>,
656 /// List of benefits granted by the product.
657 pub benefits: Vec<Benefit>,
658 /// List of medias associated to the product.
659 pub medias: Vec<Media>,
660 /// List of custom fields attached to the product.
661 pub attached_custom_fields: Vec<AttachedCustomField>,
662}
663
664#[derive(Default, Deserialize, Serialize)]
665pub struct ProductParams {
666 /// The name of the product.
667 ///
668 /// Minimum length: `3`
669 pub name: String,
670 /// The recurring interval of the product. If `None`, the product is a one-time purchase
671 pub recurring_interval: Option<RecurringInterval>,
672 /// List of available prices for this product. It should contain at most one static price (fixed, custom or free), and any number of metered prices. Metered prices are not supported on one-time purchase products.
673 pub prices: Vec<PriceParams>,
674 /// Key-value object allowing you to store additional information.
675 pub metadata: HashMap<String, String>,
676 /// The description of the product.
677 pub description: Option<String>,
678 /// List of file IDs. Each one must be on the same organization as the product, of type `product_media` and correctly uploaded.
679 pub medias: Option<Vec<Uuid>>,
680 /// List of custom fields to attach.
681 pub attached_custom_fields: Vec<AttachedCustomFieldParams>,
682 /// The ID of the organization owning the product. **Required unless you use an organization token**.
683 pub organization_id: Option<Uuid>,
684}
685
686#[derive(Deserialize)]
687pub struct Subscription {
688 /// Creation timestamp of the object.
689 pub created_at: DateTime<Utc>,
690 /// Last modification timestamp of the object.
691 pub modified_at: Option<DateTime<Utc>>,
692 /// The ID of the object.
693 pub id: Uuid,
694 /// The amount of the subscription.
695 pub amount: u32,
696 /// The currency of the subscription.
697 pub currency: String,
698 /// The interval at which the subscription recurs.
699 pub recurring_interval: RecurringInterval,
700 /// The status of the subscription.
701 pub status: SubscriptionStatus,
702 /// The start timestamp of the current billing period.
703 pub current_period_start: DateTime<Utc>,
704 /// The end timestamp of the current billing period.
705 pub current_period_end: Option<DateTime<Utc>>,
706 /// Whether the subscription will be canceled at the end of the current period.
707 pub cancel_at_period_end: bool,
708 /// The timestamp when the subscription was canceled. The subscription might still be active if `cancel_at_period_end` is `true`.
709 pub canceled_at: Option<DateTime<Utc>>,
710 /// The timestamp when the subscription started.
711 pub started_at: Option<DateTime<Utc>>,
712 /// The timestamp when the subscription will end.
713 pub ends_at: Option<DateTime<Utc>>,
714 /// The timestamp when the subscription ended.
715 pub ended_at: Option<DateTime<Utc>>,
716 /// The ID of the subscribed customer.
717 pub customer_id: Uuid,
718 /// The ID of the subscribed product.
719 pub product_id: Uuid,
720 /// The ID of the applied discount, if any.
721 pub discount_id: Option<Uuid>,
722 pub checkout_id: Option<Uuid>,
723 pub customer_cancellation_reason: Option<CustomerCancellationReason>,
724 pub customer_cancellation_comment: Option<String>,
725 pub metadata: HashMap<String, String>,
726 pub customer: Customer,
727 /// A product.
728 pub product: Product,
729 pub discount: Option<Discount>,
730 /// List of enabled prices for the subscription.
731 pub prices: Vec<Price>,
732 /// List of meters associated with the subscription.
733 pub meters: Vec<SubscriptionMeter>,
734 // Key-value object storing custom field values.
735 pub custom_field_data: HashMap<String, String>,
736}
737
738#[derive(Deserialize)]
739pub struct SubscriptionMeter {
740 /// Creation timestamp of the object.
741 pub created_at: DateTime<Utc>,
742 /// Last modification timestamp of the object.
743 pub modified_at: Option<DateTime<Utc>>,
744 /// The ID of the object.
745 pub id: Uuid,
746 /// The number of consumed units so far in this billing period.
747 pub consumed_units: usize,
748 /// The number of credited units so far in this billing period.
749 pub credited_units: usize,
750 /// The amount due in cents so far in this billing period.
751 pub amount: u32,
752 /// The ID of the meter.
753 pub meter_id: Uuid,
754 /// The meter associated with this subscription.
755 pub meter: Meter,
756}
757
758#[derive(Default, Deserialize, Serialize)]
759pub struct SubscriptionParams {
760 /// Update subscription to another product.
761 pub product_id: Option<Uuid>,
762 /// Determine how to handle the proration billing. If not provided, will use the default organization setting.
763 pub proration_behavior: Option<ProrationBehavior>,
764 /// Update the subscription to apply a new discount. If set to `None`, the discount will be removed. The change will be applied on the next billing cycle.
765 pub discount_id: Option<Uuid>,
766 /// Cancel an active subscription once the current period ends.
767 ///
768 /// Or uncancel a subscription currently set to be revoked at period end.
769 pub cancel_at_period_end: Option<bool>,
770 /// Customer reason for cancellation. Helpful to monitor reasons behind churn for future improvements.
771 ///
772 /// Only set this in case your own service is requesting the reason from the customer. Or you know based on direct conversations, i.e support, with the customer.
773 pub customer_cancellation_reason: Option<CustomerCancellationReason>,
774 /// Customer feedback and why they decided to cancel.
775 pub customer_cancellation_comment: Option<String>,
776 /// Cancel and revoke an active subscription immediately
777 pub revoke: Option<bool>,
778}
779
780#[derive(Deserialize, Serialize)]
781pub struct UpdateMeterParams {
782 /// Key-value object allowing you to store additional information.
783 pub metadata: HashMap<String, String>,
784 /// The name of the meter. Will be shown on customer's invoices and usage.
785 ///
786 /// Minimum length: `3`
787 pub name: Option<String>,
788 /// The filter to apply on events that'll be used to calculate the meter.
789 pub filter: Option<MeterFilter>,
790 /// The aggregation to apply on the filtered events to calculate the meter.
791 pub aggregation: Option<MeterAggregation>,
792}
793
794#[derive(Deserialize, Serialize)]
795pub struct UpdatePriceParams {
796 /// If you want to keep the existing price.
797 pub id: Option<Uuid>,
798 pub amount_type: Option<AmountType>,
799 /// The currency. Not required for `amount_type: Free`.
800 pub price_currency: Option<String>,
801 /// The price in cents. Only for `amount_type: Fixed`.
802 pub price_amount: Option<u32>,
803 /// The minimum amount the customer can pay. Only for `amount_type: Custom`.
804 pub minimum_amount: Option<u32>,
805 /// The maximum amount the customer can pay. Only for `amount_type: Custom`.
806 pub maximum_amount: Option<u32>,
807 /// The initial amount shown to the customer. Only for `amount_type: Custom`.
808 pub preset_amount: Option<u32>,
809 /// The ID of the meter associated to the price. Only for `amount_type: MeteredUnit`.
810 pub meter_id: Option<Uuid>,
811 /// The price per unit in cents. Only for `amount_type: MeteredUnit`.
812 pub unit_amount: Option<String>,
813 /// The maximum amount in cents that can be charged, regardless of the number of units consumed. Only for `amount_type: MeteredUnit`.
814 pub cap_amount: Option<u32>,
815}
816
817#[derive(Default, Deserialize, Serialize)]
818pub struct UpdateProductParams {
819 /// Key-value object allowing you to store additional information.
820 pub metadata: HashMap<String, String>,
821 /// The name of the product.
822 ///
823 /// Minimum length: `3`
824 pub name: Option<String>,
825 /// The description of the product.
826 pub description: Option<String>,
827 /// The recurring interval of the product. If `None`, the product is a one-time purchase
828 pub recurring_interval: Option<RecurringInterval>,
829 /// Whether the product is archived. If `true`, the product won't be available for purchase anymore. Existing customers will still have access to their benefits, and subscriptions will continue normally.
830 pub is_archived: Option<bool>,
831 /// List of available prices for this product. If you want to keep existing prices, include them in the list with only the `id`.
832 pub prices: Vec<UpdatePriceParams>,
833 /// List of file IDs. Each one must be on the same organization as the product, of type `product_media` and correctly uploaded.
834 pub medias: Option<Vec<Uuid>>,
835 /// List of custom fields to attach.
836 pub attached_custom_fields: Option<Vec<AttachedCustomFieldParams>>,
837}