Class: SynapsePayRest::User

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse_pay_rest/models/user/user.rb

Overview

TODO:

use mixins to remove duplication between Node and BaseNode.

TODO:

reduce duplicated logic between User/BaseNode/Transaction

Represents a user record and holds methods for constructing user instances from API calls. This is built on top of the SynapsePayRest::Users class and is intended to make it easier to use the API without knowing payload formats or knowledge of REST.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ User

Note:

Do not call directly. Use User.create or other class method to instantiate via API action.

Returns a new instance of User.



193
194
195
196
# File 'lib/synapse_pay_rest/models/user/user.rb', line 193

def initialize(**options)
  options.each { |key, value| instance_variable_set("@#{key}", value) }
  @base_documents  ||= []
end

Instance Attribute Details

#base_documentsArray<SynapsePayRest::BaseDocument>

Returns:



14
15
# File 'lib/synapse_pay_rest/models/user/user.rb', line 14

attr_reader :client, :id, :logins, :phone_numbers, :legal_names, :note, 
:supp_id, :is_business, :cip_tag, :permission

#cip_tagObject (readonly)

Returns the value of attribute cip_tag.



14
15
16
# File 'lib/synapse_pay_rest/models/user/user.rb', line 14

def cip_tag
  @cip_tag
end

#clientObject (readonly)

Returns the value of attribute client.



14
15
16
# File 'lib/synapse_pay_rest/models/user/user.rb', line 14

def client
  @client
end

#expires_inObject

Returns the value of attribute expires_in.



16
17
18
# File 'lib/synapse_pay_rest/models/user/user.rb', line 16

def expires_in
  @expires_in
end

#flagObject

Returns the value of attribute flag.



16
17
18
# File 'lib/synapse_pay_rest/models/user/user.rb', line 16

def flag
  @flag
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/synapse_pay_rest/models/user/user.rb', line 14

def id
  @id
end

#ipsObject

Returns the value of attribute ips.



16
17
18
# File 'lib/synapse_pay_rest/models/user/user.rb', line 16

def ips
  @ips
end

#is_businessObject (readonly)

Returns the value of attribute is_business.



14
15
16
# File 'lib/synapse_pay_rest/models/user/user.rb', line 14

def is_business
  @is_business
end

Returns the value of attribute legal_names.



14
15
16
# File 'lib/synapse_pay_rest/models/user/user.rb', line 14

def legal_names
  @legal_names
end

#loginsObject (readonly)

Returns the value of attribute logins.



14
15
16
# File 'lib/synapse_pay_rest/models/user/user.rb', line 14

def logins
  @logins
end

#noteObject (readonly)

Returns the value of attribute note.



14
15
16
# File 'lib/synapse_pay_rest/models/user/user.rb', line 14

def note
  @note
end

#oauth_keyObject

Returns the value of attribute oauth_key.



16
17
18
# File 'lib/synapse_pay_rest/models/user/user.rb', line 16

def oauth_key
  @oauth_key
end

#permissionObject (readonly)

Returns the value of attribute permission.



14
15
# File 'lib/synapse_pay_rest/models/user/user.rb', line 14

attr_reader :client, :id, :logins, :phone_numbers, :legal_names, :note, 
:supp_id, :is_business, :cip_tag, :permission

#phone_numbersObject (readonly)

Returns the value of attribute phone_numbers.



14
15
16
# File 'lib/synapse_pay_rest/models/user/user.rb', line 14

def phone_numbers
  @phone_numbers
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



16
17
18
# File 'lib/synapse_pay_rest/models/user/user.rb', line 16

def refresh_token
  @refresh_token
end

#supp_idObject (readonly)

Returns the value of attribute supp_id.



14
15
16
# File 'lib/synapse_pay_rest/models/user/user.rb', line 14

def supp_id
  @supp_id
end

Class Method Details

.all(client:, page: nil, per_page: nil, query: nil) ⇒ Array<SynapsePayRest::User>

Note:

users created this way are not automatically OAuthed

Queries the API for all users (with optional filters) and returns them as User instances.

Parameters:

  • client (SynapsePayRest::Client)
  • query (String) (defaults to: nil)

    (optional) response will be filtered to users with matching name/email

  • page (String, Integer) (defaults to: nil)

    (optional) response will default to 1

  • per_page (String, Integer) (defaults to: nil)

    (optional) response will default to 20

Returns:

Raises:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/synapse_pay_rest/models/user/user.rb', line 95

def all(client:, page: nil, per_page: nil, query: nil)
  raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
  [page, per_page].each do |arg|
    if arg && (!arg.is_a?(Integer) || arg < 1)
      raise ArgumentError, "#{arg} must be nil or an Integer >= 1"
    end
  end
  if query && !query.is_a?(String)
    raise ArgumentError, 'query must be a String'
  end

  response = client.users.get(page: page, per_page: per_page, query: query)
  multiple_from_response(client, response['users'])
end

.create(client:, logins:, phone_numbers:, legal_names:, **options) ⇒ SynapsePayRest::User

TODO:

simplify the logins argument somehow. separate class?

Creates a new user in the API and returns a User instance from the response data.

Examples:

logins argument (only :email is required)

[{
  email: "[email protected]", 
  password: "letmein", 
  read_only: false
}]

Parameters:

  • client (SynapsePayRest::Client)
  • logins (Array<Hash>)
  • phone_numbers (Array<String>)
  • legal_names (Array<String>)
  • note (String)

    (optional)

  • supp_id (String)

    (optional)

  • is_business (Boolean)

    (optional) API defaults to false

  • cip_tag (Integer)

    (optional) the CIP tag to use in this users CIP doc

Returns:

Raises:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/synapse_pay_rest/models/user/user.rb', line 43

def create(client:, logins:, phone_numbers:, legal_names:, **options)
  raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
  if [logins, phone_numbers, legal_names].any? { |arg| !arg.is_a? Array}
    raise ArgumentError, 'logins/phone_numbers/legal_names must be Array'
  end
  if [logins, phone_numbers, legal_names].any?(&:empty?)
    raise ArgumentError, 'logins/phone_numbers/legal_names cannot be empty'
  end
  unless logins.first.is_a? Hash
    raise ArgumentError, 'logins must contain at least one hash {email: (required), password:, read_only:}'
  end
  unless logins.first[:email].is_a?(String) && logins.first[:email].length > 0
    raise ArgumentError, 'logins must contain at least one hash with :email key'
  end

  payload = payload_for_create(logins: logins, phone_numbers: phone_numbers, legal_names: legal_names, **options)
  response = client.users.create(payload: payload)
  from_response(client, response)
end

.find(client:, id:, full_dehydrate: 'no') ⇒ SynapsePayRest::User

Queries the API for a user by id and returns a User instances if found.

Parameters:

  • client (SynapsePayRest::Client)
  • id (String)

    id of the user to find

  • full_dehydrate (String) (defaults to: 'no')

    (optional) if ‘yes’, returns all KYC on user

Returns:

Raises:



72
73
74
75
76
77
78
79
# File 'lib/synapse_pay_rest/models/user/user.rb', line 72

def find(client:, id:, full_dehydrate:'no')
  raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
  raise ArgumentError, 'id must be a String' unless id.is_a?(String)

  response = client.users.get(user_id: id, full_dehydrate: full_dehydrate)
  
  from_response(client, response)
end

.from_response(client, response, oauth: true) ⇒ Object

Note:

Do not call directly.

Constructs a user instance from a user response.



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/synapse_pay_rest/models/user/user.rb', line 149

def from_response(client, response, oauth: true)
  user = self.new(
    client:            client,
    id:                response['_id'],
    refresh_token:     response['refresh_token'],
    logins:            response['logins'],
    phone_numbers:     response['phone_numbers'],
    legal_names:       response['legal_names'],
    permission:        response['permission'],
    note:              response['extra']['note'],
    supp_id:           response['extra']['supp_id'],
    is_business:       response['extra']['is_business'],
    cip_tag:           response['extra']['cip_tag'],
    flag:              nil,
    ips:               nil,
    oauth_key:         nil,
    expires_in:        nil
  )

  if response.has_key?('flag')
    user.flag = response['flag']
  end

  if response.has_key?('ips')
    user.ips = response['ips']
  end

  unless response['documents'].empty?
    base_documents = BaseDocument.from_response(user, response)
    user.base_documents = base_documents
  end
  oauth ? user.authenticate : user
end

.multiple_from_response(client, response) ⇒ Object

Note:

users created this way are not automatically OAuthed

Calls from_response on each member of a response collection.



185
186
187
188
# File 'lib/synapse_pay_rest/models/user/user.rb', line 185

def multiple_from_response(client, response)
  return [] if response.empty?
  response.map { |user_data| from_response(client.dup, user_data, oauth: false)}
end

.payload_for_create(logins:, phone_numbers:, legal_names:, **options) ⇒ Object

Note:

Do not call directly.

Maps args to API payload format.



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/synapse_pay_rest/models/user/user.rb', line 130

def payload_for_create(logins:, phone_numbers:, legal_names:, **options)
  payload = {
    'logins'        => logins,
    'phone_numbers' => phone_numbers,
    'legal_names'   => legal_names,
  }
  # optional payload fields
  extra = {}
  extra['note']        = options[:note] if options[:note]
  extra['supp_id']     = options[:supp_id] if options[:supp_id]
  extra['is_business'] = options[:is_business] if options[:is_business]
  extra['cip_tag']     = options[:cip_tag] if options[:cip_tag]
  payload['extra']     = extra if extra.any?

  payload
end

.search(client:, query:, page: nil, per_page: nil) ⇒ Array<SynapsePayRest::User>

Note:

users created this way are not automatically OAuthed

Queries the API for all users with name/email matching the given query and returns them as User instances.

Parameters:

  • client (SynapsePayRest::Client)
  • query (String)

    response will be filtered to users with matching name/email

  • page (String, Integer) (defaults to: nil)

    (optional) response will default to 1

  • per_page (String, Integer) (defaults to: nil)

    (optional) response will default to 20

Returns:

Raises:



124
125
126
# File 'lib/synapse_pay_rest/models/user/user.rb', line 124

def search(client:, query:, page: nil, per_page: nil)
  all(client: client, query: query, page: page, per_page: per_page)
end

Instance Method Details

#==(other) ⇒ Object

Checks if two User instances have same id (different instances of same record).



805
806
807
# File 'lib/synapse_pay_rest/models/user/user.rb', line 805

def ==(other)
  other.instance_of?(self.class) && !id.nil? && id == other.id
end

Add a legal_name to the user.

Parameters:

  • legal_name (String)

Returns:

Raises:



328
329
330
331
332
# File 'lib/synapse_pay_rest/models/user/user.rb', line 328

def add_legal_name(legal_name)
  raise ArgumentError, 'legal_name must be a String' unless legal_name.is_a? String

  update(legal_name: legal_name)
end

#add_login(email:, password: nil, read_only: nil) ⇒ SynapsePayRest::User

Adds a login for the user.

Parameters:

  • email (String)
  • password (String) (defaults to: nil)

    (optional)

  • read_only (Boolean) (defaults to: nil)

    (optional)

Returns:

Raises:



280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/synapse_pay_rest/models/user/user.rb', line 280

def (email:, password: nil, read_only: nil)
  raise ArgumentError, 'email must be a String' unless email.is_a?(String)
  raise ArgumentError, 'password must be nil or String' if password && !password.is_a?(String)
  if read_only && ![true, false].include?(read_only)
    raise ArgumentError, 'read_only must be nil or Boolean' 
  end

   = {'email' => email}
  # optional
  ['password']  = password if password
  ['read_only'] = read_only if read_only
  update(login: )
end

#add_phone_number(phone_number) ⇒ SynapsePayRest::User

Add a phone_number to the user.

Parameters:

  • phone_number (String)

Returns:

Raises:



315
316
317
318
319
# File 'lib/synapse_pay_rest/models/user/user.rb', line 315

def add_phone_number(phone_number)
  raise ArgumentError, 'phone_number must be a String' unless phone_number.is_a? String

  update(phone_number: phone_number)
end

#authenticateSynapsePayRest::User

Updates the oauth token.

Returns:

Raises:



203
204
205
206
207
208
# File 'lib/synapse_pay_rest/models/user/user.rb', line 203

def authenticate
  response        = client.users.refresh(user_id: id, payload: payload_for_refresh)
  self.oauth_key  = response['oauth_key']
  self.expires_in = response['expires_in']
  self
end

#confirm_2fa_pin(pin:, device:) ⇒ :success

Step 3 (final) step of fingerprint registration. Confirms the PIN sent to the device after calling #select_2fa_device (step 2).

Parameters:

  • pin (String)
  • device (String)

Returns:

  • (:success)

    if successful

Raises:



403
404
405
406
407
408
409
410
411
412
# File 'lib/synapse_pay_rest/models/user/user.rb', line 403

def confirm_2fa_pin(pin:, device:)
  raise ArgumentError, 'pin must be a String' unless pin.is_a?(String)
  raise ArgumentError, 'device must be a String' unless device.is_a?(String)
  
  payload = payload_for_refresh
  payload['phone_number']   = device
  payload['validation_pin'] = pin
  client.users.refresh(user_id: id, payload: payload)
  :success
end

#create_ach_us_node(**options) ⇒ SynapsePayRest::AchUsNode

Creates an ACH-US node via account and routing numbers, belonging to this user.

Parameters:

  • nickname (String)

    nickname for the node

  • account_number (String)
  • routing_number (String)
  • account_type (String)

    ‘PERSONAL’ or ‘BUSINESS’

  • account_class (String)

    ‘CHECKING’ or ‘SAVINGS’

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



454
455
456
# File 'lib/synapse_pay_rest/models/user/user.rb', line 454

def create_ach_us_node(**options)
  AchUsNode.create(user: self, **options)
end

#create_ach_us_nodes_via_bank_login(**options) ⇒ Array<SynapsePayRest::AchUsNode>

Creates an ACH-US node via bank login, belonging to this user.

Parameters:

  • bank_name (String)
  • username (String)

    user’s bank login username

  • password (String)

    user’s bank login password

Returns:

Raises:

See Also:



468
469
470
# File 'lib/synapse_pay_rest/models/user/user.rb', line 468

def (**options)
  AchUsNode.(user: self, **options)
end

#create_ach_us_nodes_via_bank_login_mfa(**options) ⇒ <SynapsePayRest::UnverifiedNode>

Creates an Unverified Node Class node via access token, belonging to this user

Parameters:

  • access_token (String)

Returns:

Raises:

See Also:



480
481
482
# File 'lib/synapse_pay_rest/models/user/user.rb', line 480

def (**options)
  AchUsNode.(user: self, **options)
end

#create_base_document(**args) ⇒ SynapsePayRest::User

Creates a new base document for the user. To update an existing base document, see SynapsePay::BaseDocument#update.

Parameters:

  • email (String)
  • phone_number (String)
  • ip (String)
  • name (String)
  • aka (String)

    corresponds to ‘alias’ in docs, use name if no alias

  • entity_type (String)

    consult your organization’s CIP for valid options

  • entity_scope (String)

    consult your organization’s CIP for valid options

  • birth_day (Integer)
  • birth_month (Integer)
  • birth_year (Integer)
  • address_street (String)
  • address_city (String)
  • address_subdivision (String)
  • address_postal_code (String)
  • address_country_code (String)
  • physical_documents (Array<SynapsePayRest::PhysicalDocument>)

    (optional)

  • social_documents (Array<SynapsePayRest::SocialDocument>)

    (optional)

  • virtual_documents (Array<SynapsePayRest::VirtualDocument>)

    (optional)

Returns:

Raises:

See Also:



267
268
269
# File 'lib/synapse_pay_rest/models/user/user.rb', line 267

def create_base_document(**args)
  BaseDocument.create(user: self, **args)
end

#create_card_us_node(**options) ⇒ SynapsePayRest::CardUsNode

Creates a CARD-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • document_id (String)

    Document ID of user’s base document that the card is associated with

  • card_type (String)

    PHYSICAL or VIRTUAL

Returns:

Raises:



749
750
751
# File 'lib/synapse_pay_rest/models/user/user.rb', line 749

def create_card_us_node(**options)
  CardUsNode.create(user: self, **options)
end

#create_check_us_node(**options) ⇒ SynapsePayRest::CheckUsNode

Creates a CHECK-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • bank_name (String)
  • account_number (String)
  • routing_number (String)
  • name_on_account (String)
  • address (String)
  • correspondent_routing_number (String)

    (optional)

  • correspondent_bank_name (String)

    (optional)

  • correspondent_address (String)

    (optional)

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



684
685
686
# File 'lib/synapse_pay_rest/models/user/user.rb', line 684

def create_check_us_node(**options)
  CheckUsNode.create(user: self, **options)
end

#create_clearing_us_node(**options) ⇒ SynapsePayRest::ClearingUsNode

Creates a CLEARING-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



697
698
699
# File 'lib/synapse_pay_rest/models/user/user.rb', line 697

def create_clearing_us_node(**options)
  ClearingUsNode.create(user: self, **options)
end

#create_crypto_us_node(**options) ⇒ SynapsePayRest::CryptoUsNode

Creates a CRYPTO-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



775
776
777
# File 'lib/synapse_pay_rest/models/user/user.rb', line 775

def create_crypto_us_node(**options)
  CryptoUsNode.create(user: self, **options)
end

#create_custody_us_node(**options) ⇒ SynapsePayRest::CustodyUsNode

Creates a CUSTODY-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



788
789
790
# File 'lib/synapse_pay_rest/models/user/user.rb', line 788

def create_custody_us_node(**options)
  CustodyUsNode.create(user: self, **options)
end

#create_deposit_us_node(**options) ⇒ SynapsePayRest::SynapseUsNode

Creates a DEPOSIT-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



593
594
595
# File 'lib/synapse_pay_rest/models/user/user.rb', line 593

def create_deposit_us_node(**options)
  DepositUsNode.create(user: self, **options)
end

#create_eft_ind_node(**options) ⇒ SynapsePayRest::EftIndNode

Deprecated.

Creates an EFT-IND node.

Parameters:

  • nickname (String)

    nickname for the node

  • account_number (String)
  • ifsc (String)
  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



497
498
499
# File 'lib/synapse_pay_rest/models/user/user.rb', line 497

def create_eft_ind_node(**options)
  EftIndNode.create(user: self, **options)
end

#create_eft_np_node(**options) ⇒ SynapsePayRest::EftNpNode

Creates an EFT-NP node.

Parameters:

  • nickname (String)

    nickname for the node

  • bank_name (String)
  • account_number (String)
  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



512
513
514
# File 'lib/synapse_pay_rest/models/user/user.rb', line 512

def create_eft_np_node(**options)
  EftNpNode.create(user: self, **options)
end

#create_ib_deposit_us_node(**options) ⇒ SynapsePayRest::IbDepositUsNode

Creates a IB-DEPOSIT-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



710
711
712
# File 'lib/synapse_pay_rest/models/user/user.rb', line 710

def create_ib_deposit_us_node(**options)
  IbDepositUsNode.create(user: self, **options)
end

#create_ib_subaccount_us_node(**options) ⇒ SynapsePayRest::IbSubaccountUsNode

Creates a IB-SUBACCOUNT-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



723
724
725
# File 'lib/synapse_pay_rest/models/user/user.rb', line 723

def create_ib_subaccount_us_node(**options)
  IbSubaccountUsNode.create(user: self, **options)
end

#create_interchange_us_node(**options) ⇒ SynapsePayRest::InterchangeUsNode

Creates a INTERCHANGE-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • document_id (String)

    Document ID of user’s base document that the card is associated with

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



736
737
738
# File 'lib/synapse_pay_rest/models/user/user.rb', line 736

def create_interchange_us_node(**options)
  InterchangeUsNode.create(user: self, **options)
end

#create_iou_node(**options) ⇒ SynapsePayRest::IouNode

Creates an IOU node.

Parameters:

  • nickname (String)

    nickname for the node

  • currency (String)

    e.g. ‘USD’

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



526
527
528
# File 'lib/synapse_pay_rest/models/user/user.rb', line 526

def create_iou_node(**options)
  IouNode.create(user: self, **options)
end

#create_reserve_us_node(**options) ⇒ SynapsePayRest::IouNode

Creates a RESERVE-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



539
540
541
# File 'lib/synapse_pay_rest/models/user/user.rb', line 539

def create_reserve_us_node(**options)
  ReserveUsNode.create(user: self, **options)
end

#create_subaccount_us_node(**options) ⇒ SynapsePayRest::SubaccountUsNode

Creates a SUBACCOUNT-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



606
607
608
# File 'lib/synapse_pay_rest/models/user/user.rb', line 606

def create_subaccount_us_node(**options)
  SubaccountUsNode.create(user: self, **options)
end

#create_subcard_us_node(**options) ⇒ SynapsePayRest::SubcardUsNode

Creates a SUBCARD-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • document_id (String)

    Document ID of user’s base document that the card is associated with

  • card_type (String)

    PHYSICAL or VIRTUAL

Returns:

Raises:



762
763
764
# File 'lib/synapse_pay_rest/models/user/user.rb', line 762

def create_subcard_us_node(**options)
  SubcardUsNode.create(user: self, **options)
end

#create_synapse_ind_node(**options) ⇒ SynapsePayRest::SynapseIndNode

Deprecated.

Creates a SYNAPSE-IND node.

Parameters:

  • nickname (String)

    nickname for the node

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



554
555
556
# File 'lib/synapse_pay_rest/models/user/user.rb', line 554

def create_synapse_ind_node(**options)
  SynapseIndNode.create(user: self, **options)
end

#create_synapse_np_node(**options) ⇒ SynapsePayRest::SynapseNpNode

Creates a SYNAPSE-NP node.

Parameters:

  • nickname (String)

    nickname for the node

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



567
568
569
# File 'lib/synapse_pay_rest/models/user/user.rb', line 567

def create_synapse_np_node(**options)
  SynapseNpNode.create(user: self, **options)
end

#create_synapse_us_node(**options) ⇒ SynapsePayRest::SynapseUsNode

Creates a SYNAPSE-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



580
581
582
# File 'lib/synapse_pay_rest/models/user/user.rb', line 580

def create_synapse_us_node(**options)
  SynapseUsNode.create(user: self, **options)
end

#create_triumph_subaccount_us_node(**options) ⇒ SynapsePayRest::TriumphSubaccountUsNode

Creates a TRIUMPH-SUBACCOUNT-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



619
620
621
# File 'lib/synapse_pay_rest/models/user/user.rb', line 619

def create_triumph_subaccount_us_node(**options)
  TriumphSubaccountUsNode.create(user: self, **options)
end

#create_wire_int_node(**options) ⇒ SynapsePayRest::WireIntNode

Creates a WIRE-INT node.

Parameters:

  • nickname (String)

    nickname for the node

  • bank_name (String)
  • account_number (String)
  • swift (String)
  • name_on_account (String)
  • address (String)
  • routing_number (String)

    (optional)

  • correspondent_bank_name (String)

    (optional)

  • correspondent_routing_number (String)

    (optional)

  • correspondent_address (String)

    (optional)

  • correspondent_swift (String)

    (optional)

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



642
643
644
# File 'lib/synapse_pay_rest/models/user/user.rb', line 642

def create_wire_int_node(**options)
  WireIntNode.create(user: self, **options)
end

#create_wire_us_node(**options) ⇒ SynapsePayRest::WireUsNode

Creates a WIRE-US node.

Parameters:

  • nickname (String)

    nickname for the node

  • bank_name (String)
  • account_number (String)
  • routing_number (String)
  • name_on_account (String)
  • address (String)
  • correspondent_routing_number (String)

    (optional)

  • correspondent_bank_name (String)

    (optional)

  • correspondent_address (String)

    (optional)

  • supp_id (String)

    (optional)

  • gateway_restricted (Boolean)

    (optional)

Returns:

Raises:



663
664
665
# File 'lib/synapse_pay_rest/models/user/user.rb', line 663

def create_wire_us_node(**options)
  WireUsNode.create(user: self, **options)
end

#find_node(id:) ⇒ SynapsePayRest::BaseNode

Queries the API for a node belonging to this user by node id and returns a node instance if found.

Parameters:

  • id (String)

    id of the node to find

Returns:

Raises:



437
438
439
# File 'lib/synapse_pay_rest/models/user/user.rb', line 437

def find_node(id:)
  Node.find(user: self, id: id)
end

#get_statementSynapsePayRest::Statement

Gets statement for user



800
801
802
# File 'lib/synapse_pay_rest/models/user/user.rb', line 800

def get_statement()
  Statement.by_user(client: self.client, user:self)
end

#nodes(**options) ⇒ Array<SynapsePayRest::BaseNode>

Queries the API for all nodes belonging to this user and returns them as node (SynapsePayRest::BaseNode) instances.

Parameters:

  • page (String, Integer)

    (optional) response will default to 1

  • per_page (String, Integer)

    (optional) response will default to 20

  • type (String)

    (optional)

Returns:

Raises:

See Also:



425
426
427
# File 'lib/synapse_pay_rest/models/user/user.rb', line 425

def nodes(**options)
  Node.all(user: self, **options)
end

#register_fingerprint(fingerprint) ⇒ Array<String>

Step 1 of fingerprint registration. Requests a new fingerprint be registered to the user.

Parameters:

  • fingerprint (String)

Returns:

  • (Array<String>)

    array of devices (phone number / email)

Raises:



368
369
370
371
372
373
374
# File 'lib/synapse_pay_rest/models/user/user.rb', line 368

def register_fingerprint(fingerprint)
  raise ArgumentError, 'fingerprint must be a String' unless fingerprint.is_a?(String)

  client.http_client.update_headers(fingerprint: fingerprint)
  response = client.users.refresh(user_id: id, payload: payload_for_refresh)
  response['phone_numbers']
end

Removes a legal_name from the user

Parameters:

  • legal_name (String)

Returns:

Raises:



354
355
356
357
358
# File 'lib/synapse_pay_rest/models/user/user.rb', line 354

def remove_legal_name(legal_name)
  raise ArgumentError, 'legal_name must be a String' unless legal_name.is_a? String

  update(remove_legal_name: legal_name)
end

#remove_login(email:) ⇒ SynapsePayRest::User

Removes a login from the user.

Parameters:

  • email (String)

Returns:

Raises:



301
302
303
304
305
306
# File 'lib/synapse_pay_rest/models/user/user.rb', line 301

def (email:)
  raise ArgumentError, 'email must be a String' unless email.is_a? String

   = {email: email}
  update(remove_login: )
end

#remove_phone_number(phone_number) ⇒ SynapsePayRest::User

Removes a phone_number from the user.

Parameters:

  • phone_number (String)

Returns:

Raises:



341
342
343
344
345
# File 'lib/synapse_pay_rest/models/user/user.rb', line 341

def remove_phone_number(phone_number)
  raise ArgumentError, 'phone_number must be a String' unless phone_number.is_a? String

  update(remove_phone_number: phone_number)
end

#select_2fa_device(device) ⇒ :success

Step 2 of fingerprint registration. Sends a request to the API to send a 2FA PIN to the device specified. The device must be selected from return value of #register_fingerprint.

Parameters:

  • device (String)

Returns:

  • (:success)

    if successful

Raises:



385
386
387
388
389
390
391
392
# File 'lib/synapse_pay_rest/models/user/user.rb', line 385

def select_2fa_device(device)
  raise ArgumentError, 'device must be a String' unless device.is_a?(String)

  payload = payload_for_refresh
  payload['phone_number'] = device
  client.users.refresh(user_id: id, payload: payload)
  :success
end

#update(**options) ⇒ SynapsePayRest::User

Updates the given key value pairs.

Examples:

login/remove_login argument (only email is required)

{
  email: "[email protected]", 
  password: "letmein", 
  read_only: false
}

Parameters:

  • login (Hash)
  • phone_number (String)
  • legal_name (String)
  • remove_login (Hash)
  • remove_phone_number (String)
  • read_only (Boolean)
  • remove_legal_name (String)

Returns:

Raises:



230
231
232
233
234
235
236
237
238
# File 'lib/synapse_pay_rest/models/user/user.rb', line 230

def update(**options)
  if options.empty?
    raise ArgumentError, 'must provide a key-value pair to update. keys: login,
      read_only, phone_number, legal_name, remove_phone_number, remove_login'
  end
  response = client.users.update(user_id: id, payload: payload_for_update(options))
  # return an updated user instance
  self.class.from_response(client, response)
end