Sha256: 9dbe952f029aa93f2c68373e26f9fbee2358219b772ecd2bc0c23f2663ed8105

Contents?: true

Size: 729 Bytes

Versions: 53

Compression:

Stored size: 729 Bytes

Contents

module Pay
  module Stripe
    module Webhooks
      class CustomerUpdated
        def call(event)
          object = event.data.object
          pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: object.id)

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

          # Sync default card
          if (payment_method_id = pay_customer.customer.invoice_settings.default_payment_method)
            Pay::Stripe::PaymentMethod.sync(payment_method_id, stripe_account: event.try(:account))

          else
            # No default payment method set
            pay_customer.payment_methods.update_all(default: false)
          end
        end
      end
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
pay-6.6.1 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.6.0 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.5.0 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.4.0 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.3.4 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.3.3 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.3.2 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.3.1 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.3.0 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.2.4 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.2.3 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.2.2 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.2.1 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.2.0 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.1.2 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.1.1 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.1.0 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.0.3 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.0.2 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.0.1 lib/pay/stripe/webhooks/customer_updated.rb