Class: Affirm::Charge
- Inherits:
-
Object
- Object
- Affirm::Charge
- Defined in:
- lib/affirm/charge.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#auth_hold ⇒ Object
readonly
Returns the value of attribute auth_hold.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#order_id ⇒ Object
readonly
Returns the value of attribute order_id.
-
#payable ⇒ Object
readonly
Returns the value of attribute payable.
Class Method Summary collapse
-
.create(checkout_token, client: Affirm::API.client) ⇒ Object
CREATE / AUTHORIZE.
-
.retrieve(id, client: Affirm::API.client) ⇒ Object
RETRIEVE.
Instance Method Summary collapse
-
#capture(order_id: nil, shipping_carrier: nil, shipping_confirmation: nil) ⇒ Object
CAPTURE.
-
#initialize(attrs: {}, client: Affirm::API.client) ⇒ Charge
constructor
A new instance of Charge.
- #refresh ⇒ Object
-
#refund(amount: nil) ⇒ Object
REFUND.
-
#update(order_id: nil, shipping_carrier: nil, shipping_confirmation: nil) ⇒ Object
UPDATE.
-
#void ⇒ Object
VOID.
- #void? ⇒ Boolean
Constructor Details
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
3 4 5 |
# File 'lib/affirm/charge.rb', line 3 def amount @amount end |
#auth_hold ⇒ Object (readonly)
Returns the value of attribute auth_hold.
3 4 5 |
# File 'lib/affirm/charge.rb', line 3 def auth_hold @auth_hold end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
3 4 5 |
# File 'lib/affirm/charge.rb', line 3 def created @created end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
3 4 5 |
# File 'lib/affirm/charge.rb', line 3 def currency @currency end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
3 4 5 |
# File 'lib/affirm/charge.rb', line 3 def details @details end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
3 4 5 |
# File 'lib/affirm/charge.rb', line 3 def events @events end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/affirm/charge.rb', line 3 def id @id end |
#order_id ⇒ Object (readonly)
Returns the value of attribute order_id.
3 4 5 |
# File 'lib/affirm/charge.rb', line 3 def order_id @order_id end |
#payable ⇒ Object (readonly)
Returns the value of attribute payable.
3 4 5 |
# File 'lib/affirm/charge.rb', line 3 def payable @payable end |
Class Method Details
.create(checkout_token, client: Affirm::API.client) ⇒ Object
CREATE / AUTHORIZE
checkout_token - (required) string. The charge token passed through the confirmation response.
17 18 19 20 21 22 23 24 25 |
# File 'lib/affirm/charge.rb', line 17 def self.create(checkout_token, client: Affirm::API.client) response = client.make_request("/charges", :post, checkout_token: checkout_token) if response.success? new(attrs: response.body, client: client) else raise ChargeError.from_response(response) end end |
Instance Method Details
#capture(order_id: nil, shipping_carrier: nil, shipping_confirmation: nil) ⇒ Object
CAPTURE
order_id - (optional) string. Your internal order id. This is stored for your own future reference. shipping_carrier - (optional) string. The shipping carrier used to ship the items in the charge. shipping_confirmation - (optional) string. The shipping confirmation for the shipment.
33 34 35 36 37 38 39 |
# File 'lib/affirm/charge.rb', line 33 def capture(order_id: nil, shipping_carrier: nil, shipping_confirmation: nil) api_request("/charges/#{id}/capture", :post, { order_id: order_id, shipping_carrier: shipping_carrier, shipping_confirmation: shipping_confirmation }) end |
#refresh ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/affirm/charge.rb', line 77 def refresh response = @client.make_request("/charges/#{id}", :get) set_attrs(response.body) self end |
#refund(amount: nil) ⇒ Object
REFUND
amount - (optional) integer or null. The amount to refund in cents. The default amount is the remaining balance on the charge.
52 53 54 55 56 |
# File 'lib/affirm/charge.rb', line 52 def refund(amount: nil) api_request("/charges/#{id}/refund", :post, { amount: amount }) end |
#update(order_id: nil, shipping_carrier: nil, shipping_confirmation: nil) ⇒ Object
UPDATE
order_id - (optional) string. Your internal order id. This is stored for your own future reference. shipping_carrier - (optional) string. The shipping carrier used to ship the items in the charge. shipping_confirmation - (optional) string. The shipping confirmation for the shipment.
64 65 66 67 68 69 70 |
# File 'lib/affirm/charge.rb', line 64 def update(order_id: nil, shipping_carrier: nil, shipping_confirmation: nil) api_request("/charges/#{id}/update", :post, { order_id: order_id, shipping_carrier: shipping_carrier, shipping_confirmation: shipping_confirmation }) end |
#void ⇒ Object
VOID
44 45 46 |
# File 'lib/affirm/charge.rb', line 44 def void api_request("/charges/#{id}/void", :post) end |
#void? ⇒ Boolean
85 86 87 |
# File 'lib/affirm/charge.rb', line 85 def void? @void end |