Class: Pay::Stripe::Webhooks::PaymentMethodUpdated

Inherits:
Object
  • Object
show all
Defined in:
lib/pay/stripe/webhooks/payment_method_updated.rb

Instance Method Summary collapse

Instance Method Details

#call(event) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pay/stripe/webhooks/payment_method_updated.rb', line 5

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