Class: SynapseClient::Customer

Inherits:
APIResource show all
Defined in:
lib/synapse_client/customer.rb

Instance Attribute Summary collapse

Attributes inherited from APIResource

#id

Class Method Summary collapse

Instance Method Summary collapse

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(options = {})
  options = Map.new(options)

  @id            = options[:id]            || options[:user_id]
  @email         = options[:email]
  @fullname      = options[:fullname]      || options[:name]
  @phonenumber   = options[:phonenumber]   || options[:phone_number]
  @ip_address    = options[:ip_address]

  @access_token  = options[:access_token]
  @refresh_token = options[:refresh_token]
  @expires_in    = options[:expires_in]
  @username      = options[:username]
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



6
7
8
# File 'lib/synapse_client/customer.rb', line 6

def access_token
  @access_token
end

#emailObject

Returns the value of attribute email.



5
6
7
# File 'lib/synapse_client/customer.rb', line 5

def email
  @email
end

#expires_inObject

Returns the value of attribute expires_in.



6
7
8
# File 'lib/synapse_client/customer.rb', line 6

def expires_in
  @expires_in
end

#fullnameObject

Returns the value of attribute fullname.



5
6
7
# File 'lib/synapse_client/customer.rb', line 5

def fullname
  @fullname
end

#ip_addressObject

Returns the value of attribute ip_address.



5
6
7
# File 'lib/synapse_client/customer.rb', line 5

def ip_address
  @ip_address
end

#phonenumberObject

Returns the value of attribute phonenumber.



5
6
7
# File 'lib/synapse_client/customer.rb', line 5

def phonenumber
  @phonenumber
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



6
7
8
# File 'lib/synapse_client/customer.rb', line 6

def refresh_token
  @refresh_token
end

#usernameObject

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_nameObject



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 (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_accountsObject



56
57
58
# File 'lib/synapse_client/customer.rb', line 56

def bank_accounts
  BankAccount.all({:access_token => @access_token})
end

#createObject



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 (params={})
  BankAccount.finish_linking(params.merge({
    :access_token => @access_token
  }))
end


70
71
72
73
74
# File 'lib/synapse_client/customer.rb', line 70

def (params={})
  BankAccount.link(params.merge({
    :access_token => @access_token
  }))
end

#loginObject

TODO



51
52
53
# File 'lib/synapse_client/customer.rb', line 51

def 
  # use http://synapsepay.readme.io/v1.0/docs/authentication-login
end

#ordersObject



83
84
85
# File 'lib/synapse_client/customer.rb', line 83

def orders
  Order.all({:access_token => @access_token})
end

#primary_bank_accountObject



59
60
61
# File 'lib/synapse_client/customer.rb', line 59

def 
  @bank_accounts.select{|ba| ba.is_buyer_default}.first
end