Sha256: cf5d9f7c06299691578e763cbc17f3234dee7abf657659ed1863d9c278f53e1d

Contents?: true

Size: 951 Bytes

Versions: 39

Compression:

Stored size: 951 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 cancelled subscriptions need this value set
          ends_at = Time.zone.parse(event.cancellation_effective_date)
          pay_subscription.update!(
            status: :canceled,
            trial_ends_at: (ends_at if pay_subscription.trial_ends_at?),
            ends_at: ends_at
          )

          # Paddle doesn't allow reusing customers, so we should remove their payment methods
          Pay::PaymentMethod.where(customer_id: pay_subscription.customer_id).destroy_all
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
pay-6.8.1 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.8.0 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.7.2 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.7.1 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.7.0 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.6.1 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.6.0 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.5.0 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.4.0 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.3.4 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.3.3 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.3.2 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.3.1 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.3.0 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.2.4 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.2.3 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.2.2 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.2.1 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.2.0 lib/pay/paddle/webhooks/subscription_cancelled.rb
pay-6.1.2 lib/pay/paddle/webhooks/subscription_cancelled.rb