Sha256: 49df1c19e006f7ef0b39ae8373df9e2422b1a90b01ac54b6d3eb3c17447b71ee

Contents?: true

Size: 701 Bytes

Versions: 37

Compression:

Stored size: 701 Bytes

Contents

module Pay
  module Stripe
    module Webhooks
      class PaymentMethodUpdated
        def call(event)
          object = event.data.object

          if object.customer
            pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: object.customer)

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

            Pay::Stripe::PaymentMethod.sync(object.id, stripe_account: event.try(:account))
          else
            # If customer was removed, we should delete the payment method if it exists
            Pay::PaymentMethod.find_by_processor_and_id(:stripe, object.id)&.destroy
          end
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
pay-5.0.4 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-5.0.3 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-5.0.2 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-5.0.1 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-5.0.0 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-4.2.1 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-4.2.0 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-4.1.1 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-4.1.0 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-4.0.4 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-4.0.2 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-4.0.1 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-4.0.0 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-3.0.24 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-3.0.23 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-3.0.22 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-3.0.21 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-3.0.20 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-3.0.19 lib/pay/stripe/webhooks/payment_method_updated.rb
pay-3.0.18 lib/pay/stripe/webhooks/payment_method_updated.rb