Class: Pay::Stripe::Webhooks::ChargeRefunded

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

Instance Method Summary collapse

Instance Method Details

#call(event) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/pay/stripe/webhooks/charge_refunded.rb', line 5

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

  return unless charge.present?

  charge.update(amount_refunded: object.amount_refunded)
  notify_user(charge.owner, charge)
end

#notify_user(billable, charge) ⇒ Object



15
16
17
18
19
# File 'lib/pay/stripe/webhooks/charge_refunded.rb', line 15

def notify_user(billable, charge)
  if Pay.send_emails
    Pay::UserMailer.with(billable: billable, charge: charge).refund.deliver_later
  end
end