Class: Stripe::Subscription
- Inherits:
-
APIResource
- Object
- StripeObject
- APIResource
- Stripe::Subscription
- Extended by:
- APIOperations::Create, APIOperations::List, APIOperations::Search
- Includes:
- APIOperations::Save
- Defined in:
- lib/stripe/resources/subscription.rb
Overview
Subscriptions allow you to charge a customer on a recurring basis.
Related guide: [Creating subscriptions](stripe.com/docs/billing/subscriptions/creating)
Defined Under Namespace
Classes: AutomaticTax, BillingCycleAnchorConfig, BillingMode, BillingThresholds, CancelParams, CancellationDetails, CreateParams, DeleteDiscountParams, InvoiceSettings, ListParams, MigrateParams, PauseCollection, PaymentSettings, PendingInvoiceItemInterval, PendingUpdate, ResumeParams, SearchParams, TransferData, TrialSettings, UpdateParams
Constant Summary collapse
- OBJECT_NAME =
"subscription"
Constants inherited from StripeObject
Stripe::StripeObject::RESERVED_FIELD_NAMES
Instance Attribute Summary collapse
-
#application ⇒ Object
readonly
ID of the Connect Application that created the subscription.
-
#application_fee_percent ⇒ Object
readonly
A non-negative decimal between 0 and 100, with at most two decimal places.
-
#automatic_tax ⇒ Object
readonly
Attribute for field automatic_tax.
-
#billing_cycle_anchor ⇒ Object
readonly
The reference point that aligns future [billing cycle](stripe.com/docs/subscriptions/billing-cycle) dates.
-
#billing_cycle_anchor_config ⇒ Object
readonly
The fixed values used to calculate the ‘billing_cycle_anchor`.
-
#billing_mode ⇒ Object
readonly
The billing mode of the subscription.
-
#billing_thresholds ⇒ Object
readonly
Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period.
-
#cancel_at ⇒ Object
readonly
A date in the future at which the subscription will automatically get canceled.
-
#cancel_at_period_end ⇒ Object
readonly
Whether this subscription will (if ‘status=active`) or did (if `status=canceled`) cancel at the end of the current billing period.
-
#canceled_at ⇒ Object
readonly
If the subscription has been canceled, the date of that cancellation.
-
#cancellation_details ⇒ Object
readonly
Details about why this subscription was cancelled.
-
#collection_method ⇒ Object
readonly
Either ‘charge_automatically`, or `send_invoice`.
-
#created ⇒ Object
readonly
Time at which the object was created.
-
#currency ⇒ Object
readonly
Three-letter [ISO currency code](www.iso.org/iso-4217-currency-codes.html), in lowercase.
-
#customer ⇒ Object
readonly
ID of the customer who owns the subscription.
-
#days_until_due ⇒ Object
readonly
Number of days a customer has to pay invoices generated by this subscription.
-
#default_payment_method ⇒ Object
readonly
ID of the default payment method for the subscription.
-
#default_source ⇒ Object
readonly
ID of the default payment source for the subscription.
-
#default_tax_rates ⇒ Object
readonly
The tax rates that will apply to any subscription item that does not have ‘tax_rates` set.
-
#description ⇒ Object
readonly
The subscription’s description, meant to be displayable to the customer.
-
#discounts ⇒ Object
readonly
The discounts applied to the subscription.
-
#ended_at ⇒ Object
readonly
If the subscription has ended, the date the subscription ended.
-
#id ⇒ Object
readonly
Unique identifier for the object.
-
#invoice_settings ⇒ Object
readonly
Attribute for field invoice_settings.
-
#items ⇒ Object
readonly
List of subscription items, each with an attached price.
-
#latest_invoice ⇒ Object
readonly
The most recent invoice this subscription has generated.
-
#livemode ⇒ Object
readonly
Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.
-
#metadata ⇒ Object
readonly
Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object.
-
#next_pending_invoice_item_invoice ⇒ Object
readonly
Specifies the approximate timestamp on which any pending invoice items will be billed according to the schedule provided at ‘pending_invoice_item_interval`.
-
#object ⇒ Object
readonly
String representing the object’s type.
-
#on_behalf_of ⇒ Object
readonly
The account (if any) the charge was made on behalf of for charges associated with this subscription.
-
#pause_collection ⇒ Object
readonly
If specified, payment collection for this subscription will be paused.
-
#payment_settings ⇒ Object
readonly
Payment settings passed on to invoices created by the subscription.
-
#pending_invoice_item_interval ⇒ Object
readonly
Specifies an interval for how often to bill for any pending invoice items.
-
#pending_setup_intent ⇒ Object
readonly
You can use this [SetupIntent](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.
-
#pending_update ⇒ Object
readonly
If specified, [pending updates](stripe.com/docs/billing/subscriptions/pending-updates) that will be applied to the subscription once the ‘latest_invoice` has been paid.
-
#schedule ⇒ Object
readonly
The schedule attached to the subscription.
-
#start_date ⇒ Object
readonly
Date when the subscription was first created.
-
#status ⇒ Object
readonly
Possible values are ‘incomplete`, `incomplete_expired`, `trialing`, `active`, `past_due`, `canceled`, `unpaid`, or `paused`.
-
#test_clock ⇒ Object
readonly
ID of the test clock this subscription belongs to.
-
#transfer_data ⇒ Object
readonly
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 ⇒ Object
readonly
If the subscription has a trial, the end of that trial.
-
#trial_settings ⇒ Object
readonly
Settings related to subscription trials.
-
#trial_start ⇒ Object
readonly
If the subscription has a trial, the beginning of that trial.
Attributes inherited from APIResource
Attributes inherited from StripeObject
Class Method Summary collapse
-
.cancel(subscription_exposed_id, params = {}, opts = {}) ⇒ Object
Cancels a customer’s subscription immediately.
-
.create(params = {}, opts = {}) ⇒ Object
Creates a new subscription on an existing customer.
-
.delete_discount(subscription_exposed_id, params = {}, opts = {}) ⇒ Object
Removes the currently applied discount on a subscription.
-
.list(params = {}, opts = {}) ⇒ Object
By default, returns a list of subscriptions that have not been canceled.
-
.migrate(subscription, params = {}, opts = {}) ⇒ Object
Upgrade the billing_mode of an existing subscription.
- .object_name ⇒ Object
-
.resume(subscription, params = {}, opts = {}) ⇒ Object
Initiates resumption of a paused subscription, optionally resetting the billing cycle anchor and creating prorations.
- .search(params = {}, opts = {}) ⇒ Object
- .search_auto_paging_each(params = {}, opts = {}, &blk) ⇒ Object
-
.update(subscription_exposed_id, params = {}, opts = {}) ⇒ Object
Updates an existing subscription to match the specified parameters.
Instance Method Summary collapse
-
#cancel(params = {}, opts = {}) ⇒ Object
Cancels a customer’s subscription immediately.
-
#delete_discount(params = {}, opts = {}) ⇒ Object
Removes the currently applied discount on a subscription.
-
#migrate(params = {}, opts = {}) ⇒ Object
Upgrade the billing_mode of an existing subscription.
-
#resume(params = {}, opts = {}) ⇒ Object
Initiates resumption of a paused subscription, optionally resetting the billing cycle anchor and creating prorations.
Methods included from APIOperations::Create
Methods included from APIOperations::List
Methods included from APIOperations::Search
Methods included from APIOperations::Save
Methods inherited from APIResource
class_name, custom_method, #refresh, #request_stripe_object, resource_url, #resource_url, retrieve, save_nested_resource
Methods included from APIOperations::Request
Methods inherited from StripeObject
#==, #[], #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values
Constructor Details
This class inherits a constructor from Stripe::StripeObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject
Instance Attribute Details
#application ⇒ Object (readonly)
ID of the Connect Application that created the subscription.
1807 1808 1809 |
# File 'lib/stripe/resources/subscription.rb', line 1807 def application @application end |
#application_fee_percent ⇒ Object (readonly)
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.
1809 1810 1811 |
# File 'lib/stripe/resources/subscription.rb', line 1809 def application_fee_percent @application_fee_percent end |
#automatic_tax ⇒ Object (readonly)
Attribute for field automatic_tax
1811 1812 1813 |
# File 'lib/stripe/resources/subscription.rb', line 1811 def automatic_tax @automatic_tax end |
#billing_cycle_anchor ⇒ Object (readonly)
The reference point that aligns future [billing cycle](stripe.com/docs/subscriptions/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. The timestamp is in UTC format.
1813 1814 1815 |
# File 'lib/stripe/resources/subscription.rb', line 1813 def billing_cycle_anchor @billing_cycle_anchor end |
#billing_cycle_anchor_config ⇒ Object (readonly)
The fixed values used to calculate the ‘billing_cycle_anchor`.
1815 1816 1817 |
# File 'lib/stripe/resources/subscription.rb', line 1815 def billing_cycle_anchor_config @billing_cycle_anchor_config end |
#billing_mode ⇒ Object (readonly)
The billing mode of the subscription.
1817 1818 1819 |
# File 'lib/stripe/resources/subscription.rb', line 1817 def billing_mode @billing_mode end |
#billing_thresholds ⇒ Object (readonly)
Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period
1819 1820 1821 |
# File 'lib/stripe/resources/subscription.rb', line 1819 def billing_thresholds @billing_thresholds end |
#cancel_at ⇒ Object (readonly)
A date in the future at which the subscription will automatically get canceled
1821 1822 1823 |
# File 'lib/stripe/resources/subscription.rb', line 1821 def cancel_at @cancel_at end |
#cancel_at_period_end ⇒ Object (readonly)
Whether this subscription will (if ‘status=active`) or did (if `status=canceled`) cancel at the end of the current billing period.
1823 1824 1825 |
# File 'lib/stripe/resources/subscription.rb', line 1823 def cancel_at_period_end @cancel_at_period_end end |
#canceled_at ⇒ Object (readonly)
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.
1825 1826 1827 |
# File 'lib/stripe/resources/subscription.rb', line 1825 def canceled_at @canceled_at end |
#cancellation_details ⇒ Object (readonly)
Details about why this subscription was cancelled
1827 1828 1829 |
# File 'lib/stripe/resources/subscription.rb', line 1827 def cancellation_details @cancellation_details end |
#collection_method ⇒ Object (readonly)
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`.
1829 1830 1831 |
# File 'lib/stripe/resources/subscription.rb', line 1829 def collection_method @collection_method end |
#created ⇒ Object (readonly)
Time at which the object was created. Measured in seconds since the Unix epoch.
1831 1832 1833 |
# File 'lib/stripe/resources/subscription.rb', line 1831 def created @created end |
#currency ⇒ Object (readonly)
Three-letter [ISO currency code](www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](stripe.com/docs/currencies).
1833 1834 1835 |
# File 'lib/stripe/resources/subscription.rb', line 1833 def currency @currency end |
#customer ⇒ Object (readonly)
ID of the customer who owns the subscription.
1835 1836 1837 |
# File 'lib/stripe/resources/subscription.rb', line 1835 def customer @customer end |
#days_until_due ⇒ Object (readonly)
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`.
1837 1838 1839 |
# File 'lib/stripe/resources/subscription.rb', line 1837 def days_until_due @days_until_due end |
#default_payment_method ⇒ Object (readonly)
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](stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method) or [default_source](stripe.com/docs/api/customers/object#customer_object-default_source).
1839 1840 1841 |
# File 'lib/stripe/resources/subscription.rb', line 1839 def default_payment_method @default_payment_method end |
#default_source ⇒ Object (readonly)
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](stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method) or [default_source](stripe.com/docs/api/customers/object#customer_object-default_source).
1841 1842 1843 |
# File 'lib/stripe/resources/subscription.rb', line 1841 def default_source @default_source end |
#default_tax_rates ⇒ Object (readonly)
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.
1843 1844 1845 |
# File 'lib/stripe/resources/subscription.rb', line 1843 def default_tax_rates @default_tax_rates end |
#description ⇒ Object (readonly)
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.
1845 1846 1847 |
# File 'lib/stripe/resources/subscription.rb', line 1845 def description @description end |
#discounts ⇒ Object (readonly)
The discounts applied to the subscription. Subscription item discounts are applied before subscription discounts. Use ‘expand[]=discounts` to expand each discount.
1847 1848 1849 |
# File 'lib/stripe/resources/subscription.rb', line 1847 def discounts @discounts end |
#ended_at ⇒ Object (readonly)
If the subscription has ended, the date the subscription ended.
1849 1850 1851 |
# File 'lib/stripe/resources/subscription.rb', line 1849 def ended_at @ended_at end |
#id ⇒ Object (readonly)
Unique identifier for the object.
1851 1852 1853 |
# File 'lib/stripe/resources/subscription.rb', line 1851 def id @id end |
#invoice_settings ⇒ Object (readonly)
Attribute for field invoice_settings
1853 1854 1855 |
# File 'lib/stripe/resources/subscription.rb', line 1853 def invoice_settings @invoice_settings end |
#items ⇒ Object (readonly)
List of subscription items, each with an attached price.
1855 1856 1857 |
# File 'lib/stripe/resources/subscription.rb', line 1855 def items @items end |
#latest_invoice ⇒ Object (readonly)
The most recent invoice this subscription has generated.
1857 1858 1859 |
# File 'lib/stripe/resources/subscription.rb', line 1857 def latest_invoice @latest_invoice end |
#livemode ⇒ Object (readonly)
Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.
1859 1860 1861 |
# File 'lib/stripe/resources/subscription.rb', line 1859 def livemode @livemode end |
#metadata ⇒ Object (readonly)
Set of [key-value pairs](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.
1861 1862 1863 |
# File 'lib/stripe/resources/subscription.rb', line 1861 def end |
#next_pending_invoice_item_invoice ⇒ Object (readonly)
Specifies the approximate timestamp on which any pending invoice items will be billed according to the schedule provided at ‘pending_invoice_item_interval`.
1863 1864 1865 |
# File 'lib/stripe/resources/subscription.rb', line 1863 def next_pending_invoice_item_invoice @next_pending_invoice_item_invoice end |
#object ⇒ Object (readonly)
String representing the object’s type. Objects of the same type share the same value.
1865 1866 1867 |
# File 'lib/stripe/resources/subscription.rb', line 1865 def object @object end |
#on_behalf_of ⇒ Object (readonly)
The account (if any) the charge was made on behalf of for charges associated with this subscription. See the [Connect documentation](stripe.com/docs/connect/subscriptions#on-behalf-of) for details.
1867 1868 1869 |
# File 'lib/stripe/resources/subscription.rb', line 1867 def on_behalf_of @on_behalf_of end |
#pause_collection ⇒ Object (readonly)
If specified, payment collection for this subscription will be paused. Note that the subscription status will be unchanged and will not be updated to ‘paused`. Learn more about [pausing collection](stripe.com/docs/billing/subscriptions/pause-payment).
1869 1870 1871 |
# File 'lib/stripe/resources/subscription.rb', line 1869 def pause_collection @pause_collection end |
#payment_settings ⇒ Object (readonly)
Payment settings passed on to invoices created by the subscription.
1871 1872 1873 |
# File 'lib/stripe/resources/subscription.rb', line 1871 def payment_settings @payment_settings end |
#pending_invoice_item_interval ⇒ Object (readonly)
Specifies an interval for how often to bill for any pending invoice items. It is analogous to calling [Create an invoice](stripe.com/docs/api#create_invoice) for the given subscription at the specified interval.
1873 1874 1875 |
# File 'lib/stripe/resources/subscription.rb', line 1873 def pending_invoice_item_interval @pending_invoice_item_interval end |
#pending_setup_intent ⇒ Object (readonly)
You can use this [SetupIntent](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](stripe.com/docs/billing/migration/strong-customer-authentication#scenario-2).
1875 1876 1877 |
# File 'lib/stripe/resources/subscription.rb', line 1875 def pending_setup_intent @pending_setup_intent end |
#pending_update ⇒ Object (readonly)
If specified, [pending updates](stripe.com/docs/billing/subscriptions/pending-updates) that will be applied to the subscription once the ‘latest_invoice` has been paid.
1877 1878 1879 |
# File 'lib/stripe/resources/subscription.rb', line 1877 def pending_update @pending_update end |
#schedule ⇒ Object (readonly)
The schedule attached to the subscription
1879 1880 1881 |
# File 'lib/stripe/resources/subscription.rb', line 1879 def schedule @schedule end |
#start_date ⇒ Object (readonly)
Date when the subscription was first created. The date might differ from the ‘created` date due to backdating.
1881 1882 1883 |
# File 'lib/stripe/resources/subscription.rb', line 1881 def start_date @start_date end |
#status ⇒ Object (readonly)
Possible values are ‘incomplete`, `incomplete_expired`, `trialing`, `active`, `past_due`, `canceled`, `unpaid`, or `paused`.
For ‘collection_method=charge_automatically` a subscription moves into `incomplete` if the initial payment attempt fails. A subscription in this status can only have metadata and default_source updated. Once the first invoice is paid, the subscription moves into an `active` status. If the first invoice is not paid within 23 hours, the subscription transitions to `incomplete_expired`. This is a terminal status, 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.
A subscription can only enter a ‘paused` status [when a trial ends without a payment method](stripe.com/docs/billing/subscriptions/trials#create-free-trials-without-payment). A `paused` subscription doesn’t generate invoices and can be resumed after your customer adds their payment method. The ‘paused` status is different from [pausing collection](stripe.com/docs/billing/subscriptions/pause-payment), which still generates invoices and leaves the subscription’s status unchanged.
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.
1893 1894 1895 |
# File 'lib/stripe/resources/subscription.rb', line 1893 def status @status end |
#test_clock ⇒ Object (readonly)
ID of the test clock this subscription belongs to.
1895 1896 1897 |
# File 'lib/stripe/resources/subscription.rb', line 1895 def test_clock @test_clock end |
#transfer_data ⇒ Object (readonly)
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.
1897 1898 1899 |
# File 'lib/stripe/resources/subscription.rb', line 1897 def transfer_data @transfer_data end |
#trial_end ⇒ Object (readonly)
If the subscription has a trial, the end of that trial.
1899 1900 1901 |
# File 'lib/stripe/resources/subscription.rb', line 1899 def trial_end @trial_end end |
#trial_settings ⇒ Object (readonly)
Settings related to subscription trials.
1901 1902 1903 |
# File 'lib/stripe/resources/subscription.rb', line 1901 def trial_settings @trial_settings end |
#trial_start ⇒ Object (readonly)
If the subscription has a trial, the beginning of that trial.
1903 1904 1905 |
# File 'lib/stripe/resources/subscription.rb', line 1903 def trial_start @trial_start end |
Class Method Details
.cancel(subscription_exposed_id, params = {}, opts = {}) ⇒ Object
Cancels a customer’s subscription immediately. The customer won’t be charged again for the subscription. After it’s canceled, you can no longer update the subscription or its [metadata](docs.stripe.com/metadata).
Any pending invoice items that you’ve created are still charged at the end of the period, unless manually [deleted](docs.stripe.com/api#delete_invoiceitem). If you’ve set the subscription to cancel at the end of the period, any pending prorations are also left in place and collected at the end of the period. But if the subscription is set to cancel immediately, pending prorations are removed if invoice_now and prorate are both set to true.
By default, upon subscription cancellation, Stripe stops 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.
1924 1925 1926 1927 1928 1929 1930 1931 |
# File 'lib/stripe/resources/subscription.rb', line 1924 def self.cancel(subscription_exposed_id, params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/subscriptions/%<subscription_exposed_id>s", { subscription_exposed_id: CGI.escape(subscription_exposed_id) }), params: params, opts: opts ) end |
.create(params = {}, opts = {}) ⇒ Object
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](docs.stripe.com/docs/billing/subscriptions/subscription-schedules#managing) instead. Schedules provide the flexibility to model more complex billing configurations that change over time.
1940 1941 1942 |
# File 'lib/stripe/resources/subscription.rb', line 1940 def self.create(params = {}, opts = {}) request_stripe_object(method: :post, path: "/v1/subscriptions", params: params, opts: opts) end |
.delete_discount(subscription_exposed_id, params = {}, opts = {}) ⇒ Object
Removes the currently applied discount on a subscription.
1955 1956 1957 1958 1959 1960 1961 1962 |
# File 'lib/stripe/resources/subscription.rb', line 1955 def self.delete_discount(subscription_exposed_id, params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/subscriptions/%<subscription_exposed_id>s/discount", { subscription_exposed_id: CGI.escape(subscription_exposed_id) }), params: params, opts: opts ) end |
.list(params = {}, opts = {}) ⇒ Object
By default, returns a list of subscriptions that have not been canceled. In order to list canceled subscriptions, specify status=canceled.
1965 1966 1967 |
# File 'lib/stripe/resources/subscription.rb', line 1965 def self.list(params = {}, opts = {}) request_stripe_object(method: :get, path: "/v1/subscriptions", params: params, opts: opts) end |
.migrate(subscription, params = {}, opts = {}) ⇒ Object
Upgrade the billing_mode of an existing subscription.
1980 1981 1982 1983 1984 1985 1986 1987 |
# File 'lib/stripe/resources/subscription.rb', line 1980 def self.migrate(subscription, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/subscriptions/%<subscription>s/migrate", { subscription: CGI.escape(subscription) }), params: params, opts: opts ) end |
.object_name ⇒ Object
15 16 17 |
# File 'lib/stripe/resources/subscription.rb', line 15 def self.object_name "subscription" end |
.resume(subscription, params = {}, opts = {}) ⇒ Object
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.
2000 2001 2002 2003 2004 2005 2006 2007 |
# File 'lib/stripe/resources/subscription.rb', line 2000 def self.resume(subscription, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/subscriptions/%<subscription>s/resume", { subscription: CGI.escape(subscription) }), params: params, opts: opts ) end |
.search(params = {}, opts = {}) ⇒ Object
2009 2010 2011 2012 2013 2014 2015 2016 |
# File 'lib/stripe/resources/subscription.rb', line 2009 def self.search(params = {}, opts = {}) request_stripe_object( method: :get, path: "/v1/subscriptions/search", params: params, opts: opts ) end |
.search_auto_paging_each(params = {}, opts = {}, &blk) ⇒ Object
2018 2019 2020 |
# File 'lib/stripe/resources/subscription.rb', line 2018 def self.search_auto_paging_each(params = {}, opts = {}, &blk) search(params, opts).auto_paging_each(&blk) end |
.update(subscription_exposed_id, params = {}, opts = {}) ⇒ Object
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 [create preview](docs.stripe.com/docs/api/invoices/create_preview) endpoint.
By default, we prorate subscription changes. For example, if a customer signs up on May 1 for a 100 price, they’ll be billed 100 immediately. If on May 15 they switch to a 200 price, then on June 1 they’ll be billed 250 (200 for a renewal of her subscription, plus a 50 prorating adjustment for half of the previous month’s 100 difference). Similarly, a downgrade generates a credit that is applied to the next invoice. We also prorate when you make quantity changes.
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. 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. Learn about how [Stripe immediately attempts payment for subscription changes](docs.stripe.com/docs/billing/subscriptions/upgrade-downgrade#immediate-payment).
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](docs.stripe.com/docs/api/invoices/create).
If you don’t want to prorate, set the proration_behavior option to none. With this option, the customer is billed 100 on May 1 and 200 on June 1. Similarly, if you set 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 <a href=“/docs/billing/subscriptions/usage-based”>usage-based billing](docs.stripe.com/docs/rate-limits) instead.
2043 2044 2045 2046 2047 2048 2049 2050 |
# File 'lib/stripe/resources/subscription.rb', line 2043 def self.update(subscription_exposed_id, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/subscriptions/%<subscription_exposed_id>s", { subscription_exposed_id: CGI.escape(subscription_exposed_id) }), params: params, opts: opts ) end |
Instance Method Details
#cancel(params = {}, opts = {}) ⇒ Object
Cancels a customer’s subscription immediately. The customer won’t be charged again for the subscription. After it’s canceled, you can no longer update the subscription or its [metadata](docs.stripe.com/metadata).
Any pending invoice items that you’ve created are still charged at the end of the period, unless manually [deleted](docs.stripe.com/api#delete_invoiceitem). If you’ve set the subscription to cancel at the end of the period, any pending prorations are also left in place and collected at the end of the period. But if the subscription is set to cancel immediately, pending prorations are removed if invoice_now and prorate are both set to true.
By default, upon subscription cancellation, Stripe stops 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.
1910 1911 1912 1913 1914 1915 1916 1917 |
# File 'lib/stripe/resources/subscription.rb', line 1910 def cancel(params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/subscriptions/%<subscription_exposed_id>s", { subscription_exposed_id: CGI.escape(self["id"]) }), params: params, opts: opts ) end |
#delete_discount(params = {}, opts = {}) ⇒ Object
Removes the currently applied discount on a subscription.
1945 1946 1947 1948 1949 1950 1951 1952 |
# File 'lib/stripe/resources/subscription.rb', line 1945 def delete_discount(params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/subscriptions/%<subscription_exposed_id>s/discount", { subscription_exposed_id: CGI.escape(self["id"]) }), params: params, opts: opts ) end |
#migrate(params = {}, opts = {}) ⇒ Object
Upgrade the billing_mode of an existing subscription.
1970 1971 1972 1973 1974 1975 1976 1977 |
# File 'lib/stripe/resources/subscription.rb', line 1970 def migrate(params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/subscriptions/%<subscription>s/migrate", { subscription: CGI.escape(self["id"]) }), params: params, opts: opts ) end |
#resume(params = {}, opts = {}) ⇒ Object
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.
1990 1991 1992 1993 1994 1995 1996 1997 |
# File 'lib/stripe/resources/subscription.rb', line 1990 def resume(params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/subscriptions/%<subscription>s/resume", { subscription: CGI.escape(self["id"]) }), params: params, opts: opts ) end |