pub struct CreateSubscription { /* private fields */ }
Expand description
Creates a new subscription on an existing customer. Each customer can have up to 500 active or scheduled subscriptions.
When you create a subscription with collection_method=charge_automatically
, the first invoice is finalized as part of the request.
The payment_behavior
parameter determines the exact behavior of the initial payment.
To start subscriptions where the first invoice always begins in a draft
status, use subscription schedules instead.
Schedules provide the flexibility to model more complex billing configurations that change over time.
Implementations§
Source§impl CreateSubscription
impl CreateSubscription
Sourcepub fn add_invoice_items(
self,
add_invoice_items: impl Into<Vec<CreateSubscriptionAddInvoiceItems>>,
) -> Self
pub fn add_invoice_items( self, add_invoice_items: impl Into<Vec<CreateSubscriptionAddInvoiceItems>>, ) -> Self
A list of prices and quantities that will generate invoice items appended to the next invoice for this subscription. You may pass up to 20 items.
Sourcepub fn application_fee_percent(
self,
application_fee_percent: impl Into<f64>,
) -> Self
pub fn application_fee_percent( self, application_fee_percent: impl Into<f64>, ) -> Self
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. The request must be made by a platform account on a connected account in order to set an application fee percentage. For more information, see the application fees documentation.
Sourcepub fn automatic_tax(
self,
automatic_tax: impl Into<CreateSubscriptionAutomaticTax>,
) -> Self
pub fn automatic_tax( self, automatic_tax: impl Into<CreateSubscriptionAutomaticTax>, ) -> Self
Automatic tax settings for this subscription.
Sourcepub fn backdate_start_date(
self,
backdate_start_date: impl Into<Timestamp>,
) -> Self
pub fn backdate_start_date( self, backdate_start_date: impl Into<Timestamp>, ) -> Self
A past timestamp to backdate the subscription’s start date to. If set, the first invoice will contain line items for the timespan between the start date and the current time. Can be combined with trials and the billing cycle anchor.
Sourcepub fn billing_cycle_anchor(
self,
billing_cycle_anchor: impl Into<Timestamp>,
) -> Self
pub fn billing_cycle_anchor( self, billing_cycle_anchor: impl Into<Timestamp>, ) -> Self
A future timestamp in UTC format to anchor the subscription’s billing cycle.
The anchor is the reference point that aligns future billing cycle dates.
It sets the day of week for week
intervals, the day of month for month
and year
intervals, and the month of year for year
intervals.
Sourcepub fn billing_cycle_anchor_config(
self,
billing_cycle_anchor_config: impl Into<CreateSubscriptionBillingCycleAnchorConfig>,
) -> Self
pub fn billing_cycle_anchor_config( self, billing_cycle_anchor_config: impl Into<CreateSubscriptionBillingCycleAnchorConfig>, ) -> Self
Mutually exclusive with billing_cycle_anchor and only valid with monthly and yearly price intervals. When provided, the billing_cycle_anchor is set to the next occurrence of the day_of_month at the hour, minute, and second UTC.
Sourcepub fn billing_mode(
self,
billing_mode: impl Into<CreateSubscriptionBillingMode>,
) -> Self
pub fn billing_mode( self, billing_mode: impl Into<CreateSubscriptionBillingMode>, ) -> Self
Controls how prorations and invoices for subscriptions are calculated and orchestrated.
Sourcepub fn billing_thresholds(
self,
billing_thresholds: impl Into<BillingThresholdsParam>,
) -> Self
pub fn billing_thresholds( self, billing_thresholds: impl Into<BillingThresholdsParam>, ) -> Self
Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period. When updating, pass an empty string to remove previously-defined thresholds.
Sourcepub fn cancel_at(self, cancel_at: impl Into<CreateSubscriptionCancelAt>) -> Self
pub fn cancel_at(self, cancel_at: impl Into<CreateSubscriptionCancelAt>) -> Self
A timestamp at which the subscription should cancel.
If set to a date before the current period ends, this will cause a proration if prorations have been enabled using proration_behavior
.
If set during a future period, this will always cause a proration for that period.
Sourcepub fn cancel_at_period_end(self, cancel_at_period_end: impl Into<bool>) -> Self
pub fn cancel_at_period_end(self, cancel_at_period_end: impl Into<bool>) -> Self
Indicate whether this subscription should cancel at the end of the current period (current_period_end
).
Defaults to false
.
Sourcepub fn collection_method(
self,
collection_method: impl Into<SubscriptionCollectionMethod>,
) -> Self
pub fn collection_method( self, collection_method: impl Into<SubscriptionCollectionMethod>, ) -> Self
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
.
Defaults to charge_automatically
.
Sourcepub fn currency(self, currency: impl Into<Currency>) -> Self
pub fn currency(self, currency: impl Into<Currency>) -> Self
Three-letter ISO currency code, in lowercase. Must be a supported currency.
Sourcepub fn days_until_due(self, days_until_due: impl Into<u32>) -> Self
pub fn days_until_due(self, days_until_due: impl Into<u32>) -> Self
Number of days a customer has to pay invoices generated by this subscription.
Valid only for subscriptions where collection_method
is set to send_invoice
.
Sourcepub fn default_payment_method(
self,
default_payment_method: impl Into<String>,
) -> Self
pub fn default_payment_method( self, default_payment_method: impl Into<String>, ) -> Self
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 or default_source.
Sourcepub fn default_source(self, default_source: impl Into<String>) -> Self
pub fn default_source(self, default_source: impl Into<String>) -> Self
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 or default_source.
Sourcepub fn default_tax_rates(
self,
default_tax_rates: impl Into<Vec<String>>,
) -> Self
pub fn default_tax_rates( self, default_tax_rates: impl Into<Vec<String>>, ) -> Self
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.
Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
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.
Sourcepub fn discounts(self, discounts: impl Into<Vec<DiscountsDataParam>>) -> Self
pub fn discounts(self, discounts: impl Into<Vec<DiscountsDataParam>>) -> Self
The coupons to redeem into discounts for the subscription. If not specified or empty, inherits the discount from the subscription’s customer.
Sourcepub fn expand(self, expand: impl Into<Vec<String>>) -> Self
pub fn expand(self, expand: impl Into<Vec<String>>) -> Self
Specifies which fields in the response should be expanded.
Sourcepub fn invoice_settings(
self,
invoice_settings: impl Into<CreateSubscriptionInvoiceSettings>,
) -> Self
pub fn invoice_settings( self, invoice_settings: impl Into<CreateSubscriptionInvoiceSettings>, ) -> Self
All invoices will be billed using the specified settings.
Sourcepub fn items(self, items: impl Into<Vec<CreateSubscriptionItems>>) -> Self
pub fn items(self, items: impl Into<Vec<CreateSubscriptionItems>>) -> Self
A list of up to 20 subscription items, each with an attached price.
Sourcepub fn metadata(self, metadata: impl Into<HashMap<String, String>>) -> Self
pub fn metadata(self, metadata: impl Into<HashMap<String, String>>) -> Self
Set of key-value pairs that you can attach to an object.
This can be useful for storing additional information about the object in a structured format.
Individual keys can be unset by posting an empty value to them.
All keys can be unset by posting an empty value to metadata
.
Sourcepub fn off_session(self, off_session: impl Into<bool>) -> Self
pub fn off_session(self, off_session: impl Into<bool>) -> Self
Indicates if a customer is on or off-session while an invoice payment is attempted.
Defaults to false
(on-session).
Sourcepub fn on_behalf_of(self, on_behalf_of: impl Into<String>) -> Self
pub fn on_behalf_of(self, on_behalf_of: impl Into<String>) -> Self
The account on behalf of which to charge, for each of the subscription’s invoices.
Sourcepub fn payment_behavior(
self,
payment_behavior: impl Into<CreateSubscriptionPaymentBehavior>,
) -> Self
pub fn payment_behavior( self, payment_behavior: impl Into<CreateSubscriptionPaymentBehavior>, ) -> Self
Only applies to subscriptions with collection_method=charge_automatically
.
Use allow_incomplete
to create Subscriptions with status=incomplete
if the first invoice can’t be paid.
Creating Subscriptions with this status allows you to manage scenarios where additional customer actions are needed to pay a subscription’s invoice.
For example, SCA regulation may require 3DS authentication to complete payment.
See the SCA Migration Guide for Billing to learn more.
This is the default behavior.
Use default_incomplete
to create Subscriptions with status=incomplete
when the first invoice requires payment, otherwise start as active.
Subscriptions transition to status=active
when successfully confirming the PaymentIntent on the first invoice.
This allows simpler management of scenarios where additional customer actions are needed to pay a subscription’s invoice, such as failed payments, SCA regulation, or collecting a mandate for a bank debit payment method.
If the PaymentIntent is not confirmed within 23 hours Subscriptions transition to status=incomplete_expired
, which is a terminal state.
Use error_if_incomplete
if you want Stripe to return an HTTP 402 status code if a subscription’s first invoice can’t be paid.
For example, if a payment method requires 3DS authentication due to SCA regulation and further customer action is needed, this parameter doesn’t create a Subscription and returns an error instead.
This was the default behavior for API versions prior to 2019-03-14.
See the changelog to learn more.
pending_if_incomplete
is only used with updates and cannot be passed when creating a Subscription.
Subscriptions with collection_method=send_invoice
are automatically activated regardless of the first Invoice status.
Sourcepub fn payment_settings(
self,
payment_settings: impl Into<CreateSubscriptionPaymentSettings>,
) -> Self
pub fn payment_settings( self, payment_settings: impl Into<CreateSubscriptionPaymentSettings>, ) -> Self
Payment settings to pass to invoices created by the subscription.
Sourcepub fn pending_invoice_item_interval(
self,
pending_invoice_item_interval: impl Into<CreateSubscriptionPendingInvoiceItemInterval>,
) -> Self
pub fn pending_invoice_item_interval( self, pending_invoice_item_interval: impl Into<CreateSubscriptionPendingInvoiceItemInterval>, ) -> Self
Specifies an interval for how often to bill for any pending invoice items. It is analogous to calling Create an invoice for the given subscription at the specified interval.
Sourcepub fn proration_behavior(
self,
proration_behavior: impl Into<CreateSubscriptionProrationBehavior>,
) -> Self
pub fn proration_behavior( self, proration_behavior: impl Into<CreateSubscriptionProrationBehavior>, ) -> Self
Determines how to handle prorations resulting from the billing_cycle_anchor
.
If no value is passed, the default is create_prorations
.
Sourcepub fn transfer_data(self, transfer_data: impl Into<TransferDataSpecs>) -> Self
pub fn transfer_data(self, transfer_data: impl Into<TransferDataSpecs>) -> Self
If specified, the funds from the subscription’s invoices will be transferred to the destination and the ID of the resulting transfers will be found on the resulting charges.
Sourcepub fn trial_end(self, trial_end: impl Into<CreateSubscriptionTrialEnd>) -> Self
pub fn trial_end(self, trial_end: impl Into<CreateSubscriptionTrialEnd>) -> Self
Unix timestamp representing the end of the trial period the customer will get before being charged for the first time.
If set, trial_end will override the default trial period of the plan the customer is being subscribed to.
The special value now
can be provided to end the customer’s trial immediately.
Can be at most two years from billing_cycle_anchor
.
See Using trial periods on subscriptions to learn more.
Sourcepub fn trial_from_plan(self, trial_from_plan: impl Into<bool>) -> Self
pub fn trial_from_plan(self, trial_from_plan: impl Into<bool>) -> Self
Indicates if a plan’s trial_period_days
should be applied to the subscription.
Setting trial_end
per subscription is preferred, and this defaults to false
.
Setting this flag to true
together with trial_end
is not allowed.
See Using trial periods on subscriptions to learn more.
Sourcepub fn trial_period_days(self, trial_period_days: impl Into<u32>) -> Self
pub fn trial_period_days(self, trial_period_days: impl Into<u32>) -> Self
Integer representing the number of trial period days before the customer is charged for the first time. This will always overwrite any trials that might apply via a subscribed plan. See Using trial periods on subscriptions to learn more.
Sourcepub fn trial_settings(
self,
trial_settings: impl Into<CreateSubscriptionTrialSettings>,
) -> Self
pub fn trial_settings( self, trial_settings: impl Into<CreateSubscriptionTrialSettings>, ) -> Self
Settings related to subscription trials.
Source§impl CreateSubscription
impl CreateSubscription
Sourcepub async fn send<C: StripeClient>(
&self,
client: &C,
) -> Result<<Self as StripeRequest>::Output, C::Err>
pub async fn send<C: StripeClient>( &self, client: &C, ) -> Result<<Self as StripeRequest>::Output, C::Err>
Send the request and return the deserialized response.
Sourcepub fn send_blocking<C: StripeBlockingClient>(
&self,
client: &C,
) -> Result<<Self as StripeRequest>::Output, C::Err>
pub fn send_blocking<C: StripeBlockingClient>( &self, client: &C, ) -> Result<<Self as StripeRequest>::Output, C::Err>
Send the request and return the deserialized response, blocking until completion.
Trait Implementations§
Source§impl Clone for CreateSubscription
impl Clone for CreateSubscription
Source§fn clone(&self) -> CreateSubscription
fn clone(&self) -> CreateSubscription
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more