use serde::{Serialize, Deserialize};
use super::{SubscriptionAutomaticTax, SubscriptionItemList, TaxRate};
/**Subscriptions allow you to charge a customer on a recurring basis.
Related guide: [Creating subscriptions](https://stripe.com/docs/billing/subscriptions/creating)*/
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Subscription {
///ID of the Connect Application that created the subscription.
#[serde(skip_serializing_if = "Option::is_none")]
pub application: Option<serde_json::Value>,
///A non-negative decimal between 0 and 100, with at most two decimal places. This represents the percentage of the subscription invoice total that will be transferred to the application owner's Stripe account.
#[serde(skip_serializing_if = "Option::is_none")]
pub application_fee_percent: Option<f64>,
///
pub automatic_tax: SubscriptionAutomaticTax,
///Determines the date of the first full invoice, and, for plans with `month` or `year` intervals, the day of the month for subsequent invoices. The timestamp is in UTC format.
pub billing_cycle_anchor: i64,
///Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period
#[serde(skip_serializing_if = "Option::is_none")]
pub billing_thresholds: Option<serde_json::Value>,
///A date in the future at which the subscription will automatically get canceled
#[serde(skip_serializing_if = "Option::is_none")]
pub cancel_at: Option<i64>,
///If the subscription has been canceled with the `at_period_end` flag set to `true`, `cancel_at_period_end` on the subscription will be true. You can use this attribute to determine whether a subscription that has a status of active is scheduled to be canceled at the end of the current period.
pub cancel_at_period_end: bool,
///If the subscription has been canceled, the date of that cancellation. If the subscription was canceled with `cancel_at_period_end`, `canceled_at` will reflect the time of the most recent update request, not the end of the subscription period when the subscription is automatically moved to a canceled state.
#[serde(skip_serializing_if = "Option::is_none")]
pub canceled_at: Option<i64>,
///Details about why this subscription was cancelled
#[serde(skip_serializing_if = "Option::is_none")]
pub cancellation_details: Option<serde_json::Value>,
///Either `charge_automatically`, or `send_invoice`. When charging automatically, Stripe will attempt to pay this subscription at the end of the cycle using the default source attached to the customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as `active`.
pub collection_method: String,
///Time at which the object was created. Measured in seconds since the Unix epoch.
pub created: i64,
///Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
pub currency: String,
///End of the current period that the subscription has been invoiced for. At the end of this period, a new invoice will be created.
pub current_period_end: i64,
///Start of the current period that the subscription has been invoiced for.
pub current_period_start: i64,
///ID of the customer who owns the subscription.
pub customer: serde_json::Value,
///Number of days a customer has to pay invoices generated by this subscription. This value will be `null` for subscriptions where `collection_method=charge_automatically`.
#[serde(skip_serializing_if = "Option::is_none")]
pub days_until_due: Option<i64>,
///ID of the default payment method for the subscription. It must belong to the customer associated with the subscription. This takes precedence over `default_source`. If neither are set, invoices will use the customer's [invoice_settings.default_payment_method](https://stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method) or [default_source](https://stripe.com/docs/api/customers/object#customer_object-default_source).
#[serde(skip_serializing_if = "Option::is_none")]
pub default_payment_method: Option<serde_json::Value>,
///ID of the default payment source for the subscription. It must belong to the customer associated with the subscription and be in a chargeable state. If `default_payment_method` is also set, `default_payment_method` will take precedence. If neither are set, invoices will use the customer's [invoice_settings.default_payment_method](https://stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method) or [default_source](https://stripe.com/docs/api/customers/object#customer_object-default_source).
#[serde(skip_serializing_if = "Option::is_none")]
pub default_source: Option<serde_json::Value>,
///The tax rates that will apply to any subscription item that does not have `tax_rates` set. Invoices created will have their `default_tax_rates` populated from the subscription.
#[serde(skip_serializing_if = "Option::is_none")]
pub default_tax_rates: Option<Vec<TaxRate>>,
///The subscription's description, meant to be displayable to the customer. Use this field to optionally store an explanation of the subscription for rendering in Stripe surfaces and certain local payment methods UIs.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
///Describes the current discount applied to this subscription, if there is one. When billing, a discount applied to a subscription overrides a discount applied on a customer-wide basis.
#[serde(skip_serializing_if = "Option::is_none")]
pub discount: Option<serde_json::Value>,
///If the subscription has ended, the date the subscription ended.
#[serde(skip_serializing_if = "Option::is_none")]
pub ended_at: Option<i64>,
///Unique identifier for the object.
pub id: String,
///List of subscription items, each with an attached price.
pub items: SubscriptionItemList,
///The most recent invoice this subscription has generated.
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_invoice: Option<serde_json::Value>,
///Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
pub livemode: bool,
///Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
pub metadata: serde_json::Value,
///Specifies the approximate timestamp on which any pending invoice items will be billed according to the schedule provided at `pending_invoice_item_interval`.
#[serde(skip_serializing_if = "Option::is_none")]
pub next_pending_invoice_item_invoice: Option<i64>,
///String representing the object's type. Objects of the same type share the same value.
pub object: String,
///The account (if any) the charge was made on behalf of for charges associated with this subscription. See the Connect documentation for details.
#[serde(skip_serializing_if = "Option::is_none")]
pub on_behalf_of: Option<serde_json::Value>,
///If specified, payment collection for this subscription will be paused.
#[serde(skip_serializing_if = "Option::is_none")]
pub pause_collection: Option<serde_json::Value>,
///Payment settings passed on to invoices created by the subscription.
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_settings: Option<serde_json::Value>,
///Specifies an interval for how often to bill for any pending invoice items. It is analogous to calling [Create an invoice](https://stripe.com/docs/api#create_invoice) for the given subscription at the specified interval.
#[serde(skip_serializing_if = "Option::is_none")]
pub pending_invoice_item_interval: Option<serde_json::Value>,
///You can use this [SetupIntent](https://stripe.com/docs/api/setup_intents) to collect user authentication when creating a subscription without immediate payment or updating a subscription's payment method, allowing you to optimize for off-session payments. Learn more in the [SCA Migration Guide](https://stripe.com/docs/billing/migration/strong-customer-authentication#scenario-2).
#[serde(skip_serializing_if = "Option::is_none")]
pub pending_setup_intent: Option<serde_json::Value>,
///If specified, [pending updates](https://stripe.com/docs/billing/subscriptions/pending-updates) that will be applied to the subscription once the `latest_invoice` has been paid.
#[serde(skip_serializing_if = "Option::is_none")]
pub pending_update: Option<serde_json::Value>,
///The schedule attached to the subscription
#[serde(skip_serializing_if = "Option::is_none")]
pub schedule: Option<serde_json::Value>,
///Date when the subscription was first created. The date might differ from the `created` date due to backdating.
pub start_date: i64,
/**Possible values are `incomplete`, `incomplete_expired`, `trialing`, `active`, `past_due`, `canceled`, or `unpaid`.
For `collection_method=charge_automatically` a subscription moves into `incomplete` if the initial payment attempt fails. A subscription in this state can only have metadata and default_source updated. Once the first invoice is paid, the subscription moves into an `active` state. If the first invoice is not paid within 23 hours, the subscription transitions to `incomplete_expired`. This is a terminal state, the open invoice will be voided and no further invoices will be generated.
A subscription that is currently in a trial period is `trialing` and moves to `active` when the trial period is over.
If subscription `collection_method=charge_automatically`, it becomes `past_due` when payment is required but cannot be paid (due to failed payment or awaiting additional user actions). Once Stripe has exhausted all payment retry attempts, the subscription will become `canceled` or `unpaid` (depending on your subscriptions settings).
If subscription `collection_method=send_invoice` it becomes `past_due` when its invoice is not paid by the due date, and `canceled` or `unpaid` if it is still not paid by an additional deadline after that. Note that when a subscription has a status of `unpaid`, no subsequent invoices will be attempted (invoices will be created, but then immediately automatically closed). After receiving updated payment information from a customer, you may choose to reopen and pay their closed invoices.*/
pub status: String,
///ID of the test clock this subscription belongs to.
#[serde(skip_serializing_if = "Option::is_none")]
pub test_clock: Option<serde_json::Value>,
///The account (if any) the subscription's payments will be attributed to for tax reporting, and where funds from each payment will be transferred to for each of the subscription's invoices.
#[serde(skip_serializing_if = "Option::is_none")]
pub transfer_data: Option<serde_json::Value>,
///If the subscription has a trial, the end of that trial.
#[serde(skip_serializing_if = "Option::is_none")]
pub trial_end: Option<i64>,
///Settings related to subscription trials.
#[serde(skip_serializing_if = "Option::is_none")]
pub trial_settings: Option<serde_json::Value>,
///If the subscription has a trial, the beginning of that trial.
#[serde(skip_serializing_if = "Option::is_none")]
pub trial_start: Option<i64>,
}
impl std::fmt::Display for Subscription {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(f, "{}", serde_json::to_string(self).unwrap())
}
}