Method: Pay::PaddleClassic::Subscription#cancel
- Defined in:
- app/models/pay/paddle_classic/subscription.rb
#cancel(**options) ⇒ Object
Paddle subscriptions are canceled immediately, however we still want to give the user access to the end of the period they paid for
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/pay/paddle_classic/subscription.rb', line 60 def cancel(**) return if canceled? ends_at = if on_trial? trial_ends_at elsif paused? pause_starts_at else Time.parse(api_record.next_payment.date) end PaddleClassic.client.users.cancel(subscription_id: processor_id) update( status: (ends_at.future? ? :active : :canceled), ends_at: ends_at ) # Remove payment methods since customer cannot be reused after cancelling Pay::PaymentMethod.where(customer_id: customer_id).destroy_all rescue ::Paddle::Error => e raise Pay::PaddleClassic::Error, e end |