Class: Balanced::Card

Inherits:
DebitableFundingInstrument show all
Includes:
HypermediaRegistry, 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, #href, #hyperlinks, #id, #links

Instance Method Summary collapse

Methods included from HypermediaRegistry

included

Methods included from Resource

#copy_from, #does_resource_respond_to?, #fetch, #hydrate, included, #initialize, #method_missing, #reload, #respond_to?, #respond_to_missing?, #sanitize, #save, #unstore

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Balanced::Resource

Instance Method Details

#associate_to_customer(customer) ⇒ Object



44
45
46
47
# File 'lib/balanced/resources/card.rb', line 44

def associate_to_customer(customer)
  self.links['customer'] = Balanced::Utils.extract_href_from_object(customer)
  save
end

#credit(options = {}) ⇒ Credit

Creates a Credit of funds to this Card.

Parameters:

  • options (Hash) (defaults to: {})

Returns:



25
26
27
28
29
30
31
32
33
# File 'lib/balanced/resources/card.rb', line 25

def credit(options={})
  if ! self.respond_to?(:credits)
    raise Balanced::FundingInstrumentNotCreditable
  end

  options[:href] = self.credits.href
  credit = Balanced::Credit.new(options)
  credit.save
end

#debit(options = {}) ⇒ Debit

Creates a Debit of funds from this Card.

Parameters:

  • options (Hash) (defaults to: {})

Returns:



15
16
17
18
19
# File 'lib/balanced/resources/card.rb', line 15

def debit(options={})
  options[:href] = self.debits.href
  debit = Balanced::Debit.new(options)
  debit.save
end

#hold(options = {}) ⇒ Hold

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

Returns:

  • (Hold)


38
39
40
41
42
# File 'lib/balanced/resources/card.rb', line 38

def hold(options={})
  options[:href] = self.card_holds.href
  hold = Balanced::CardHold.new(options)
  hold.save
end