Class: Balanced::Hold
- Inherits:
-
Object
- Object
- Balanced::Hold
- Includes:
- Resource
- Defined in:
- lib/balanced/resources/hold.rb
Overview
A Hold is a reservation of funds on a funding source such as a Card. This reservation is guaranteed until the expires_at
date. You may capture the Hold at any time before then which will create a Debit and transfer the funds to your Marketplace. If you do not capture the Hold it will be marked as invalid which is represented by the is_void
field being set to true
.
By default a Hold is created using the most recently added funding source on the Account. You may specify a specific funding source such as a Card or BankAccount uri.
Instance Attribute Summary
Attributes included from Resource
Instance Method Summary collapse
-
#capture(*args) ⇒ Debit
Captures a valid Hold and returns a Debit representing the transfer of funds from the buyer’s Account to your Marketplace.
-
#initialize(attributes = {}) ⇒ Hold
constructor
A new instance of Hold.
-
#void ⇒ Object
Cancels an active Hold.
Methods included from Resource
#copy_from, #destroy, #find, included, #method_missing, #reload, #save, #warn_on_positional
Constructor Details
#initialize(attributes = {}) ⇒ Hold
Returns a new instance of Hold.
16 17 18 19 20 21 22 |
# File 'lib/balanced/resources/hold.rb', line 16 def initialize attributes = {} Balanced::Utils.stringify_keys! attributes unless attributes.has_key? 'uri' attributes['uri'] = self.class.uri end super attributes end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Balanced::Resource
Instance Method Details
#capture(*args) ⇒ Debit
Captures a valid Hold and returns a Debit representing the transfer of funds from the buyer’s Account to your Marketplace.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/balanced/resources/hold.rb', line 40 def capture *args warn_on_positional args = args.last.is_a?(Hash) ? args.pop : {} amount = args[0] || .fetch(:amount) { nil } appears_on_statement_as = args[1] || .fetch(:appears_on_statement_as) { nil } = args[2] || .fetch(:meta) { nil } description = args[3] || .fetch(:description) { nil } amount ||= self.amount self.account.debit( :amount => amount, :appears_on_statement_as => appears_on_statement_as, :hold_uri => self.uri, :meta => , :description => description ) end |