Module: Pay::Paddle::Charge

Extended by:
ActiveSupport::Concern
Defined in:
lib/pay/paddle/charge.rb

Instance Method Summary collapse

Instance Method Details

#paddle?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/pay/paddle/charge.rb', line 12

def paddle?
  processor == "paddle"
end

#paddle_chargeObject



16
17
18
19
20
21
22
23
# File 'lib/pay/paddle/charge.rb', line 16

def paddle_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

#paddle_refund!(amount_to_refund) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pay/paddle/charge.rb', line 25

def paddle_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})
    update(amount_refunded: amount_to_refund)
  else
    raise Error, "Payment not found"
  end
rescue ::PaddlePay::PaddlePayError => e
  raise Pay::Paddle::Error, e
end