Sha256: 2503bd2caeaf15bedfd8d650978f56a98b483379ed7ef52fde93929ef4443f3f
Contents?: true
Size: 1.11 KB
Versions: 15
Compression:
Stored size: 1.11 KB
Contents
module Pay module Paddle class Charge attr_reader :pay_charge delegate :processor_id, :owner, to: :pay_charge def initialize(pay_charge) @pay_charge = pay_charge end def charge return unless owner.subscription payments = PaddlePay::Subscription::Payment.list({subscription_id: owner.subscription.processor_id}) charges = payments.select { |p| p[:id].to_s == processor_id } charges.try(:first) rescue ::PaddlePay::PaddlePayError => e raise Pay::Paddle::Error, e end def refund!(amount_to_refund) return unless owner.subscription payments = PaddlePay::Subscription::Payment.list({subscription_id: owner.subscription.processor_id, is_paid: 1}) if payments.count > 0 PaddlePay::Subscription::Payment.refund(payments.last[:id], {amount: amount_to_refund}) pay_charge.update(amount_refunded: amount_to_refund) else raise Error, "Payment not found" end rescue ::PaddlePay::PaddlePayError => e raise Pay::Paddle::Error, e end end end end
Version data entries
15 entries across 15 versions & 1 rubygems