Sha256: 412e7259b4662a0c1f1796473c14158a71b5e5563ea6f5ebfcf333b4f1a858e9

Contents?: true

Size: 733 Bytes

Versions: 4

Compression:

Stored size: 733 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.account}.compact)

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pay-3.0.4 lib/pay/stripe/webhooks/customer_updated.rb
pay-3.0.2 lib/pay/stripe/webhooks/customer_updated.rb
pay-3.0.1 lib/pay/stripe/webhooks/customer_updated.rb
pay-3.0.0 lib/pay/stripe/webhooks/customer_updated.rb