Class: Payola::CancelSubscription
- Inherits:
-
Object
- Object
- Payola::CancelSubscription
- Defined in:
- app/services/payola/cancel_subscription.rb
Class Method Summary collapse
Class Method Details
.call(subscription, options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/services/payola/cancel_subscription.rb', line 3 def self.call(subscription, = {}) secret_key = Payola.secret_key_for_sale(subscription) customer = Stripe::Customer.retrieve(subscription.stripe_customer_id, secret_key) customer.subscriptions.retrieve(subscription.stripe_id, secret_key).delete(, secret_key) if [:at_period_end] == true # Store that the subscription will be canceled at the end of the billing period subscription.update_attributes(cancel_at_period_end: true) else # Cancel the subscription immediately subscription.cancel! end end |