Sha256: 9f47a3f4890d12ce33713c7adc395db3992edc5dd971c05884a1a9d989d049ed

Contents?: true

Size: 687 Bytes

Versions: 4

Compression:

Stored size: 687 Bytes

Contents

module Pay
  module Stripe
    module Webhooks
      class CustomerDeleted
        def call(event)
          object = event.data.object
          user = Pay.user_model.find_by(processor: :stripe, processor_id: object.id)

          # Couldn't find user, we can skip
          return unless user.present?

          user.update(
            processor_id: nil,
            trial_ends_at: nil,
            card_type: nil,
            card_last4: nil,
            card_exp_month: nil,
            card_exp_year: nil,
          )

          user.subscriptions.update_all(
            trial_ends_at: nil,
            ends_at: Time.zone.now,
          )
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pay-2.0.3 lib/pay/stripe/webhooks/customer_deleted.rb
pay-2.0.2 lib/pay/stripe/webhooks/customer_deleted.rb
pay-2.0.1 lib/pay/stripe/webhooks/customer_deleted.rb
pay-2.0.0 lib/pay/stripe/webhooks/customer_deleted.rb