Sha256: e194a95879487ff1070c14580ace466fe2a6208392cdab55fa4c60fdfbcd638c

Contents?: true

Size: 623 Bytes

Versions: 4

Compression:

Stored size: 623 Bytes

Contents

module Pay
  module Paddle
    module Webhooks
      class SubscriptionPaymentRefunded
        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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pay-2.4.4 lib/pay/paddle/webhooks/subscription_payment_refunded.rb
pay-2.4.3 lib/pay/paddle/webhooks/subscription_payment_refunded.rb
pay-2.4.2 lib/pay/paddle/webhooks/subscription_payment_refunded.rb
pay-2.4.0 lib/pay/paddle/webhooks/subscription_payment_refunded.rb