lib/paidy/charge.rb in paidy-0.0.2 vs lib/paidy/charge.rb in paidy-0.0.3
- old
+ new
@@ -4,10 +4,17 @@
def create(params)
res = Paidy.request(:post, 'payments', params, {})
self.new(res['id'])
end
+
+ def retrieve(id)
+ instance = self.new(id)
+ instance.refresh
+
+ instance
+ end
end
def initialize(id)
@id = id
@capture_id = nil
@@ -37,9 +44,17 @@
def refund_or_close
if capture_id.nil?
close
else
refund
+ end
+ end
+
+ def refresh
+ res = Paidy.request(:get, "payments/#{id}")
+
+ if res['status'] == 'closed' && res['captures'].present?
+ @capture_id = res['captures'][0]['id']
end
end
private