View Source Stripe.Subscription (stripity_stripe v3.2.0)
Subscriptions allow you to charge a customer on a recurring basis.
Related guide: Creating subscriptions
Summary
Types
Configuration for the bank transfer funding type, if the funding_type
is set to bank_transfer
.
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 occurence of the day_of_month at the hour, minute, and second UTC.
Details about why this subscription was cancelled
Defines how the subscription should behave when the user's free trial ends.
Configuration for eu_bank_transfer funding type.
Additional fields for Financial Connections Session creation
Additional fields for Mandate creation
Payment-method-specific configuration to provide to invoices created by the subscription.
Payment settings to pass to invoices created by the subscription.
Data used to generate a new Price object inline.
The recurring components of a price such as interval
and interval_count
.
The subscription
type.
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.
Settings related to subscription trials.
Functions
Cancels a customer’s subscription immediately. The customer will not be charged again for the subscription.
Creates a new subscription on an existing customer. Each customer can have up to 500 active or scheduled subscriptions.
Removes the currently applied discount on a subscription.
By default, returns a list of subscriptions that have not been canceled. In order to list canceled subscriptions, specify status=canceled
.
Initiates resumption of a paused subscription, optionally resetting the billing cycle anchor and creating prorations. If a resumption invoice is generated, it must be paid or marked uncollectible before the subscription will be unpaused. If payment succeeds the subscription will become active
, and if payment fails the subscription will be past_due
. The resumption invoice will void automatically if not paid by the expiration date.
Retrieves the subscription with the given ID.
Search for subscriptions you’ve previously created using Stripe’s Search Query Language.Don’t use search in read-after-write flows where strict consistency is necessary. Under normal operating conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up to an hour behind during outages. Search functionality is not available to merchants in India.
Updates an existing subscription to match the specified parameters.When changing prices or quantities, we optionally prorate the price we charge next month to make up for any price changes. To preview how the proration is calculated, use the upcoming invoice endpoint.
Types
@type acss_debit() :: %{ optional(:mandate_options) => mandate_options(), optional(:verification_method) => :automatic | :instant | :microdeposits }
@type add_invoice_items() :: %{ optional(:price) => binary(), optional(:price_data) => price_data(), optional(:quantity) => integer(), optional(:tax_rates) => [binary()] | binary() }
@type automatic_tax() :: %{optional(:enabled) => boolean()}
@type bancontact() :: %{optional(:preferred_language) => :de | :en | :fr | :nl}
@type bank_transfer() :: %{ optional(:eu_bank_transfer) => eu_bank_transfer(), optional(:type) => binary() }
Configuration for the bank transfer funding type, if the funding_type
is set to bank_transfer
.
@type billing_cycle_anchor_config() :: %{ optional(:day_of_month) => integer(), optional(:hour) => integer(), optional(:minute) => integer(), optional(:month) => integer(), optional(:second) => integer() }
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 occurence of the day_of_month at the hour, minute, and second UTC.
@type cancellation_details() :: %{ optional(:comment) => binary() | binary(), optional(:feedback) => :customer_service | :low_quality | :missing_features | :other | :switched_service | :too_complex | :too_expensive | :unused }
Details about why this subscription was cancelled
@type card() :: %{ optional(:mandate_options) => mandate_options(), optional(:network) => :amex | :cartes_bancaires | :diners | :discover | :eftpos_au | :interac | :jcb | :mastercard | :unionpay | :unknown | :visa, optional(:request_three_d_secure) => :any | :automatic }
@type customer_balance() :: %{ optional(:bank_transfer) => bank_transfer(), optional(:funding_type) => binary() }
@type end_behavior() :: %{
optional(:missing_payment_method) => :cancel | :create_invoice | :pause
}
Defines how the subscription should behave when the user's free trial ends.
@type eu_bank_transfer() :: %{optional(:country) => binary()}
Configuration for eu_bank_transfer funding type.
@type financial_connections() :: %{
optional(:permissions) => [
:balances | :ownership | :payment_method | :transactions
],
optional(:prefetch) => [:balances | :transactions]
}
Additional fields for Financial Connections Session creation
@type items() :: %{ optional(:billing_thresholds) => billing_thresholds() | binary(), optional(:metadata) => %{optional(binary()) => binary()}, optional(:plan) => binary(), optional(:price) => binary(), optional(:price_data) => price_data(), optional(:quantity) => integer(), optional(:tax_rates) => [binary()] | binary() }
@type mandate_options() :: %{optional(:transaction_type) => :business | :personal}
Additional fields for Mandate creation
@type pause_collection() :: %{ optional(:behavior) => :keep_as_draft | :mark_uncollectible | :void, optional(:resumes_at) => integer() }
@type payment_method_options() :: %{ optional(:acss_debit) => acss_debit() | binary(), optional(:bancontact) => bancontact() | binary(), optional(:card) => card() | binary(), optional(:customer_balance) => customer_balance() | binary(), optional(:konbini) => map() | binary(), optional(:us_bank_account) => us_bank_account() | binary() }
Payment-method-specific configuration to provide to invoices created by the subscription.
@type payment_settings() :: %{ optional(:payment_method_options) => payment_method_options(), optional(:payment_method_types) => [ :ach_credit_transfer | :ach_debit | :acss_debit | :au_becs_debit | :bacs_debit | :bancontact | :boleto | :card | :cashapp | :customer_balance | :eps | :fpx | :giropay | :grabpay | :ideal | :konbini | :link | :p24 | :paynow | :paypal | :promptpay | :sepa_credit_transfer | :sepa_debit | :sofort | :us_bank_account | :wechat_pay ] | binary(), optional(:save_default_payment_method) => :off | :on_subscription }
Payment settings to pass to invoices created by the subscription.
@type pending_invoice_item_interval() :: %{ optional(:interval) => :day | :month | :week | :year, optional(:interval_count) => integer() }
@type price_data() :: %{ optional(:currency) => binary(), optional(:product) => binary(), optional(:recurring) => recurring(), optional(:tax_behavior) => :exclusive | :inclusive | :unspecified, optional(:unit_amount) => integer(), optional(:unit_amount_decimal) => binary() }
Data used to generate a new Price object inline.
@type recurring() :: %{ optional(:interval) => :day | :month | :week | :year, optional(:interval_count) => integer() }
The recurring components of a price such as interval
and interval_count
.
@type t() :: %Stripe.Subscription{ application: (binary() | term() | term()) | nil, application_fee_percent: term() | nil, automatic_tax: term(), billing_cycle_anchor: integer(), billing_cycle_anchor_config: term() | nil, billing_thresholds: term() | nil, cancel_at: integer() | nil, cancel_at_period_end: boolean(), canceled_at: integer() | nil, cancellation_details: term() | nil, collection_method: binary(), created: integer(), currency: binary(), current_period_end: integer(), current_period_start: integer(), customer: binary() | Stripe.Customer.t() | Stripe.DeletedCustomer.t(), days_until_due: integer() | nil, default_payment_method: (binary() | Stripe.PaymentMethod.t()) | nil, default_source: (binary() | Stripe.PaymentSource.t()) | nil, default_tax_rates: term() | nil, description: binary() | nil, discount: term() | nil, ended_at: integer() | nil, id: binary(), items: term(), latest_invoice: (binary() | Stripe.Invoice.t()) | nil, livemode: boolean(), metadata: term(), next_pending_invoice_item_invoice: integer() | nil, object: binary(), on_behalf_of: (binary() | Stripe.Account.t()) | nil, pause_collection: term() | nil, payment_settings: term() | nil, pending_invoice_item_interval: term() | nil, pending_setup_intent: (binary() | Stripe.SetupIntent.t()) | nil, pending_update: term() | nil, schedule: (binary() | Stripe.SubscriptionSchedule.t()) | nil, start_date: integer(), status: binary(), test_clock: (binary() | Stripe.TestHelpers.TestClock.t()) | nil, transfer_data: term() | nil, trial_end: integer() | nil, trial_settings: term() | nil, trial_start: integer() | nil }
The subscription
type.
application
ID of the Connect Application that created the subscription.application_fee_percent
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.automatic_tax
billing_cycle_anchor
The reference point that aligns future billing cycle dates. It sets the day of week forweek
intervals, the day of month formonth
andyear
intervals, and the month of year foryear
intervals. The timestamp is in UTC format.billing_cycle_anchor_config
The fixed values used to calculate thebilling_cycle_anchor
.billing_thresholds
Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing periodcancel_at
A date in the future at which the subscription will automatically get canceledcancel_at_period_end
If the subscription has been canceled with theat_period_end
flag set totrue
,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.canceled_at
If the subscription has been canceled, the date of that cancellation. If the subscription was canceled withcancel_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.cancellation_details
Details about why this subscription was cancelledcollection_method
Eithercharge_automatically
, orsend_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 asactive
.created
Time at which the object was created. Measured in seconds since the Unix epoch.currency
Three-letter ISO currency code, in lowercase. Must be a supported currency.current_period_end
End of the current period that the subscription has been invoiced for. At the end of this period, a new invoice will be created.current_period_start
Start of the current period that the subscription has been invoiced for.customer
ID of the customer who owns the subscription.days_until_due
Number of days a customer has to pay invoices generated by this subscription. This value will benull
for subscriptions wherecollection_method=charge_automatically
.default_payment_method
ID of the default payment method for the subscription. It must belong to the customer associated with the subscription. This takes precedence overdefault_source
. If neither are set, invoices will use the customer's invoice_settings.default_payment_method or default_source.default_source
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. Ifdefault_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.default_tax_rates
The tax rates that will apply to any subscription item that does not havetax_rates
set. Invoices created will have theirdefault_tax_rates
populated from the subscription.description
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.discount
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.ended_at
If the subscription has ended, the date the subscription ended.id
Unique identifier for the object.items
List of subscription items, each with an attached price.latest_invoice
The most recent invoice this subscription has generated.livemode
Has the valuetrue
if the object exists in live mode or the valuefalse
if the object exists in test mode.metadata
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.next_pending_invoice_item_invoice
Specifies the approximate timestamp on which any pending invoice items will be billed according to the schedule provided atpending_invoice_item_interval
.object
String representing the object's type. Objects of the same type share the same value.on_behalf_of
The account (if any) the charge was made on behalf of for charges associated with this subscription. See the Connect documentation for details.pause_collection
If specified, payment collection for this subscription will be paused.payment_settings
Payment settings passed on to invoices created by the subscription.pending_invoice_item_interval
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.pending_setup_intent
You can use this SetupIntent 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.pending_update
If specified, pending updates that will be applied to the subscription once thelatest_invoice
has been paid.schedule
The schedule attached to the subscriptionstart_date
Date when the subscription was first created. The date might differ from thecreated
date due to backdating.status
Possible values areincomplete
,incomplete_expired
,trialing
,active
,past_due
,canceled
, orunpaid
.
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.
test_clock
ID of the test clock this subscription belongs to.transfer_data
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.trial_end
If the subscription has a trial, the end of that trial.trial_settings
Settings related to subscription trials.trial_start
If the subscription has a trial, the beginning of that trial.
@type transfer_data() :: %{ optional(:amount_percent) => number(), optional(:destination) => binary() }
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.
@type trial_settings() :: %{optional(:end_behavior) => end_behavior()}
Settings related to subscription trials.
@type us_bank_account() :: %{ optional(:financial_connections) => financial_connections(), optional(:verification_method) => :automatic | :instant | :microdeposits }
Functions
@spec cancel( subscription_exposed_id :: binary(), params :: %{ optional(:cancellation_details) => cancellation_details(), optional(:expand) => [binary()], optional(:invoice_now) => boolean(), optional(:prorate) => boolean() }, opts :: Keyword.t() ) :: {:ok, t()} | {:error, Stripe.ApiErrors.t()} | {:error, term()}
Cancels a customer’s subscription immediately. The customer will not be charged again for the subscription.
Note, however, that any pending invoice items that you’ve created will still be charged for at the end of the period, unless manually deleted. If you’ve set the subscription to cancel at the end of the period, any pending prorations will also be left in place and collected at the end of the period. But if the subscription is set to cancel immediately, pending prorations will be removed.
By default, upon subscription cancellation, Stripe will stop automatic collection of all finalized invoices for the customer. This is intended to prevent unexpected payment attempts after the customer has canceled a subscription. However, you can resume automatic collection of the invoices manually after subscription cancellation to have us proceed. Or, you could check for unpaid invoices before allowing the customer to cancel the subscription at all.
Details
- Method:
delete
- Path:
/v1/subscriptions/{subscription_exposed_id}
@spec create( params :: %{ optional(:application_fee_percent) => number(), optional(:add_invoice_items) => [add_invoice_items()], optional(:collection_method) => :charge_automatically | :send_invoice, optional(:default_payment_method) => binary(), optional(:expand) => [binary()], optional(:coupon) => binary(), optional(:metadata) => %{optional(binary()) => binary()} | binary(), optional(:description) => binary(), optional(:on_behalf_of) => binary() | binary(), optional(:customer) => binary(), optional(:days_until_due) => integer(), optional(:promotion_code) => binary(), optional(:payment_settings) => payment_settings(), optional(:pending_invoice_item_interval) => pending_invoice_item_interval() | binary(), optional(:billing_thresholds) => billing_thresholds() | binary(), optional(:default_source) => binary(), optional(:cancel_at_period_end) => boolean(), optional(:trial_from_plan) => boolean(), optional(:billing_cycle_anchor_config) => billing_cycle_anchor_config(), optional(:billing_cycle_anchor) => integer(), optional(:trial_period_days) => integer(), optional(:automatic_tax) => automatic_tax(), optional(:currency) => binary(), optional(:trial_end) => :now | integer(), optional(:cancel_at) => integer(), optional(:trial_settings) => trial_settings(), optional(:payment_behavior) => :allow_incomplete | :default_incomplete | :error_if_incomplete | :pending_if_incomplete, optional(:items) => [items()], optional(:transfer_data) => transfer_data(), optional(:proration_behavior) => :always_invoice | :create_prorations | :none, optional(:off_session) => boolean(), optional(:default_tax_rates) => [binary()] | binary(), optional(:backdate_start_date) => integer() }, opts :: Keyword.t() ) :: {:ok, t()} | {:error, Stripe.ApiErrors.t()} | {:error, term()}
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.
@spec delete_discount(subscription_exposed_id :: binary(), opts :: Keyword.t()) :: {:ok, Stripe.DeletedDiscount.t()} | {:error, Stripe.ApiErrors.t()} | {:error, term()}
Removes the currently applied discount on a subscription.
Details
- Method:
delete
- Path:
/v1/subscriptions/{subscription_exposed_id}/discount
@spec list( params :: %{ optional(:automatic_tax) => automatic_tax(), optional(:collection_method) => :charge_automatically | :send_invoice, optional(:created) => created() | integer(), optional(:current_period_end) => current_period_end() | integer(), optional(:current_period_start) => current_period_start() | integer(), optional(:customer) => binary(), optional(:ending_before) => binary(), optional(:expand) => [binary()], optional(:limit) => integer(), optional(:plan) => binary(), optional(:price) => binary(), optional(:starting_after) => binary(), optional(:status) => :active | :all | :canceled | :ended | :incomplete | :incomplete_expired | :past_due | :paused | :trialing | :unpaid, optional(:test_clock) => binary() }, opts :: Keyword.t() ) :: {:ok, Stripe.List.t(t())} | {:error, Stripe.ApiErrors.t()} | {:error, term()}
By default, returns a list of subscriptions that have not been canceled. In order to list canceled subscriptions, specify status=canceled
.
Details
- Method:
get
- Path:
/v1/subscriptions
@spec resume( subscription :: binary(), params :: %{ optional(:billing_cycle_anchor) => :now | :unchanged, optional(:expand) => [binary()], optional(:proration_behavior) => :always_invoice | :create_prorations | :none, optional(:proration_date) => integer() }, opts :: Keyword.t() ) :: {:ok, t()} | {:error, Stripe.ApiErrors.t()} | {:error, term()}
Initiates resumption of a paused subscription, optionally resetting the billing cycle anchor and creating prorations. If a resumption invoice is generated, it must be paid or marked uncollectible before the subscription will be unpaused. If payment succeeds the subscription will become active
, and if payment fails the subscription will be past_due
. The resumption invoice will void automatically if not paid by the expiration date.
Details
- Method:
post
- Path:
/v1/subscriptions/{subscription}/resume
@spec retrieve( subscription_exposed_id :: binary(), params :: %{optional(:expand) => [binary()]}, opts :: Keyword.t() ) :: {:ok, t()} | {:error, Stripe.ApiErrors.t()} | {:error, term()}
Retrieves the subscription with the given ID.
Details
- Method:
get
- Path:
/v1/subscriptions/{subscription_exposed_id}
@spec search( params :: %{ optional(:expand) => [binary()], optional(:limit) => integer(), optional(:page) => binary(), optional(:query) => binary() }, opts :: Keyword.t() ) :: {:ok, Stripe.SearchResult.t(t())} | {:error, Stripe.ApiErrors.t()} | {:error, term()}
Search for subscriptions you’ve previously created using Stripe’s Search Query Language.Don’t use search in read-after-write flows where strict consistency is necessary. Under normal operating conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up to an hour behind during outages. Search functionality is not available to merchants in India.
#### Details * Method: `get` * Path: `/v1/subscriptions/search`@spec update( subscription_exposed_id :: binary(), params :: %{ optional(:add_invoice_items) => [add_invoice_items()], optional(:application_fee_percent) => number(), optional(:automatic_tax) => automatic_tax(), optional(:billing_cycle_anchor) => :now | :unchanged, optional(:billing_thresholds) => billing_thresholds() | binary(), optional(:cancel_at) => integer() | binary(), optional(:cancel_at_period_end) => boolean(), optional(:cancellation_details) => cancellation_details(), optional(:collection_method) => :charge_automatically | :send_invoice, optional(:coupon) => binary(), optional(:days_until_due) => integer(), optional(:default_payment_method) => binary(), optional(:default_source) => binary() | binary(), optional(:default_tax_rates) => [binary()] | binary(), optional(:description) => binary() | binary(), optional(:expand) => [binary()], optional(:items) => [items()], optional(:metadata) => %{optional(binary()) => binary()} | binary(), optional(:off_session) => boolean(), optional(:on_behalf_of) => binary() | binary(), optional(:pause_collection) => pause_collection() | binary(), optional(:payment_behavior) => :allow_incomplete | :default_incomplete | :error_if_incomplete | :pending_if_incomplete, optional(:payment_settings) => payment_settings(), optional(:pending_invoice_item_interval) => pending_invoice_item_interval() | binary(), optional(:promotion_code) => binary(), optional(:proration_behavior) => :always_invoice | :create_prorations | :none, optional(:proration_date) => integer(), optional(:transfer_data) => transfer_data() | binary(), optional(:trial_end) => :now | integer(), optional(:trial_from_plan) => boolean(), optional(:trial_settings) => trial_settings() }, opts :: Keyword.t() ) :: {:ok, t()} | {:error, Stripe.ApiErrors.t()} | {:error, term()}
Updates an existing subscription to match the specified parameters.When changing prices or quantities, we optionally prorate the price we charge next month to make up for any price changes. To preview how the proration is calculated, use the upcoming invoice endpoint.
By default, we prorate subscription changes. For example, if a customer signs up on May 1 for a
Switching prices does not normally change the billing date or generate an immediate charge unless:
- The billing interval is changed (for example, from monthly to yearly).
- The subscription moves from free to paid, or paid to free.
- A trial starts or ends.
In these cases, we apply a credit for the unused time on the previous price, immediately charge the customer using the new price, and reset the billing date.
If you want to charge for an upgrade immediately, pass proration_behavior
as always_invoice
to create prorations, automatically invoice the customer for those proration adjustments, and attempt to collect payment. If you pass create_prorations
, the prorations are created but not automatically invoiced. If you want to bill the customer for the prorations before the subscription’s renewal date, you need to manually invoice the customer.
If you don’t want to prorate, set the proration_behavior
option to none
. With this option, the customer is billed proration_behavior
to none
when switching between different billing intervals (for example, from monthly to yearly), we don’t generate any credits for the old subscription’s unused time. We still reset the billing date and bill immediately for the new subscription.
Updating the quantity on a subscription many times in an hour may result in rate limiting. If you need to bill for a frequently changing quantity, consider integrating usage-based billing instead.
#### Details * Method: `post` * Path: `/v1/subscriptions/{subscription_exposed_id}`