Class: SynapsePayments::UserClient

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse_payments/user_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, user_id, fingerprint, response) ⇒ UserClient

Returns a new instance of UserClient.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/synapse_payments/user_client.rb', line 4

def initialize(client, user_id, fingerprint, response)
  @client = client
  @user_id = user_id
  @fingerprint = fingerprint
  @response = response
  @oauth_key = response[:oauth_key]

  response.each do |key, value|
    (class << self; self; end).class_eval do
      define_method key do |*args|
        response[key]
      end
    end
  end

  @nodes = Nodes.new(@client, @user_id, @oauth_key, @fingerprint)
end

Instance Method Details

#add_bank_account(name:, account_number:, routing_number:, category:, type:, **args) ⇒ Hash

Adds a bank account by creating a node of node type ACH-US.

Parameters:

  • name (String)

    the name of the account holder

  • account_number (String)
  • routing_number (String)
  • category (String)

    the account category, ‘personal` or `business`

  • type (String)

    the account type, ‘checking` or `savings`

Returns:

  • (Hash)


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/synapse_payments/user_client.rb', line 85

def (name:, account_number:, routing_number:, category:, type:, **args)
  data = {
    type: 'ACH-US',
    info: {
      nickname: args[:nickname] || name,
      name_on_account: name,
      account_num: ,
      routing_num: routing_number,
      type: category,
      class: type
    },
    extra: {
      supp_id: args[:supp_id]
    }
  }
  nodes.create(data)
end

#add_document(birthdate:, first_name:, last_name:, street:, postal_code:, country_code:, document_type:, document_value:) ⇒ Hash

Adds a virtual document for KYC

Parameters:

  • birthdate (Date)
  • first_name (String)
  • last_name (String)
  • street (String)
  • postal_code (String)
  • country_code (String)

    The country code in ISO format e.g. US

  • document_type (String)

    Acceptable document types: SSN, PASSPORT, DRIVERS_LICENSE, PERSONAL_IDENTIFICATION, NONE

  • document_value (String)

Returns:

  • (Hash)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/synapse_payments/user_client.rb', line 47

def add_document(birthdate:, first_name:, last_name:, street:, postal_code:, country_code:, document_type:, document_value:)
  data = {
    doc: {
      birth_day: birthdate.day,
      birth_month: birthdate.month,
      birth_year: birthdate.year,
      name_first: first_name,
      name_last: last_name,
      address_street1: street,
      address_postal_code: postal_code,
      address_country_code: country_code,
      document_type: document_type,
      document_value: document_value
    }
  }

  @client.patch(path: "/users/#{@user_id}", oauth_key: @oauth_key, fingerprint: @fingerprint, json: data)
end

#answer_kba(question_set_id:, answers:) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/synapse_payments/user_client.rb', line 66

def answer_kba(question_set_id:, answers:)
  data = {
    doc: {
      question_set_id: question_set_id,
      answers: answers
    }
  }

  @client.patch(path: "/users/#{@user_id}", oauth_key: @oauth_key, fingerprint: @fingerprint, json: data)
end

#bank_login(bank_name:, username:, password:) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/synapse_payments/user_client.rb', line 103

def (bank_name:, username:, password:)
  data = {
    type: 'ACH-US',
    info: {
      bank_id: username,
      bank_pw: password,
      bank_name: bank_name
    }
  }

  nodes.create(data)
end

#nodes(id = nil) ⇒ Object



129
130
131
132
133
134
135
# File 'lib/synapse_payments/user_client.rb', line 129

def nodes(id=nil)
  if id.nil?
    @nodes
  else
    Node.new(@client, @user_id, id, @oauth_key, @fingerprint)
  end
end

#send_money(from:, to:, to_node_type:, amount:, currency:, ip_address:, **args) ⇒ Object



125
126
127
# File 'lib/synapse_payments/user_client.rb', line 125

def send_money(from:, to:, to_node_type:, amount:, currency:, ip_address:, **args)
  nodes(from).transactions.create(node_id: to, node_type: to_node_type, amount: amount, currency: currency, ip_address: ip_address, **args)
end

#update(data) ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
# File 'lib/synapse_payments/user_client.rb', line 26

def update(data)
  raise ArgumentError, 'Argument is not a hash' unless data.is_a? Hash

  if data[:doc].nil?
    data = { refresh_token: self.refresh_token, update: data }
  end

  @client.patch(path: "/users/#{@user_id}", oauth_key: @oauth_key, fingerprint: @fingerprint, json: data)
end

#userObject



22
23
24
# File 'lib/synapse_payments/user_client.rb', line 22

def user
  @client.get(path: "/users/#{@user_id}", oauth_key: @oauth_key)
end

#verify_mfa(access_token:, answer:) ⇒ Object



116
117
118
119
120
121
122
123
# File 'lib/synapse_payments/user_client.rb', line 116

def verify_mfa(access_token:, answer:)
  data = {
    access_token: access_token,
    mfa_answer: answer
  }

  nodes.create(data)
end