Class: SynapseClient::Customer
- Inherits:
-
APIResource
- Object
- APIResource
- SynapseClient::Customer
- Defined in:
- lib/synapse_client/customer.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#email ⇒ Object
Returns the value of attribute email.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
-
#fullname ⇒ Object
Returns the value of attribute fullname.
-
#ip_address ⇒ Object
Returns the value of attribute ip_address.
-
#phonenumber ⇒ Object
Returns the value of attribute phonenumber.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes inherited from APIResource
Class Method Summary collapse
- .api_resource_name ⇒ Object
- .create(opts = {}) ⇒ Object
- .retrieve(access_token, refresh_token) ⇒ Object
Instance Method Summary collapse
- #add_bank_account(params = {}) ⇒ Object
- #add_order(params = {}) ⇒ Object
- #bank_accounts ⇒ Object
- #create ⇒ Object
- #finish_linking_bank_account(params = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Customer
constructor
A new instance of Customer.
- #link_bank_account(params = {}) ⇒ Object
-
#login ⇒ Object
TODO.
- #orders ⇒ Object
- #primary_bank_account ⇒ Object
Methods inherited from APIResource
class_name, #refresh, #successful?, #to_hash, #url, url
Constructor Details
#initialize(options = {}) ⇒ Customer
Returns a new instance of Customer.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/synapse_client/customer.rb', line 9 def initialize( = {}) = Map.new() @id = [:id] || [:user_id] @email = [:email] @fullname = [:fullname] || [:name] @phonenumber = [:phonenumber] || [:phone_number] @ip_address = [:ip_address] @access_token = [:access_token] @refresh_token = [:refresh_token] @expires_in = [:expires_in] @username = [:username] end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
6 7 8 |
# File 'lib/synapse_client/customer.rb', line 6 def access_token @access_token end |
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/synapse_client/customer.rb', line 5 def email @email end |
#expires_in ⇒ Object
Returns the value of attribute expires_in.
6 7 8 |
# File 'lib/synapse_client/customer.rb', line 6 def expires_in @expires_in end |
#fullname ⇒ Object
Returns the value of attribute fullname.
5 6 7 |
# File 'lib/synapse_client/customer.rb', line 5 def fullname @fullname end |
#ip_address ⇒ Object
Returns the value of attribute ip_address.
5 6 7 |
# File 'lib/synapse_client/customer.rb', line 5 def ip_address @ip_address end |
#phonenumber ⇒ Object
Returns the value of attribute phonenumber.
5 6 7 |
# File 'lib/synapse_client/customer.rb', line 5 def phonenumber @phonenumber end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
6 7 8 |
# File 'lib/synapse_client/customer.rb', line 6 def refresh_token @refresh_token end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/synapse_client/customer.rb', line 7 def username @username end |
Class Method Details
.api_resource_name ⇒ Object
24 25 26 |
# File 'lib/synapse_client/customer.rb', line 24 def self.api_resource_name "user" # see README.md end |
.create(opts = {}) ⇒ Object
28 29 30 |
# File 'lib/synapse_client/customer.rb', line 28 def self.create(opts={}) Customer.new(opts).create end |
.retrieve(access_token, refresh_token) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/synapse_client/customer.rb', line 40 def self.retrieve(access_token, refresh_token) response = SynapseClient.request(:post, url + "show", {:access_token => access_token}) return response unless response.successful? Customer.new(response.data.user.merge({ :access_token => access_token, :refresh_token => refresh_token })) end |
Instance Method Details
#add_bank_account(params = {}) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/synapse_client/customer.rb', line 63 def add_bank_account(params={}) BankAccount.add(params.merge({ :access_token => @access_token, :fullname => @fullname })) end |
#add_order(params = {}) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/synapse_client/customer.rb', line 87 def add_order(params={}) if SynapseClient.merchant_synapse_id.nil? raise ArgumentError.new("You need to set SynapseClient.merchant_synapse_id before you can submit orders.") else Order.create(params.merge({ :access_token => @access_token, :seller_id => SynapseClient.merchant_synapse_id, :bank_pay => "yes" # see README.md })) end end |
#bank_accounts ⇒ Object
56 57 58 |
# File 'lib/synapse_client/customer.rb', line 56 def bank_accounts BankAccount.all({:access_token => @access_token}) end |
#create ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/synapse_client/customer.rb', line 32 def create headers = {"REMOTE_ADDR" => @ip_address} response = SynapseClient.request(:post, url + "create", to_hash, headers) return response unless response.successful? update_attributes(response.data) end |
#finish_linking_bank_account(params = {}) ⇒ Object
76 77 78 79 80 |
# File 'lib/synapse_client/customer.rb', line 76 def finish_linking_bank_account(params={}) BankAccount.finish_linking(params.merge({ :access_token => @access_token })) end |
#link_bank_account(params = {}) ⇒ Object
70 71 72 73 74 |
# File 'lib/synapse_client/customer.rb', line 70 def link_bank_account(params={}) BankAccount.link(params.merge({ :access_token => @access_token })) end |
#login ⇒ Object
TODO
51 52 53 |
# File 'lib/synapse_client/customer.rb', line 51 def login # use http://synapsepay.readme.io/v1.0/docs/authentication-login end |
#orders ⇒ Object
83 84 85 |
# File 'lib/synapse_client/customer.rb', line 83 def orders Order.all({:access_token => @access_token}) end |
#primary_bank_account ⇒ Object
59 60 61 |
# File 'lib/synapse_client/customer.rb', line 59 def primary_bank_account @bank_accounts.select{|ba| ba.is_buyer_default}.first end |