lib/paidy/charge.rb in paidy-0.0.3 vs lib/paidy/charge.rb in paidy-0.0.4
- old
+ new
@@ -18,11 +18,11 @@
def initialize(id)
@id = id
@capture_id = nil
end
- attr_reader :id, :capture_id, :status
+ attr_reader :id, :capture_id
def capture
res = Paidy.request(:post, "#{base_path}/captures", {}, {})
@capture_id = res['captures'][0]['id']
@@ -33,20 +33,24 @@
res = Paidy.request(:post, "#{base_path}/close", {}, {})
self
end
- def refund
- res = Paidy.request(:post, "#{base_path}/refund", { capture_id: capture_id }, {})
+ def refund(amount: nil, refund_reason: nil)
+ params = { capture_id: capture_id }
+ params[:amount] = amount if amount.present?
+ params[:reason] = refund_reason if refund_reason.present?
+ res = Paidy.request(:post, "#{base_path}/refunds", params, {})
+
self
end
- def refund_or_close
+ def refund_or_close(amount: nil, refund_reason: nil)
if capture_id.nil?
close
else
- refund
+ refund(amount: amount, refund_reason: refund_reason)
end
end
def refresh
res = Paidy.request(:get, "payments/#{id}")