paddle_rust_sdk/
entities.rs

1//! Contains all Paddle entity types.
2
3use std::collections::HashMap;
4
5use chrono::DateTime;
6use chrono::FixedOffset;
7use chrono::Utc;
8use serde::{Deserialize, Serialize};
9use serde_with::skip_serializing_none;
10
11use crate::enums::*;
12use crate::ids::*;
13
14/// Import information for this entity. `null` if this entity is not imported.
15#[derive(Clone, Debug, Serialize, Deserialize)]
16pub struct ImportMeta {
17    /// Reference or identifier for this entity from the solution where it was imported from.
18    pub external_id: Option<String>,
19    /// Name of the platform where this entity was imported from.
20    pub imported_from: String,
21}
22
23/// Represents an address entity.
24#[derive(Clone, Debug, Serialize, Deserialize)]
25pub struct Address {
26    /// Unique Paddle ID for this address entity, prefixed with `add_`.
27    pub id: AddressID,
28    /// Unique Paddle ID for this customer entity, prefixed with `ctm_`.
29    pub customer_id: CustomerID,
30    /// Memorable description for this address.
31    pub description: Option<String>,
32    /// First line of this address.
33    pub first_line: Option<String>,
34    /// Second line of this address.
35    pub second_line: Option<String>,
36    /// City of this address.
37    pub city: Option<String>,
38    /// ZIP or postal code of this address. Required for some countries.
39    pub postal_code: Option<String>,
40    /// State, county, or region of this address.
41    pub region: Option<String>,
42    /// Supported two-letter ISO 3166-1 alpha-2 country code.
43    pub country_code: CountryCodeSupported,
44    /// Your own structured key-value data.
45    pub custom_data: Option<serde_json::Value>,
46    /// Whether this entity can be used in Paddle.
47    pub status: Status,
48    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
49    pub created_at: DateTime<Utc>,
50    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
51    pub updated_at: DateTime<Utc>,
52    /// Import information for this entity. `null` if this entity is not imported.
53    pub import_meta: Option<ImportMeta>,
54}
55
56/// Represents an address entity when previewing addresses.
57#[derive(Clone, Debug, Serialize, Deserialize)]
58pub struct AddressPreview {
59    /// ZIP or postal code of this address. Include for more accurate tax calculations.
60    pub postal_code: Option<String>,
61    /// Supported two-letter ISO 3166-1 alpha-2 country code.
62    pub country_code: CountryCodeSupported,
63}
64
65/// Breakdown of the total for an adjustment.
66#[derive(Clone, Debug, Serialize, Deserialize)]
67pub struct AdjustmentTotals {
68    /// Total before tax. For tax adjustments, the value is 0.
69    pub subtotal: String,
70    /// Total tax on the subtotal.
71    pub tax: String,
72    /// Total after tax.
73    pub total: String,
74    /// Total fee taken by Paddle for this adjustment.
75    pub fee: String,
76    /// Total earnings. This is the subtotal minus the Paddle fee.
77    /// For tax adjustments, this value is negative, which means a positive effect in the transaction earnings.
78    /// This is because the fee is originally calculated from the transaction total, so if a tax adjustment is made,
79    /// then the fee portion of it is returned.
80    pub earnings: String,
81    /// Supported three-letter ISO 4217 currency code.
82    pub currency_code: CurrencyCode,
83}
84
85/// Chargeback fee before conversion to the payout currency. `null` when the chargeback fee is the same as the payout currency.
86#[derive(Clone, Debug, Serialize, Deserialize)]
87pub struct Original {
88    /// Fee amount for this chargeback in the original currency.
89    pub amount: String,
90    /// Three-letter ISO 4217 currency code for chargeback fees.
91    pub currency_code: CurrencyCodeChargebacks,
92}
93
94/// Chargeback fees incurred for this adjustment. Only returned when the adjustment `action` is `chargeback` or `chargeback_warning`.
95#[derive(Clone, Debug, Serialize, Deserialize)]
96pub struct ChargebackFee {
97    /// Chargeback fee converted into the payout currency.
98    pub amount: String,
99    /// Chargeback fee before conversion to the payout currency. `null` when the chargeback fee is the same as the payout currency.
100    pub original: Option<Original>,
101}
102
103/// Breakdown of how this adjustment affects your payout balance.
104#[derive(Clone, Debug, Serialize, Deserialize)]
105pub struct AdjustmentPayoutTotals {
106    /// Adjustment total before tax and fees.
107    pub subtotal: String,
108    /// Total tax on the adjustment subtotal.
109    pub tax: String,
110    /// Adjustment total after tax.
111    pub total: String,
112    /// Adjusted Paddle fee.
113    pub fee: String,
114    /// Chargeback fees incurred for this adjustment. Only returned when the adjustment `action` is `chargeback` or `chargeback_warning`.
115    pub chargeback_fee: Option<ChargebackFee>,
116    /// Adjusted payout earnings. This is the adjustment total plus adjusted Paddle fees, excluding chargeback fees.
117    pub earnings: String,
118    /// Supported three-letter ISO 4217 currency code for payouts from Paddle.
119    pub currency_code: CurrencyCodePayouts,
120}
121
122/// Calculated totals for the tax applied to this adjustment.
123#[derive(Clone, Debug, Serialize, Deserialize)]
124pub struct AdjustmentTaxRateUsedTotals {
125    /// Total before tax. For tax adjustments, the value is 0.
126    pub subtotal: String,
127    /// Total tax on the subtotal.
128    pub tax: String,
129    /// Total after tax.
130    pub total: String,
131}
132
133#[derive(Clone, Debug, Serialize, Deserialize)]
134pub struct AdjustmentTaxRateUsed {
135    /// Rate used to calculate tax for this adjustment.
136    pub tax_rate: String,
137    /// Calculated totals for the tax applied to this adjustment.
138    pub totals: AdjustmentTaxRateUsedTotals,
139}
140
141/// Represents an adjustment entity.
142#[derive(Clone, Debug, Serialize, Deserialize)]
143pub struct Adjustment {
144    /// Unique Paddle ID for this adjustment entity, prefixed with `adj_`.
145    pub id: AdjustmentID,
146    /// How this adjustment impacts the related transaction.
147    pub action: AdjustmentAction,
148    /// Type of adjustment. Use `full` to adjust the grand total for the related transaction. Include an `items` array when creating a `partial` adjustment. If omitted, defaults to `partial`.
149    pub r#type: AdjustmentType,
150    /// Unique Paddle ID for this transaction entity, prefixed with `txn_`.
151    pub transaction_id: TransactionID,
152    /// Paddle ID for the subscription related to this adjustment, prefixed with `sub_`.
153    /// Set automatically by Paddle based on the `subscription_id` of the related transaction.
154    pub subscription_id: Option<SubscriptionID>,
155    /// Unique Paddle ID for this customer entity, prefixed with `ctm_`.
156    pub customer_id: CustomerID,
157    /// Why this adjustment was created. Appears in the Paddle dashboard. Retained for record-keeping purposes.
158    pub reason: String,
159    /// Whether this adjustment was applied to the related customer's credit balance. Only returned for `credit` adjustments.
160    pub credit_applied_to_balance: Option<bool>,
161    /// Supported three-letter ISO 4217 currency code.
162    pub currency_code: CurrencyCode,
163    /// Status of this adjustment. Set automatically by Paddle.
164    ///
165    /// Most refunds for live accounts are created with the status of `pending_approval` until reviewed by Paddle, but some are automatically approved. For sandbox accounts, Paddle automatically approves refunds every ten minutes.
166    ///
167    /// Credit adjustments don't require approval from Paddle, so they're created as `approved`.
168    pub status: AdjustmentStatus,
169    /// List of items on this adjustment. Required if `type` is not populated or set to `partial`.
170    pub items: Vec<AdjustmentItem>,
171    /// Breakdown of the total for an adjustment.
172    pub totals: AdjustmentTotals,
173    /// Breakdown of how this adjustment affects your payout balance.
174    pub payout_totals: Option<AdjustmentPayoutTotals>,
175    /// List of tax rates applied for this adjustment.
176    #[serde(default)]
177    pub tax_rates_used: Vec<AdjustmentTaxRateUsed>,
178    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
179    pub created_at: DateTime<Utc>,
180    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
181    pub updated_at: DateTime<Utc>,
182}
183
184/// Represents an adjustment entity when creating adjustments.
185#[derive(Clone, Debug, Serialize, Deserialize)]
186pub struct AdjustmentCreate {
187    /// Unique Paddle ID for this adjustment entity, prefixed with `adj_`.
188    pub id: AdjustmentID,
189    /// How this adjustment impacts the related transaction.
190    pub action: AdjustmentAction,
191    /// Type of adjustment. Use `full` to adjust the grand total for the related transaction. Include an `items` array when creating a `partial` adjustment. If omitted, defaults to `partial`.
192    pub r#type: AdjustmentType,
193    /// Unique Paddle ID for this transaction entity, prefixed with `txn_`.
194    pub transaction_id: TransactionID,
195    /// Paddle ID for the subscription related to this adjustment, prefixed with `sub_`.
196    /// Set automatically by Paddle based on the `subscription_id` of the related transaction.
197    pub subscription_id: SubscriptionID,
198    /// Unique Paddle ID for this customer entity, prefixed with `ctm_`.
199    pub customer_id: CustomerID,
200    /// Why this adjustment was created. Appears in the Paddle dashboard. Retained for recordkeeping purposes.
201    pub reason: String,
202    /// Whether this adjustment was applied to the related customer's credit balance. Only returned for `credit` adjustments.
203    pub credit_applied_to_balance: Option<bool>,
204    /// Supported three-letter ISO 4217 currency code.
205    pub currency_code: CurrencyCode,
206    /// Status of this adjustment. Set automatically by Paddle.
207    ///
208    /// Most refunds for live accounts are created with the status of `pending_approval` until reviewed by Paddle, but some are automatically approved. For sandbox accounts, Paddle automatically approves refunds every ten minutes.
209    ///
210    /// Credit adjustments don't require approval from Paddle, so they're created as `approved`.
211    pub status: AdjustmentStatus,
212    /// List of transaction items to adjust. Required if `type` is not populated or set to `partial`.
213    pub items: Option<Vec<AdjustmentItem>>,
214    /// Breakdown of the total for an adjustment.
215    pub totals: AdjustmentTotals,
216    /// Breakdown of how this adjustment affects your payout balance.
217    pub payout_totals: Option<AdjustmentPayoutTotals>,
218    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
219    pub created_at: String,
220    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
221    pub updated_at: String,
222}
223
224#[derive(Clone, Debug, Serialize, Deserialize)]
225pub struct TimePeriod {
226    /// RFC 3339 datetime string.
227    pub starts_at: DateTime<Utc>,
228    /// RFC 3339 datetime string.
229    pub ends_at: DateTime<Utc>,
230}
231
232/// How proration was calculated for this item. Populated when a transaction is created from a subscription change, where `proration_billing_mode` was `prorated_immediately` or `prorated_next_billing_period`. Set automatically by Paddle.
233#[derive(Clone, Debug, Serialize, Deserialize)]
234pub struct Proration {
235    /// Rate used to calculate proration.
236    pub rate: String,
237    pub billing_period: TimePeriod,
238}
239
240/// Breakdown of the total for an adjustment item.
241#[derive(Clone, Debug, Serialize, Deserialize)]
242pub struct AdjustmentItemTotals {
243    /// Amount multiplied by quantity.
244    pub subtotal: String,
245    /// Total tax on the subtotal.
246    pub tax: String,
247    /// Total after tax.
248    pub total: String,
249}
250
251#[derive(Clone, Debug, Serialize, Deserialize)]
252pub struct AdjustmentItem {
253    /// Unique Paddle ID for this transaction item, prefixed with `txnitm_`. Used when working with [adjustments](https://developer.paddle.com/build/transactions/create-transaction-adjustments).
254    pub item_id: TransactionItemID,
255    /// Type of adjustment for this transaction item. `tax` adjustments are automatically created by Paddle.
256    /// Include `amount` when creating a `partial` adjustment.
257    pub r#type: AdjustmentItemType,
258    /// Amount adjusted for this transaction item. Required when item type is `partial`.
259    pub amount: Option<String>,
260    /// How proration was calculated for this adjustment item.
261    pub proration: Option<Proration>,
262    /// Breakdown of the total for an adjustment item.
263    pub totals: AdjustmentItemTotals,
264}
265
266#[derive(Clone, Debug, Serialize, Deserialize)]
267pub struct AdjustmentItemInput {
268    /// Unique Paddle ID for this transaction item, prefixed with `txnitm_`. Used when working with [adjustments](https://developer.paddle.com/build/transactions/create-transaction-adjustments).
269    pub item_id: TransactionItemID,
270    /// Type of adjustment for this transaction item. `tax` adjustments are automatically created by Paddle.
271    /// Include `amount` when creating a `partial` adjustment.
272    pub r#type: AdjustmentItemType,
273    /// Amount adjusted for this transaction item. Required when item type is `partial`.
274    pub amount: Option<String>,
275}
276
277/// Represents an adjustment entity when previewing adjustments.
278#[derive(Clone, Debug, Serialize, Deserialize)]
279pub struct AdjustmentPreview {
280    /// Unique Paddle ID for this transaction entity, prefixed with `txn_`.
281    pub transaction_id: TransactionID,
282    /// List of transaction items that this adjustment is for.
283    pub items: Vec<AdjustmentItem>,
284    /// Breakdown of the total for an adjustment.
285    pub totals: AdjustmentTotals,
286}
287
288#[derive(Clone, Debug, Serialize, Deserialize)]
289pub struct Duration {
290    /// Unit of time.
291    pub interval: Interval,
292    /// Amount of time.
293    pub frequency: u64,
294}
295
296/// Details for invoicing. Required if `collection_mode` is `manual`.
297#[derive(Clone, Debug, Serialize, Deserialize)]
298pub struct BillingDetails {
299    /// Whether the related transaction may be paid using Paddle Checkout. If omitted when creating a transaction, defaults to `false`.
300    pub enable_checkout: bool,
301    /// Customer purchase order number. Appears on invoice documents.
302    pub purchase_order_number: String,
303    /// Notes or other information to include on this invoice. Appears on invoice documents.
304    pub additional_information: Option<String>,
305    pub payment_terms: Duration,
306}
307
308/// Details for invoicing. Required if `collection_mode` is `manual`.
309#[derive(Clone, Debug, Serialize, Deserialize)]
310pub struct BillingDetailsUpdate {
311    /// Whether the related transaction may be paid using Paddle Checkout.
312    pub enable_checkout: bool,
313    /// Customer purchase order number. Appears on invoice documents.
314    pub purchase_order_number: String,
315    /// Notes or other information to include on this invoice. Appears on invoice documents.
316    pub additional_information: Option<String>,
317    pub payment_terms: Duration,
318}
319
320#[derive(Clone, Debug, Serialize, Deserialize)]
321pub struct Contact {
322    /// Full name.
323    pub name: String,
324    /// Email address for this entity.
325    pub email: String,
326}
327
328/// Represents a business entity.
329#[derive(Clone, Debug, Serialize, Deserialize)]
330pub struct Business {
331    /// Unique Paddle ID for this business entity, prefixed with `biz_`.
332    pub id: BusinessID,
333    /// Unique Paddle ID for this customer entity, prefixed with `ctm_`.
334    pub customer_id: CustomerID,
335    /// Full name.
336    pub name: String,
337    /// Company number for this business.
338    pub company_number: Option<String>,
339    /// Tax or VAT Number for this business.
340    pub tax_identifier: Option<String>,
341    /// Whether this entity can be used in Paddle.
342    pub status: Status,
343    /// List of contacts related to this business, typically used for sending invoices.
344    pub contacts: Option<Vec<Contact>>,
345    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
346    pub created_at: DateTime<Utc>,
347    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
348    pub updated_at: DateTime<Utc>,
349    /// Your own structured key-value data.
350    pub custom_data: Option<serde_json::Value>,
351    /// Import information for this entity. `null` if this entity is not imported.
352    pub import_meta: Option<ImportMeta>,
353}
354
355/// Card metadata
356#[derive(Clone, Debug, Serialize, Deserialize)]
357pub struct Card {
358    /// Type of credit or debit card used to pay.
359    pub r#type: CardType,
360    /// Last four digits of the card used to pay.
361    pub last4: String,
362    /// Month of the expiry date of the card used to pay.
363    pub expiry_month: i64,
364    /// Year of the expiry date of the card used to pay.
365    pub expiry_year: i64,
366    /// The name on the card used to pay.
367    pub cardholder_name: String,
368}
369
370#[derive(Clone, Debug, Serialize, Deserialize)]
371pub struct CustomerBalance {
372    /// Total amount of credit available to use.
373    pub available: String,
374    /// Total amount of credit temporarily reserved for `billed` transactions.
375    pub reserved: String,
376    /// Total amount of credit used.
377    pub used: String,
378}
379
380/// Represents a credit balance for a customer.
381#[derive(Clone, Debug, Serialize, Deserialize)]
382pub struct CreditBalance {
383    /// Unique Paddle ID for this customer entity, prefixed with `ctm_`.
384    pub customer_id: CustomerID,
385    /// Supported three-letter ISO 4217 currency code.
386    pub currency_code: CurrencyCode,
387    pub balance: CustomerBalance,
388}
389
390/// Represents a customer entity.
391#[derive(Clone, Debug, Serialize, Deserialize)]
392pub struct Customer {
393    /// Unique Paddle ID for this customer entity, prefixed with `ctm_`.
394    pub id: CustomerID,
395    /// Full name of this customer. Required when creating transactions where `collection_mode` is `manual` (invoices).
396    pub name: Option<String>,
397    /// Email address for this entity.
398    pub email: String,
399    /// Whether this customer opted into marketing from you. `false` unless customers check the marketing consent box
400    /// when using Paddle Checkout. Set automatically by Paddle.
401    pub marketing_consent: bool,
402    /// Whether this entity can be used in Paddle.
403    pub status: Status,
404    /// Your own structured key-value data.
405    pub custom_data: Option<serde_json::Value>,
406    /// Valid IETF BCP 47 short form locale tag. If omitted, defaults to `en`.
407    pub locale: String,
408    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
409    pub created_at: DateTime<Utc>,
410    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
411    pub updated_at: DateTime<Utc>,
412    /// Import information for this entity. `null` if this entity is not imported.
413    pub import_meta: Option<ImportMeta>,
414}
415
416/// PayPal metadata
417#[derive(Clone, Debug, Serialize, Deserialize)]
418pub struct PayPal {
419    /// Email address associated with the PayPal account.
420    pub email: String,
421    /// PayPal payment method identifier.
422    pub reference: String,
423}
424
425/// Represents a customer payment method entity.
426#[derive(Clone, Debug, Serialize, Deserialize)]
427pub struct PaymentMethod {
428    /// Unique Paddle ID for this payment method entity, prefixed with `paymtd_`.
429    pub id: PaymentMethodID,
430    /// Unique Paddle ID for this customer entity, prefixed with `ctm_`.
431    pub customer_id: CustomerID,
432    /// Unique Paddle ID for this address entity, prefixed with `add_`.
433    pub address_id: AddressID,
434    /// Type of payment method saved.
435    pub r#type: SavedPaymentMethodType,
436    /// Information about the credit or debit card saved. `null` unless `type` is `card`.
437    pub card: Option<Card>,
438    /// Information about the PayPal payment method saved. `null` unless `type` is `paypal`.
439    pub paypal: Option<PayPal>,
440    /// Describes how this payment method was saved.
441    pub origin: PaymentMethodOrigin,
442    /// RFC 3339 datetime string of when this entity was saved. Set automatically by Paddle.
443    pub saved_at: DateTime<Utc>,
444    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
445    pub updated_at: DateTime<Utc>,
446}
447
448/// Authenticated customer portal deep links that aren't associated with a specific entity.
449#[derive(Clone, Debug, Serialize, Deserialize)]
450pub struct CustomerPortalSessionGeneralUrls {
451    /// Link to the overview page in the customer portal.
452    pub overview: String,
453}
454
455#[derive(Clone, Debug, Serialize, Deserialize)]
456pub struct CustomerPortalSessionSubscriptionUrls {
457    /// Unique Paddle ID for this subscription entity, prefixed with `sub_`.
458    pub id: SubscriptionID,
459    /// Link to the page for this subscription in the customer portal with the subscription cancellation form pre-opened. Use as part of cancel subscription workflows.
460    pub cancel_subscription: String,
461    /// Link to the page for this subscription in the customer portal with the payment method update form pre-opened. Use as part of workflows to let customers update their payment details.
462    ///
463    /// If a manually-collected subscription, opens the overview page for this subscription.
464    pub update_subscription_payment_method: String,
465}
466
467/// Authenticated customer portal deep links. For security, the `token` appended to each link is temporary. You shouldn't store these links.
468#[derive(Clone, Debug, Serialize, Deserialize)]
469pub struct CustomerPortalSessionUrls {
470    /// Authenticated customer portal deep links that aren't associated with a specific entity.
471    pub general: CustomerPortalSessionGeneralUrls,
472    /// List of generated authenticated customer portal deep links for the subscriptions passed in the `subscription_ids` array in the request.
473    ///
474    /// If subscriptions are paused or canceled, links open the overview page for a subscription.
475    ///
476    /// Empty if no subscriptions passed in the request.
477    pub subscriptions: Vec<CustomerPortalSessionSubscriptionUrls>,
478}
479
480/// Represents a customer portal session.
481#[derive(Clone, Debug, Serialize, Deserialize)]
482pub struct CustomerPortalSession {
483    /// Unique Paddle ID for this customer portal session entity, prefixed with `cpls_`.
484    pub id: CustomerPortalSessionID,
485    /// Unique Paddle ID for this customer entity, prefixed with `ctm_`.
486    pub customer_id: CustomerID,
487    /// Authenticated customer portal deep links. For security, the `token` appended to each link is temporary. You shouldn't store these links.
488    pub urls: CustomerPortalSessionUrls,
489    /// RFC 3339 datetime string.
490    pub created_at: DateTime<Utc>,
491}
492
493/// Represents a customer authentication token.
494#[derive(Clone, Debug, Serialize, Deserialize)]
495pub struct CustomerAuthenticationToken {
496    /// Authentication token generated by Paddle for this customer. Pass to Paddle.js when opening a checkout to let customers work with saved payment methods.
497    pub customer_auth_token: String,
498    /// RFC 3339 datetime string.
499    pub expires_at: DateTime<Utc>,
500}
501
502/// Represents a discount entity.
503#[derive(Clone, Debug, Serialize, Deserialize)]
504pub struct Discount {
505    /// Unique Paddle ID for this discount, prefixed with `dsc_`.
506    pub id: DiscountID,
507    /// Whether this entity can be used in Paddle.
508    pub status: DiscountStatus,
509    /// Short description for this discount for your reference. Not shown to customers.
510    pub description: String,
511    /// Whether this discount can be redeemed by customers at checkout (`true`) or not (`false`).
512    pub enabled_for_checkout: bool,
513    /// Unique code that customers can use to redeem this discount at checkout. Not case-sensitive.
514    pub code: Option<String>,
515    /// Type of discount. Determines how this discount impacts the checkout or transaction total.
516    pub r#type: DiscountType,
517    /// Amount to discount by. For `percentage` discounts, must be an amount between `0.01` and `100`. For `flat` and `flat_per_seat` discounts, amount in the lowest denomination for a currency.
518    pub amount: String,
519    /// Supported three-letter ISO 4217 currency code. Required where discount type is `flat` or `flat_per_seat`.
520    pub currency_code: Option<CurrencyCode>,
521    /// Whether this discount applies for multiple subscription billing periods (`true`) or not (`false`).
522    pub recur: bool,
523    /// Number of subscription billing periods that this discount recurs for. Requires `recur`. `null` if this discount recurs forever.
524    ///
525    /// Subscription renewals, midcycle changes, and one-time charges billed to a subscription aren't considered a redemption. `times_used` is not incremented in these cases.
526    pub maximum_recurring_intervals: Option<i64>,
527    /// Maximum number of times this discount can be redeemed. This is an overall limit for this discount, rather than a per-customer limit. `null` if this discount can be redeemed an unlimited amount of times.
528    ///
529    /// Paddle counts a usage as a redemption on a checkout, transaction, or the initial application against a subscription. Transactions created for subscription renewals, midcycle changes, and one-time charges aren't considered a redemption.
530    pub usage_limit: Option<i64>,
531    /// Product or price IDs that this discount is for. When including a product ID, all prices for that product can be discounted. `null` if this discount applies to all products and prices.
532    pub restrict_to: Option<Vec<String>>,
533    /// RFC 3339 datetime string of when this discount expires. Discount can no longer be redeemed after this date has elapsed. `null` if this discount can be redeemed forever.
534    ///
535    /// Expired discounts can't be redeemed against transactions or checkouts, but can be applied when updating subscriptions.
536    pub expires_at: Option<DateTime<Utc>>,
537    /// Your own structured key-value data.
538    pub custom_data: Option<serde_json::Value>,
539    /// How many times this discount has been redeemed. Automatically incremented by Paddle.
540    ///
541    /// Paddle counts a usage as a redemption on a checkout, transaction, or subscription. Transactions created for subscription renewals, midcycle changes, and one-time charges aren't considered a redemption.
542    #[serde(default)]
543    pub times_used: i64,
544    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
545    pub created_at: DateTime<Utc>,
546    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
547    pub updated_at: DateTime<Utc>,
548    /// Import information for this entity. `null` if this entity is not imported.
549    pub import_meta: Option<ImportMeta>,
550}
551
552/// Details of the discount applied to this subscription.
553#[derive(Clone, Debug, Serialize, Deserialize)]
554pub struct SubscriptionDiscountTimePeriod {
555    /// Unique Paddle ID for this discount, prefixed with `dsc_`.
556    pub id: DiscountID,
557    /// RFC 3339 datetime string of when this discount was first applied. `null` for canceled subscriptions where a discount was redeemed but never applied to a transaction.
558    pub starts_at: Option<DateTime<FixedOffset>>,
559    /// RFC 3339 datetime string of when this discount no longer applies. Where a discount has `maximum_recurring_intervals`, this is the date of the last billing period where this discount applies. `null` where a discount recurs forever.
560    pub ends_at: Option<DateTime<FixedOffset>>,
561}
562
563#[derive(Clone, Debug, Serialize, Deserialize)]
564pub struct Errors {
565    /// Field where validation error occurred.
566    pub field: String,
567    /// Information about how the field failed validation.
568    pub message: String,
569}
570
571/// Represents an error.
572#[derive(Clone, Debug, Serialize, Deserialize)]
573pub struct Error {
574    /// Type of error encountered.
575    pub r#type: Type,
576    /// Short snake case string that describes this error. Use to search the error reference.
577    pub code: String,
578    /// Some information about what went wrong as a human-readable string.
579    pub detail: String,
580    /// Link to a page in the error reference for this specific error.
581    pub documentation_url: String,
582    /// List of validation errors. Only returned when there's a validation error.
583    pub errors: Vec<Errors>,
584}
585
586/// Information about this response.
587#[derive(Clone, Debug, Serialize, Deserialize)]
588pub struct Meta {
589    /// Unique ID for the request relating to this response. Provide this when contacting Paddle support about a specific request.
590    pub request_id: String,
591}
592
593#[derive(Clone, Debug, Serialize, Deserialize)]
594pub struct ValidationError {
595    /// Represents an error.
596    pub error: Error,
597    /// Information about this response.
598    pub meta: Meta,
599}
600
601/// Represents an event entity.
602#[derive(Clone, Debug, Serialize, Deserialize)]
603pub struct Event {
604    /// Unique Paddle ID for this event, prefixed with `evt_`.
605    pub event_id: EventID,
606    /// RFC 3339 datetime string.
607    pub occurred_at: DateTime<Utc>,
608    /// New or changed entity.
609    #[serde(flatten)]
610    pub data: EventData,
611}
612
613/// Represents an event type.
614#[derive(Clone, Debug, Serialize, Deserialize)]
615pub struct EventType {
616    /// Type of event sent by Paddle, in the format `entity.event_type`.
617    pub name: String, // EventTypeName,
618    /// Short description of this event type.
619    pub description: String,
620    /// Group for this event type. Typically the entity that this event relates to.
621    pub group: String,
622    /// List of API versions that this event type supports.
623    pub available_versions: Vec<u64>,
624}
625
626/// A base representation of monetary value unformatted in the lowest denomination with currency code.
627#[derive(Clone, Debug, Serialize, Deserialize)]
628pub struct Money {
629    /// Amount in the lowest denomination for the currency, e.g. 10 USD = 1000 (cents). Although represented as a string, this value must be a valid integer.
630    pub amount: String,
631    /// Supported three-letter ISO 4217 currency code.
632    pub currency_code: CurrencyCode,
633}
634
635#[derive(Clone, Debug, Serialize, Deserialize)]
636pub struct UnitPriceOverride {
637    /// Supported two-letter ISO 3166-1 alpha-2 country code. Customers located in the listed countries are charged the override price.
638    pub country_codes: Vec<CountryCodeSupported>,
639    /// A base representation of monetary value unformatted in the lowest denomination with currency code.
640    pub unit_price: Money,
641}
642
643#[derive(Clone, Debug, Serialize, Deserialize)]
644pub struct PriceQuantity {
645    /// Minimum quantity of the product related to this price that can be bought. Required if `maximum` set.
646    pub minimum: u64,
647    /// Maximum quantity of the product related to this price that can be bought. Required if `minimum` set. Must be greater than or equal to the `minimum` value.
648    pub maximum: u64,
649}
650
651/// Represents a price entity.
652#[derive(Clone, Debug, Serialize, Deserialize)]
653pub struct Price {
654    /// Unique Paddle ID for this price, prefixed with `pri_`.
655    pub id: PriceID,
656    /// Unique Paddle ID for this product, prefixed with `pro_`.
657    pub product_id: ProductID,
658    /// Internal description for this price, not shown to customers. Typically notes for your team.
659    pub description: String,
660    /// Type of item. Standard items are considered part of your catalog and are shown on the Paddle dashboard.
661    pub r#type: CatalogType,
662    /// Name of this price, shown to customers at checkout and on invoices. Typically describes how often the related product bills.
663    pub name: Option<String>,
664    /// How often this price should be charged. `null` if price is non-recurring (one-time).
665    pub billing_cycle: Option<Duration>,
666    /// Trial period for the product related to this price. The billing cycle begins once the trial period is over. `null` for no trial period. Requires `billing_cycle`.
667    pub trial_period: Option<Duration>,
668    /// How tax is calculated for this price.
669    pub tax_mode: TaxMode,
670    /// A base representation of monetary value unformatted in the lowest denomination with currency code.
671    pub unit_price: Money,
672    /// List of unit price overrides. Use to override the base price with a custom price and currency for a country or group of countries.
673    #[serde(default)]
674    pub unit_price_overrides: Vec<UnitPriceOverride>,
675    pub quantity: PriceQuantity,
676    /// Whether this entity can be used in Paddle.
677    pub status: Status,
678    /// Your own structured key-value data.
679    pub custom_data: Option<serde_json::Value>,
680    /// Import information for this entity. `null` if this entity is not imported.
681    pub import_meta: Option<ImportMeta>,
682    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
683    pub created_at: DateTime<Utc>,
684    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
685    pub updated_at: DateTime<Utc>,
686}
687
688/// Represents a product entity.
689#[derive(Clone, Debug, Serialize, Deserialize)]
690pub struct Product {
691    /// Unique Paddle ID for this product, prefixed with `pro_`.
692    pub id: ProductID,
693    /// Name of this product.
694    pub name: String,
695    /// Short description for this product.
696    pub description: Option<String>,
697    /// Type of item. Standard items are considered part of your catalog and are shown on the Paddle dashboard.
698    pub r#type: CatalogType,
699    /// Tax category for this product. Used for charging the correct rate of tax. Selected tax category must be enabled on your Paddle account.
700    pub tax_category: TaxCategory,
701    /// Image for this product. Included in the checkout and on some customer documents.
702    pub image_url: Option<String>,
703    /// Your own structured key-value data.
704    pub custom_data: Option<serde_json::Value>,
705    /// Whether this entity can be used in Paddle.
706    pub status: Status,
707    /// Import information for this entity. `null` if this entity is not imported.
708    pub import_meta: Option<ImportMeta>,
709    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
710    pub created_at: DateTime<Utc>,
711    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
712    pub updated_at: DateTime<Utc>,
713}
714
715/// Represents a subscription item.
716#[derive(Clone, Debug, Serialize, Deserialize)]
717pub struct SubscriptionItem {
718    /// Status of this subscription item. Set automatically by Paddle.
719    pub status: SubscriptionItemStatus,
720    /// Quantity of this item on the subscription.
721    pub quantity: i64,
722    /// Whether this is a recurring item. `false` if one-time.
723    pub recurring: bool,
724    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
725    pub created_at: DateTime<Utc>,
726    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
727    pub updated_at: DateTime<Utc>,
728    /// RFC 3339 datetime string of when this item was last billed.
729    pub previously_billed_at: Option<DateTime<FixedOffset>>,
730    /// RFC 3339 datetime string of when this item is next scheduled to be billed.
731    pub next_billed_at: Option<DateTime<FixedOffset>>,
732    /// Trial dates for this item.
733    pub trial_dates: Option<TimePeriod>,
734    /// Represents a price entity.
735    pub price: Price,
736    /// Represents a product entity.
737    pub product: Product,
738}
739
740/// Keys used for working with paginated results.
741#[derive(Clone, Debug, Serialize, Deserialize)]
742pub struct Pagination {
743    /// Number of entities per page for this response. May differ from the number requested if the requested number is greater than the maximum.
744    pub per_page: i64,
745    /// URL containing the query parameters of the original request, along with the `after` parameter that marks the starting point of the next page. Always returned, even if `has_more` is `false`.
746    pub next: String,
747    /// Whether this response has another page.
748    pub has_more: bool,
749    /// Estimated number of entities for this response.
750    pub estimated_total: i64,
751}
752
753/// Information about this response.
754#[derive(Clone, Debug, Serialize, Deserialize)]
755pub struct MetaPaginated {
756    /// Unique ID for the request relating to this response. Provide this when contacting Paddle support about a specific request.
757    pub request_id: String,
758    /// Keys used for working with paginated results.
759    pub pagination: Pagination,
760}
761
762/// Information about the payment method used for a payment attempt.
763#[derive(Clone, Debug, Serialize, Deserialize)]
764pub struct MethodDetails {
765    /// Type of payment method used for this payment attempt.
766    pub r#type: PaymentMethodType,
767    /// Information about the credit or debit card used to pay. `null` unless `type` is `card`.
768    pub card: Option<Card>,
769}
770
771/// Notification payload. Includes the new or changed event.
772#[derive(Clone, Debug, Serialize, Deserialize)]
773pub struct NotificationPayload {
774    /// Unique Paddle ID for this notification, prefixed with `ntf_`.
775    pub notification_id: NotificationID,
776    /// Unique Paddle ID for this event, prefixed with `evt_`.
777    pub event_id: EventID,
778    /// Type of event sent by Paddle, in the format `entity.event_type`.
779    pub event_type: EventTypeName,
780    /// RFC 3339 datetime string.
781    pub occurred_at: String,
782    /// New or changed entity.
783    pub data: HashMap<String, String>,
784}
785
786/// Represents a notification entity.
787#[derive(Clone, Debug, Serialize, Deserialize)]
788pub struct Notification {
789    /// Unique Paddle ID for this notification, prefixed with `ntf_`.
790    pub id: NotificationID,
791    /// Type of event sent by Paddle, in the format `entity.event_type`.
792    pub r#type: EventTypeName,
793    /// Status of this notification.
794    pub status: NotificationStatus,
795    pub payload: NotificationPayload,
796    /// RFC 3339 datetime string.
797    pub occurred_at: DateTime<FixedOffset>,
798    /// RFC 3339 datetime string of when this notification was delivered. `null` if not yet delivered successfully.
799    pub delivered_at: Option<DateTime<FixedOffset>>,
800    /// RFC 3339 datetime string of when this notification was replayed. `null` if not replayed.
801    pub replayed_at: Option<DateTime<FixedOffset>>,
802    /// Describes how this notification was created.
803    pub origin: NotificationOrigin,
804    /// RFC 3339 datetime string of when this notification was last attempted.
805    pub last_attempt_at: Option<DateTime<FixedOffset>>,
806    /// RFC 3339 datetime string of when this notification is scheduled to be retried.
807    pub retry_at: Option<DateTime<FixedOffset>>,
808    /// How many times delivery of this notification has been attempted. Automatically incremented by Paddle after an attempt.
809    pub times_attempted: i64,
810    /// Unique Paddle ID for this notification setting, prefixed with `ntfset_`.
811    pub notification_setting_id: NotificationSettingID,
812}
813
814/// Represents a notification log entity.
815#[derive(Clone, Debug, Serialize, Deserialize)]
816pub struct NotificationLog {
817    /// Unique Paddle ID for this notification log, prefixed with `ntflog_`.
818    pub id: NotificationLogID,
819    /// HTTP code sent by the responding server.
820    pub response_code: i64,
821    /// Content-Type sent by the responding server.
822    pub response_content_type: Option<String>,
823    /// Response body sent by the responding server. Typically empty for success responses.
824    pub response_body: String,
825    /// RFC 3339 datetime string.
826    pub attempted_at: String,
827}
828
829/// Represents a notification destination.
830#[derive(Clone, Debug, Serialize, Deserialize)]
831pub struct NotificationSetting {
832    /// Unique Paddle ID for this notification setting, prefixed with `ntfset_`.
833    pub id: NotificationSettingID,
834    /// Short description for this notification destination. Shown in the Paddle dashboard.
835    pub description: String,
836    /// Where notifications should be sent for this destination.
837    pub r#type: NotificationSettingType,
838    /// Webhook endpoint URL or email address.
839    pub destination: String,
840    /// Whether Paddle should try to deliver events to this notification destination.
841    pub active: bool,
842    /// API version that returned objects for events should conform to. Must be a valid version of the Paddle API. Can't be a version older than your account default.
843    pub api_version: i64,
844    /// Whether potentially sensitive fields should be sent to this notification destination.
845    pub include_sensitive_fields: bool,
846    /// Subscribed events for this notification destination.
847    pub subscribed_events: Vec<EventType>,
848    /// Webhook destination secret key, prefixed with `pdl_ntfset_`. Used for signature verification.
849    pub endpoint_secret_key: EndpointSecretKey,
850    /// Whether Paddle should deliver real platform events, simulation events or both to this notification destination.
851    pub traffic_source: TrafficSource,
852}
853
854/// Represents a notification destination when creating notification destinations.
855#[derive(Clone, Debug, Serialize, Deserialize)]
856pub struct NotificationSettingCreate {
857    /// Unique Paddle ID for this notification setting, prefixed with `ntfset_`.
858    pub id: NotificationSettingID,
859    /// Short description for this notification destination. Shown in the Paddle Dashboard.
860    pub description: String,
861    /// Where notifications should be sent for this destination.
862    pub r#type: NotificationSettingType,
863    /// Webhook endpoint URL or email address.
864    pub destination: String,
865    /// Whether Paddle should try to deliver events to this notification destination.
866    pub active: bool,
867    /// API version that returned objects for events should conform to. Must be a valid version of the Paddle API. Can't be a version older than your account default. If omitted, defaults to your account default version.
868    pub api_version: i64,
869    /// Whether potentially sensitive fields should be sent to this notification destination. If omitted, defaults to `false`.
870    pub include_sensitive_fields: bool,
871    /// Subscribed events for this notification destination. When creating or updating a notification destination, pass an array of event type names only. Paddle returns the complete event type object.
872    pub subscribed_events: Vec<String>,
873    /// Webhook destination secret key, prefixed with `pdl_ntfset_`. Used for signature verification.
874    pub endpoint_secret_key: EndpointSecretKey,
875    /// Whether Paddle should deliver real platform events, simulation events or both to this notification destination. If omitted, defaults to `platform`.
876    pub traffic_source: TrafficSource,
877}
878
879/// Represents a notification destination when updating notification destinations.
880#[derive(Clone, Debug, Serialize, Deserialize)]
881pub struct NotificationSettingUpdate {
882    /// Short description for this notification destination. Shown in the Paddle Dashboard.
883    pub description: String,
884    /// Webhook endpoint URL or email address.
885    pub destination: String,
886    /// Whether Paddle should try to deliver events to this notification destination.
887    pub active: bool,
888    /// API version that returned objects for events should conform to. Must be a valid version of the Paddle API. Can't be a version older than your account default. Defaults to your account default if omitted.
889    pub api_version: i64,
890    /// Whether potentially sensitive fields should be sent to this notification destination.
891    pub include_sensitive_fields: bool,
892    /// Subscribed events for this notification destination. When creating or updating a notification destination, pass an array of event type names only. Paddle returns the complete event type object.
893    pub subscribed_events: Option<Vec<String>>,
894    /// Whether Paddle should deliver real platform events, simulation events or both to this notification destination.
895    pub traffic_source: TrafficSource,
896}
897
898/// Represents a price preview entity.
899#[derive(Clone, Debug, Serialize, Deserialize)]
900pub struct PricePreview {
901    /// Unique Paddle ID for this price, prefixed with `pri_`.
902    /// The value is null for custom prices being previewed.
903    pub id: Option<PriceID>,
904    /// Paddle ID for the product that this price is for, prefixed with `pro_`.
905    /// The value is null for custom products being previewed.
906    pub product_id: Option<ProductID>,
907    /// Internal description for this price, not shown to customers. Typically notes for your team.
908    pub description: String,
909    /// Type of item. Standard items are considered part of your catalog and are shown on the Paddle dashboard.
910    pub r#type: CatalogType,
911    /// Name of this price, shown to customers at checkout and on invoices. Typically describes how often the related product bills.
912    pub name: Option<String>,
913    /// How often this price should be charged. `null` if price is non-recurring (one-time).
914    pub billing_cycle: Option<Duration>,
915    /// Trial period for the product related to this price. The billing cycle begins once the trial period is over. `null` for no trial period. Requires `billing_cycle`.
916    pub trial_period: Option<Duration>,
917    /// How tax is calculated for this price.
918    pub tax_mode: TaxMode,
919    /// A base representation of monetary value unformatted in the lowest denomination with currency code.
920    pub unit_price: Money,
921    /// List of unit price overrides. Use to override the base price with a custom price and currency for a country or group of countries.
922    pub unit_price_overrides: Vec<UnitPriceOverride>,
923    pub quantity: PriceQuantity,
924    /// Whether this entity can be used in Paddle.
925    pub status: Status,
926    /// Your own structured key-value data.
927    pub custom_data: Option<serde_json::Value>,
928    /// Import information for this entity. `null` if this entity is not imported.
929    pub import_meta: ImportMeta,
930    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
931    pub created_at: String,
932    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
933    pub updated_at: String,
934}
935
936/// Represents a product (preview) entity.
937#[derive(Clone, Debug, Serialize, Deserialize)]
938pub struct ProductPreview {
939    /// Unique Paddle ID for this product, prefixed with `pro_`.
940    /// The value is null for custom products being previewed.
941    pub id: Option<ProductID>,
942    /// Name of this product.
943    pub name: String,
944    /// Short description for this product.
945    pub description: Option<String>,
946    /// Type of item. Standard items are considered part of your catalog and are shown on the Paddle dashboard.
947    pub r#type: CatalogType,
948    /// Tax category for this product. Used for charging the correct rate of tax. Selected tax category must be enabled on your Paddle account.
949    pub tax_category: TaxCategory,
950    /// Image for this product. Included in the checkout and on some customer documents.
951    pub image_url: Option<String>,
952    /// Your own structured key-value data.
953    pub custom_data: Option<serde_json::Value>,
954    /// Whether this entity can be used in Paddle.
955    pub status: Status,
956    /// Import information for this entity. `null` if this entity is not imported.
957    pub import_meta: Option<ImportMeta>,
958    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
959    pub created_at: DateTime<Utc>,
960    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
961    pub updated_at: DateTime<Utc>,
962}
963
964#[derive(Clone, Debug, Serialize, Deserialize)]
965#[serde(untagged)]
966pub enum ReportFilterValue {
967    String(String),
968    Array(Vec<String>),
969}
970
971#[derive(Serialize, Deserialize, Clone, Debug)]
972pub struct ReportFilter<T: Serialize> {
973    /// Field name to filter by.
974    pub name: T,
975    /// Operator to use when filtering. Valid when filtering by `updated_at`, `null` otherwise.
976    pub operator: Option<FilterOperator>,
977    /// Value to filter by. Check the allowed values descriptions for the `name` field to see valid values for a field.
978    pub value: ReportFilterValue,
979}
980
981/// Represents a report entity.
982#[derive(Clone, Debug, Serialize, Deserialize)]
983pub struct ReportBase {
984    /// Unique Paddle ID for this entity.
985    pub id: PaddleID,
986    pub r#type: String,
987    pub filters: Vec<serde_json::Value>,
988    /// Status of this report. Set automatically by Paddle.
989    ///
990    /// Reports are created as `pending` initially, then move to `ready` when they're available to download.
991    pub status: ReportStatus,
992    /// Number of records in this report. `null` if the report is `pending`.
993    pub rows: Option<i64>,
994    /// RFC 3339 datetime string of when this report expires. The report is no longer available to download after this date.
995    pub expires_at: Option<DateTime<Utc>>,
996    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
997    pub updated_at: DateTime<Utc>,
998    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
999    pub created_at: DateTime<Utc>,
1000}
1001
1002/// Information about the request. Sent by Paddle as part of the simulation.
1003#[derive(Clone, Debug, Serialize, Deserialize)]
1004pub struct SimulationEventRequest {
1005    /// Request body sent by Paddle.
1006    pub body: String,
1007}
1008
1009/// Information about the response. Sent by the responding server for the notification setting.
1010#[derive(Clone, Debug, Serialize, Deserialize)]
1011pub struct SimulationEventResponse {
1012    /// Response body sent by the responding server. May be empty for success responses.
1013    pub body: String,
1014    /// HTTP status code sent by the responding server.
1015    pub status_code: i64,
1016}
1017
1018/// Represents a simulation event.
1019#[derive(Clone, Debug, Serialize, Deserialize)]
1020pub struct SimulationEvent {
1021    /// Unique Paddle ID for this simulation event, prefixed with `ntfsimevt_`.
1022    pub id: SimulationEventID,
1023    /// Status of this simulation run log.
1024    pub status: SimulationEventStatus,
1025    /// Type of event sent by Paddle, in the format `entity.event_type`.
1026    pub event_type: EventTypeName,
1027    /// Simulation payload. Pass a JSON object that matches the schema for an event type to simulate a custom payload. If omitted, Paddle populates with a demo example.
1028    pub payload: serde_json::Value,
1029    /// Information about the request. Sent by Paddle as part of the simulation.
1030    pub request: SimulationEventRequest,
1031    /// Information about the response. Sent by the responding server for the notification setting.
1032    pub response: SimulationEventResponse,
1033    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
1034    pub created_at: String,
1035    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
1036    pub updated_at: String,
1037}
1038
1039/// Represents a simulation run entity for a scenario.
1040#[derive(Clone, Debug, Serialize, Deserialize)]
1041pub struct SimulationRunScenario {
1042    /// Unique Paddle ID for this simulation run, prefixed with `ntfsimrun_`.
1043    pub id: SimulationRunID,
1044    /// Status of this simulation run.
1045    pub status: SimulationRunStatus,
1046    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
1047    pub created_at: String,
1048    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
1049    pub updated_at: String,
1050    /// Scenario for a simulation.
1051    pub r#type: SimulationScenarioType,
1052}
1053
1054/// Represents a simulation run entity for a single event.
1055#[derive(Clone, Debug, Serialize, Deserialize)]
1056pub struct SimulationRunSingleEvent {
1057    /// Unique Paddle ID for this simulation run, prefixed with `ntfsimrun_`.
1058    pub id: SimulationRunID,
1059    /// Status of this simulation run.
1060    pub status: SimulationRunStatus,
1061    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
1062    pub created_at: String,
1063    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
1064    pub updated_at: String,
1065    /// Type of event sent by Paddle, in the format `entity.event_type`.
1066    pub r#type: EventTypeName,
1067}
1068
1069/// Represents a simulation entity for a scenario.
1070#[derive(Clone, Debug, Serialize, Deserialize)]
1071pub struct SimulationScenario {
1072    /// Unique Paddle ID for this simulation, prefixed with `ntfsim_`.
1073    pub id: SimulationID,
1074    /// Whether this entity can be used in Paddle.
1075    pub status: Status,
1076    /// Unique Paddle ID for this notification setting, prefixed with `ntfset_`.
1077    pub notification_setting_id: NotificationSettingID,
1078    /// Name of this simulation.
1079    pub name: String,
1080    /// Scenario for a simulation.
1081    pub r#type: SimulationScenarioType,
1082    /// Simulation payload. `null` for scenarios.
1083    pub payload: Option<serde_json::Value>,
1084    /// RFC 3339 datetime string of when this simulation was last run. `null` until run. Set automatically by Paddle.
1085    pub last_run_at: Option<DateTime<FixedOffset>>,
1086    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
1087    pub created_at: String,
1088    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
1089    pub updated_at: String,
1090}
1091
1092/// Represents a simulation entity for a scenario when creating.
1093#[derive(Clone, Debug, Serialize, Deserialize)]
1094pub struct SimulationScenarioCreate {
1095    /// Unique Paddle ID for this notification setting, prefixed with `ntfset_`.
1096    pub notification_setting_id: NotificationSettingID,
1097    /// Name of this simulation.
1098    pub name: String,
1099    /// Scenario for a simulation.
1100    pub r#type: SimulationScenarioType,
1101}
1102
1103/// Represents a simulation entity for a scenario when updating.
1104#[derive(Clone, Debug, Serialize, Deserialize)]
1105pub struct SimulationScenarioUpdate {
1106    /// Unique Paddle ID for this notification setting, prefixed with `ntfset_`.
1107    pub notification_setting_id: NotificationSettingID,
1108    /// Name of this simulation.
1109    pub name: Option<String>,
1110    /// Whether this entity can be used in Paddle.
1111    pub status: Status,
1112    /// Scenario for a simulation.
1113    pub r#type: SimulationScenarioType,
1114}
1115
1116/// Represents a simulation entity for a single event when creating.
1117#[derive(Clone, Debug, Serialize, Deserialize)]
1118pub struct SimulationSingleEventCreate {
1119    /// Unique Paddle ID for this notification setting, prefixed with `ntfset_`.
1120    pub notification_setting_id: NotificationSettingID,
1121    /// Name of this simulation.
1122    pub name: Option<String>,
1123    /// Type of event sent by Paddle, in the format `entity.event_type`.
1124    pub r#type: EventTypeName,
1125    /// Simulation payload. Pass a JSON object that matches the schema for an event type to simulate a custom payload. If omitted, Paddle populates with a demo example.
1126    pub payload: Option<serde_json::Value>,
1127}
1128
1129/// Represents a simulation entity for a single event when updating.
1130#[derive(Clone, Debug, Serialize, Deserialize)]
1131pub struct SimulationSingleEventUpdate {
1132    /// Unique Paddle ID for this notification setting, prefixed with `ntfset_`.
1133    pub notification_setting_id: NotificationSettingID,
1134    /// Name of this simulation.
1135    pub name: Option<String>,
1136    /// Whether this entity can be used in Paddle.
1137    pub status: Status,
1138    /// Type of event sent by Paddle, in the format `entity.event_type`.
1139    pub r#type: EventTypeName,
1140    /// Simulation payload. Pass a JSON object that matches the schema for an event type to simulate a custom payload. Set to `null` to clear and populate with a demo example.
1141    pub payload: Option<serde_json::Value>,
1142}
1143
1144/// Represents a simulation type.
1145#[derive(Clone, Debug, Serialize, Deserialize)]
1146pub struct SimulationType {
1147    /// Type of simulation sent by Paddle. Single event simulations are in the format `entity.event_type`; scenario simulations are in `snake_case`.
1148    pub name: String,
1149    /// Descriptive label for this simulation type. Typically gives more context about a scenario. Single event simulations are in the format `entity.event_type`.
1150    pub label: String,
1151    /// Short description of this simulation type.
1152    pub description: String,
1153    /// Group for this simulation type. Typically the entity that this event relates to.
1154    pub group: String,
1155    /// Type of simulation.
1156    pub r#type: SimulationKind,
1157    /// List of events that will be sent for this simulation type.
1158    pub events: Vec<EventTypeName>,
1159}
1160
1161/// Change that's scheduled to be applied to a subscription. Use the pause subscription, cancel subscription, and resume subscription operations to create scheduled changes. `null` if no scheduled changes.
1162#[derive(Clone, Debug, Serialize, Deserialize)]
1163pub struct SubscriptionScheduledChange {
1164    /// Kind of change that's scheduled to be applied to this subscription.
1165    pub action: ScheduledChangeAction,
1166    /// RFC 3339 datetime string.
1167    pub effective_at: DateTime<FixedOffset>,
1168    /// RFC 3339 datetime string of when a paused subscription should resume. Only used for `pause` scheduled changes.
1169    pub resume_at: Option<DateTime<FixedOffset>>,
1170}
1171
1172/// Authenticated customer portal deep links for this subscription. For security, the `token` appended to each link is temporary. You shouldn't store these links.
1173#[derive(Clone, Debug, Serialize, Deserialize)]
1174pub struct SubscriptionManagementUrls {
1175    /// Link to the page for this subscription in the customer portal with the payment method update form pre-opened. Use as part of workflows to let customers update their payment details. `null` for manually-collected subscriptions.
1176    pub update_payment_method: Option<String>,
1177    /// Link to the page for this subscription in the customer portal with the subscription cancellation form pre-opened. Use as part of cancel subscription workflows.
1178    pub cancel: String,
1179}
1180
1181/// Represents a subscription entity.
1182#[derive(Clone, Debug, Serialize, Deserialize)]
1183pub struct Subscription {
1184    /// Unique Paddle ID for this subscription entity, prefixed with `sub_`.
1185    pub id: SubscriptionID,
1186    /// Status of this subscription. Set automatically by Paddle. Use the pause subscription or cancel subscription operations to change.
1187    pub status: SubscriptionStatus,
1188    /// Unique Paddle ID for this customer entity, prefixed with `ctm_`.
1189    pub customer_id: CustomerID,
1190    /// Unique Paddle ID for this address entity, prefixed with `add_`.
1191    pub address_id: AddressID,
1192    /// Paddle ID of the business that this subscription is for, prefixed with `biz_`.
1193    pub business_id: Option<BusinessID>,
1194    /// Supported three-letter ISO 4217 currency code.
1195    pub currency_code: CurrencyCode,
1196    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
1197    pub created_at: DateTime<Utc>,
1198    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
1199    pub updated_at: DateTime<Utc>,
1200    /// RFC 3339 datetime string of when this subscription started. This may be different from `first_billed_at` if the subscription started in trial.
1201    pub started_at: Option<DateTime<Utc>>,
1202    /// RFC 3339 datetime string of when this subscription was first billed. This may be different from `started_at` if the subscription started in trial.
1203    pub first_billed_at: Option<DateTime<Utc>>,
1204    /// RFC 3339 datetime string of when this subscription is next scheduled to be billed.
1205    pub next_billed_at: Option<DateTime<Utc>>,
1206    /// RFC 3339 datetime string of when this subscription was paused. Set automatically by Paddle when the pause subscription operation is used. `null` if not paused.
1207    pub paused_at: Option<DateTime<Utc>>,
1208    /// RFC 3339 datetime string of when this subscription was canceled. Set automatically by Paddle when the cancel subscription operation is used. `null` if not canceled.
1209    pub canceled_at: Option<DateTime<Utc>>,
1210    /// Details of the discount applied to this subscription.
1211    pub discount: Option<SubscriptionDiscountTimePeriod>,
1212    /// How payment is collected. `automatic` for checkout, `manual` for invoices.
1213    pub collection_mode: CollectionMode,
1214    /// Details for invoicing. Required if `collection_mode` is `manual`.
1215    pub billing_details: Option<BillingDetails>,
1216    /// Current billing period for this subscription. Set automatically by Paddle based on the billing cycle. `null` for `paused` and `canceled` subscriptions.
1217    pub current_billing_period: Option<TimePeriod>,
1218    pub billing_cycle: Duration,
1219    /// Change that's scheduled to be applied to a subscription. Use the pause subscription, cancel subscription, and resume subscription operations to create scheduled changes. `null` if no scheduled changes.
1220    pub scheduled_change: Option<SubscriptionScheduledChange>,
1221    /// Authenticated customer portal deep links for this subscription. For security, the `token` appended to each link is temporary. You shouldn't store these links.
1222    pub management_urls: Option<SubscriptionManagementUrls>,
1223    /// List of items on this subscription. Only recurring items are returned.
1224    pub items: Vec<SubscriptionItem>,
1225    /// Your own structured key-value data.
1226    pub custom_data: Option<serde_json::Value>,
1227    /// Import information for this entity. `null` if this entity is not imported.
1228    pub import_meta: Option<ImportMeta>,
1229}
1230
1231#[derive(Clone, Debug, Serialize, Deserialize)]
1232pub enum SubscriptionChargeItem {
1233    /// Add a catalog item to a subscription. In this case, the product and price that you're billing for exist in your product catalog in Paddle.
1234    CatalogItem(SubscriptionItemCreateWithPriceId),
1235    /// Add a non-catalog price for an existing product in your catalog to a subscription. In this case, the product you're billing for is a catalog product, but you charge a specific price for it.
1236    NonCatalogExistingProduct(SubscriptionChargeCreateWithPrice),
1237    /// Add a non-catalog price for a non-catalog product in your catalog to a subscription. In this case, the product and price that you're billing for are specific to this subscription.
1238    NonCatalogPriceAndProduct(SubscriptionChargeCreateWithPriceAndProduct),
1239}
1240
1241/// Represents a one-time charge for a subscription.
1242#[derive(Clone, Debug, Serialize, Deserialize)]
1243pub struct SubscriptionCharge {
1244    /// When this subscription change should take effect from. Defaults to `next_billing_period`, which creates a
1245    /// `scheduled_change` to apply the subscription change at the end of the billing period.
1246    pub effective_from: EffectiveFrom,
1247    /// List of one-time charges to bill for. Only prices where the `billing_cycle` is `null` may be added.
1248    ///
1249    /// You can charge for items that you've added to your catalog by passing the Paddle ID of an existing price entity, or you can charge for non-catalog items by passing a price object.
1250    ///
1251    /// Non-catalog items can be for existing products, or you can pass a product object as part of your price to charge for a non-catalog product.
1252    pub items: Vec<SubscriptionChargeItem>,
1253    /// How Paddle should handle changes made to a subscription or its items if the payment fails during update. If omitted, defaults to `prevent_change`.
1254    pub on_payment_failure: SubscriptionOnPaymentFailure,
1255}
1256
1257/// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
1258#[derive(Clone, Debug, Serialize, Deserialize)]
1259pub struct Totals {
1260    /// Subtotal before discount, tax, and deductions. If an item, unit price multiplied by quantity.
1261    pub subtotal: String,
1262    /// Total discount as a result of any discounts applied.
1263    ///
1264    /// Except for percentage discounts, Paddle applies tax to discounts based on the line item `price.tax_mode`. If `price.tax_mode` for a line item is `internal`, Paddle removes tax from the discount applied.
1265    pub discount: String,
1266    /// Total tax on the subtotal.
1267    pub tax: String,
1268    /// Total after discount and tax.
1269    pub total: String,
1270}
1271
1272#[derive(Clone, Debug, Serialize, Deserialize)]
1273pub struct TaxRatesUsed {
1274    /// Rate used to calculate tax for this transaction preview.
1275    pub tax_rate: String,
1276    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
1277    pub totals: Totals,
1278}
1279
1280/// Breakdown of the total for a transaction. These numbers can be negative when dealing with subscription updates that result in credit.
1281#[derive(Clone, Debug, Serialize, Deserialize)]
1282pub struct TransactionTotals {
1283    /// Subtotal before discount, tax, and deductions. If an item, unit price multiplied by quantity.
1284    pub subtotal: String,
1285    /// Total discount as a result of any discounts applied.
1286    ///
1287    /// Except for percentage discounts, Paddle applies tax to discounts based on the line item `price.tax_mode`. If `price.tax_mode` for a line item is `internal`, Paddle removes tax from the discount applied.
1288    pub discount: String,
1289    /// Total tax on the subtotal.
1290    pub tax: String,
1291    /// Total after discount and tax.
1292    pub total: String,
1293    /// Total credit applied to this transaction. This includes credits applied using a customer's credit balance and adjustments to a `billed` transaction.
1294    pub credit: String,
1295    /// Additional credit generated from negative `details.line_items`. This credit is added to the customer balance.
1296    pub credit_to_balance: String,
1297    /// Total due on a transaction after credits and any payments.
1298    pub balance: String,
1299    /// Total due on a transaction after credits but before any payments.
1300    pub grand_total: String,
1301    /// Total fee taken by Paddle for this transaction. `null` until the transaction is `completed` and the fee is processed.
1302    pub fee: Option<String>,
1303    /// Total earnings for this transaction. This is the total minus the Paddle fee. `null` until the transaction is `completed` and the fee is processed.
1304    pub earnings: Option<String>,
1305    /// Three-letter ISO 4217 currency code of the currency used for this transaction.
1306    pub currency_code: CurrencyCode,
1307}
1308
1309/// SubscriptionTransactionDetailsPreview requires same fields as TransactionLineItemPreview but proration is optional
1310#[derive(Clone, Debug, Serialize, Deserialize)]
1311pub struct SubscriptionTransactionDetailsPreviewItem {
1312    /// Paddle ID for the price related to this transaction line item, prefixed with `pri_`.
1313    /// The value is null for custom prices being previewed.
1314    pub price_id: Option<PriceID>,
1315    /// Quantity of this transaction line item.
1316    pub quantity: i64,
1317    /// Rate used to calculate tax for this transaction line item.
1318    pub tax_rate: String,
1319    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
1320    pub unit_totals: Totals,
1321    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
1322    pub totals: Totals,
1323    /// Represents a product (preview) entity.
1324    pub product: ProductPreview,
1325    /// How proration was calculated for this item.
1326    pub proration: Option<Proration>,
1327}
1328
1329/// Calculated totals for a transaction preview, including discounts, tax, and currency conversion. Considered the source of truth for totals on a transaction preview.
1330#[derive(Clone, Debug, Serialize, Deserialize)]
1331pub struct SubscriptionTransactionDetailsPreview {
1332    /// List of tax rates applied to this transaction preview.
1333    pub tax_rates_used: Vec<TaxRatesUsed>,
1334    /// Breakdown of the total for a transaction. These numbers can be negative when dealing with subscription updates that result in credit.
1335    pub totals: TransactionTotals,
1336    /// Information about line items for this transaction preview. Different from transaction preview `items` as they include totals calculated by Paddle. Considered the source of truth for line item totals.
1337    pub line_items: Vec<SubscriptionTransactionDetailsPreviewItem>,
1338}
1339
1340/// Preview of the next transaction for this subscription. May include prorated charges that aren't yet billed and one-time charges. `null` if the subscription is scheduled to cancel or pause.
1341#[derive(Clone, Debug, Serialize, Deserialize)]
1342pub struct NextTransaction {
1343    pub billing_period: TimePeriod,
1344    /// Calculated totals for a transaction preview, including discounts, tax, and currency conversion. Considered the source of truth for totals on a transaction preview.
1345    pub details: SubscriptionTransactionDetailsPreview,
1346    /// Preview of adjustments for the next transaction.
1347    pub adjustments: Vec<AdjustmentPreview>,
1348}
1349
1350/// Details of the result of credits and charges. Where the total of any credit adjustments is greater than the total charge, the result is a prorated credit; otherwise, the result is a prorated charge.
1351#[derive(Clone, Debug, Serialize, Deserialize)]
1352pub struct UpdateSummaryResult {
1353    /// Whether the subscription change results in a prorated credit or a charge.
1354    pub action: UpdateSummaryResultAction,
1355    /// Amount representing the result of this update, either a charge or a credit.
1356    pub amount: String,
1357    /// Supported three-letter ISO 4217 currency code.
1358    pub currency_code: CurrencyCode,
1359}
1360
1361/// Impact of this subscription change. Includes whether the change results in a charge or credit, and totals for prorated amounts.
1362#[derive(Clone, Debug, Serialize, Deserialize)]
1363pub struct SubscriptionPreviewUpdateSummary {
1364    /// A base representation of monetary value unformatted in the lowest denomination with currency code.
1365    pub credit: Money,
1366    /// A base representation of monetary value unformatted in the lowest denomination with currency code.
1367    pub charge: Money,
1368    /// Details of the result of credits and charges. Where the total of any credit adjustments is greater than the total charge, the result is a prorated credit; otherwise, the result is a prorated charge.
1369    pub result: UpdateSummaryResult,
1370}
1371
1372/// Represents a subscription preview when previewing a subscription.
1373#[derive(Clone, Debug, Serialize, Deserialize)]
1374pub struct SubscriptionPreview {
1375    /// Status of this subscription. Set automatically by Paddle. Use the pause subscription or cancel subscription operations to change.
1376    pub status: SubscriptionStatus,
1377    /// Unique Paddle ID for this customer entity, prefixed with `ctm_`.
1378    pub customer_id: CustomerID,
1379    /// Unique Paddle ID for this address entity, prefixed with `add_`.
1380    pub address_id: AddressID,
1381    /// Paddle ID of the business that this subscription is for, prefixed with `biz_`.
1382    pub business_id: Option<BusinessID>,
1383    /// Supported three-letter ISO 4217 currency code.
1384    pub currency_code: CurrencyCode,
1385    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
1386    pub created_at: DateTime<Utc>,
1387    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
1388    pub updated_at: DateTime<Utc>,
1389    /// RFC 3339 datetime string of when this subscription started. This may be different from `first_billed_at` if the subscription started in trial.
1390    pub started_at: Option<DateTime<Utc>>,
1391    /// RFC 3339 datetime string of when this subscription was first billed. This may be different from `started_at` if the subscription started in trial.
1392    pub first_billed_at: Option<DateTime<Utc>>,
1393    /// RFC 3339 datetime string of when this subscription is next scheduled to be billed.
1394    pub next_billed_at: Option<DateTime<Utc>>,
1395    /// RFC 3339 datetime string of when this subscription was paused. Set automatically by Paddle when the pause subscription operation is used. `null` if not paused.
1396    pub paused_at: Option<DateTime<Utc>>,
1397    /// RFC 3339 datetime string of when this subscription was canceled. Set automatically by Paddle when the cancel subscription operation is used. `null` if not canceled.
1398    pub canceled_at: Option<DateTime<Utc>>,
1399    /// Details of the discount applied to this subscription.
1400    pub discount: Option<Discount>,
1401    /// How payment is collected. `automatic` for checkout, `manual` for invoices.
1402    pub collection_mode: CollectionMode,
1403    /// Details for invoicing. Required if `collection_mode` is `manual`.
1404    pub billing_details: Option<BillingDetails>,
1405    /// Current billing period for this subscription. Set automatically by Paddle based on the billing cycle. `null` for `paused` and `canceled` subscriptions.
1406    pub current_billing_period: Option<TimePeriod>,
1407    pub billing_cycle: Duration,
1408    /// Change that's scheduled to be applied to a subscription. Use the pause subscription, cancel subscription, and resume subscription operations to create scheduled changes. `null` if no scheduled changes.
1409    pub scheduled_change: Option<SubscriptionScheduledChange>,
1410    /// Authenticated customer portal deep links for this subscription. For security, the `token` appended to each link is temporary. You shouldn't store these links.
1411    pub management_urls: SubscriptionManagementUrls,
1412    /// List of items on this subscription. Only recurring items are returned.
1413    pub items: Vec<SubscriptionItem>,
1414    /// Your own structured key-value data.
1415    pub custom_data: Option<serde_json::Value>,
1416    /// Preview of the immediate transaction created as a result of changes to the subscription. Returns a complete object where `proration_billing_mode` is `prorated_immediately` or `full_immediately`; `null` otherwise.
1417    pub immediate_transaction: Option<NextTransaction>,
1418    /// Preview of the next transaction for this subscription. Includes charges created where `proration_billing_mode` is `prorated_next_billing_period` or `full_next_billing_period`, as well as one-time charges. `null` if the subscription is scheduled to cancel or pause.
1419    pub next_transaction: NextTransaction,
1420    /// Calculated totals for a transaction preview, including discounts, tax, and currency conversion. Considered the source of truth for totals on a transaction preview.
1421    pub recurring_transaction_details: SubscriptionTransactionDetailsPreview,
1422    pub update_summary: Option<SubscriptionPreviewUpdateSummary>,
1423    /// Import information for this entity. `null` if this entity is not imported.
1424    pub import_meta: Option<ImportMeta>,
1425}
1426
1427/// Details of the discount applied to this subscription. Include to add a discount to a subscription. `null` to remove a discount.
1428#[derive(Clone, Debug, Serialize, Deserialize)]
1429pub struct SubscriptionDiscountEffectiveFrom {
1430    /// Unique Paddle ID for this discount, prefixed with `dsc_`.
1431    pub id: DiscountID,
1432    /// When this subscription change should take effect from. Defaults to `next_billing_period`, which creates a
1433    /// `scheduled_change` to apply the subscription change at the end of the billing period.
1434    pub effective_from: EffectiveFrom,
1435}
1436
1437/// Represents a subscription entity when updating subscriptions.
1438#[derive(Clone, Debug, Serialize, Deserialize)]
1439pub struct SubscriptionUpdate {
1440    /// Unique Paddle ID for this customer entity, prefixed with `ctm_`.
1441    pub customer_id: CustomerID,
1442    /// Unique Paddle ID for this address entity, prefixed with `add_`.
1443    pub address_id: AddressID,
1444    /// Paddle ID of the business that this subscription is for, prefixed with `biz_`. Include to change the business for a subscription.
1445    pub business_id: BusinessID,
1446    /// Supported three-letter ISO 4217 currency code.
1447    pub currency_code: CurrencyCode,
1448    /// RFC 3339 datetime string.
1449    pub next_billed_at: DateTime<Utc>,
1450    /// Details of the discount applied to this subscription. Include to add a discount to a subscription. `null` to remove a discount.
1451    pub discount: SubscriptionDiscountEffectiveFrom,
1452    /// How payment is collected. `automatic` for checkout, `manual` for invoices.
1453    pub collection_mode: CollectionMode,
1454    /// Details for invoicing. Required if `collection_mode` is `manual`. `null` if changing `collection_mode` to `automatic`.
1455    pub billing_details: BillingDetails,
1456    /// Change that's scheduled to be applied to a subscription. When updating, you may only set to `null` to remove a scheduled change. Use the pause subscription, cancel subscription, and resume subscription operations to create scheduled changes.
1457    pub scheduled_change: Option<()>,
1458    /// List of items on this subscription. Only recurring items may be added. Send the complete list of items that should be on this subscription, including existing items to retain.
1459    pub items: Vec<SubscriptionChargeItem>,
1460    /// Your own structured key-value data.
1461    pub custom_data: Option<serde_json::Value>,
1462    /// How Paddle should handle proration calculation for changes made to a subscription or its items. Required when making
1463    /// changes that impact billing.
1464    ///
1465    /// For automatically-collected subscriptions, responses may take longer than usual if a proration billing mode that
1466    /// collects for payment immediately is used.
1467    pub proration_billing_mode: ProrationBillingMode,
1468    /// How Paddle should handle changes made to a subscription or its items if the payment fails during update. If omitted, defaults to `prevent_change`.
1469    pub on_payment_failure: SubscriptionOnPaymentFailure,
1470}
1471
1472/// Price object for a non-catalog item to bill for. Include a `product_id` to relate this non-catalog price to an existing catalog price.
1473#[derive(Clone, Debug, Serialize, Deserialize)]
1474pub struct SubscriptionChargeCreateWithPricePrice {
1475    /// Unique Paddle ID for this product, prefixed with `pro_`.
1476    pub product_id: ProductID,
1477    /// Internal description for this price, not shown to customers. Typically notes for your team.
1478    pub description: String,
1479    /// Name of this price, shown to customers at checkout and on invoices. Typically describes how often the related product bills.
1480    pub name: Option<String>,
1481    /// How tax is calculated for this price.
1482    pub tax_mode: TaxMode,
1483    /// A base representation of monetary value unformatted in the lowest denomination with currency code.
1484    pub unit_price: Money,
1485    /// List of unit price overrides. Use to override the base price with a custom price and currency for a country or group of countries.
1486    pub unit_price_overrides: Vec<UnitPriceOverride>,
1487    pub quantity: PriceQuantity,
1488    /// Your own structured key-value data.
1489    pub custom_data: Option<serde_json::Value>,
1490}
1491
1492/// Price object for a non-catalog item to charge for. Include a `product` object to create a non-catalog product for this non-catalog price.
1493#[derive(Clone, Debug, Serialize, Deserialize)]
1494pub struct SubscriptionChargeCreateWithPriceAndProduct {
1495    /// Internal description for this price, not shown to customers. Typically notes for your team.
1496    pub description: String,
1497    /// Name of this price, shown to customers at checkout and on invoices. Typically describes how often the related product bills.
1498    pub name: Option<String>,
1499    /// How tax is calculated for this price.
1500    pub tax_mode: TaxMode,
1501    /// A base representation of monetary value unformatted in the lowest denomination with currency code.
1502    pub unit_price: Money,
1503    /// List of unit price overrides. Use to override the base price with a custom price and currency for a country or group of countries.
1504    pub unit_price_overrides: Vec<UnitPriceOverride>,
1505    pub quantity: PriceQuantity,
1506    /// Your own structured key-value data.
1507    pub custom_data: Option<serde_json::Value>,
1508    /// Product object for a non-catalog item to charge for.
1509    pub product: TransactionSubscriptionProductCreate,
1510}
1511
1512#[derive(Clone, Debug, Serialize, Deserialize)]
1513pub struct SubscriptionChargeCreateWithPrice {
1514    /// Quantity to bill for.
1515    pub quantity: i64,
1516    /// Price object for a non-catalog item to bill for. Include a `product_id` to relate this non-catalog price to an existing catalog price.
1517    pub price: SubscriptionChargeCreateWithPricePrice,
1518}
1519
1520#[derive(Clone, Debug, Serialize, Deserialize)]
1521pub struct TransactionPriceCreateWithProductId {
1522    /// Internal description for this price, not shown to customers. Typically notes for your team.
1523    pub description: String,
1524    /// Name of this price, shown to customers at checkout and on invoices. Typically describes how often the related product bills.
1525    pub name: Option<String>,
1526    /// How often this price should be charged. `null` if price is non-recurring (one-time).
1527    pub billing_cycle: Option<Duration>,
1528    /// Trial period for the product related to this price. The billing cycle begins once the trial period is over. `null` for no trial period. Requires `billing_cycle`.
1529    pub trial_period: Option<Duration>,
1530    /// How tax is calculated for this price.
1531    pub tax_mode: TaxMode,
1532    /// A base representation of monetary value unformatted in the lowest denomination with currency code.
1533    pub unit_price: Money,
1534    /// List of unit price overrides. Use to override the base price with a custom price and currency for a country or group of countries.
1535    pub unit_price_overrides: Vec<UnitPriceOverride>,
1536    pub quantity: PriceQuantity,
1537    /// Your own structured key-value data.
1538    pub custom_data: Option<serde_json::Value>,
1539    /// Paddle ID for the product that this price is for, prefixed with `pro_`.
1540    pub product_id: ProductID,
1541}
1542
1543#[derive(Clone, Debug, Serialize, Deserialize)]
1544pub struct SubscriptionItemCreateWithPrice {
1545    /// Quantity to bill for.
1546    pub quantity: i64,
1547    pub price: TransactionPriceCreateWithProductId,
1548}
1549
1550#[derive(Clone, Debug, Serialize, Deserialize)]
1551pub struct SubscriptionItemCreateWithPriceId {
1552    /// Quantity to bill for.
1553    pub quantity: i64,
1554    /// Unique Paddle ID for this price, prefixed with `pri_`.
1555    pub price_id: PriceID,
1556}
1557
1558#[derive(Clone, Debug, Serialize, Deserialize)]
1559pub struct SubscriptionUpdateItem {
1560    /// Unique Paddle ID for this price, prefixed with `pri_`.
1561    pub price_id: PriceID,
1562    /// Quantity of this item to add to the subscription. If updating an existing item and not changing the quantity, you may omit `quantity`.
1563    pub quantity: i64,
1564}
1565
1566/// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
1567#[derive(Clone, Debug, Serialize, Deserialize)]
1568pub struct TotalsWithoutDiscount {
1569    /// Subtotal before tax, and deductions. If an item, unit price multiplied by quantity.
1570    pub subtotal: String,
1571    /// Total tax on the subtotal.
1572    pub tax: String,
1573    /// Total after tax.
1574    pub total: String,
1575}
1576
1577#[derive(Clone, Debug, Serialize, Deserialize)]
1578pub struct TransactionItem {
1579    /// Represents a price entity.
1580    pub price: Price,
1581    /// Quantity of this item on the transaction.
1582    pub quantity: i64,
1583    /// How proration was calculated for this item. Populated when a transaction is created from a subscription change, where `proration_billing_mode` was `prorated_immediately` or `prorated_next_billing_period`. Set automatically by Paddle.
1584    pub proration: Option<Proration>,
1585}
1586
1587/// Breakdown of the totals for a transaction after adjustments.
1588#[derive(Clone, Debug, Serialize, Deserialize)]
1589pub struct TransactionTotalsAdjusted {
1590    /// Subtotal before discount, tax, and deductions. If an item, unit price multiplied by quantity.
1591    pub subtotal: String,
1592    /// Total tax on the subtotal.
1593    pub tax: String,
1594    /// Total after tax.
1595    pub total: String,
1596    /// Total due after credits but before any payments.
1597    pub grand_total: String,
1598    /// Total fee taken by Paddle for this transaction. `null` until the transaction is `completed` and the fee is processed.
1599    pub fee: Option<String>,
1600    /// Total earnings for this transaction. This is the total minus the Paddle fee.
1601    /// `null` until the transaction is `completed` and the fee is processed.
1602    pub earnings: Option<String>,
1603    /// Supported three-letter ISO 4217 currency code.
1604    pub currency_code: CurrencyCode,
1605}
1606
1607/// Breakdown of the payout total for a transaction after adjustments. `null` until the transaction is `completed`.
1608#[derive(Clone, Debug, Serialize, Deserialize)]
1609pub struct TransactionPayoutTotalsAdjusted {
1610    /// Total before tax and fees.
1611    pub subtotal: String,
1612    /// Total tax on the subtotal.
1613    pub tax: String,
1614    /// Total after tax.
1615    pub total: String,
1616    /// Total fee taken by Paddle for this payout.
1617    pub fee: String,
1618    /// Details of any chargeback fees incurred for this transaction.
1619    pub chargeback_fee: ChargebackFee,
1620    /// Total earnings for this payout. This is the subtotal minus the Paddle fee, excluding chargeback fees.
1621    pub earnings: String,
1622    /// Supported three-letter ISO 4217 currency code for payouts from Paddle.
1623    pub currency_code: CurrencyCodePayouts,
1624}
1625
1626/// Information about line items for this transaction. Different from transaction `items` as they include totals calculated by Paddle. Considered the source of truth for line item totals.
1627#[derive(Clone, Debug, Serialize, Deserialize)]
1628pub struct TransactionLineItemWithId {
1629    /// Unique Paddle ID for this transaction item, prefixed with `txnitm_`.
1630    pub id: TransactionItemID,
1631    /// Unique Paddle ID for this price, prefixed with `pri_`.
1632    pub price_id: PriceID,
1633    /// Quantity of this transaction line item.
1634    pub quantity: i64,
1635    /// How proration was calculated for this item. Populated when a transaction is created from a subscription change, where `proration_billing_mode` was `prorated_immediately` or `prorated_next_billing_period`. Set automatically by Paddle.
1636    pub proration: Option<Proration>,
1637    /// Rate used to calculate tax for this transaction line item.
1638    pub tax_rate: String,
1639    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
1640    pub unit_totals: Totals,
1641    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
1642    pub totals: Totals,
1643    /// Represents a product entity.
1644    pub product: Product,
1645}
1646
1647/// Calculated totals for a transaction, including proration, discounts, tax, and currency conversion. Considered the source of truth for totals on a transaction.
1648#[derive(Clone, Debug, Serialize, Deserialize)]
1649pub struct TransactionDetails {
1650    /// List of tax rates applied for this transaction.
1651    pub tax_rates_used: Vec<TaxRatesUsed>,
1652    /// Breakdown of the total for a transaction. These numbers can be negative when dealing with subscription updates that result in credit.
1653    pub totals: TransactionTotals,
1654    /// Breakdown of the totals for a transaction after adjustments.
1655    pub adjusted_totals: TransactionTotalsAdjusted,
1656    /// Breakdown of the payout total for a transaction. `null` until the transaction is `completed`. Returned in your payout currency.
1657    pub payout_totals: Option<TransactionPayoutTotals>,
1658    /// Breakdown of the payout total for a transaction after adjustments. `null` until the transaction is `completed`.
1659    pub adjusted_payout_totals: Option<TransactionPayoutTotalsAdjusted>,
1660    /// Information about line items for this transaction. Different from transaction `items` as they include totals calculated by Paddle. Considered the source of truth for line item totals.
1661    pub line_items: Vec<TransactionLineItemWithId>,
1662}
1663
1664#[derive(Clone, Debug, Serialize, Deserialize)]
1665pub struct TransactionPaymentAttempt {
1666    /// UUID for this payment attempt.
1667    pub payment_attempt_id: String,
1668    /// UUID for the stored payment method used for this payment attempt. Deprecated - use `payment_method_id` instead.
1669    pub stored_payment_method_id: String,
1670    /// Paddle ID of the payment method used for this payment attempt, prefixed with `paymtd_`.
1671    pub payment_method_id: Option<PaymentMethodID>,
1672    /// Amount for collection in the lowest denomination of a currency (e.g. cents for USD).
1673    pub amount: String,
1674    /// Status of this payment attempt.
1675    pub status: PaymentAttemptStatus,
1676    /// Reason why a payment attempt failed. Returns `null` if payment captured successfully.
1677    pub error_code: Option<ErrorCode>,
1678    /// Information about the payment method used for a payment attempt.
1679    pub method_details: MethodDetails,
1680    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
1681    pub created_at: String,
1682    /// RFC 3339 datetime string of when this payment was captured. `null` if `status` is not `captured`.
1683    pub captured_at: Option<DateTime<FixedOffset>>,
1684}
1685
1686/// Paddle Checkout details for this transaction. Returned for automatically-collected transactions and where `billing_details.enable_checkout` is `true` for manually-collected transactions; `null` otherwise.
1687#[derive(Clone, Debug, Serialize, Deserialize)]
1688pub struct TransactionCheckout {
1689    /// Paddle Checkout URL for this transaction, composed of the URL passed in the request or your default payment URL + `?_ptxn=` and the Paddle ID for this transaction.
1690    pub url: Option<String>,
1691}
1692
1693/// Contains an invoice PDF url for a transaction.
1694#[derive(Clone, Debug, Serialize, Deserialize)]
1695pub struct TransactionInvoice {
1696    /// URL of the requested resource.
1697    pub url: Option<String>,
1698}
1699
1700/// Represents a transaction entity.
1701#[derive(Clone, Debug, Serialize, Deserialize)]
1702pub struct Transaction {
1703    /// Unique Paddle ID for this transaction entity, prefixed with `txn_`.
1704    pub id: TransactionID,
1705    /// Status of this transaction. You may set a transaction to `billed` or `canceled`, other statuses are set automatically by Paddle. Automatically-collected transactions may return `completed` if payment is captured successfully, or `past_due` if payment failed.
1706    pub status: TransactionStatus,
1707    /// Paddle ID of the customer that this transaction is for, prefixed with `ctm_`.
1708    pub customer_id: Option<CustomerID>,
1709    /// Paddle ID of the address that this transaction is for, prefixed with `add_`.
1710    pub address_id: Option<AddressID>,
1711    /// Paddle ID of the business that this transaction is for, prefixed with `biz_`.
1712    pub business_id: Option<BusinessID>,
1713    /// Your own structured key-value data.
1714    //pub custom_data: Option<serde_json::Value>,
1715    pub custom_data: Option<serde_json::Value>,
1716    /// Supported three-letter ISO 4217 currency code.
1717    pub currency_code: CurrencyCode,
1718    /// Describes how this transaction was created.
1719    pub origin: TransactionOrigin,
1720    /// Paddle ID of the subscription that this transaction is for, prefixed with `sub_`.
1721    pub subscription_id: Option<SubscriptionID>,
1722    /// Paddle ID of the invoice that this transaction is related to, prefixed with `inv_`. Used for compatibility with the Paddle Invoice API, which is now deprecated. This field is scheduled to be removed in the next version of the Paddle API.
1723    pub invoice_id: Option<InvoiceId>,
1724    /// Invoice number for this transaction. Automatically generated by Paddle when you mark a transaction as `billed` where `collection_mode` is `manual`.
1725    pub invoice_number: Option<String>,
1726    /// How payment is collected. `automatic` for checkout, `manual` for invoices.
1727    pub collection_mode: CollectionMode,
1728    /// Paddle ID of the discount applied to this transaction, prefixed with `dsc_`.
1729    pub discount_id: Option<DiscountID>,
1730    /// Details for invoicing. Required if `collection_mode` is `manual`.
1731    pub billing_details: Option<BillingDetails>,
1732    /// Time period that this transaction is for. Set automatically by Paddle for subscription renewals to describe the period that charges are for.
1733    pub billing_period: Option<TimePeriod>,
1734    /// List of items on this transaction. For calculated totals, use `details.line_items`.
1735    pub items: Vec<TransactionItem>,
1736    /// Calculated totals for a transaction, including proration, discounts, tax, and currency conversion. Considered the source of truth for totals on a transaction.
1737    pub details: TransactionDetails,
1738    /// List of payment attempts for this transaction, including successful payments. Sorted by `created_at` in descending order, so most recent attempts are returned first.
1739    pub payments: Vec<TransactionPaymentAttempt>,
1740    /// Paddle Checkout details for this transaction. Returned for automatically-collected transactions and where `billing_details.enable_checkout` is `true` for manually-collected transactions; `null` otherwise.
1741    pub checkout: TransactionCheckout,
1742    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
1743    pub created_at: DateTime<Utc>,
1744    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
1745    pub updated_at: DateTime<Utc>,
1746    /// RFC 3339 datetime string of when this transaction was marked as `billed`. `null` for transactions that aren't `billed` or `completed`. Set automatically by Paddle.
1747    pub billed_at: Option<DateTime<Utc>>,
1748    /// RFC 3339 datetime string of when a transaction was revised. Revisions describe an update to customer information for a billed or completed transaction. `null` if not revised. Set automatically by Paddle.
1749    pub revised_at: Option<DateTime<Utc>>,
1750}
1751
1752/// Represents a transaction entity when creating transactions.
1753#[derive(Clone, Debug, Serialize, Deserialize)]
1754pub struct TransactionCreate {
1755    /// Unique Paddle ID for this transaction entity, prefixed with `txn_`.
1756    pub id: TransactionID,
1757    /// Status of this transaction. You may set a transaction to `billed` or `canceled`, other statuses are set automatically by Paddle. Automatically-collected transactions may return `completed` if payment is captured successfully, or `past_due` if payment failed.
1758    pub status: TransactionStatus,
1759    /// Paddle ID of the customer that this transaction is for, prefixed with `ctm_`. If omitted, transaction status is `draft`.
1760    pub customer_id: CustomerID,
1761    /// Paddle ID of the address that this transaction is for, prefixed with `add_`. Requires `customer_id`. If omitted, transaction status is `draft`.
1762    pub address_id: AddressID,
1763    /// Paddle ID of the business that this transaction is for, prefixed with `biz_`. Requires `customer_id`.
1764    pub business_id: BusinessID,
1765    /// Your own structured key-value data.
1766    pub custom_data: Option<serde_json::Value>,
1767    /// Supported three-letter ISO 4217 currency code. Must be `USD`, `EUR`, or `GBP` if `collection_mode` is `manual`.
1768    pub currency_code: CurrencyCode,
1769    /// Describes how this transaction was created.
1770    pub origin: TransactionOrigin,
1771    /// Paddle ID of the subscription that this transaction is for, prefixed with `sub_`.
1772    pub subscription_id: SubscriptionID,
1773    /// Paddle ID of the invoice that this transaction is related to, prefixed with `inv_`. Used for compatibility with the Paddle Invoice API, which is now deprecated. This field is scheduled to be removed in the next version of the Paddle API.
1774    pub invoice_id: InvoiceId,
1775    /// Invoice number for this transaction. Automatically generated by Paddle when you mark a transaction as `billed` where `collection_mode` is `manual`.
1776    pub invoice_number: Option<String>,
1777    /// How payment is collected. `automatic` for checkout, `manual` for invoices.
1778    pub collection_mode: CollectionMode,
1779    /// Paddle ID of the discount applied to this transaction, prefixed with `dsc_`.
1780    pub discount_id: DiscountID,
1781    /// Details for invoicing. Required if `collection_mode` is `manual`.
1782    pub billing_details: BillingDetails,
1783    /// Time period that this transaction is for. Set automatically by Paddle for subscription renewals to describe the period that charges are for.
1784    pub billing_period: Option<TimePeriod>,
1785    /// List of items to charge for. You can charge for items that you've added to your catalog by passing the Paddle ID of an existing price entity, or you can charge for non-catalog items by passing a price object.
1786    ///
1787    /// Non-catalog items can be for existing products, or you can pass a product object as part of your price to charge for a non-catalog product.
1788    pub items: Vec<SubscriptionChargeItem>,
1789    /// Calculated totals for a transaction, including proration, discounts, tax, and currency conversion. Considered the source of truth for totals on a transaction.
1790    pub details: TransactionDetails,
1791    /// List of payment attempts for this transaction, including successful payments. Sorted by `created_at` in descending order, so most recent attempts are returned first.
1792    pub payments: Vec<TransactionPaymentAttempt>,
1793    /// Paddle Checkout details for this transaction. You may pass a URL when creating or updating an automatically-collected transaction, or when creating or updating a manually-collected transaction where `billing_details.enable_checkout` is `true`.
1794    pub checkout: TransactionCheckout,
1795    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
1796    pub created_at: DateTime<FixedOffset>,
1797    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
1798    pub updated_at: DateTime<FixedOffset>,
1799    /// RFC 3339 datetime string of when this transaction was marked as `billed`. `null` for transactions that aren't `billed` or `completed`. Set automatically by Paddle.
1800    pub billed_at: Option<DateTime<FixedOffset>>,
1801}
1802
1803/// Information about line items for this transaction preview. Different from transaction preview `items` as they include totals calculated by Paddle. Considered the source of truth for line item totals.
1804#[derive(Clone, Debug, Serialize, Deserialize)]
1805pub struct TransactionLineItemPreview {
1806    /// Paddle ID for the price related to this transaction line item, prefixed with `pri_`.
1807    /// The value is null for custom prices being previewed.
1808    pub price_id: Option<PriceID>,
1809    /// Quantity of this transaction line item.
1810    pub quantity: i64,
1811    /// Rate used to calculate tax for this transaction line item.
1812    pub tax_rate: String,
1813    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
1814    pub unit_totals: Totals,
1815    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
1816    pub totals: Totals,
1817    /// Represents a product (preview) entity.
1818    pub product: ProductPreview,
1819    /// How proration was calculated for this item.
1820    pub proration: Option<Proration>,
1821}
1822
1823/// Calculated totals for a transaction preview, including discounts, tax, and currency conversion. Considered the source of truth for totals on a transaction preview.
1824#[derive(Clone, Debug, Serialize, Deserialize)]
1825pub struct TransactionDetailsPreview {
1826    /// List of tax rates applied to this transaction preview.
1827    pub tax_rates_used: Vec<TaxRatesUsed>,
1828    /// Breakdown of the total for a transaction. These numbers can be negative when dealing with subscription updates that result in credit.
1829    pub totals: TransactionTotals,
1830    /// Information about line items for this transaction preview. Different from transaction preview `items` as they include totals calculated by Paddle. Considered the source of truth for line item totals.
1831    pub line_items: Vec<TransactionLineItemPreview>,
1832}
1833
1834/// Represents a transaction entity when previewing transactions.
1835#[derive(Clone, Debug, Serialize, Deserialize)]
1836pub struct TransactionPreview {
1837    /// Paddle ID of the customer that this transaction preview is for, prefixed with `ctm_`.
1838    pub customer_id: Option<CustomerID>,
1839    /// Paddle ID of the address that this transaction preview is for, prefixed with `add_`. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
1840    pub address_id: Option<AddressID>,
1841    /// Paddle ID of the business that this transaction preview is for, prefixed with `biz_`.
1842    pub business_id: Option<BusinessID>,
1843    /// Supported three-letter ISO 4217 currency code.
1844    pub currency_code: CurrencyCode,
1845    /// Paddle ID of the discount applied to this transaction preview, prefixed with `dsc_`.
1846    pub discount_id: Option<DiscountID>,
1847    /// IP address for this transaction preview. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
1848    pub customer_ip_address: Option<String>,
1849    /// Address for this transaction preview. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
1850    pub address: Option<AddressPreview>,
1851    /// Whether trials should be ignored for transaction preview calculations.
1852    ///
1853    /// By default, recurring items with trials are considered to have a zero charge when previewing. Set to `true` to disable this.
1854    pub ignore_trials: bool,
1855    /// List of items to preview transaction calculations for.
1856    pub items: Vec<TransactionItemPreviewBase>,
1857    /// Calculated totals for a transaction preview, including discounts, tax, and currency conversion. Considered the source of truth for totals on a transaction preview.
1858    pub details: TransactionDetailsPreview,
1859    pub available_payment_methods: Vec<PaymentMethodType>,
1860}
1861
1862/// Represents an entity for previewing prices.
1863#[derive(Clone, Debug, Serialize, Deserialize)]
1864pub struct PricingPreview {
1865    /// Paddle ID of the customer that this transaction preview is for, prefixed with `ctm_`.
1866    pub customer_id: Option<CustomerID>,
1867    /// Paddle ID of the address that this transaction preview is for, prefixed with `add_`. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
1868    pub address_id: Option<AddressID>,
1869    /// Paddle ID of the business that this transaction preview is for, prefixed with `biz_`.
1870    pub business_id: Option<BusinessID>,
1871    /// Supported three-letter ISO 4217 currency code.
1872    pub currency_code: CurrencyCode,
1873    /// Paddle ID of the discount applied to this transaction preview, prefixed with `dsc_`.
1874    pub discount_id: Option<DiscountID>,
1875    /// Address for this transaction preview. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
1876    pub address: Option<AddressPreview>,
1877    /// IP address for this transaction preview. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
1878    pub customer_ip_address: Option<String>,
1879    /// Calculated totals for a transaction preview, including discounts, tax, and currency conversion. Considered the source of truth for totals on a transaction preview.
1880    pub details: PricePreviewDetails,
1881    pub available_payment_methods: Vec<PaymentMethodType>,
1882}
1883
1884/// Represents a transaction entity when previewing.
1885#[derive(Clone, Debug, Serialize, Deserialize)]
1886pub struct TransactionPreviewCreate {
1887    /// Paddle ID of the customer that this transaction preview is for, prefixed with `ctm_`.
1888    pub customer_id: CustomerID,
1889    /// Supported three-letter ISO 4217 currency code.
1890    pub currency_code: CurrencyCode,
1891    /// Paddle ID of the discount applied to this transaction preview, prefixed with `dsc_`.
1892    pub discount_id: DiscountID,
1893    /// Whether trials should be ignored for transaction preview calculations.
1894    ///
1895    /// By default, recurring items with trials are considered to have a zero charge when previewing. Set to `true` to disable this.
1896    pub ignore_trials: bool,
1897    /// List of items to preview charging for. You can preview charging for items that you've added to your catalog by passing the Paddle ID of an existing price entity, or you can preview charging for non-catalog items by passing a price object.
1898    ///
1899    /// Non-catalog items can be for existing products, or you can pass a product object as part of your price to preview charging for a non-catalog product.
1900    pub items: Vec<SubscriptionChargeItem>,
1901}
1902
1903/// Represents a price entity.
1904#[derive(Clone, Debug, Serialize, Deserialize)]
1905pub struct TransactionPriceCreateBase {
1906    /// Internal description for this price, not shown to customers. Typically notes for your team.
1907    pub description: String,
1908    /// Name of this price, shown to customers at checkout and on invoices. Typically describes how often the related product bills.
1909    pub name: Option<String>,
1910    /// How often this price should be charged. `null` if price is non-recurring (one-time).
1911    pub billing_cycle: Option<Duration>,
1912    /// Trial period for the product related to this price. The billing cycle begins once the trial period is over. `null` for no trial period. Requires `billing_cycle`.
1913    pub trial_period: Option<Duration>,
1914    /// How tax is calculated for this price.
1915    pub tax_mode: TaxMode,
1916    /// A base representation of monetary value unformatted in the lowest denomination with currency code.
1917    pub unit_price: Money,
1918    /// List of unit price overrides. Use to override the base price with a custom price and currency for a country or group of countries.
1919    pub unit_price_overrides: Vec<UnitPriceOverride>,
1920    pub quantity: PriceQuantity,
1921    /// Your own structured key-value data.
1922    pub custom_data: Option<serde_json::Value>,
1923}
1924
1925/// Represents a customer information revision for a transaction.
1926#[derive(Clone, Debug, Serialize, Deserialize)]
1927pub struct TransactionRevise {
1928    /// Revised customer information for this transaction.
1929    pub customer: Customer,
1930    /// Revised business information for this transaction.
1931    pub business: Business,
1932    /// Revised address information for this transaction.
1933    pub address: Address,
1934}
1935
1936#[derive(Clone, Debug, Serialize, Deserialize)]
1937pub struct TransactionSubscriptionProductCreate {
1938    /// Name of this product.
1939    pub name: String,
1940    /// Short description for this product.
1941    pub description: Option<String>,
1942    /// Tax category for this product. Used for charging the correct rate of tax. Selected tax category must be enabled on your Paddle account.
1943    pub tax_category: TaxCategory,
1944    /// Image for this product. Included in the checkout and on some customer documents.
1945    pub image_url: Option<String>,
1946    /// Your own structured key-value data.
1947    pub custom_data: Option<serde_json::Value>,
1948}
1949
1950/// Represents a transaction entity when updating transactions.
1951#[derive(Clone, Debug, Serialize, Deserialize)]
1952pub struct TransactionUpdate {
1953    /// Unique Paddle ID for this transaction entity, prefixed with `txn_`.
1954    pub id: TransactionID,
1955    /// Status of this transaction. You may set a transaction to `billed` or `canceled`, other statuses are set automatically by Paddle. Automatically-collected transactions may return `completed` if payment is captured successfully, or `past_due` if payment failed.
1956    pub status: TransactionStatus,
1957    /// Paddle ID of the customer that this transaction is for, prefixed with `ctm_`.
1958    pub customer_id: CustomerID,
1959    /// Paddle ID of the address that this transaction is for, prefixed with `add_`.
1960    pub address_id: AddressID,
1961    /// Paddle ID of the business that this transaction is for, prefixed with `biz_`.
1962    pub business_id: BusinessID,
1963    /// Your own structured key-value data.
1964    pub custom_data: Option<serde_json::Value>,
1965    /// Supported three-letter ISO 4217 currency code. Must be `USD`, `EUR`, or `GBP` if `collection_mode` is `manual`.
1966    pub currency_code: CurrencyCode,
1967    /// Describes how this transaction was created.
1968    pub origin: TransactionOrigin,
1969    /// Paddle ID of the subscription that this transaction is for, prefixed with `sub_`.
1970    pub subscription_id: SubscriptionID,
1971    /// Paddle ID of the invoice that this transaction is related to, prefixed with `inv_`. Used for compatibility with the Paddle Invoice API, which is now deprecated. This field is scheduled to be removed in the next version of the Paddle API.
1972    pub invoice_id: InvoiceId,
1973    /// Invoice number for this transaction. Automatically generated by Paddle when you mark a transaction as `billed` where `collection_mode` is `manual`.
1974    pub invoice_number: Option<String>,
1975    /// How payment is collected. `automatic` for checkout, `manual` for invoices.
1976    pub collection_mode: CollectionMode,
1977    /// Paddle ID of the discount applied to this transaction, prefixed with `dsc_`.
1978    pub discount_id: DiscountID,
1979    /// Details for invoicing. Required if `collection_mode` is `manual`.
1980    pub billing_details: BillingDetails,
1981    /// Time period that this transaction is for. Set automatically by Paddle for subscription renewals to describe the period that charges are for.
1982    pub billing_period: Option<TimePeriod>,
1983    /// List of items on this transaction.
1984    ///
1985    /// When making a request, each object must contain either a `price_id` or a `price` object, and a `quantity`.
1986    ///
1987    /// Include a `price_id` to charge for an existing catalog item, or a `price` object to charge for a non-catalog item.
1988    pub items: Vec<SubscriptionChargeItem>,
1989    /// Calculated totals for a transaction, including proration, discounts, tax, and currency conversion. Considered the source of truth for totals on a transaction.
1990    pub details: TransactionDetails,
1991    /// List of payment attempts for this transaction, including successful payments. Sorted by `created_at` in descending order, so most recent attempts are returned first.
1992    pub payments: Vec<TransactionPaymentAttempt>,
1993    /// Paddle Checkout details for this transaction. You may pass a URL when creating or updating an automatically-collected transaction, or when creating or updating a manually-collected transaction where `billing_details.enable_checkout` is `true`.
1994    pub checkout: TransactionCheckout,
1995    /// RFC 3339 datetime string of when this entity was created. Set automatically by Paddle.
1996    pub created_at: DateTime<FixedOffset>,
1997    /// RFC 3339 datetime string of when this entity was updated. Set automatically by Paddle.
1998    pub updated_at: DateTime<FixedOffset>,
1999    /// RFC 3339 datetime string of when this transaction was marked as `billed`. `null` for transactions that aren't `billed` or `completed`. Set automatically by Paddle.
2000    pub billed_at: Option<DateTime<FixedOffset>>,
2001}
2002
2003#[derive(Clone, Debug, Serialize, Deserialize)]
2004pub struct TransactionItemCreateBase {
2005    /// Quantity of this item on the transaction.
2006    pub quantity: i64,
2007    /// How proration was calculated for this item. Populated when a transaction is created from a subscription change, where `proration_billing_mode` was `prorated_immediately` or `prorated_next_billing_period`. Set automatically by Paddle.
2008    pub proration: Proration,
2009}
2010
2011/// Information about line items for this transaction. Different from transaction `items` as they include totals calculated by Paddle. Considered the source of truth for line item totals.
2012#[derive(Clone, Debug, Serialize, Deserialize)]
2013pub struct TransactionLineItem {
2014    /// Unique Paddle ID for this price, prefixed with `pri_`.
2015    pub price_id: PriceID,
2016    /// Quantity of this transaction line item.
2017    pub quantity: i64,
2018    /// How proration was calculated for this item. Populated when a transaction is created from a subscription change, where `proration_billing_mode` was `prorated_immediately` or `prorated_next_billing_period`. Set automatically by Paddle.
2019    pub proration: Proration,
2020    /// Rate used to calculate tax for this transaction line item.
2021    pub tax_rate: String,
2022    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
2023    pub unit_totals: Totals,
2024    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
2025    pub totals: Totals,
2026    /// Represents a product entity.
2027    pub product: Product,
2028}
2029
2030/// Breakdown of the payout total for a transaction. `null` until the transaction is `completed`. Returned in your payout currency.
2031#[derive(Clone, Debug, Serialize, Deserialize)]
2032pub struct TransactionPayoutTotals {
2033    /// Total before tax and fees.
2034    pub subtotal: String,
2035    /// Total discount as a result of any discounts applied.
2036    /// Except for percentage discounts, Paddle applies tax to discounts based on the line item `price.tax_mode`. If `price.tax_mode` for a line item is `internal`, Paddle removes tax from the discount applied.
2037    pub discount: String,
2038    /// Total tax on the subtotal.
2039    pub tax: String,
2040    /// Total after tax.
2041    pub total: String,
2042    /// Total credit applied to this transaction. This includes credits applied using a customer's credit balance and adjustments to a `billed` transaction.
2043    pub credit: String,
2044    /// Additional credit generated from negative `details.line_items`. This credit is added to the customer balance.
2045    pub credit_to_balance: String,
2046    /// Total due on a transaction after credits and any payments.
2047    pub balance: String,
2048    /// Total due on a transaction after credits but before any payments.
2049    pub grand_total: String,
2050    /// Total fee taken by Paddle for this payout.
2051    pub fee: String,
2052    /// Total earnings for this payout. This is the subtotal minus the Paddle fee.
2053    pub earnings: String,
2054    /// Supported three-letter ISO 4217 currency code for payouts from Paddle.
2055    pub currency_code: CurrencyCodePayouts,
2056}
2057
2058#[derive(Clone, Debug, Serialize, Deserialize)]
2059pub struct TransactionItemPreviewBase {
2060    /// Quantity of this item on the transaction.
2061    pub quantity: i64,
2062    /// Whether this item should be included in totals for this transaction preview. Typically used to exclude one-time charges from calculations.
2063    pub include_in_totals: bool,
2064    /// How proration was calculated for this item. `null` for transaction previews.
2065    pub proration: Option<Proration>,
2066}
2067
2068#[derive(Clone, Debug, Serialize, Deserialize)]
2069pub struct PricePreviewBase {
2070    /// Paddle ID of the customer that this preview is for, prefixed with `ctm_`.
2071    pub customer_id: CustomerID,
2072    /// Paddle ID of the address that this preview is for, prefixed with `add_`. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
2073    pub address_id: AddressID,
2074    /// Paddle ID of the business that this preview is for, prefixed with `biz_`.
2075    pub business_id: BusinessID,
2076    /// Supported three-letter ISO 4217 currency code.
2077    pub currency_code: CurrencyCode,
2078    /// Paddle ID of the discount applied to this preview, prefixed with `dsc_`.
2079    pub discount_id: DiscountID,
2080    /// Address for this preview. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
2081    pub address: Address,
2082    /// IP address for this transaction preview. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
2083    pub customer_ip_address: Option<String>,
2084}
2085
2086/// Array of discounts applied to this preview line item. Empty if no discounts applied.
2087#[derive(Clone, Debug, Serialize, Deserialize)]
2088pub struct PricePreviewDiscounts {
2089    /// Represents a discount entity.
2090    pub discount: Discount,
2091    /// Total amount discounted as a result of this discount.
2092    pub total: String,
2093    /// Total amount discounted as a result of this discount in the format of a given currency. '
2094    pub formatted_total: String,
2095}
2096
2097/// Information about line items for this preview. Includes totals calculated by Paddle. Considered the source of truth for line item totals.
2098#[derive(Clone, Debug, Serialize, Deserialize)]
2099pub struct PricePreviewLineItem {
2100    /// Represents a price entity.
2101    pub price: Price,
2102    /// Quantity of this preview line item.
2103    pub quantity: i64,
2104    /// Rate used to calculate tax for this preview line item.
2105    pub tax_rate: String,
2106    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
2107    pub unit_totals: Totals,
2108    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
2109    pub formatted_unit_totals: Totals,
2110    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
2111    pub totals: Totals,
2112    /// Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
2113    pub formatted_totals: Totals,
2114    /// Represents a product entity.
2115    pub product: Product,
2116    pub discounts: Vec<PricePreviewDiscounts>,
2117}
2118
2119/// Payout entity received from a payout event
2120#[derive(Clone, Debug, Serialize, Deserialize)]
2121pub struct Payout {
2122    /// ID for this payout.
2123    pub id: PayoutID,
2124    /// Status of this payout.
2125    pub status: PayoutStatus,
2126    /// Fee amount for this chargeback in the original currency.
2127    pub amount: String,
2128    /// Three-letter ISO 4217 currency code for chargeback fees.
2129    pub currency_code: CurrencyCodeChargebacks,
2130}
2131
2132/// ApiKey entity
2133#[derive(Clone, Debug, Serialize, Deserialize)]
2134pub struct ApiKey {
2135    /// Unique Paddle ID for this API key entity, prefixed with apikey_.
2136    pub id: ApiKeyID,
2137    /// Short name of this API key. Typically unique and human-identifiable.
2138    pub name: String,
2139    /// Short description of this API key. Typically gives details about what the API key is used for and where it's used.
2140    pub description: Option<String>,
2141    /// An obfuscated version of this API key, prefixed with `pdl_` and containing `_apikey_`.
2142    pub key: String,
2143    /// Status of this API key.
2144    pub status: ApiKeyStatus,
2145    /// Permissions assigned to this API key. Determines what actions the API key can perform.
2146    pub permissions: Vec<String>,
2147    /// Datetime of when this API key expires.
2148    pub expires_at: Option<DateTime<Utc>>,
2149    /// Datetime of when this API key was last used (accurate to within 1 hour). null if never used.
2150    pub last_used_at: Option<DateTime<Utc>>,
2151    /// Datetime of when this entity was created. Set automatically by Paddle.
2152    pub created_at: DateTime<Utc>,
2153    /// Datetime of when this entity was updated. Set automatically by Paddle.
2154    pub updated_at: DateTime<Utc>,
2155}
2156
2157/// Calculated totals for a price preview, including discounts, tax, and currency conversion.
2158#[derive(Clone, Debug, Serialize, Deserialize)]
2159pub struct PricePreviewDetails {
2160    pub line_items: Vec<PricePreviewLineItem>,
2161}
2162
2163#[derive(Clone, Debug, Serialize, Deserialize)]
2164pub struct PricePreviewItem {
2165    /// Unique Paddle ID for this price, prefixed with `pri_`.
2166    pub price_id: PriceID,
2167    /// Quantity of the item to preview.
2168    pub quantity: i64,
2169}
2170
2171/// Price object for a non-catalog item to charge for.
2172///
2173/// Can be for existing products, or you can pass a product object as part of your price to charge for a non-catalog product.
2174#[skip_serializing_none]
2175#[derive(Serialize)]
2176pub struct TransactionItemNonCatalogPrice {
2177    description: String,
2178    name: Option<String>,
2179    billing_cycle: Option<Duration>,
2180    trial_period: Option<Duration>,
2181    tax_mode: Option<TaxMode>,
2182    unit_price: Money,
2183    unit_price_overrides: Option<Vec<UnitPriceOverride>>,
2184    quantity: Option<PriceQuantity>,
2185    custom_data: Option<serde_json::Value>,
2186    product_id: Option<ProductID>,
2187    product: Option<TransactionSubscriptionProductCreate>,
2188}
2189
2190impl TransactionItemNonCatalogPrice {
2191    /// Create new price object for non-catalog item.
2192    ///
2193    /// - `description` - Internal description for this price, not shown to customers. Typically notes for your team.
2194    /// - `amount` - Amount in the lowest denomination for the currency, e.g. 10 USD = 1000 (cents). Although represented as a string, this value must be a valid integer.
2195    /// - `currency` - Currency code.
2196    pub fn new(description: impl Into<String>, amount: u64, currency: CurrencyCode) -> Self {
2197        Self {
2198            description: description.into(),
2199            name: None,
2200            billing_cycle: None,
2201            trial_period: None,
2202            tax_mode: None,
2203            unit_price: Money {
2204                amount: amount.to_string(),
2205                currency_code: currency,
2206            },
2207            unit_price_overrides: None,
2208            quantity: None,
2209            custom_data: None,
2210            product_id: None,
2211            product: None,
2212        }
2213    }
2214
2215    /// Name of this price, shown to customers at checkout and on invoices. Typically describes how often the related product bills.
2216    pub fn name(mut self, name: impl Into<String>) -> Self {
2217        self.name = Some(name.into());
2218        self
2219    }
2220
2221    /// How often this price should be charged.
2222    pub fn billing_cycle(mut self, billing_cycle: Duration) -> Self {
2223        self.billing_cycle = Some(billing_cycle);
2224        self
2225    }
2226
2227    /// Trial period for the product related to this price. The billing cycle begins once the trial period is over.
2228    pub fn trial_period(mut self, trial_period: Duration) -> Self {
2229        self.trial_period = Some(trial_period);
2230        self
2231    }
2232
2233    /// How tax is calculated for this price.
2234    pub fn tax_mode(mut self, tax_mode: TaxMode) -> Self {
2235        self.tax_mode = Some(tax_mode);
2236        self
2237    }
2238
2239    /// Use to override the base price with a custom price and currency for a country or group of countries.
2240    /// See [UnitPriceOverride] for more information.
2241    /// See [CountryCodeSupported] for more information.
2242    /// See [Money] for more information.
2243    /// See [CurrencyCode] for more information.
2244    pub fn add_unit_price_override(
2245        mut self,
2246        country_codes: impl IntoIterator<Item = CountryCodeSupported>,
2247        amount: u64,
2248        currency: CurrencyCode,
2249    ) -> Self {
2250        if self.unit_price_overrides.is_none() {
2251            self.unit_price_overrides = Some(vec![]);
2252        }
2253
2254        self.unit_price_overrides
2255            .as_mut()
2256            .unwrap()
2257            .push(UnitPriceOverride {
2258                country_codes: country_codes.into_iter().collect(),
2259                unit_price: Money {
2260                    amount: amount.to_string(),
2261                    currency_code: currency,
2262                },
2263            });
2264
2265        self
2266    }
2267
2268    /// Use to override the base price with a custom price and currency for a country or group of countries.
2269    /// This will replace any existing overrides.
2270    /// Use `add_unit_price_override` to add additional overrides.
2271    /// See [UnitPriceOverride] for more information.
2272    /// See [CountryCodeSupported] for more information.
2273    /// See [Money] for more information.
2274    /// See [CurrencyCode] for more information.
2275    pub fn set_unit_price_overrides(mut self, overrides: Vec<UnitPriceOverride>) -> Self {
2276        self.unit_price_overrides = Some(overrides);
2277        self
2278    }
2279
2280    /// Limits on how many times the related product can be purchased at this price. Useful for discount campaigns. If omitted, defaults to 1-100.
2281    pub fn quantity(mut self, quantity: PriceQuantity) -> Self {
2282        self.quantity = Some(quantity);
2283        self
2284    }
2285
2286    /// Your own structured key-value data.
2287    pub fn custom_data(mut self, custom_data: serde_json::Value) -> Self {
2288        self.custom_data = Some(custom_data);
2289        self
2290    }
2291
2292    /// Paddle ID of the product that this price is for, prefixed with `prd_`.
2293    pub fn product_id(mut self, product_id: impl Into<ProductID>) -> Self {
2294        self.product_id = Some(product_id.into());
2295        self.product = None;
2296        self
2297    }
2298
2299    /// Product object for a non-catalog item to charge for.
2300    ///
2301    /// Setting a non-catalog product to this price will override the catalog product id.
2302    pub fn product(mut self, product: TransactionSubscriptionProductCreate) -> Self {
2303        self.product = Some(product);
2304        self.product_id = None;
2305        self
2306    }
2307}