Class: Balanced::Card
- Inherits:
-
Object
- Object
- Balanced::Card
- Includes:
- Resource
- Defined in:
- lib/balanced/resources/card.rb
Overview
A card represents a source of funds for an Account. You may Hold or Debit funds from the account associated with the Card.
Instance Attribute Summary
Attributes included from Resource
Instance Method Summary collapse
-
#debit(*args) ⇒ Debit
Creates a Debit of funds from this Card to your Marketplace’s escrow account.
-
#hold(*args) ⇒ Hold
Creates a Hold of funds from this Card to your Marketplace.
-
#initialize(attributes = {}) ⇒ Card
constructor
A new instance of Card.
- #invalidate ⇒ Object
Methods included from Resource
#copy_from, #destroy, #find, included, #method_missing, #reload, #save, #warn_on_positional
Constructor Details
#initialize(attributes = {}) ⇒ Card
Returns a new instance of Card.
8 9 10 11 12 13 14 |
# File 'lib/balanced/resources/card.rb', line 8 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
#debit(*args) ⇒ Debit
Creates a Debit of funds from this Card to your Marketplace’s escrow account.
If appears_on_statement_as
is nil, then Balanced will use the domain_name
property from your Marketplace.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/balanced/resources/card.rb', line 30 def debit *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 } hold_uri = args[2] || .fetch(:hold_uri) { nil } = args[3] || .fetch(:meta) { nil } description = args[3] || .fetch(:description) { nil } self.account.debit( :amount => amount, :appears_on_statement_as => appears_on_statement_as, :hold_uri => hold_uri, :meta => , :description => description, :source_uri => self.uri ) end |
#hold(*args) ⇒ Hold
Creates a Hold of funds from this Card to your Marketplace.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/balanced/resources/card.rb', line 52 def hold *args warn_on_positional args = args.last.is_a?(Hash) ? args.pop : {} amount = args[0] || .fetch(:amount) { nil } = args[1] || .fetch(:meta) { nil } self.account.hold( :amount => amount, :meta => , :source_uri => self.uri ) end |
#invalidate ⇒ Object
65 66 67 68 |
# File 'lib/balanced/resources/card.rb', line 65 def invalidate self.is_valid = false save end |