# File generated from our OpenAPI spec # frozen_string_literal: true module Stripe # Subscriptions allow you to charge a customer on a recurring basis. # # Related guide: [Creating subscriptions](https://stripe.com/docs/billing/subscriptions/creating) class Subscription < APIResource extend Stripe::APIOperations::Create extend Stripe::APIOperations::List extend Stripe::APIOperations::Search include Stripe::APIOperations::Save OBJECT_NAME = "subscription" # 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](https://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. def cancel(params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/subscriptions/%s", { subscription_exposed_id: CGI.escape(self["id"]) }), params: params, opts: opts ) end # Removes the currently applied discount on a subscription. def delete_discount(params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/subscriptions/%s/discount", { subscription_exposed_id: CGI.escape(self["id"]) }), params: params, opts: opts ) end # 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. def resume(params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/subscriptions/%s/resume", { subscription: CGI.escape(self["id"]) }), params: params, opts: opts ) end # 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](https://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. def self.cancel(subscription_exposed_id, params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/subscriptions/%s", { subscription_exposed_id: CGI.escape(subscription_exposed_id) }), params: params, opts: opts ) end # Removes the currently applied discount on a subscription. def self.delete_discount(subscription_exposed_id, params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/subscriptions/%s/discount", { subscription_exposed_id: CGI.escape(subscription_exposed_id) }), params: params, opts: opts ) end # 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. def self.resume(subscription, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/subscriptions/%s/resume", { subscription: CGI.escape(subscription) }), params: params, opts: opts ) end save_nested_resource :source def self.search(params = {}, opts = {}) _search("/v1/subscriptions/search", params, opts) end def self.search_auto_paging_each(params = {}, opts = {}, &blk) search(params, opts).auto_paging_each(&blk) end end end