View Source Stripe.Subscription (Striped v0.1.0)
Subscriptions allow you to charge a customer on a recurring basis.
Related guide: Creating Subscriptions.
Link to this section Summary
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.
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 on a customer to match the specified parameters. When changing plans or quantities, we will optionally prorate the price we charge next month to make up for any price changes. To preview how the proration will be calculated, use the upcoming invoice endpoint.
Link to this section Types
@type t() :: %Stripe.Subscription{ application: (binary() | term() | term()) | nil, application_fee_percent: term() | nil, automatic_tax: term(), billing_cycle_anchor: integer(), billing_thresholds: term() | nil, cancel_at: integer() | nil, cancel_at_period_end: boolean(), canceled_at: integer() | 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(), 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_start: integer() | nil }
The subscription type.
application_fee_percentA non-negative decimal between 0 and 100, with at most two decimal places. This represents the percentage of the subscription invoice subtotal that will be transferred to the application owner's Stripe account.livemodeHas the valuetrueif the object exists in live mode or the valuefalseif the object exists in test mode.collection_methodEithercharge_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.default_payment_methodID 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.metadataSet 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.descriptionThe 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.pending_setup_intentYou 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.discountDescribes 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.start_dateDate when the subscription was first created. The date might differ from thecreateddate due to backdating.pause_collectionIf specified, payment collection for this subscription will be paused.customerID of the customer who owns the subscription.ended_atIf the subscription has ended, the date the subscription ended.days_until_dueNumber of days a customer has to pay invoices generated by this subscription. This value will benullfor subscriptions wherecollection_method=charge_automatically.payment_settingsPayment settings passed on to invoices created by the subscription.applicationID of the Connect Application that created the subscription.pending_invoice_item_intervalSpecifies 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.billing_thresholdsDefine thresholds at which an invoice will be sent, and the subscription advanced to a new billing periodnext_pending_invoice_item_invoiceSpecifies the approximate timestamp on which any pending invoice items will be billed according to the schedule provided atpending_invoice_item_interval.default_sourceID 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_methodis also set,default_payment_methodwill take precedence. If neither are set, invoices will use the customer's invoice_settings.default_payment_method or default_source.cancel_at_period_endIf the subscription has been canceled with theat_period_endflag set totrue,cancel_at_period_endon 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.objectString representing the object's type. Objects of the same type share the same value.billing_cycle_anchorDetermines the date of the first full invoice, and, for plans withmonthoryearintervals, the day of the month for subsequent invoices. The timestamp is in UTC format.test_clockID of the test clock this subscription belongs to.automatic_taxscheduleThe schedule attached to the subscriptioncanceled_atIf the subscription has been canceled, the date of that cancellation. If the subscription was canceled withcancel_at_period_end,canceled_atwill 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.current_period_endEnd of the current period that the subscription has been invoiced for. At the end of this period, a new invoice will be created.latest_invoiceThe most recent invoice this subscription has generated.currencyThree-letter ISO currency code, in lowercase. Must be a supported currency.createdTime at which the object was created. Measured in seconds since the Unix epoch.trial_endIf the subscription has a trial, the end of that trial.cancel_atA date in the future at which the subscription will automatically get canceledtrial_startIf the subscription has a trial, the beginning of that trial.current_period_startStart of the current period that the subscription has been invoiced for.statusPossible 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 to renew it fails and canceled or unpaid (depending on your subscriptions settings) when Stripe has exhausted all payment retry attempts.
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.
itemsList of subscription items, each with an attached price.transfer_dataThe 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.idUnique identifier for the object.pending_updateIf specified, pending updates that will be applied to the subscription once thelatest_invoicehas been paid.default_tax_ratesThe tax rates that will apply to any subscription item that does not havetax_ratesset. Invoices created will have theirdefault_tax_ratespopulated from the subscription.
Link to this section Functions
@spec cancel(client :: term(), subscription_exposed_id :: binary(), params :: map()) :: {: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(client :: term(), params :: map()) :: {: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(client :: term(), subscription_exposed_id :: binary()) :: {: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(client :: term(), params :: map()) :: {: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
Query parameters
:collection_methodstring:createdany of:- object with (optional) properties:
gt: integergte: integerlt: integerlte: integer
- integer
- object with (optional) properties:
:current_period_endany of:- object with (optional) properties:
gt: integergte: integerlt: integerlte: integer
- integer
- object with (optional) properties:
:current_period_startany of:- object with (optional) properties:
gt: integergte: integerlt: integerlte: integer
- integer
- object with (optional) properties:
:customerstring:ending_beforestring:expandarray of: string:limitinteger:planstring:pricestring:starting_afterstring:statusstring:test_clockstring
@spec retrieve(client :: term(), subscription_exposed_id :: binary(), params :: map()) :: {:ok, t()} | {:error, Stripe.ApiErrors.t()} | {:error, term()}
Retrieves the subscription with the given ID.
Details
- Method:
get - Path:
/v1/subscriptions/{subscription_exposed_id}
Query parameters
:expandarray of: string
@spec search(client :: term(), params :: map()) :: {: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` #### Query parameters * `:expand` array of: string * `:limit` integer * `:page` string * `:query` (Required) string@spec update(client :: term(), subscription_exposed_id :: binary(), params :: map()) :: {:ok, t()} | {:error, Stripe.ApiErrors.t()} | {:error, term()}
Updates an existing subscription on a customer to match the specified parameters. When changing plans or quantities, we will optionally prorate the price we charge next month to make up for any price changes. To preview how the proration will be calculated, use the upcoming invoice endpoint.
Details
- Method:
post - Path:
/v1/subscriptions/{subscription_exposed_id}