Sha256: f0772bcb47c324b1cf324aa923ee7fc93a5536370966d03a474dd036d366b8dc

Contents?: true

Size: 849 Bytes

Versions: 17

Compression:

Stored size: 849 Bytes

Contents

module Pay
  module Paddle
    module Webhooks
      class SubscriptionCancelled
        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
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
pay-3.0.17 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.16 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.15 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.14 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.13 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.12 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.11 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.10 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.9 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.8 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.7 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.6 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.5 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.4 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.2 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.1 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-3.0.0 lib/pay/paddle/webhooks/subscription_cancelled.rb