Class: Pay::Stripe::Webhooks::ChargeSucceeded

Inherits:
Object
  • Object
show all
Defined in:
lib/pay/stripe/webhooks/charge_succeeded.rb,
lib/pay/stripe_marketplace/webhooks/charge_succeeded.rb

Instance Method Summary collapse

Instance Method Details

#call(event) ⇒ Object



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

def call(event)
  object = event.data.object
  billable = Pay.find_billable(processor: :stripe, processor_id: object.customer)

  return unless billable.present?
  return if billable.charges.where(processor_id: object.id).any?

  charge = Pay::Stripe::Billable.new(billable).save_pay_charge(object)
  notify_user(billable, charge)
end

#notify_user(billable, charge) ⇒ Object



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

def notify_user(billable, charge)
  if Pay.send_emails && charge.respond_to?(:receipt)
    Pay::UserMailer.with(billable: billable, charge: charge).receipt.deliver_later
  end
end