Class: Pay::PaddleClassic::Charge
- Inherits:
-
Charge
show all
- Defined in:
- app/models/pay/paddle_classic/charge.rb
Instance Method Summary
collapse
Methods inherited from Charge
#amount_refunded_with_currency, #amount_with_currency, #captured?, #charged_to, find_by_processor_and_id, #full_refund?, #line_items, #partial_refund?, #refunded?
Instance Method Details
#api_record ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'app/models/pay/paddle_classic/charge.rb', line 6
def api_record
return unless customer.subscription
payments = PaddleClassic.client.payments.list(subscription_id: customer.subscription.processor_id)
charges = payments.data.select { |p| p[:id].to_s == processor_id }
charges.try(:first)
rescue ::Paddle::Classic::Error => e
raise Pay::PaddleClassic::Error, e
end
|
#refund!(amount_to_refund = nil) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/models/pay/paddle_classic/charge.rb', line 16
def refund!(amount_to_refund = nil)
return unless customer.subscription
amount_to_refund ||= amount
payments = PaddleClassic.client.payments.list(subscription_id: customer.subscription.processor_id, is_paid: 1)
raise Error, "Payment not found" unless payments.total > 0
PaddleClassic.client.payments.refund(order_id: payments.data.last[:id], amount: amount_to_refund)
update(amount_refunded: amount_to_refund)
rescue ::Paddle::Classic::Error => e
raise Pay::PaddleClassic::Error, e
end
|