Class: Pay::PaddleClassic::Webhooks::SubscriptionPaymentRefunded

Inherits:
Object
  • Object
show all
Defined in:
lib/pay/paddle_classic/webhooks/subscription_payment_refunded.rb

Instance Method Summary collapse

Instance Method Details

#call(event) ⇒ Object



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

def call(event)
  pay_charge = Pay::Charge.find_by_processor_and_id(:paddle_classic, event.subscription_payment_id)
  return unless pay_charge.present?

  pay_charge.update!(amount_refunded: (event.gross_refund.to_f * 100).to_i)

  if Pay.send_email?(:refund, pay_charge)
    Pay.mailer.with(pay_customer: pay_charge.customer, pay_charge: pay_charge).refund.deliver_later
  end
end