Class: SynapsePayments::UserClient
- Inherits:
-
Object
- Object
- SynapsePayments::UserClient
- Defined in:
- lib/synapse_payments/user_client.rb
Instance Method Summary collapse
-
#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.
-
#add_document(birthdate:, first_name:, last_name:, street:, postal_code:, country_code:, document_type:, document_value:) ⇒ Hash
Adds a virtual document for KYC.
- #answer_kba(question_set_id:, answers:) ⇒ Object
- #bank_login(bank_name:, username:, password:) ⇒ Object
-
#initialize(client, user_id, fingerprint, response) ⇒ UserClient
constructor
A new instance of UserClient.
- #nodes(id = nil) ⇒ Object
- #send_money(from:, to:, to_node_type:, amount:, currency:, ip_address:, **args) ⇒ Object
- #update(data) ⇒ Object
- #user ⇒ Object
- #verify_mfa(access_token:, answer:) ⇒ Object
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.
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 add_bank_account(name:, account_number:, routing_number:, category:, type:, **args) data = { type: 'ACH-US', info: { nickname: args[:nickname] || name, name_on_account: name, account_num: account_number, 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
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_login(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
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 |
#user ⇒ Object
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 |