Class: Paidy::Charge
- Inherits:
-
Object
- Object
- Paidy::Charge
- Defined in:
- lib/paidy/charge.rb
Instance Attribute Summary collapse
-
#capture_id ⇒ Object
readonly
Returns the value of attribute capture_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #capture ⇒ Object
- #close ⇒ Object
-
#initialize(id) ⇒ Charge
constructor
A new instance of Charge.
- #refresh ⇒ Object
- #refund ⇒ Object
- #refund_or_close ⇒ Object
Constructor Details
#initialize(id) ⇒ Charge
Returns a new instance of Charge.
18 19 20 21 |
# File 'lib/paidy/charge.rb', line 18 def initialize(id) @id = id @capture_id = nil end |
Instance Attribute Details
#capture_id ⇒ Object (readonly)
Returns the value of attribute capture_id.
23 24 25 |
# File 'lib/paidy/charge.rb', line 23 def capture_id @capture_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
23 24 25 |
# File 'lib/paidy/charge.rb', line 23 def id @id end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
23 24 25 |
# File 'lib/paidy/charge.rb', line 23 def status @status end |
Class Method Details
.create(params) ⇒ Object
4 5 6 7 8 |
# File 'lib/paidy/charge.rb', line 4 def create(params) res = Paidy.request(:post, 'payments', params, {}) self.new(res['id']) end |
.retrieve(id) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/paidy/charge.rb', line 10 def retrieve(id) instance = self.new(id) instance.refresh instance end |
Instance Method Details
#capture ⇒ Object
25 26 27 28 29 30 |
# File 'lib/paidy/charge.rb', line 25 def capture res = Paidy.request(:post, "#{base_path}/captures", {}, {}) @capture_id = res['captures'][0]['id'] self end |
#close ⇒ Object
32 33 34 35 36 |
# File 'lib/paidy/charge.rb', line 32 def close res = Paidy.request(:post, "#{base_path}/close", {}, {}) self end |
#refresh ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/paidy/charge.rb', line 52 def refresh res = Paidy.request(:get, "payments/#{id}") if res['status'] == 'closed' && res['captures'].present? @capture_id = res['captures'][0]['id'] end end |
#refund ⇒ Object
38 39 40 41 42 |
# File 'lib/paidy/charge.rb', line 38 def refund res = Paidy.request(:post, "#{base_path}/refund", { capture_id: capture_id }, {}) self end |
#refund_or_close ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/paidy/charge.rb', line 44 def refund_or_close if capture_id.nil? close else refund end end |