synapse_pay_rest 3.2.9 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e1254529baa7987ffaf86abeeffaff7b0219331
4
- data.tar.gz: be4f9b1df87137bf78189aae8062986e0825baf9
3
+ metadata.gz: 503d134992f78bafbfe89fd3ebbe6430fe35ca87
4
+ data.tar.gz: a23d139910156322ff423ed7dc01d0e2d23d5f81
5
5
  SHA512:
6
- metadata.gz: 23a3ed5f4a1ca4073df50437910bef26c88a3f819c576c3bd74fdae61ca09d8edc4986fa5dc4486a3ca3ab4e68e3e6e7851e3aa87c661abfe9cd688f1cbc903c
7
- data.tar.gz: 6c2bba6907cb3ec22ad8e877a241d766de06200825e9428ea6f066a2ff5998d5745a56b3e901c4f080ab6a1528cdf8690b19697b33bed34b9111ae81508bc47b
6
+ metadata.gz: 2a55b51ce0018030f2dc71a238751132ec436a99365ae6e68a0362f8c2787fcf4f12142534bdf921c339a377e03986e7f003afa08cb740bba9619e20157006a1
7
+ data.tar.gz: 00642c06e8e320fd101b7db256c3833949b3b293ca25bddd42386e722083fa35ebeecb33bd0b6e1d8d3293b3f80f7720004becb51f8a4470412cff3e5570abe7
@@ -5,9 +5,11 @@ require 'synapse_pay_rest/http_client'
5
5
  # base API classes
6
6
  require 'synapse_pay_rest/api/users'
7
7
  require 'synapse_pay_rest/api/nodes'
8
+ require 'synapse_pay_rest/api/subnets'
8
9
  require 'synapse_pay_rest/api/transactions'
9
10
  require 'synapse_pay_rest/api/subscriptions'
10
11
  require 'synapse_pay_rest/api/institutions'
12
+ require 'synapse_pay_rest/api/client'
11
13
 
12
14
  # general library classes
13
15
  require 'synapse_pay_rest/error'
@@ -37,6 +39,8 @@ require 'synapse_pay_rest/models/node/subaccount_us_node.rb'
37
39
  # ach
38
40
  require 'synapse_pay_rest/models/node/ach_us_node.rb'
39
41
  require 'synapse_pay_rest/models/node/unverified_node.rb'
42
+ #check
43
+ require 'synapse_pay_rest/models/node/check_us_node.rb'
40
44
  # eft
41
45
  require 'synapse_pay_rest/models/node/eft_ind_node.rb'
42
46
  require 'synapse_pay_rest/models/node/eft_np_node.rb'
@@ -50,12 +54,20 @@ require 'synapse_pay_rest/models/node/triumph_subaccount_us_node.rb'
50
54
  require 'synapse_pay_rest/models/node/subaccount_us_node.rb'
51
55
  require 'synapse_pay_rest/models/node/deposit_us_node.rb'
52
56
 
57
+ require 'synapse_pay_rest/models/node/clearing_us_node.rb'
58
+ require 'synapse_pay_rest/models/node/ib_deposit_us_node.rb'
59
+ require 'synapse_pay_rest/models/node/ib_subaccount_us_node.rb'
60
+ require 'synapse_pay_rest/models/node/interchange_us_node.rb'
61
+
53
62
  # iou
54
63
  require 'synapse_pay_rest/models/node/iou_node.rb'
55
64
 
56
65
  # BaseNode factory
57
66
  require 'synapse_pay_rest/models/node/node'
58
67
 
68
+ # subnet-related classes
69
+ require 'synapse_pay_rest/models/subnet/subnet'
70
+
59
71
  # transaction-related classes
60
72
  require 'synapse_pay_rest/models/transaction/transaction'
61
73
 
@@ -65,6 +77,10 @@ require 'synapse_pay_rest/models/subscription/subscription'
65
77
  # institution-related classes
66
78
  require 'synapse_pay_rest/models/institution/institution'
67
79
 
80
+ require 'synapse_pay_rest/models/client/issue_public_key'
81
+
82
+
83
+
68
84
  # Namespace for all SynapsePayRest classes and modules
69
85
  module SynapsePayRest
70
86
  # Modifies the default method to print a warning when deprecated constants
@@ -0,0 +1,30 @@
1
+ module SynapsePayRest
2
+ # Wrapper class for /client endpoint
3
+ class ClientEndpoint
4
+
5
+ # @!attribute [rw] client
6
+ # @return [SynapsePayRest::HTTPClient]
7
+ attr_accessor :client
8
+
9
+ # @param client [SynapsePayRest::HTTPClient]
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ # Sends a GET request to /client endpoint to issue public key, and returns the
15
+ # response.
16
+ #
17
+ # @param scope [String]
18
+ #
19
+ # @raise [SynapsePayRest::Error] may return subclasses of error based on
20
+ # HTTP response from API
21
+ #
22
+ # @return [Hash] API response
23
+ def issue_public_key(scope: "OAUTH|POST,USERS|POST,USERS|GET,USER|GET,USER|PATCH,SUBSCRIPTIONS|GET,SUBSCRIPTIONS|POST,SUBSCRIPTION|GET,SUBSCRIPTION|PATCH,CLIENT|REPORTS,CLIENT|CONTROLS")
24
+ path = '/client?issue_public_key=YES'
25
+ path += "&scope=#{scope}"
26
+ client.get(path)
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,87 @@
1
+ module SynapsePayRest
2
+ # Wrapper class for /subnets endpoints
3
+ #
4
+ class Subnets
5
+
6
+ # Valid optional args for #get
7
+ # @todo Refactor to HTTPClient
8
+ VALID_QUERY_PARAMS = [:page, :per_page].freeze
9
+
10
+ # @!attribute [rw] client
11
+ # @return [SynapsePayRest::HTTPClient]
12
+ attr_accessor :client
13
+
14
+ # @param client [SynapsePayRest::HTTPClient]
15
+ def initialize(client)
16
+ @client = client
17
+ end
18
+
19
+ # Sends a GET request to /subnets endpoint. Queries a specific subnet_id
20
+ # if subnet_id supplied, else queries all transactions. Returns the response.
21
+ #
22
+ # @param user_id [String]
23
+ # @param node_id [String] id of node
24
+ # @param subnet_id [String,void] (optional) id of a subnet to look up
25
+ # @param page [String,Integer] (optional) response will default to 1
26
+ # @param per_page [String,Integer] (optional) response will default to 20
27
+ #
28
+ # @raise [SynapsePayRest::Error] may return subclasses of error based on
29
+ # HTTP response from API
30
+ #
31
+ # @return [Hash] API response
32
+ #
33
+ def get(user_id:, node_id:, subnet_id: nil, **options)
34
+ path = create_subnet_path(user_id: user_id, node_id: node_id, subnet_id: subnet_id)
35
+
36
+ params = VALID_QUERY_PARAMS.map do |p|
37
+ options[p] ? "#{p}=#{options[p]}" : nil
38
+ end.compact
39
+
40
+ path += '?' + params.join('&') if params.any?
41
+ client.get(path)
42
+ end
43
+
44
+ # Sends a POST request to /subents endpoint to create a new subnet.
45
+ # Returns the response.
46
+ #
47
+ # @param user_id [String] user_id associated with the subnet
48
+ # @param node_id [String] node the subnet belongs to
49
+ # @param payload [Hash]
50
+ # @see https://docs.synapsepay.com/docs/create-subnet payload structure
51
+ #
52
+ # @raise [SynapsePayRest::Error] may return subclasses of error based on
53
+ # HTTP response from API
54
+ #
55
+ # @return [Hash] API response
56
+ def create(user_id:, node_id:, payload:)
57
+ path = create_subnet_path(user_id: user_id, node_id: node_id)
58
+ client.post(path, payload)
59
+ end
60
+
61
+ # Sends a PATCH request to /subnets endpoint to update a subnet.
62
+ # Returns the response.
63
+ #
64
+ # @param user_id [String] id of user associated with the subnet
65
+ # @param node_id [String] id of node the subnet belongs to
66
+ # @param subnet_id [String] id of subnet
67
+ # @param payload [Hash]
68
+ # @see https://docs.synapsepay.com/docs/subnet-1 payload structure
69
+ #
70
+ # @raise [SynapsePayRest::Error] may return subclasses of error based on
71
+ # HTTP response from API
72
+ #
73
+ # @return [Hash] API response
74
+ def update(user_id:, node_id:, subnet_id:, payload:)
75
+ path = create_subnet_path(user_id: user_id, node_id: node_id, subnet_id: subnet_id)
76
+ client.patch(path, payload)
77
+ end
78
+
79
+ private
80
+
81
+ def create_subnet_path(user_id:, node_id:, subnet_id: nil)
82
+ path = "/users/#{user_id}/nodes/#{node_id}/subnets"
83
+ path += "/#{subnet_id}" if subnet_id
84
+ path
85
+ end
86
+ end
87
+ end
@@ -13,7 +13,8 @@ module SynapsePayRest
13
13
  # @return [SynapsePayRest::Transactions]
14
14
  # @!attribute [rw] subscriptions
15
15
  # @return [SynapsePayRest::Subscriptions]
16
- attr_accessor :http_client, :users, :nodes, :transactions, :subscriptions, :institutions
16
+ attr_accessor :http_client, :users, :nodes, :subnets, :transactions, :subscriptions, :institutions,
17
+ :client_endpoint
17
18
 
18
19
  # Alias for #transactions (legacy name)
19
20
  alias_method :trans, :transactions
@@ -32,7 +33,7 @@ module SynapsePayRest
32
33
  base_url = if development_mode
33
34
  'https://uat-api.synapsefi.com/v3.1'
34
35
  else
35
- 'https://synapsepay.com/api/3'
36
+ 'https://api.synapsefi.com/v3.1'
36
37
  end
37
38
 
38
39
  @http_client = HTTPClient.new(base_url: base_url,
@@ -41,11 +42,19 @@ module SynapsePayRest
41
42
  fingerprint: fingerprint,
42
43
  ip_address: ip_address,
43
44
  **options)
44
- @users = Users.new @http_client
45
- @nodes = Nodes.new @http_client
46
- @transactions = Transactions.new @http_client
47
- @subscriptions = Subscriptions.new @http_client
48
- @institutions = Institutions.new @http_client
45
+ @users = Users.new @http_client
46
+ @nodes = Nodes.new @http_client
47
+ @subnets = Subnets.new @http_client
48
+ @transactions = Transactions.new @http_client
49
+ @subscriptions = Subscriptions.new @http_client
50
+ @institutions = Institutions.new @http_client
51
+ @client_endpoint = ClientEndpoint.new @http_client
52
+ end
53
+
54
+
55
+
56
+ def issue_public_key(scope: "OAUTH|POST,USERS|POST,USERS|GET,USER|GET,USER|PATCH,SUBSCRIPTIONS|GET,SUBSCRIPTIONS|POST,SUBSCRIPTION|GET,SUBSCRIPTION|PATCH,CLIENT|REPORTS,CLIENT|CONTROLS")
57
+ PublicKey.issue(client: self, scope: scope)
49
58
  end
50
59
  end
51
60
  end
@@ -0,0 +1,47 @@
1
+ module SynapsePayRest
2
+ # Represents a public key record and holds methods for getting public key instances
3
+ # from API calls. This is built on top of the SynapsePayRest::Client class and
4
+ # is intended to make it easier to use the API without knowing payload formats
5
+ # or knowledge of REST.
6
+ class PublicKey
7
+ attr_reader :client, :client_obj_id, :expires_at, :expires_in, :public_key, :scope
8
+
9
+ class << self
10
+ # Creates a client public key from a response hash.
11
+ # @note Shouldn't need to call this directly.
12
+ def from_response(response)
13
+ args = {
14
+ client: response['client'],
15
+ client_obj_id: response['public_key_obj']['client_obj_id'],
16
+ expires_at: response['public_key_obj']['expires_at'],
17
+ expires_in: response['public_key_obj']['expires_in'],
18
+ public_key: response['public_key_obj']['public_key'],
19
+ scope: response['public_key_obj']['scope']
20
+ }
21
+ self.new(args)
22
+ end
23
+
24
+ #Issues public key for client.
25
+ # @param client [SynapsePayRest::Client]
26
+ # @param scope [String]
27
+ #
28
+ # @raise [SynapsePayRest::Error]
29
+ #
30
+ # @return [SynapsePayRest::PublicKey] new instance corresponding to same API record
31
+ def issue(client:, scope: "OAUTH|POST,USERS|POST,USERS|GET,USER|GET,USER|PATCH,SUBSCRIPTIONS|GET,SUBSCRIPTIONS|POST,SUBSCRIPTION|GET,SUBSCRIPTION|PATCH,CLIENT|REPORTS,CLIENT|CONTROLS")
32
+ raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
33
+ raise ArgumentError, 'scope must be a String' unless scope.is_a?(String)
34
+
35
+ response = client.client_endpoint.issue_public_key(scope: scope)
36
+ from_response(response)
37
+ end
38
+ end
39
+
40
+ # @note Do not call directly. Use PublicKey.issue or other class method
41
+ # to instantiate via API action.
42
+ def initialize(**options)
43
+ options.each { |key, value| instance_variable_set("@#{key}", value) }
44
+ end
45
+
46
+ end
47
+ end
@@ -126,6 +126,7 @@ module SynapsePayRest
126
126
  response = user.client.nodes.resend_micro(user_id: user.id, node_id: id)
127
127
  self.class.from_response(user, response)
128
128
  end
129
+
129
130
 
130
131
  private
131
132
 
@@ -133,5 +134,6 @@ module SynapsePayRest
133
134
  def verify_microdeposits_payload(amount1:, amount2:)
134
135
  {'micro' => [amount1, amount2]}
135
136
  end
137
+
136
138
  end
137
139
  end
@@ -20,7 +20,10 @@ module SynapsePayRest
20
20
  :correspondent_routing_number, :correspondent_bank_name,
21
21
  :correspondent_address, :correspondent_swift, :account_id, :balance,
22
22
  :ifsc, :swift, :bank_long_name, :type, :gateway_restricted,
23
- :email_match, :name_match, :phonenumber_match
23
+ :email_match, :name_match, :phonenumber_match, :address_street,
24
+ :address_city, :address_subdivision, :address_country_code,
25
+ :address_postal_code, :payee_address, :payee_name, :other, :network,
26
+ :document_id, :card_type
24
27
 
25
28
  class << self
26
29
  # Creates a new node in the API associated to the provided user and
@@ -91,6 +94,10 @@ module SynapsePayRest
91
94
  address: response['info']['address'],
92
95
  swift: response['info']['swift'],
93
96
  ifsc: response['info']['ifsc'],
97
+ payee_name: response['info']['payee_name'],
98
+ document_id: response['info']['document_id'],
99
+ network: response['info']['network'],
100
+ card_type: response['info']['type'],
94
101
  user_info: nil,
95
102
  transactions: nil,
96
103
  timeline: nil,
@@ -144,6 +151,15 @@ module SynapsePayRest
144
151
  args[:timeline] = timeline
145
152
  end
146
153
 
154
+ if response['info']['payee_address']
155
+ payee_address = response['info']['payee_address']
156
+ args[:address_street] = payee_address['address_street']
157
+ args[:address_city] = payee_address['address_city']
158
+ args[:address_subdivision] = payee_address['address_subdivision']
159
+ args[:address_country_code] = payee_address['address_country_code']
160
+ args[:address_postal_code] = payee_address['address_postal_code']
161
+ end
162
+
147
163
  self.new(**args)
148
164
  end
149
165
 
@@ -159,7 +175,7 @@ module SynapsePayRest
159
175
  }
160
176
 
161
177
  info_fields = [
162
- :swift, :name_on_account, :bank_name, :address, :ifsc,:nickname,
178
+ :swift, :name_on_account, :bank_name, :address, :ifsc, :nickname,
163
179
  :bank_name
164
180
  ]
165
181
  info_fields.each do |field|
@@ -200,6 +216,18 @@ module SynapsePayRest
200
216
  if options[:password]
201
217
  payload['info']['bank_pw'] = options[:password]
202
218
  end
219
+ if options[:payee_name]
220
+ payload['info']['payee_name'] = options[:payee_name]
221
+ end
222
+ if options[:card_number]
223
+ payload['info']['card_number'] = options[:card_number]
224
+ end
225
+ if options[:exp_date]
226
+ payload['info']['exp_date'] = options[:exp_date]
227
+ end
228
+ if options[:document_id]
229
+ payload['info']['document_id'] = options[:document_id]
230
+ end
203
231
 
204
232
  balance_fields = [:currency]
205
233
  balance_fields.each do |field|
@@ -209,7 +237,7 @@ module SynapsePayRest
209
237
  end
210
238
  end
211
239
 
212
- extra_fields = [:supp_id, :gateway_restricted]
240
+ extra_fields = [:supp_id, :gateway_restricted, :other]
213
241
  extra_fields.each do |field|
214
242
  if options[field]
215
243
  payload['extra'] ||= {}
@@ -217,6 +245,15 @@ module SynapsePayRest
217
245
  end
218
246
  end
219
247
 
248
+ payee_address_fields = [:address_street, :address_city, :address_subdivision,
249
+ :address_country_code, :address_postal_code]
250
+ payee_address_fields.each do |field|
251
+ if options[field]
252
+ payload['info']['payee_address'] ||= {}
253
+ payload['info']['payee_address'][field.to_s] = options[field] if options[field]
254
+ end
255
+ end
256
+
220
257
  payload
221
258
  end
222
259
  end
@@ -278,6 +315,44 @@ module SynapsePayRest
278
315
  Transaction.find(node: self, id: id)
279
316
  end
280
317
 
318
+ # Creates a subnet belonging to this node and returns it as a Subnet
319
+ # instance.
320
+ #
321
+ #
322
+ # @raise [SynapsePayRest::Error] if HTTP error or invalid argument format
323
+ #
324
+ # @return [SynapsePayRest::Subnet]
325
+ def create_subnet(**options)
326
+ Subnet.create(node: self, **options)
327
+ end
328
+
329
+ # Queries the API for all subnets belonging to this node and returns
330
+ # them as Subnet instances.
331
+ #
332
+ # @param page [String,Integer] (optional) response will default to 1
333
+ # @param per_page [String,Integer] (optional) response will default to 20
334
+ #
335
+ # @raise [SynapsePayRest::Error]
336
+ #
337
+ # @return [Array<SynapsePayRest::Subnet>]
338
+ def subnets(**options)
339
+ Subnet.all(node: self, **options)
340
+ end
341
+
342
+ # Queries the API for a subnet belonging to this node by subnet id
343
+ # and returns a Subnet instance if found.
344
+ #
345
+ # @param id [String] id of the subnet to find
346
+ #
347
+ # @raise [SynapsePayRest::Error] if not found or other HTTP error
348
+ #
349
+ # @return [SynapsePayRest::Subnet]
350
+ def find_subnet(id:)
351
+ raise ArgumentError, 'id must be a String' unless id.is_a?(String)
352
+
353
+ Subnet.find(node: self, id: id)
354
+ end
355
+
281
356
  # Deactivates the node.
282
357
  #
283
358
  # @raise [SynapsePayRest::Error]
@@ -0,0 +1,25 @@
1
+ module SynapsePayRest
2
+ # This node allows you to send a check to any individual or entity in the US.
3
+ #Currently in sandbox only.
4
+ class CheckUsNode < BaseNode
5
+ class << self
6
+ private
7
+
8
+ def payload_for_create(nickname:, payee_name:, address_street:, address_city:,
9
+ address_subdivision:, address_country_code:, address_postal_code:, **options)
10
+ args = {
11
+ type: 'CHECK-US',
12
+ nickname: nickname,
13
+ payee_name: payee_name,
14
+ address_street: address_street,
15
+ address_city: address_city,
16
+ address_subdivision: address_subdivision,
17
+ address_country_code: address_country_code,
18
+ address_postal_code: address_postal_code
19
+ }.merge(options)
20
+ super(args)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,16 @@
1
+ module SynapsePayRest
2
+ #
3
+ class ClearingUsNode < BaseNode
4
+ class << self
5
+ private
6
+
7
+ def payload_for_create(nickname:, **options)
8
+ args = {
9
+ type: 'CLEARING-US',
10
+ nickname: nickname
11
+ }.merge(options)
12
+ super(args)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module SynapsePayRest
2
+ #
3
+ class IbDepositUsNode < BaseNode
4
+ class << self
5
+ private
6
+
7
+ def payload_for_create(nickname:, **options)
8
+ args = {
9
+ type: 'IB-DEPOSIT-US',
10
+ nickname: nickname
11
+ }.merge(options)
12
+ super(args)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module SynapsePayRest
2
+ #
3
+ class IbSubaccountUsNode < BaseNode
4
+ class << self
5
+ private
6
+
7
+ def payload_for_create(nickname:, **options)
8
+ args = {
9
+ type: 'IB-SUBACCOUNT-US',
10
+ nickname: nickname
11
+ }.merge(options)
12
+ super(args)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ module SynapsePayRest
2
+
3
+ class InterchangeUsNode < BaseNode
4
+ class << self
5
+ private
6
+
7
+ def payload_for_create(nickname:, card_number:, exp_date:, document_id:, **options)
8
+ args = {
9
+ type: 'INTERCHANGE-US',
10
+ nickname: nickname,
11
+ card_number: card_number,
12
+ exp_date: exp_date,
13
+ document_id: document_id
14
+ }.merge(options)
15
+ super(args)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -18,7 +18,12 @@ module SynapsePayRest
18
18
  'TRIUMPH-SUBACCOUNT-US' => TriumphSubaccountUsNode,
19
19
  'SUBACCOUNT-US' => SubaccountUsNode,
20
20
  'WIRE-INT' => WireIntNode,
21
- 'WIRE-US' => WireUsNode
21
+ 'WIRE-US' => WireUsNode,
22
+ 'CHECK-US' => CheckUsNode,
23
+ 'CLEARING-US' => ClearingUsNode,
24
+ 'IB-DEPOSIT-US' => IbDepositUsNode,
25
+ 'IB-SUBACCOUNT-US' => IbSubaccountUsNode,
26
+ 'INTERCHANGE-US' => InterchangeUsNode
22
27
  }.freeze
23
28
 
24
29
  class << self
@@ -0,0 +1,161 @@
1
+ module SynapsePayRest
2
+ # Represents a subnet record and holds methods for constructing subnet instances
3
+ # from API calls. This is built on top of the SynapsePayRest::Subnets class and
4
+ # is intended to make it easier to use the API without knowing payload formats
5
+ # or knowledge of REST.
6
+ #
7
+ class Subnet
8
+ # @!attribute [rw] node
9
+ attr_reader :id, :account_num, :allowed, :client_id, :client_name, :nickname, :node, :routing_num_ach,
10
+ :routing_num_wire
11
+
12
+
13
+ class << self
14
+ # Creates a new subnet in the API belonging to the provided node and
15
+ # returns a subnet instance from the response data.
16
+ #
17
+ # @param nickname [String] any nicknames
18
+ # @param node [SynapsePayRest::BaseNode] node to which the Subnet belongs
19
+ # @see https://docs.synapsepay.com/docs/subnets
20
+ #
21
+ # @raise [SynapsePayRest::Error] if HTTP error or invalid argument format
22
+ #
23
+ # @return [SynapsePayRest::Subnet]
24
+ #
25
+ def create(node:, nickname:, **options)
26
+ raise ArgumentError, 'cannot create a transaction with an UnverifiedNode' if node.is_a?(UnverifiedNode)
27
+ raise ArgumentError, 'node must be a type of BaseNode object' unless node.is_a?(BaseNode)
28
+ [nickname].each do |arg|
29
+ if options[arg] && !options[arg].is_a?(String)
30
+ raise ArgumentError, "#{arg} must be a String"
31
+ end
32
+ end
33
+
34
+ payload = payload_for_create(node: node, nickname: nickname, **options)
35
+ response = node.user.client.subnets.create(
36
+ user_id: node.user.id,
37
+ node_id: node.id,
38
+ payload: payload,
39
+ )
40
+ from_response(node, response)
41
+ end
42
+
43
+ # Queries the API for a subnet belonging to the supplied node by subnet id
44
+ # and returns a Subnet n instance if found.
45
+ #
46
+ # @param node [SynapsePayRest::BaseNode] node to which the subnet belongs
47
+ # @param id [String] id of the subnet to find
48
+ #
49
+ # @raise [SynapsePayRest::Error] if not found or other HTTP error
50
+ #
51
+ # @return [SynapsePayRest::Subnet]
52
+ def find(node:, id:)
53
+ raise ArgumentError, 'node must be a type of BaseNode object' unless node.is_a?(BaseNode)
54
+ raise ArgumentError, 'id must be a String' unless id.is_a?(String)
55
+
56
+ response = node.user.client.subnets.get(
57
+ user_id: node.user.id,
58
+ node_id: node.id,
59
+ subnet_id: id
60
+ )
61
+ from_response(node, response)
62
+ end
63
+
64
+ # Queries the API for all subnets belonging to the supplied node and returns
65
+ # them as Subnet instances.
66
+ #
67
+ # @param node [SynapsePayRest::BaseNode] node to which the subnet belongs
68
+ # @param page [String,Integer] (optional) response will default to 1
69
+ # @param per_page [String,Integer] (optional) response will default to 20
70
+ #
71
+ # @raise [SynapsePayRest::Error]
72
+ #
73
+ # @return [Array<SynapsePayRest::Subnet>]
74
+ def all(node:, page: nil, per_page: nil)
75
+ raise ArgumentError, 'node must be a type of BaseNode object' unless node.is_a?(BaseNode)
76
+ [page, per_page].each do |arg|
77
+ if arg && (!arg.is_a?(Integer) || arg < 1)
78
+ raise ArgumentError, "#{arg} must be nil or an Integer >= 1"
79
+ end
80
+ end
81
+
82
+ response = node.user.client.subnets.get(
83
+ user_id: node.user.id,
84
+ node_id: node.id,
85
+ page: page,
86
+ per_page: per_page
87
+ )
88
+ multiple_from_response(node, response['subnets'])
89
+ end
90
+
91
+ # Creates a Subnet from a response hash.
92
+ #
93
+ # @note Shouldn't need to call this directly.
94
+ #
95
+ def from_response(node, response)
96
+ args = {
97
+ node: node,
98
+ id: response['_id'],
99
+ account_num: response['account_num'],
100
+ allowed: response['allowed'],
101
+ client_id: response['client']['id'],
102
+ client_name: response['client']['name'],
103
+ nickname: response['nickname'],
104
+ node_id: response['node_id'],
105
+ routing_num_ach: response['routing_num']['ach'],
106
+ routing_num_wire: response['routing_num']['wire'],
107
+ user_id: response['user_id']
108
+ }
109
+ self.new(args)
110
+ end
111
+
112
+ private
113
+
114
+ def payload_for_create(node:, nickname:, **options)
115
+ payload = {
116
+ 'nickname' => nickname
117
+ }
118
+ end
119
+
120
+ def multiple_from_response(node, response)
121
+ return [] if response.empty?
122
+ response.map { |subnets_data| from_response(node, subnets_data) }
123
+ end
124
+ end
125
+
126
+ # @note Do not call directly. Use Subnet.create or other class
127
+ # method to instantiate via API action.
128
+ def initialize(**options)
129
+ options.each { |key, value| instance_variable_set("@#{key}", value) }
130
+ end
131
+
132
+ # Changes Subnet's allowed permission from 'CREDIT' to 'LOCKED'.
133
+ #
134
+ # @param comment [String]
135
+ #
136
+ # @raise [SynapsePayRest::Error]
137
+ #
138
+ # @return [Array<SynapsePayRest::Subnet>] (self)
139
+ def lock
140
+ payload = {'allowed' => 'LOCKED'}
141
+ response = node.user.client.subnets.update(
142
+ user_id: node.user.id,
143
+ node_id: node.id,
144
+ subnet_id: id,
145
+ payload: payload
146
+ )
147
+ if response['subnets']
148
+ # api v3.1
149
+ self.class.from_response(node, response['subnets'])
150
+ else
151
+ # api v3.1.1
152
+ self.class.from_response(node, response)
153
+ end
154
+ end
155
+
156
+ # Checks if two Subnet instances have same id (different instances of same record).
157
+ def ==(other)
158
+ other.instance_of?(self.class) && !id.nil? && id == other.id
159
+ end
160
+ end
161
+ end
@@ -74,11 +74,11 @@ module SynapsePayRest
74
74
  # @raise [SynapsePayRest::Error] if HTTP error or invalid argument format
75
75
  #
76
76
  # @return [SynapsePayRest::Subscription] new instance corresponding to same API record
77
- def update(client:, is_active:, url:, scope:, **options)
77
+ def update(client:, id:, **options)
78
78
  raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
79
79
 
80
- payload = payload_for_update(is_active: is_active, url: url, scope: scope, **options)
81
- response = client.subscriptions.update(payload: payload)
80
+ payload = payload_for_update(options)
81
+ response = client.subscriptions.update(subscription_id: id, payload: payload)
82
82
  from_response(response)
83
83
  end
84
84
 
@@ -3,5 +3,41 @@ module SynapsePayRest
3
3
  #
4
4
  # @see https://docs.synapsepay.com/docs/user-resources#section-social-document-types
5
5
  # social document types
6
- class SocialDocument < Document; end
6
+ class SocialDocument < Document
7
+
8
+ # Verifies the pin sent via the user's social doc either EMAIL_2FA or PHONE_NUMBER_2FA
9
+ # status is SUBMITTED|MFA_PENDING before verified
10
+ #
11
+ # @param mfa_answer [String]
12
+ # @param value [String]
13
+ #
14
+ # @raise [SynapsePayRest::Error] if wrong guess or HTTP error
15
+ #
16
+ # @return [SynapsePayRest::SocialDocument]
17
+ def verify_2fa(mfa_answer:, value:)
18
+ user = base_document.user
19
+ payload = verify_social_doc_2fa_payload(mfa_answer: mfa_answer, type: type, value: value)
20
+ response = user.client.users.update(user_id: user.id, payload: payload)
21
+ user = User.from_response(user.client, response)
22
+ social_doc = base_document.social_documents.find { |doc| doc.type == type }
23
+ end
24
+
25
+ private
26
+
27
+ # Converts the data to hash format for request JSON.
28
+ def verify_social_doc_2fa_payload(mfa_answer:, type:, value:)
29
+ {
30
+ 'documents' => [{
31
+ 'id' => base_document.id,
32
+ 'social_docs' => [{
33
+ 'id' => id,
34
+ 'document_value' => value,
35
+ 'document_type' => type,
36
+ 'mfa_answer' => mfa_answer
37
+ }]
38
+ }]
39
+ }
40
+ end
41
+
42
+ end
7
43
  end
@@ -591,7 +591,7 @@ module SynapsePayRest
591
591
  #
592
592
  # @return [SynapsePayRest::SynapseUsNode]
593
593
  def create_deposit_us_node(**options)
594
- SynapseUsNode.create(user: self, **options)
594
+ DepositUsNode.create(user: self, **options)
595
595
  end
596
596
 
597
597
  # Creates a SUBACCOUNT-US node.
@@ -664,6 +664,79 @@ module SynapsePayRest
664
664
  WireUsNode.create(user: self, **options)
665
665
  end
666
666
 
667
+ # Creates a CHECK-US node.
668
+ #
669
+ # @param nickname [String] nickname for the node
670
+ # @param bank_name [String]
671
+ # @param account_number [String]
672
+ # @param routing_number [String]
673
+ # @param name_on_account [String]
674
+ # @param address [String]
675
+ # @param correspondent_routing_number [String] (optional)
676
+ # @param correspondent_bank_name [String] (optional)
677
+ # @param correspondent_address [String] (optional)
678
+ # @param supp_id [String] (optional)
679
+ # @param gateway_restricted [Boolean] (optional)
680
+ #
681
+ # @raise [SynapsePayRest::Error]
682
+ #
683
+ # @return [SynapsePayRest::CheckUsNode]
684
+ def create_check_us_node(**options)
685
+ CheckUsNode.create(user: self, **options)
686
+ end
687
+
688
+ # Creates a CLEARING-US node.
689
+ #
690
+ # @param nickname [String] nickname for the node
691
+ # @param supp_id [String] (optional)
692
+ # @param gateway_restricted [Boolean] (optional)
693
+ #
694
+ # @raise [SynapsePayRest::Error]
695
+ #
696
+ # @return [SynapsePayRest::ClearingUsNode]
697
+ def create_clearing_us_node(**options)
698
+ ClearingUsNode.create(user: self, **options)
699
+ end
700
+
701
+ # Creates a IB-DEPOSIT-US node.
702
+ #
703
+ # @param nickname [String] nickname for the node
704
+ # @param supp_id [String] (optional)
705
+ # @param gateway_restricted [Boolean] (optional)
706
+ #
707
+ # @raise [SynapsePayRest::Error]
708
+ #
709
+ # @return [SynapsePayRest::IbDepositUsNode]
710
+ def create_ib_deposit_us_node(**options)
711
+ IbDepositUsNode.create(user: self, **options)
712
+ end
713
+
714
+ # Creates a IB-SUBACCOUNT-US node.
715
+ #
716
+ # @param nickname [String] nickname for the node
717
+ # @param supp_id [String] (optional)
718
+ # @param gateway_restricted [Boolean] (optional)
719
+ #
720
+ # @raise [SynapsePayRest::Error]
721
+ #
722
+ # @return [SynapsePayRest::IbSubaccountUsNode]
723
+ def create_ib_subaccount_us_node(**options)
724
+ IbSubaccountUsNode.create(user: self, **options)
725
+ end
726
+
727
+ # Creates a INTERCHANGE-US node.
728
+ #
729
+ # @param nickname [String] nickname for the node
730
+ # @param supp_id [String] (optional)
731
+ # @param gateway_restricted [Boolean] (optional)
732
+ #
733
+ # @raise [SynapsePayRest::Error]
734
+ #
735
+ # @return [SynapsePayRest::InterchangeUsNode]
736
+ def create_interchange_us_node(**options)
737
+ InterchangeUsNode.create(user: self, **options)
738
+ end
739
+
667
740
  # Checks if two User instances have same id (different instances of same record).
668
741
  def ==(other)
669
742
  other.instance_of?(self.class) && !id.nil? && id == other.id
@@ -1,4 +1,4 @@
1
1
  module SynapsePayRest
2
2
  # Gem version
3
- VERSION = '3.2.9'.freeze
3
+ VERSION = '3.3.1'.freeze
4
4
  end
data/samples.md CHANGED
@@ -443,6 +443,25 @@ base_doc = base_doc.add_virtual_documents(virtual_doc)
443
443
  # => #<SynapsePayRest::BaseDocument>
444
444
  ```
445
445
 
446
+ #### Add and verify email and phone number 2fa
447
+
448
+ ```ruby
449
+ social_doc = SynapsePayRest::SocialDocument.create(
450
+ type: 'EMAIL_2FA',
451
+ value: '1111111111'
452
+ )
453
+
454
+ # reassign base_doc to the output because it returns a new instance
455
+ base_doc = base_doc.add_social_documents(social_doc)
456
+ # => #<SynapsePayRest::BaseDocument>
457
+
458
+ # find the social doc with the same doc type
459
+ social_doc_email = base_doc.social_documents.find { |doc| doc.type == 'EMAIL_2FA' }
460
+
461
+ #verify the mfa_answer sent
462
+ social_doc_email.verify_2fa(mfa_answer: '123456' , value: '1111111111')
463
+ ```
464
+
446
465
  ## Node Methods
447
466
 
448
467
  #### All Nodes for a User
@@ -1074,6 +1093,38 @@ node = node.verify_microdeposits(amount1: 0.1, amount2: 0.1)
1074
1093
  # => #<SynapsePayRest::AchUsNode>
1075
1094
  ```
1076
1095
 
1096
+ #### Create CHECK-US Node
1097
+
1098
+ ```ruby
1099
+ check_info = {
1100
+ type: 'CHECK-US',
1101
+ nickname: 'test check-us',
1102
+ payee_name: 'Test McTest',
1103
+ address_street: '1 Market St',
1104
+ address_city: 'San Francisco',
1105
+ address_subdivision: 'CA',
1106
+ address_country_code: 'US',
1107
+ address_postal_code: '94105'
1108
+ }
1109
+
1110
+ node = user.create_check_us_node(check_info)
1111
+ # => #<SynapsePayRest::CheckUsNode>
1112
+ ```
1113
+
1114
+ #### Create INTERCHANGE-US Node
1115
+
1116
+ ```ruby
1117
+ node_info = {
1118
+ nickname: 'my debit card',
1119
+ card_number: [string of encrypted card number],
1120
+ exp_date: [string of encrypted exp date (YYYYMM)],
1121
+ document_id: [string of base doc id],
1122
+ }
1123
+
1124
+ node = user.create_interchange_us_node(node_info)
1125
+ # => #<SynapsePayRest::InterchangeUsNode>
1126
+ ```
1127
+
1077
1128
  #### Deactivate a Node
1078
1129
 
1079
1130
  This deactivates the node. It does not automatically cancel any transactions already underway.
@@ -1164,3 +1215,86 @@ transaction = transaction.add_comment('this is my favorite transaction')
1164
1215
  transaction = transaction.cancel
1165
1216
  # => #<SynapsePayRest::Transaction>
1166
1217
  ```
1218
+
1219
+ ## Subnet Methods
1220
+
1221
+ #### All Subnets from a Node
1222
+
1223
+ ##### a) Node#subnets
1224
+
1225
+ ```ruby
1226
+ subnets = node.subnets(page: 1, per_page: 15)
1227
+ # => [#<SynapsePayRest::Subnet>, #<SynapsePayRest::Subnet>, ...]
1228
+ ```
1229
+
1230
+ ##### b) Subnet#all
1231
+
1232
+ ```ruby
1233
+ subnets = SynapsePayRest::Subnet.all(node: node, page: 1, per_page: 15)
1234
+ # => [#<SynapsePayRest::Subnet>, #<SynapsePayRest::Subnet>, ...]
1235
+ ```
1236
+
1237
+ #### Find a Node's Subnet by ID
1238
+
1239
+ ##### a) Node#find_subnet
1240
+
1241
+ ```ruby
1242
+ subnet= node.find_subnet(id: '167e11516')
1243
+ # => #<SynapsePayRest::Subnet>
1244
+ ```
1245
+
1246
+ ##### b) Subnet#find
1247
+
1248
+ ```ruby
1249
+ subnet = SynapsePayRest::Subnet.find(node: node, id: '57fab7d186c2733525dd7eac')
1250
+ # => #<SynapsePayRest::Subnet>
1251
+ ```
1252
+
1253
+ #### Create a Subnet
1254
+
1255
+ ##### a) Node#create_subnet
1256
+
1257
+ ```ruby
1258
+ subnet_settings = {
1259
+ "nickname":"Test AC/RT"
1260
+ }
1261
+
1262
+ subnet = node.create_subnet(subnet_settings)
1263
+ # => #<SynapsePayRest::Subnet>
1264
+ ```
1265
+
1266
+ ##### b) Subnet#create
1267
+
1268
+ ```ruby
1269
+ subnet_settings = {
1270
+ "nickname":"Test AC/RT"
1271
+ }
1272
+
1273
+ subnet = SynapsePayRest::Subnet.create(subnet_settings)
1274
+ # => #<SynapsePayRest::Subnet>
1275
+ ```
1276
+
1277
+ #### To lock a Subnet
1278
+
1279
+ ```ruby
1280
+ subnet = subnet.lock
1281
+ # => #<SynapsePayRest::Subnet>
1282
+ ```
1283
+
1284
+ ## Issue Public Key Method
1285
+
1286
+ #### Issue Public Key From Client
1287
+
1288
+ ##### a) Client#issue_public_key
1289
+
1290
+ ```ruby
1291
+ public_key = client.issue_public_key(scope: ‘CLIENT|CONTROLS’)
1292
+ # => #<SynapsePayRest::Public_key>
1293
+ ```
1294
+
1295
+ ##### b) Subnet#all
1296
+
1297
+ ```ruby
1298
+ public_key = SynapsePayRest::PublicKey.issue(client: client, scope: ‘CLIENT|CONTROLS')
1299
+ # => #<SynapsePayRest::Public_key>
1300
+ ```
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: 3.2.9
4
+ version: 3.3.1
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: 2017-10-19 00:00:00.000000000 Z
12
+ date: 2018-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -151,20 +151,28 @@ files:
151
151
  - Rakefile
152
152
  - bin/console
153
153
  - lib/synapse_pay_rest.rb
154
+ - lib/synapse_pay_rest/api/client.rb
154
155
  - lib/synapse_pay_rest/api/institutions.rb
155
156
  - lib/synapse_pay_rest/api/nodes.rb
157
+ - lib/synapse_pay_rest/api/subnets.rb
156
158
  - lib/synapse_pay_rest/api/subscriptions.rb
157
159
  - lib/synapse_pay_rest/api/transactions.rb
158
160
  - lib/synapse_pay_rest/api/users.rb
159
161
  - lib/synapse_pay_rest/client.rb
160
162
  - lib/synapse_pay_rest/error.rb
161
163
  - lib/synapse_pay_rest/http_client.rb
164
+ - lib/synapse_pay_rest/models/client/issue_public_key.rb
162
165
  - lib/synapse_pay_rest/models/institution/institution.rb
163
166
  - lib/synapse_pay_rest/models/node/ach_us_node.rb
164
167
  - lib/synapse_pay_rest/models/node/base_node.rb
168
+ - lib/synapse_pay_rest/models/node/check_us_node.rb
169
+ - lib/synapse_pay_rest/models/node/clearing_us_node.rb
165
170
  - lib/synapse_pay_rest/models/node/deposit_us_node.rb
166
171
  - lib/synapse_pay_rest/models/node/eft_ind_node.rb
167
172
  - lib/synapse_pay_rest/models/node/eft_np_node.rb
173
+ - lib/synapse_pay_rest/models/node/ib_deposit_us_node.rb
174
+ - lib/synapse_pay_rest/models/node/ib_subaccount_us_node.rb
175
+ - lib/synapse_pay_rest/models/node/interchange_us_node.rb
168
176
  - lib/synapse_pay_rest/models/node/iou_node.rb
169
177
  - lib/synapse_pay_rest/models/node/node.rb
170
178
  - lib/synapse_pay_rest/models/node/reserve_us_node.rb
@@ -176,6 +184,7 @@ files:
176
184
  - lib/synapse_pay_rest/models/node/unverified_node.rb
177
185
  - lib/synapse_pay_rest/models/node/wire_int_node.rb
178
186
  - lib/synapse_pay_rest/models/node/wire_us_node.rb
187
+ - lib/synapse_pay_rest/models/subnet/subnet.rb
179
188
  - lib/synapse_pay_rest/models/subscription/subscription.rb
180
189
  - lib/synapse_pay_rest/models/transaction/transaction.rb
181
190
  - lib/synapse_pay_rest/models/user/base_document.rb
@@ -208,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
217
  version: '0'
209
218
  requirements: []
210
219
  rubyforge_project:
211
- rubygems_version: 2.6.11
220
+ rubygems_version: 2.5.1
212
221
  signing_key:
213
222
  specification_version: 4
214
223
  summary: SynapsePay v3 Rest Native API Library