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)
Constant Summary collapse
- OBJECT_NAME =
"subscription"
Constants inherited from StripeObject
Stripe::StripeObject::RESERVED_FIELD_NAMES
Instance Attribute Summary
Attributes inherited from APIResource
Class Method Summary collapse
-
.cancel(subscription_exposed_id, params = {}, opts = {}) ⇒ Object
Cancels a customer’s subscription immediately.
-
.delete_discount(subscription_exposed_id, params = {}, opts = {}) ⇒ Object
Removes the currently applied discount on a subscription.
-
.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
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.
-
#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
Class Method Details
.cancel(subscription_exposed_id, params = {}, opts = {}) ⇒ Object
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](stripe.com/docs/api#delete_invoiceitem). 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.
55 56 57 58 59 60 61 62 |
# File 'lib/stripe/resources/subscription.rb', line 55 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 |
.delete_discount(subscription_exposed_id, params = {}, opts = {}) ⇒ Object
Removes the currently applied discount on a subscription.
65 66 67 68 69 70 71 72 |
# File 'lib/stripe/resources/subscription.rb', line 65 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 |
.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.
75 76 77 78 79 80 81 82 |
# File 'lib/stripe/resources/subscription.rb', line 75 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
86 87 88 |
# File 'lib/stripe/resources/subscription.rb', line 86 def self.search(params = {}, opts = {}) _search("/v1/subscriptions/search", params, opts) end |
.search_auto_paging_each(params = {}, opts = {}, &blk) ⇒ Object
90 91 92 |
# File 'lib/stripe/resources/subscription.rb', line 90 def self.search_auto_paging_each(params = {}, opts = {}, &blk) search(params, opts).auto_paging_each(&blk) end |
Instance Method Details
#cancel(params = {}, opts = {}) ⇒ Object
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](stripe.com/docs/api#delete_invoiceitem). 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.
21 22 23 24 25 26 27 28 |
# File 'lib/stripe/resources/subscription.rb', line 21 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.
31 32 33 34 35 36 37 38 |
# File 'lib/stripe/resources/subscription.rb', line 31 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 |
#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.
41 42 43 44 45 46 47 48 |
# File 'lib/stripe/resources/subscription.rb', line 41 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 |