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.



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

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)


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/synapse_payments/user_client.rb', line 90

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)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/synapse_payments/user_client.rb', line 39

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



58
59
60
61
62
63
64
65
66
67
# File 'lib/synapse_payments/user_client.rb', line 58

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

#attach_file(file_path) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/synapse_payments/user_client.rb', line 69

def attach_file(file_path)
  file_contents = open(file_path) { |f| f.read }
  file_type = ::MIME::Types.type_for(file_path).first.content_type

  data = {
    doc: {
      attachment: "data:#{file_type};base64,#{Base64.encode64(file_contents)}"
    }
  }

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

#nodes(id = nil) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/synapse_payments/user_client.rb', line 112

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



108
109
110
# File 'lib/synapse_payments/user_client.rb', line 108

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

#userObject



24
25
26
# File 'lib/synapse_payments/user_client.rb', line 24

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