Class: Billy::Paddle::Webhooks::SubscriptionCancelled

Inherits:
Object
  • Object
show all
Defined in:
lib/billy/paddle/webhooks/subscription_cancelled.rb

Instance Method Summary collapse

Instance Method Details

#call(event) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/billy/paddle/webhooks/subscription_cancelled.rb', line 6

def call(event)
  billy_subscription = Billy::Subscription.find_by(processor: "paddle", processor_id: event.subscription_id)

  # We couldn't find the subscription for some reason, maybe it's from another service
  return if billy_subscription.nil?

  # User cancelled subscriptions have an ends_at
  # Automatically cancelled subscriptions need this value set
  billy_subscription.update!(ends_at: Time.zone.parse(event.cancellation_effective_date)) if billy_subscription.ends_at.blank? && event.cancellation_effective_date.present?

  # Paddle doesn't allow reusing customers, so we should remove their payment methods
  Billy::PaymentMethod.where(account_id: billy_subscription.).destroy_all

  # Send Discord Event
  billy_subscription..discord(kind: :subscription_cancelled)
end