Class: Balanced::Card

Inherits:
Object
  • Object
show all
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

#attributes

Instance Method Summary collapse

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.

Parameters:

  • args (Array)

Options Hash (*args):

  • :amount (Integer)

    the amount of the purchase in cents

  • :appears_on_statement_as (String)
  • :hold_uri (String)
  • :meta (Hash)

    a hash of data to save with the Debit

  • :description (String)
  • :source_uri (String)

Returns:



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
  options = args.last.is_a?(Hash) ? args.pop : {}
  amount = args[0] || options.fetch(:amount) { nil }
  appears_on_statement_as = args[1] || options.fetch(:appears_on_statement_as) { nil }
  hold_uri = args[2] || options.fetch(:hold_uri) { nil }
  meta = args[3] || options.fetch(:meta) { nil }
  description = args[3] || options.fetch(:description) { nil }

  self..debit(
      :amount => amount,
      :appears_on_statement_as => appears_on_statement_as,
      :hold_uri => hold_uri,
      :meta => meta,
      :description => description,
      :source_uri => self.uri
  )
end

#hold(*args) ⇒ Hold

Creates a Hold of funds from this Card to your Marketplace.

Returns:



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
  options = args.last.is_a?(Hash) ? args.pop : {}
  amount = args[0] || options.fetch(:amount) { nil }
  meta = args[1] || options.fetch(:meta) { nil }

  self..hold(
      :amount => amount,
      :meta => meta,
      :source_uri => self.uri
  )
end

#invalidateObject



65
66
67
68
# File 'lib/balanced/resources/card.rb', line 65

def invalidate
  self.is_valid = false
  save
end