Class: Pay::Paddle::Webhooks::SubscriptionCancelled
- Inherits:
-
Object
- Object
- Pay::Paddle::Webhooks::SubscriptionCancelled
- Defined in:
- lib/pay/paddle/webhooks/subscription_cancelled.rb
Instance Method Summary collapse
Instance Method Details
#call(event) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pay/paddle/webhooks/subscription_cancelled.rb', line 5 def call(event) pay_subscription = Pay::Subscription.find_by_processor_and_id(:paddle, event.subscription_id) # We couldn't find the subscription for some reason, maybe it's from another service return if pay_subscription.nil? # User canceled subscriptions have an ends_at # Automatically canceled subscriptions need this value set pay_subscription.update!(ends_at: Time.zone.parse(event.cancellation_effective_date)) if pay_subscription.ends_at.blank? && event.cancellation_effective_date.present? # Paddle doesn't allow reusing customers, so we should remove their payment methods pay_subscription.customer.payment_methods.destroy_all end |