Class: Pay::Paddle::Webhooks::SubscriptionCancelled

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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ SubscriptionCancelled

Returns a new instance of SubscriptionCancelled.



5
6
7
8
9
10
11
12
13
14
# File 'lib/pay/paddle/webhooks/subscription_cancelled.rb', line 5

def initialize(data)
  subscription = Pay.subscription_model.find_by(processor: :paddle, processor_id: data["subscription_id"])

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

  # User canceled subscriptions have an ends_at
  # Automatically canceled subscriptions need this value set
  subscription.update!(ends_at: Time.zone.parse(data["cancellation_effective_date"])) if subscription.ends_at.blank? && data["cancellation_effective_date"].present?
end