Class: Balanced::Customer

Inherits:
Object
  • Object
show all
Includes:
HypermediaRegistry, Resource
Defined in:
lib/balanced/resources/customer.rb

Overview

A customer represents a business or person within your Marketplace. A customer can have many funding instruments such as cards and bank accounts associated to them.

Instance Attribute Summary

Attributes included from Resource

#attributes, #href, #hyperlinks, #id, #links

Class Method Summary collapse

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

Class Method Details

.find_by_email(email) ⇒ Customer?

Attempts to find an existing customer by email

NOTE: There is no unique constraint on email_address.

Multiple customers with the same email may exist.
Only one Customer is returned.

Parameters:

  • email (String)

    An email of a customer

Returns:

  • (Customer)

    if customer is found

  • (nil)

    if customer is not found



22
23
24
# File 'lib/balanced/resources/customer.rb', line 22

def self.find_by_email email
  self.find(:first, :email => email)
end

.ownerObject



26
27
28
29
# File 'lib/balanced/resources/customer.rb', line 26

def self.owner
  owner_customer = Balanced::Marketplace.mine.owner_customer
  owner_customer
end

Instance Method Details

#add_destination(destination) ⇒ Customer

Associates the BankAccount represented by bank_account with this Customer.

Returns:



53
54
55
56
57
58
59
60
# File 'lib/balanced/resources/customer.rb', line 53

def add_destination(destination)
  if destination.is_a?(Balanced::Resource)
    self.links['destination'] = destination.id
  else
    self.links['destination'] = destination
  end
  save
end

#add_source(source) ⇒ Customer

Associates the Card represented by ‘card’ with this Customer.

Returns:



40
41
42
43
44
45
46
47
# File 'lib/balanced/resources/customer.rb', line 40

def add_source(source)
  if source.is_a?(Balanced::Resource)
    self.links['source'] = source.id
  else
    self.links['source'] = source
  end
  save
end

#create_order(options = {}) ⇒ Object



31
32
33
34
35
# File 'lib/balanced/resources/customer.rb', line 31

def create_order(options = {})
  options[:href] = self.orders.href
  order = Balanced::Order.new(options)
  order.save
end

#payable_accountCustomer

Returns an Account with type ‘payable’

Returns:



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

def 
   = self.accounts.where(:type=>'payable').first
  
end