Class: Pay::Paddle::Webhooks::SubscriptionPaymentRefunded

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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ SubscriptionPaymentRefunded

Returns a new instance of SubscriptionPaymentRefunded.



5
6
7
8
9
10
11
# File 'lib/pay/paddle/webhooks/subscription_payment_refunded.rb', line 5

def initialize(data)
  charge = Pay.charge_model.find_by(processor: :paddle, processor_id: data["subscription_payment_id"])
  return unless charge.present?

  charge.update(amount_refunded: Integer(data["gross_refund"].to_f * 100))
  notify_user(charge.owner, charge)
end

Instance Method Details

#notify_user(billable, charge) ⇒ Object



13
14
15
16
17
# File 'lib/pay/paddle/webhooks/subscription_payment_refunded.rb', line 13

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