Class: Balanced::Customer
- Inherits:
-
Object
- Object
- Balanced::Customer
- 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
-
.find_by_email(email) ⇒ Customer?
Attempts to find an existing customer by email.
- .owner ⇒ Object
Instance Method Summary collapse
-
#add_destination(destination) ⇒ Customer
Associates the BankAccount represented by bank_account with this Customer.
-
#add_source(source) ⇒ Customer
Associates the Card represented by ‘card’ with this Customer.
- #create_order(options = {}) ⇒ Object
-
#payable_account ⇒ Customer
Returns an Account with type ‘payable’.
Methods included from HypermediaRegistry
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.
22 23 24 |
# File 'lib/balanced/resources/customer.rb', line 22 def self.find_by_email email self.find(:first, :email => email) end |
.owner ⇒ Object
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.
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.
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( = {}) [:href] = self.orders.href order = Balanced::Order.new() order.save end |
#payable_account ⇒ Customer
Returns an Account with type ‘payable’
65 66 67 68 |
# File 'lib/balanced/resources/customer.rb', line 65 def payable_account payable_account = self.accounts.where(:type=>'payable').first payable_account end |