Sha256: 9192d09e0fb022b9aede3c0f38df5e2ae1f22b92611a1fbf67826e504415808a

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

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?

          stripe_customer = pay_customer.customer

          # Sync default card
          if (payment_method_id = stripe_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

          # Sync invoice credit balance and currency
          if stripe_customer.invoice_credit_balance.present?
            pay_customer.update(
              invoice_credit_balance: stripe_customer.invoice_credit_balance,
              currency: stripe_customer.currency
            )
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pay-7.3.0 lib/pay/stripe/webhooks/customer_updated.rb
pay-7.2.1 lib/pay/stripe/webhooks/customer_updated.rb
pay-7.1.1 lib/pay/stripe/webhooks/customer_updated.rb
pay-7.1.0 lib/pay/stripe/webhooks/customer_updated.rb
pay-7.0.0 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.8.1 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.8.0 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.7.2 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.7.1 lib/pay/stripe/webhooks/customer_updated.rb
pay-6.7.0 lib/pay/stripe/webhooks/customer_updated.rb