synapse_pay_rest 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf13c67916c9560ecd7993d03b00691ea15ca16e
4
- data.tar.gz: 4df8ab520d132d23e4196c63a8ea2fdb9bc5cc46
3
+ metadata.gz: 4c6efa02c0a05bc9450793c2988d145d2b9d6179
4
+ data.tar.gz: b620267e190dfefb5d2cde8f0247ee7fd432d30b
5
5
  SHA512:
6
- metadata.gz: eace5ad6f06ecb638f69eaffd0a505e903444d78f0e1324d1a4e19f06d2ef423b40719abbf4b8d23ddf60157a8066428e7abdbfd36f0ce907c4234f3ae98e353
7
- data.tar.gz: 10fe666bec184de1cd0b72a5d1ae4ae09e4a1a4a238bddab316c93ea1fc5dcb8558f68b766aef529dc5cdcbd0b19f6d9e9b2fd4fb4766739f4c81ca76900c27b
6
+ metadata.gz: beb7d951f9faca9e76120ba2e4f2de687af5dbc82f5ec53d486d7003fe39562b8e1fec62eb97f3dddccb2972be38f5260d4b49eefd3179f957a3af0ce45e5fc1
7
+ data.tar.gz: b0ea2ebef0446b633cb84b290d3805922c8a91e3e145640a714bc4ff00aeaae3519abf7ead1a29ee0453adf6df1ec3e07c772bc9e03b787dec615ba2a01a1122
data/README.md CHANGED
@@ -38,12 +38,12 @@ $ gem install synapse_pay_rest
38
38
  ## Documentation
39
39
 
40
40
  - [Samples demonstrating common operations](samples.md)
41
- - [Gem docs](http://www.rubydoc.info/gems/synapse_pay_rest)
41
+ - [synapse_pay_rest gem docs](http://www.rubydoc.info/github/synapsepay/SynapsePayRest-Ruby)
42
42
  - [API docs](http://docs.synapsepay.com/v3.1)
43
43
 
44
44
  ## Contributing
45
45
 
46
- Just open a pull request. Please document and test any public constants/methods. Open an issue or email steven@synapsepay.com if you have any questions.
46
+ For minor issues, just open a pull request. For larger changes or features, please email steven@synapsepay.com.Please document and test any public constants/methods. Open an issue or email steven@synapsepay.com if you have any questions.
47
47
 
48
48
  ## Running the Test Suite
49
49
 
@@ -66,27 +66,6 @@ To run a specific file or test, install the [m](https://github.com/qrush/m) gem
66
66
  m path/to/file:line_number
67
67
  ```
68
68
 
69
- ## Todos
70
-
71
- - Smartly update the existing instances with response data instead of re-instantiating for every response. I started with this approach but it gets pretty complicated with the interconnected models of User/BaseDocument/Document. Also, certain values are only known if the user created an object, but not when the object is built from API response data. This is solveable but requires more dev time and testing.
72
- - Various factory helper methods should be private but are public. Would be good to refactor in a way that they can be private.
73
- - `User`/`Node`/`Transaction` have similar REST methods that could probably be factored into a superclass or module.
74
- - Use mixins instead of inheritance for the shared behavior of `Node`s and `Document`s. The parent classes are never instantiated anyways.
75
- - Refactor the redundant code in each `Node` type's version of `#payload_for_create`.
76
- - Better way to handle bank MFA nodes? Virtual doc KBA?
77
- - Add an option for logging responses in addition to requests.
78
- - Organize tests better.
79
- - Use mocked responses whenever possible in tests.
80
- - More examples.
81
- - More Error types (bad MFA answer, for example).
82
- - Add some methods to BaseDocument to return doc by type (e.g. `base_document.ssn_doc`).
83
-
84
- Specific todos are marked throughout in this format:
85
-
86
- ```ruby
87
- # @todo Description of todo.
88
- ```
89
-
90
69
  ## License
91
70
 
92
- [MIT License](LICENSE)
71
+ [MIT License](LICENSE)
@@ -17,7 +17,8 @@ module SynapsePayRest
17
17
  # Sends a GET request to /nodes endpoint. Queries a specific node_id if
18
18
  # node_id supplied, else queries all nodes. Returns the response.
19
19
  #
20
- # @param node_id [String] id of the node
20
+ # @param user_id [String]
21
+ # @param node_id [String,void]
21
22
  # @param page [String,Integer] (optional) response will default to 1
22
23
  # @param per_page [String,Integer] (optional) response will default to 20
23
24
  # @param type [String] (optional)
@@ -31,12 +32,12 @@ module SynapsePayRest
31
32
  # @todo should use CGI or RestClient's param builder instead of
32
33
  # rolling our own, probably error-prone and untested
33
34
  # https://github.com/rest-client/rest-client#usage-raw-url
34
- def get(node_id: nil, **options)
35
+ def get(user_id:, node_id: nil, **options)
35
36
  params = VALID_QUERY_PARAMS.map do |p|
36
37
  options[p] ? "#{p}=#{options[p]}" : nil
37
38
  end.compact
38
39
 
39
- path = create_node_path(node_id: node_id)
40
+ path = node_path(user_id: user_id, node_id: node_id)
40
41
  path += '?' + params.join('&') if params.any?
41
42
  client.get(path)
42
43
  end
@@ -44,6 +45,7 @@ module SynapsePayRest
44
45
  # Sends a POST request to /nodes endpoint, to create a new node for the
45
46
  # current user, and returns the response.
46
47
  #
48
+ # @param user_id [String]
47
49
  # @param payload [Hash] format depends on node type
48
50
  # @see https://docs.synapsepay.com/docs/node-resources payload structure
49
51
  #
@@ -51,18 +53,18 @@ module SynapsePayRest
51
53
  # HTTP response from API
52
54
  #
53
55
  # @return [Hash] API response
54
- def post(payload:)
55
- path = create_node_path
56
+ def post(user_id:, payload:)
57
+ path = node_path(user_id: user_id)
56
58
  client.post(path, payload)
57
59
  end
58
-
59
60
  # Alias for #post (legacy name)
60
61
  alias_method :add, :post
61
62
 
62
63
  # Sends a PATCH request to /nodes endpoint to update a node, and returns the
63
64
  # response. Only used to verify microdeposits for ACH-US nodes currently.
64
65
  #
65
- # @param node_id [String] id of the node
66
+ # @param user_id [String]
67
+ # @param node_id [String]
66
68
  # @param payload [Hash]
67
69
  # @see https://docs.synapsepay.com/docs/verify-micro-deposit payload structure
68
70
  #
@@ -70,50 +72,52 @@ module SynapsePayRest
70
72
  # HTTP response from API
71
73
  #
72
74
  # @return [Hash] API response
73
- def patch(node_id:, payload:)
74
- path = create_node_path(node_id: node_id)
75
- @client.patch(path, payload)
75
+ def patch(user_id:, node_id:, payload:)
76
+ path = node_path(user_id: user_id, node_id: node_id)
77
+ client.patch(path, payload)
76
78
  end
77
79
 
78
80
  # Sends a DELETE request to /node endpoint to remove a node, and returns the response.
79
81
  #
80
- # @param node_id [String] id of the node
82
+ # @param user_id [String]
83
+ # @param node_id [String]
81
84
  #
82
85
  # @raise [SynapsePayRest::Error] may return subclasses of error based on
83
86
  # HTTP response from API
84
87
  #
85
88
  # @return [Hash] API response
86
- def delete(node_id:)
87
- path = create_node_path(node_id: node_id)
89
+ def delete(user_id:, node_id:)
90
+ path = node_path(user_id: user_id, node_id: node_id)
88
91
  client.delete(path)
89
92
  end
90
93
 
91
94
  # Verifies microdeposits (via #patch) for a node if a node_id supplied, else
92
95
  # submits answers to bank login MFA questions (via #post).
93
96
  #
94
- # @param node_id [String] id of the node
97
+ # @param user_id [String]
98
+ # @param node_id [String,void]
95
99
  # @param payload [Hash] see #patch and #post for payload format
96
100
  # @deprecated Use #update for microdeposit verification or #post for MFA answers.
97
- def verify(node_id: nil, payload:)
101
+ def verify(user_id:, node_id: nil, payload:)
98
102
  if node_id
99
103
  warn caller.first + " DEPRECATION WARNING: #{self.class}##{__method__} is deprecated. Use #patch instead."
100
104
 
101
105
  # verify microdeposits
102
- patch(node_id: node_id, payload: payload)
106
+ patch(user_id: user_id, node_id: node_id, payload: payload)
103
107
  else
104
108
  warn caller.first + " DEPRECATION WARNING: #{self.class}##{__method__} is deprecated. Use #post instead."
105
109
 
106
110
  # verify MFA questions
107
- post(payload: payload)
111
+ post(user_id: user_id, payload: payload)
108
112
  end
109
113
  end
110
114
 
111
115
  private
112
116
 
113
- def create_node_path(node_id: nil)
114
- path = ['/users', client.user_id, 'nodes' ]
115
- path << node_id if node_id
116
- path.join('/')
117
+ def node_path(user_id:, node_id: nil)
118
+ path = "/users/#{user_id}/nodes"
119
+ path += "/#{node_id}" if node_id
120
+ path
117
121
  end
118
122
  end
119
123
  end
@@ -20,6 +20,7 @@ module SynapsePayRest
20
20
  # Sends a GET request to /trans endpoint. Queries a specific transaction_id
21
21
  # if trans_id supplied, else queries all transactions. Returns the response.
22
22
  #
23
+ # @param user_id [String]
23
24
  # @param node_id [String] id of the from node
24
25
  # @param trans_id [String,void] (optional) id of a transaction to look up
25
26
  # @param page [String,Integer] (optional) response will default to 1
@@ -33,8 +34,8 @@ module SynapsePayRest
33
34
  # @todo Probably should use CGI or RestClient's param builder instead of
34
35
  # rolling our own, probably error-prone and untested version
35
36
  # https://github.com/rest-client/rest-client#usage-raw-url
36
- def get(node_id:, trans_id: nil, **options)
37
- path = create_transaction_path(node_id: node_id, trans_id: trans_id)
37
+ def get(user_id:, node_id:, trans_id: nil, **options)
38
+ path = create_transaction_path(user_id: user_id, node_id: node_id, trans_id: trans_id)
38
39
 
39
40
  params = VALID_QUERY_PARAMS.map do |p|
40
41
  options[p] ? "#{p}=#{options[p]}" : nil
@@ -47,6 +48,7 @@ module SynapsePayRest
47
48
  # Sends a POST request to /trans endpoint to create a new transaction.
48
49
  # Returns the response.
49
50
  #
51
+ # @param user_id [String]
50
52
  # @param node_id [String] id of the from node
51
53
  # @param payload [Hash]
52
54
  # @see https://docs.synapsepay.com/docs/create-transaction payload structure
@@ -55,14 +57,15 @@ module SynapsePayRest
55
57
  # HTTP response from API
56
58
  #
57
59
  # @return [Hash] API response
58
- def create(node_id:, payload:)
59
- path = create_transaction_path(node_id: node_id)
60
+ def create(user_id:, node_id:, payload:)
61
+ path = create_transaction_path(user_id: user_id, node_id: node_id)
60
62
  client.post(path, payload)
61
63
  end
62
64
 
63
65
  # Sends a PATCH request to /trans endpoint to update a transaction.
64
66
  # Returns the response.
65
67
  #
68
+ # @param user_id [String]
66
69
  # @param node_id [String] id of the from node
67
70
  # @param trans_id [String] id of a transaction to update
68
71
  # @param payload [Hash]
@@ -72,14 +75,15 @@ module SynapsePayRest
72
75
  # HTTP response from API
73
76
  #
74
77
  # @return [Hash] API response
75
- def update(node_id:, trans_id:, payload:)
76
- path = create_transaction_path(node_id: node_id, trans_id: trans_id)
78
+ def update(user_id:, node_id:, trans_id:, payload:)
79
+ path = create_transaction_path(user_id: user_id, node_id: node_id, trans_id: trans_id)
77
80
  client.patch(path, payload)
78
81
  end
79
82
 
80
83
  # Sends a DELETE request to /trans endpoint to cancel a transaction.
81
84
  # Returns the response.
82
85
  #
86
+ # @param user_id [String]
83
87
  # @param node_id [String] id of the from node
84
88
  # @param trans_id [String] id of a transaction to delete
85
89
  #
@@ -87,17 +91,17 @@ module SynapsePayRest
87
91
  # HTTP response from API
88
92
  #
89
93
  # @return [Hash] API response
90
- def delete(node_id:, trans_id:)
91
- path = create_transaction_path(node_id: node_id, trans_id: trans_id)
94
+ def delete(user_id:, node_id:, trans_id:)
95
+ path = create_transaction_path(user_id: user_id, node_id: node_id, trans_id: trans_id)
92
96
  client.delete(path)
93
97
  end
94
98
 
95
99
  private
96
100
 
97
- def create_transaction_path(node_id:, trans_id: nil)
98
- path = ['/users', client.user_id, 'nodes', node_id, 'trans' ]
99
- path << trans_id if trans_id
100
- return path.join('/')
101
+ def create_transaction_path(user_id:, node_id:, trans_id: nil)
102
+ path = "/users/#{user_id}/nodes/#{node_id}/trans"
103
+ path += "/#{trans_id}" if trans_id
104
+ path
101
105
  end
102
106
  end
103
107
  end
@@ -36,13 +36,9 @@ module SynapsePayRest
36
36
  # rolling our own, probably error-prone and untested version
37
37
  # https://github.com/rest-client/rest-client#usage-raw-url
38
38
  def get(user_id: nil, **options)
39
- path = create_user_path(user_id: user_id)
39
+ path = user_path(user_id: user_id)
40
40
 
41
- if user_id
42
- response = client.get(path)
43
- client.update_headers(user_id: response['_id']) if response['_id']
44
- return response
45
- end
41
+ return client.get(path) if user_id
46
42
 
47
43
  params = VALID_QUERY_PARAMS.map do |p|
48
44
  options[p] ? "#{p}=#{options[p]}" : nil
@@ -63,15 +59,13 @@ module SynapsePayRest
63
59
  #
64
60
  # @return [Hash] API response
65
61
  def create(payload:)
66
- path = create_user_path
67
- response = client.post(path, payload)
68
- client.update_headers(user_id: response['_id']) if response['_id']
69
- response
62
+ client.post(user_path, payload)
70
63
  end
71
64
 
72
65
  # Sends a POST request to /oauth/:user_id endpoint to obtain a new oauth key
73
66
  # and update the client's headers, and returns the response
74
67
  #
68
+ # @param user_id [String]
75
69
  # @param payload [Hash]
76
70
  # @see https://docs.synapsepay.com/docs/get-oauth_key-refresh-token payload structure
77
71
  #
@@ -79,9 +73,9 @@ module SynapsePayRest
79
73
  # HTTP response from API
80
74
  #
81
75
  # @return [Hash] API response
82
- def refresh(payload:)
83
- path = "/oauth/#{@client.user_id}"
84
- response = @client.post(path, payload)
76
+ def refresh(user_id:, payload:)
77
+ path = "/oauth/#{user_id}"
78
+ response = client.post(path, payload)
85
79
  client.update_headers(oauth_key: response['oauth_key']) if response['oauth_key']
86
80
  response
87
81
  end
@@ -101,11 +95,9 @@ module SynapsePayRest
101
95
  # HTTP response from API
102
96
  #
103
97
  # @return [Hash] API response
104
- def update(payload:)
105
- path = create_user_path(user_id: client.user_id)
106
- response = client.patch(path, payload)
107
- client.update_headers(user_id: response['_id']) if response['_id']
108
- response
98
+ def update(user_id:, payload:)
99
+ path = user_path(user_id: user_id)
100
+ client.patch(path, payload)
109
101
  end
110
102
  # Alias for #update (legacy name)
111
103
  alias_method :answer_kba, :update
@@ -142,16 +134,16 @@ module SynapsePayRest
142
134
  #
143
135
  # @param file_path [String]
144
136
  # @deprecated Use #update with KYC 2.0 payload instead.
145
- def attach_file(file_path:)
137
+ def attach_file(user_id:, file_path:)
146
138
  warn caller.first + " DEPRECATION WARNING: #{self.class}##{__method__} is deprecated. Use #update with encode_attachment instead."
147
139
 
148
140
  file_contents = open(file_path) { |f| f.read }
149
141
  content_types = MIME::Types.type_for(file_path)
150
142
  file_type = content_types.first.content_type if content_types.any?
151
143
  if file_type.nil?
152
- raise('File type not found. Use attach_file_with_file_type(file_path: <file_path>, file_type: <file_type>)')
144
+ raise('File type not found. Use attach_file_with_file_type(user_id: <user_id>, file_path: <file_path>, file_type: <file_type>)')
153
145
  else
154
- attach_file_with_file_type(file_path: file_path, file_type: file_type)
146
+ attach_file_with_file_type(user_id: user_id, file_path: file_path, file_type: file_type)
155
147
  end
156
148
  end
157
149
 
@@ -161,10 +153,10 @@ module SynapsePayRest
161
153
  # @param file_path [String]
162
154
  # @param file_type [String] MIME type
163
155
  # @deprecated Use #update with KYC 2.0 payload instead.
164
- def attach_file_with_file_type(file_path:, file_type:)
156
+ def attach_file_with_file_type(user_id:, file_path:, file_type:)
165
157
  warn caller.first + " DEPRECATION WARNING: #{self.class}##{__method__} is deprecated. Use #update with encode_attachment instead."
166
158
 
167
- path = create_user_path(user_id: @client.user_id)
159
+ path = user_path(user_id: user_id)
168
160
  file_contents = open(file_path) { |f| f.read }
169
161
  encoded = Base64.encode64(file_contents)
170
162
  mime_padding = "data:#{file_type};base64,"
@@ -180,10 +172,10 @@ module SynapsePayRest
180
172
 
181
173
  private
182
174
 
183
- def create_user_path(user_id: nil)
184
- path = ['/users']
185
- path << user_id if user_id
186
- path.join('/')
175
+ def user_path(user_id: nil)
176
+ path = "/users"
177
+ path += "/#{user_id}" if user_id
178
+ path
187
179
  end
188
180
  end
189
181
  end
@@ -22,12 +22,11 @@ module SynapsePayRest
22
22
  # @param client_secret [String] should be stored in environment variable
23
23
  # @param ip_address [String] user's IP address
24
24
  # @param fingerprint [String] a hashed value, either unique to user or static
25
- # @param user_id [String] (optional)
26
25
  # @param development_mode [String] default true
27
26
  # @param logging [Boolean] (optional) logs to stdout when true
28
27
  # @param log_to [String] (optional) file path to log to file (logging must be true)
29
28
  def initialize(client_id:, client_secret:, ip_address:, fingerprint: nil,
30
- user_id: nil, development_mode: true, **options)
29
+ development_mode: true, **options)
31
30
  base_url = if development_mode
32
31
  'https://sandbox.synapsepay.com/api/3'
33
32
  else
@@ -37,7 +36,6 @@ module SynapsePayRest
37
36
  @http_client = HTTPClient.new(base_url: base_url,
38
37
  client_id: client_id,
39
38
  client_secret: client_secret,
40
- user_id: user_id,
41
39
  fingerprint: fingerprint,
42
40
  ip_address: ip_address,
43
41
  **options)
@@ -8,31 +8,29 @@ module SynapsePayRest
8
8
  # @return [String] the base url of the API (production or sandbox)
9
9
  # @!attribute [rw] config
10
10
  # @return [Hash] various settings related to request headers
11
- # @!attribute [rw] user_id
12
- # @return [String] the user_id which is stored upon a call to Users#get or Users#create
13
- attr_accessor :base_url, :config, :user_id
11
+ attr_accessor :base_url, :config
14
12
 
15
13
  # @param base_url [String] the base url of the API (production or sandbox)
16
14
  # @param client_id [String]
17
15
  # @param client_secret [String]
18
16
  # @param fingerprint [String]
19
17
  # @param ip_address [String]
20
- # @param user_id [String] (optional) automatically stored on call to Users#get or Users#create
21
18
  # @param logging [Boolean] (optional) logs to stdout when true
22
19
  # @param log_to [String] (optional) file path to log to file (logging must be true)
23
- def initialize(base_url:, client_id:, fingerprint:, ip_address:, client_secret:,
24
- user_id: nil, **options)
25
-
20
+ def initialize(base_url:, client_id:, fingerprint:, ip_address:,
21
+ client_secret:, **options)
26
22
  log_to = options[:log_to] || 'stdout'
27
23
  RestClient.log = log_to if options[:logging]
24
+ @logging = options[:logging]
28
25
 
29
26
  @config = {
30
- fingerprint: fingerprint,
31
27
  client_id: client_id,
32
- client_secret: client_secret
28
+ client_secret: client_secret,
29
+ fingerprint: fingerprint,
30
+ ip_address: ip_address,
31
+ oauth_key: '',
33
32
  }
34
33
  @base_url = base_url
35
- @user_id = user_id
36
34
  end
37
35
 
38
36
  # Returns headers for HTTP requests.
@@ -52,9 +50,8 @@ module SynapsePayRest
52
50
  # Alias for #headers (legacy name)
53
51
  alias_method :get_headers, :headers
54
52
 
55
- # Updates headers and/or user_id.
53
+ # Updates headers.
56
54
  #
57
- # @param user_id [String,void]
58
55
  # @param oauth_key [String,void]
59
56
  # @param fingerprint [String,void]
60
57
  # @param client_id [String,void]
@@ -62,11 +59,8 @@ module SynapsePayRest
62
59
  # @param ip_address [String,void]
63
60
  #
64
61
  # @return [void]
65
- #
66
- # @todo logic to update user_id doesn't belong here
67
- def update_headers(user_id: nil, oauth_key: nil, fingerprint: nil,
68
- client_id: nil, client_secret: nil, ip_address: nil)
69
- self.user_id = user_id if user_id
62
+ def update_headers(oauth_key: nil, fingerprint: nil, client_id: nil,
63
+ client_secret: nil, ip_address: nil, **options)
70
64
  config[:fingerprint] = fingerprint if fingerprint
71
65
  config[:oauth_key] = oauth_key if oauth_key
72
66
  config[:client_id] = client_id if client_id
@@ -85,6 +79,7 @@ module SynapsePayRest
85
79
  # @return [Hash] API response
86
80
  def post(path, payload)
87
81
  response = with_error_handling { RestClient.post(full_url(path), payload.to_json, headers) }
82
+ p 'RESPONSE:', JSON.parse(response) if @logging
88
83
  JSON.parse(response)
89
84
  end
90
85
 
@@ -98,6 +93,7 @@ module SynapsePayRest
98
93
  # @return [Hash] API response
99
94
  def patch(path, payload)
100
95
  response = with_error_handling { RestClient.patch(full_url(path), payload.to_json, headers) }
96
+ p 'RESPONSE:', JSON.parse(response) if @logging
101
97
  JSON.parse(response)
102
98
  end
103
99
 
@@ -110,6 +106,7 @@ module SynapsePayRest
110
106
  # @return [Hash] API response
111
107
  def get(path)
112
108
  response = with_error_handling { RestClient.get(full_url(path), headers) }
109
+ p 'RESPONSE:', JSON.parse(response) if @logging
113
110
  JSON.parse(response)
114
111
  end
115
112
 
@@ -122,6 +119,7 @@ module SynapsePayRest
122
119
  # @return [Hash] API response
123
120
  def delete(path)
124
121
  response = with_error_handling { RestClient.delete(full_url(path), headers) }
122
+ p 'RESPONSE:', JSON.parse(response) if @logging
125
123
  JSON.parse(response)
126
124
  end
127
125
 
@@ -25,7 +25,7 @@ module SynapsePayRest
25
25
 
26
26
  payload = payload_for_create_via_bank_login(bank_name: bank_name, username: username, password: password)
27
27
  user.authenticate
28
- response = user.client.nodes.add(payload: payload)
28
+ response = user.client.nodes.add(user_id: user.id, payload: payload)
29
29
  # MFA questions
30
30
  if response['mfa']
31
31
  create_unverified_node(user, response)
@@ -89,7 +89,7 @@ module SynapsePayRest
89
89
  end
90
90
 
91
91
  payload = verify_microdeposits_payload(amount1: amount1, amount2: amount2)
92
- response = user.client.nodes.patch(node_id: id, payload: payload)
92
+ response = user.client.nodes.patch(user_id: user.id, node_id: id, payload: payload)
93
93
  self.class.from_response(user, response)
94
94
  end
95
95
 
@@ -39,7 +39,7 @@ module SynapsePayRest
39
39
 
40
40
  payload = payload_for_create(nickname: nickname, **options)
41
41
  user.authenticate
42
- response = user.client.nodes.add(payload: payload)
42
+ response = user.client.nodes.add(user_id: user.id, payload: payload)
43
43
  from_response(user, response['nodes'].first)
44
44
  end
45
45
 
@@ -65,7 +65,12 @@ module SynapsePayRest
65
65
  end
66
66
 
67
67
  user.authenticate
68
- response = user.client.nodes.get(page: page, per_page: per_page, type: self.type)
68
+ response = user.client.nodes.get(
69
+ user_id: user.id,
70
+ page: page,
71
+ per_page: per_page,
72
+ type: self.type
73
+ )
69
74
  multiple_from_response(user, response['nodes'])
70
75
  end
71
76
 
@@ -258,7 +263,7 @@ module SynapsePayRest
258
263
  # @return [:success]
259
264
  def deactivate
260
265
  user.authenticate
261
- user.client.nodes.delete(node_id: id)
266
+ user.client.nodes.delete(user_id: user.id, node_id: id)
262
267
  :success
263
268
  end
264
269
 
@@ -62,7 +62,12 @@ module SynapsePayRest
62
62
  end
63
63
 
64
64
  user.authenticate
65
- response = user.client.nodes.get(page: page, per_page: per_page, type: type)
65
+ response = user.client.nodes.get(
66
+ user_id: user.id,
67
+ page: page,
68
+ per_page: per_page,
69
+ type: type
70
+ )
66
71
  multiple_from_response(user, response['nodes'])
67
72
  end
68
73
 
@@ -1,5 +1,7 @@
1
1
  module SynapsePayRest
2
2
  # Represents a Synapse node allowing any user to hold Nepali Rupees.
3
+ #
4
+ # @deprecated
3
5
  class SynapseNpNode < BaseNode
4
6
  class << self
5
7
  private
@@ -1,6 +1,7 @@
1
1
  module SynapsePayRest
2
- # Represents a Synapse node allowing any user to hold funds. You can use this
3
- # node as a wallet, an escrow account or something else along those lines.
2
+ # Represents a subaccount inside a FBO account at Triumph Bank.
3
+ #
4
+ # @deprecated
4
5
  class TriumphSubaccountUsNode < BaseNode
5
6
  class << self
6
7
  private
@@ -31,7 +31,7 @@ module SynapsePayRest
31
31
  # @todo make a new Error subclass for incorrect MFA
32
32
  def answer_mfa(answer)
33
33
  payload = payload_for_answer_mfa(answer: answer)
34
- response = user.client.nodes.post(payload: payload)
34
+ response = user.client.nodes.post(user_id: user.id, payload: payload)
35
35
 
36
36
  handle_answer_mfa_response(response)
37
37
  end
@@ -8,7 +8,6 @@ module SynapsePayRest
8
8
  # better to refactor this into a mixin altogether since this shouldn't be instantiated.
9
9
  # @todo reduce duplicated logic between User/BaseNode/Transaction
10
10
  class Transaction
11
-
12
11
  # @!attribute [rw] node
13
12
  # @return [SynapsePayRest::Node] the node to which the transaction belongs
14
13
  attr_reader :node, :id, :amount, :currency, :client_id, :client_name, :created_on,
@@ -53,7 +52,11 @@ module SynapsePayRest
53
52
  payload = payload_for_create(node: node, to_type: to_type, to_id: to_id,
54
53
  amount: amount, currency: currency, ip: ip, **options)
55
54
  node.user.authenticate
56
- response = node.user.client.trans.create(node_id: node.id, payload: payload)
55
+ response = node.user.client.trans.create(
56
+ user_id: node.user.id,
57
+ node_id: node.id,
58
+ payload: payload
59
+ )
57
60
  from_response(node, response)
58
61
  end
59
62
 
@@ -71,7 +74,11 @@ module SynapsePayRest
71
74
  raise ArgumentError, 'id must be a String' unless id.is_a?(String)
72
75
 
73
76
  node.user.authenticate
74
- response = node.user.client.trans.get(node_id: node.id, trans_id: id)
77
+ response = node.user.client.trans.get(
78
+ user_id: node.user.id,
79
+ node_id: node.id,
80
+ trans_id: id
81
+ )
75
82
  from_response(node, response)
76
83
  end
77
84
 
@@ -94,7 +101,12 @@ module SynapsePayRest
94
101
  end
95
102
 
96
103
  node.user.authenticate
97
- response = node.user.client.trans.get(node_id: node.id, page: page, per_page: per_page)
104
+ response = node.user.client.trans.get(
105
+ user_id: node.user.id,
106
+ node_id: node.id,
107
+ page: page,
108
+ per_page: per_page
109
+ )
98
110
  multiple_from_response(node, response['trans'])
99
111
  end
100
112
 
@@ -190,7 +202,12 @@ module SynapsePayRest
190
202
  # @return [Array<SynapsePayRest::Transaction>] (self)
191
203
  def add_comment(comment)
192
204
  payload = {'comment': comment}
193
- response = node.user.client.trans.update(node_id: node.id, trans_id: id, payload: payload)
205
+ response = node.user.client.trans.update(
206
+ user_id: node.user.id,
207
+ node_id: node.id,
208
+ trans_id: id,
209
+ payload: payload
210
+ )
194
211
  self.class.from_response(node, response['trans'])
195
212
  end
196
213
 
@@ -200,7 +217,11 @@ module SynapsePayRest
200
217
  #
201
218
  # @return [Array<SynapsePayRest::Transaction>] (self)
202
219
  def cancel
203
- response = node.user.client.trans.delete(node_id: node.id, trans_id: id)
220
+ response = node.user.client.trans.delete(
221
+ user_id: node.user.id,
222
+ node_id: node.id,
223
+ trans_id: id
224
+ )
204
225
  self.class.from_response(node, response)
205
226
  end
206
227
 
@@ -165,7 +165,7 @@ module SynapsePayRest
165
165
  # @return [SynapsePayRest::BaseDocument] new instance with updated info (id will be different if email or phone changed)
166
166
  def submit
167
167
  user.authenticate
168
- response = user.client.users.update(payload: payload_for_submit)
168
+ response = user.client.users.update(user_id: user.id, payload: payload_for_submit)
169
169
  @user = User.from_response(user.client, response)
170
170
 
171
171
  if id
@@ -212,7 +212,7 @@ module SynapsePayRest
212
212
  end
213
213
  user.authenticate
214
214
  payload = payload_for_update(changes)
215
- response = user.client.users.update(payload: payload)
215
+ response = user.client.users.update(user_id: user.id, payload: payload)
216
216
  @user = User.from_response(user.client, response)
217
217
 
218
218
  if id
@@ -174,7 +174,6 @@ module SynapsePayRest
174
174
  # to instantiate via API action.
175
175
  def initialize(**options)
176
176
  options.each { |key, value| instance_variable_set("@#{key}", value) }
177
- @client.http_client.user_id = id
178
177
  @base_documents ||= []
179
178
  end
180
179
 
@@ -203,7 +202,7 @@ module SynapsePayRest
203
202
  read_only, phone_number, legal_name, remove_phone_number, remove_login'
204
203
  end
205
204
  authenticate
206
- response = client.users.update(payload: payload_for_update(options))
205
+ response = client.users.update(user_id: id, payload: payload_for_update(options))
207
206
  # return an updated user instance
208
207
  self.class.from_response(client, response)
209
208
  end
@@ -308,7 +307,7 @@ module SynapsePayRest
308
307
  #
309
308
  # @return [SynapsePayRest::User] (self)
310
309
  def authenticate
311
- client.users.refresh(payload: payload_for_refresh)
310
+ client.users.refresh(user_id: id, payload: payload_for_refresh)
312
311
  self
313
312
  end
314
313
 
@@ -342,7 +341,7 @@ module SynapsePayRest
342
341
 
343
342
  payload = payload_for_refresh
344
343
  payload['phone_number'] = device
345
- client.users.refresh(payload: payload)
344
+ client.users.refresh(user_id: id, payload: payload)
346
345
  :success
347
346
  end
348
347
 
@@ -362,7 +361,7 @@ module SynapsePayRest
362
361
  payload = payload_for_refresh
363
362
  payload['phone_number'] = device
364
363
  payload['validation_pin'] = pin
365
- client.users.refresh(payload: payload)
364
+ client.users.refresh(user_id: id, payload: payload)
366
365
  :success
367
366
  end
368
367
 
@@ -30,7 +30,7 @@ module SynapsePayRest
30
30
  # @todo should raise error if any questions aren't answered yet.
31
31
  def submit_kba
32
32
  user = base_document.user
33
- response = user.client.users.update(payload: payload_for_kba)
33
+ response = user.client.users.update(user_id: user.id, payload: payload_for_kba)
34
34
  user = User.from_response(user.client, response)
35
35
  base_doc = user.base_documents.find { |doc| doc.id == base_document.id }
36
36
  ssn_doc = base_doc.virtual_documents.find { |doc| doc.id == id }
@@ -1,4 +1,4 @@
1
1
  module SynapsePayRest
2
- # gem version
3
- VERSION = '2.1.0'.freeze
2
+ # gem version:
3
+ VERSION = '2.2.0'.freeze
4
4
  end
data/samples.md CHANGED
@@ -221,7 +221,7 @@ social_doc = SynapsePayRest::SocialDocument.create(
221
221
  )
222
222
 
223
223
  # reassign base_doc to the output because it returns a new instance
224
- base_doc = base_doc.add_social_documents([social_doc])
224
+ base_doc = base_doc.add_social_documents(social_doc)
225
225
  # => #<SynapsePayRest::BaseDocument>
226
226
  ```
227
227
 
@@ -234,7 +234,7 @@ virtual_doc = SynapsePayRest::VirtualDocument.create(
234
234
  )
235
235
 
236
236
  # reassign base_doc to the output because it returns a new instance
237
- base_doc = base_doc.add_virtual_documents([virtual_doc])
237
+ base_doc = base_doc.add_virtual_documents(virtual_doc)
238
238
  # => #<SynapsePayRest::BaseDocument>
239
239
  ```
240
240
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synapse_pay_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Broderick
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-12-01 00:00:00.000000000 Z
12
+ date: 2016-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client