Class: Pay::Stripe::Webhooks::CustomerDeleted

Inherits:
Object
  • Object
show all
Defined in:
lib/pay/stripe/webhooks/customer_deleted.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
20
# File 'lib/pay/stripe/webhooks/customer_deleted.rb', line 5

def call(event)
  object = event.data.object
  pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: object.id)

  # Skip processing if this customer is not in the database
  return unless pay_customer

  # Mark all subscriptions as canceled
  pay_customer.subscriptions.active.update_all(ends_at: Time.current, status: "canceled")

  # Remove all payment methods
  pay_customer.payment_methods.destroy_all

  # Mark customer as deleted
  pay_customer.update!(default: false, deleted_at: Time.current)
end