synapse_pay_rest 2.0.2 → 2.1.0
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 +4 -4
- data/README.md +1 -1
- data/lib/synapse_pay_rest.rb +3 -1
- data/lib/synapse_pay_rest/error.rb +1 -0
- data/lib/synapse_pay_rest/http_client.rb +2 -0
- data/lib/synapse_pay_rest/models/node/ach_us_node.rb +11 -19
- data/lib/synapse_pay_rest/models/node/base_node.rb +88 -17
- data/lib/synapse_pay_rest/models/node/eft_ind_node.rb +7 -6
- data/lib/synapse_pay_rest/models/node/eft_np_node.rb +3 -4
- data/lib/synapse_pay_rest/models/node/iou_node.rb +6 -15
- data/lib/synapse_pay_rest/models/node/node.rb +18 -17
- data/lib/synapse_pay_rest/models/node/reserve_us_node.rb +5 -11
- data/lib/synapse_pay_rest/models/node/synapse_ind_node.rb +4 -8
- data/lib/synapse_pay_rest/models/node/synapse_np_node.rb +2 -8
- data/lib/synapse_pay_rest/models/node/synapse_us_node.rb +2 -8
- data/lib/synapse_pay_rest/models/node/triumph_subaccount_us_node.rb +17 -0
- data/lib/synapse_pay_rest/models/node/unverified_node.rb +1 -1
- data/lib/synapse_pay_rest/models/node/wire_int_node.rb +3 -4
- data/lib/synapse_pay_rest/models/node/wire_us_node.rb +1 -2
- data/lib/synapse_pay_rest/models/transaction/transaction.rb +9 -9
- data/lib/synapse_pay_rest/models/user/base_document.rb +12 -16
- data/lib/synapse_pay_rest/models/user/document.rb +2 -2
- data/lib/synapse_pay_rest/models/user/physical_document.rb +58 -17
- data/lib/synapse_pay_rest/models/user/user.rb +27 -10
- data/lib/synapse_pay_rest/models/user/virtual_document.rb +7 -8
- data/lib/synapse_pay_rest/version.rb +1 -1
- data/samples.md +41 -60
- data/synapse_pay_rest.gemspec +8 -8
- metadata +4 -6
- data/lib/synapse_pay_rest/models/node/eft_node.rb +0 -27
- data/lib/synapse_pay_rest/models/node/synapse_node.rb +0 -25
- data/lib/synapse_pay_rest/models/node/wire_node.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf13c67916c9560ecd7993d03b00691ea15ca16e
|
4
|
+
data.tar.gz: 4df8ab520d132d23e4196c63a8ea2fdb9bc5cc46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eace5ad6f06ecb638f69eaffd0a505e903444d78f0e1324d1a4e19f06d2ef423b40719abbf4b8d23ddf60157a8066428e7abdbfd36f0ce907c4234f3ae98e353
|
7
|
+
data.tar.gz: 10fe666bec184de1cd0b72a5d1ae4ae09e4a1a4a238bddab316c93ea1fc5dcb8558f68b766aef529dc5cdcbd0b19f6d9e9b2fd4fb4766739f4c81ca76900c27b
|
data/README.md
CHANGED
@@ -60,7 +60,7 @@ To run all tests, execute:
|
|
60
60
|
rake
|
61
61
|
```
|
62
62
|
|
63
|
-
To run a specific
|
63
|
+
To run a specific file or test, install the [m](https://github.com/qrush/m) gem and execute:
|
64
64
|
|
65
65
|
```bash
|
66
66
|
m path/to/file:line_number
|
data/lib/synapse_pay_rest.rb
CHANGED
@@ -22,7 +22,7 @@ require 'synapse_pay_rest/models/user/question'
|
|
22
22
|
|
23
23
|
# node-related classes
|
24
24
|
|
25
|
-
# ancestor of all
|
25
|
+
# ancestor of all node classes
|
26
26
|
require 'synapse_pay_rest/models/node/base_node'
|
27
27
|
|
28
28
|
# BaseNode subclasses
|
@@ -44,6 +44,8 @@ require 'synapse_pay_rest/models/node/wire_us_node.rb'
|
|
44
44
|
require 'synapse_pay_rest/models/node/wire_int_node.rb'
|
45
45
|
# reserve
|
46
46
|
require 'synapse_pay_rest/models/node/reserve_us_node.rb'
|
47
|
+
# triump subaccount
|
48
|
+
require 'synapse_pay_rest/models/node/triumph_subaccount_us_node.rb'
|
47
49
|
# iou
|
48
50
|
require 'synapse_pay_rest/models/node/iou_node.rb'
|
49
51
|
|
@@ -87,6 +87,7 @@ module SynapsePayRest
|
|
87
87
|
# @param code [Integer]
|
88
88
|
# @return [SynapsePayRest::Error]
|
89
89
|
def error_from_response(body, code)
|
90
|
+
# require 'pry'; binding.pry
|
90
91
|
code = code.to_i
|
91
92
|
klass = ERRORS[code] || SynapsePayRest::Error
|
92
93
|
message, error_code = parse_error(body)
|
@@ -62,6 +62,8 @@ module SynapsePayRest
|
|
62
62
|
# @param ip_address [String,void]
|
63
63
|
#
|
64
64
|
# @return [void]
|
65
|
+
#
|
66
|
+
# @todo logic to update user_id doesn't belong here
|
65
67
|
def update_headers(user_id: nil, oauth_key: nil, fingerprint: nil,
|
66
68
|
client_id: nil, client_secret: nil, ip_address: nil)
|
67
69
|
self.user_id = user_id if user_id
|
@@ -30,7 +30,7 @@ module SynapsePayRest
|
|
30
30
|
if response['mfa']
|
31
31
|
create_unverified_node(user, response)
|
32
32
|
else
|
33
|
-
|
33
|
+
multiple_from_response(user, response['nodes'])
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -39,23 +39,15 @@ module SynapsePayRest
|
|
39
39
|
# Converts args into payload for request JSON.
|
40
40
|
def payload_for_create(nickname:, account_number:, routing_number:,
|
41
41
|
account_type:, account_class:, **options)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
}
|
52
|
-
# optional payload fields
|
53
|
-
extra = {}
|
54
|
-
extra['supp_id'] = options[:supp_id] if options[:supp_id]
|
55
|
-
extra['gateway_restricted'] = options[:gateway_restricted] if options[:gateway_restricted]
|
56
|
-
payload['extra'] = extra if extra.any?
|
57
|
-
|
58
|
-
payload
|
42
|
+
args = {
|
43
|
+
type: 'ACH-US',
|
44
|
+
nickname: nickname,
|
45
|
+
account_number: account_number,
|
46
|
+
routing_number: routing_number,
|
47
|
+
account_type: account_type,
|
48
|
+
account_class: account_class
|
49
|
+
}.merge(options)
|
50
|
+
super(args)
|
59
51
|
end
|
60
52
|
|
61
53
|
def payload_for_create_via_bank_login(bank_name:, username:, password:)
|
@@ -98,7 +90,7 @@ module SynapsePayRest
|
|
98
90
|
|
99
91
|
payload = verify_microdeposits_payload(amount1: amount1, amount2: amount2)
|
100
92
|
response = user.client.nodes.patch(node_id: id, payload: payload)
|
101
|
-
self.class.
|
93
|
+
self.class.from_response(user, response)
|
102
94
|
end
|
103
95
|
|
104
96
|
private
|
@@ -40,7 +40,7 @@ module SynapsePayRest
|
|
40
40
|
payload = payload_for_create(nickname: nickname, **options)
|
41
41
|
user.authenticate
|
42
42
|
response = user.client.nodes.add(payload: payload)
|
43
|
-
|
43
|
+
from_response(user, response['nodes'].first)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Queries the API for all nodes belonging to the supplied user (with optional
|
@@ -66,11 +66,11 @@ module SynapsePayRest
|
|
66
66
|
|
67
67
|
user.authenticate
|
68
68
|
response = user.client.nodes.get(page: page, per_page: per_page, type: self.type)
|
69
|
-
|
69
|
+
multiple_from_response(user, response['nodes'])
|
70
70
|
end
|
71
71
|
|
72
72
|
# @note Not meant to be accessed directly on BaseNode but through children.
|
73
|
-
def
|
73
|
+
def from_response(user, response)
|
74
74
|
args = {
|
75
75
|
user: user,
|
76
76
|
type: response['type'],
|
@@ -92,35 +92,106 @@ module SynapsePayRest
|
|
92
92
|
}
|
93
93
|
|
94
94
|
if response['info']['correspondent_info']
|
95
|
-
|
96
|
-
args[:
|
97
|
-
args[:
|
98
|
-
args[:
|
99
|
-
args[:
|
95
|
+
correspondent_info = response['info']['correspondent_info']
|
96
|
+
args[:correspondent_swift] = correspondent_info['swift']
|
97
|
+
args[:correspondent_bank_name] = correspondent_info['bank_name']
|
98
|
+
args[:correspondent_routing_number] = correspondent_info['routing_num']
|
99
|
+
args[:correspondent_address] = correspondent_info['address']
|
100
100
|
end
|
101
101
|
|
102
102
|
if response['info']['match_info']
|
103
|
-
|
104
|
-
args[:
|
105
|
-
args[:
|
103
|
+
match_info = response['info']['match_info']
|
104
|
+
args[:email_match] = match_info['email_match']
|
105
|
+
args[:name_match] = match_info['name_match']
|
106
|
+
args[:phonenumber_match] = match_info['phonenumber_match']
|
106
107
|
end
|
107
108
|
|
108
109
|
if response['info']['balance']
|
109
|
-
|
110
|
-
args[:
|
110
|
+
balance = response['info']['balance']
|
111
|
+
args[:balance] = balance['amount']
|
112
|
+
args[:currency] = balance['currency']
|
111
113
|
end
|
112
114
|
|
113
115
|
if response['extra']
|
114
|
-
|
115
|
-
args[:
|
116
|
+
extra = response['extra']
|
117
|
+
args[:supp_id] = extra['supp_id']
|
118
|
+
args[:gateway_restricted] = extra['gateway_restricted']
|
116
119
|
end
|
117
120
|
|
118
121
|
self.new(**args)
|
119
122
|
end
|
120
123
|
|
121
124
|
# @note Not meant to be accessed directly on BaseNode but through children.
|
122
|
-
def
|
123
|
-
response.map { |node_data|
|
125
|
+
def multiple_from_response(user, response)
|
126
|
+
response.map { |node_data| from_response(user, node_data)}
|
127
|
+
end
|
128
|
+
|
129
|
+
def payload_for_create(type:, **options)
|
130
|
+
payload = {
|
131
|
+
'type' => type,
|
132
|
+
'info' => {}
|
133
|
+
}
|
134
|
+
|
135
|
+
info_fields = [
|
136
|
+
:swift, :name_on_account, :bank_name, :address, :ifsc,:nickname,
|
137
|
+
:bank_name
|
138
|
+
]
|
139
|
+
info_fields.each do |field|
|
140
|
+
payload['info'][field.to_s] = options[field] if options[field]
|
141
|
+
end
|
142
|
+
|
143
|
+
# the rest are done individually since they are custom renamed
|
144
|
+
correspondent_info = {}
|
145
|
+
if options[:correspondent_routing_number]
|
146
|
+
correspondent_info['routing_num'] = options[:correspondent_routing_number]
|
147
|
+
end
|
148
|
+
if options[:correspondent_bank_name]
|
149
|
+
correspondent_info['bank_name'] = options[:correspondent_bank_name]
|
150
|
+
end
|
151
|
+
if options[:correspondent_address]
|
152
|
+
correspondent_info['address'] = options[:correspondent_address]
|
153
|
+
end
|
154
|
+
if options[:correspondent_swift]
|
155
|
+
correspondent_info['swift'] = options[:correspondent_swift]
|
156
|
+
end
|
157
|
+
payload['info']['correspondent_info'] = correspondent_info if correspondent_info.any?
|
158
|
+
|
159
|
+
if options[:account_number]
|
160
|
+
payload['info']['account_num'] = options[:account_number]
|
161
|
+
end
|
162
|
+
if options[:routing_number]
|
163
|
+
payload['info']['routing_num'] = options[:routing_number]
|
164
|
+
end
|
165
|
+
if options[:account_type]
|
166
|
+
payload['info']['type'] = options[:account_type]
|
167
|
+
end
|
168
|
+
if options[:account_class]
|
169
|
+
payload['info']['class'] = options[:account_class]
|
170
|
+
end
|
171
|
+
if options[:username]
|
172
|
+
payload['info']['bank_id'] = options[:username]
|
173
|
+
end
|
174
|
+
if options[:password]
|
175
|
+
payload['info']['bank_pw'] = options[:password]
|
176
|
+
end
|
177
|
+
|
178
|
+
balance_fields = [:currency]
|
179
|
+
balance_fields.each do |field|
|
180
|
+
if options[field]
|
181
|
+
payload['info']['balance'] ||= {}
|
182
|
+
payload['info']['balance'][field.to_s] = options[field] if options[field]
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
extra_fields = [:supp_id, :gateway_restricted]
|
187
|
+
extra_fields.each do |field|
|
188
|
+
if options[field]
|
189
|
+
payload['extra'] ||= {}
|
190
|
+
payload['extra'][field.to_s] = options[field]
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
payload
|
124
195
|
end
|
125
196
|
end
|
126
197
|
|
@@ -1,18 +1,19 @@
|
|
1
1
|
module SynapsePayRest
|
2
2
|
# Represents an Indian bank account for EFT credits.
|
3
|
-
|
3
|
+
#
|
4
|
+
# @deprecated
|
5
|
+
class EftIndNode < BaseNode
|
4
6
|
class << self
|
5
7
|
private
|
6
8
|
|
7
9
|
def payload_for_create(nickname:, account_number:, ifsc:, **options)
|
8
|
-
|
10
|
+
payload = {
|
9
11
|
type: 'EFT-IND',
|
10
12
|
nickname: nickname,
|
11
|
-
account_number: account_number
|
13
|
+
account_number: account_number,
|
14
|
+
ifsc: ifsc
|
12
15
|
}.merge(options)
|
13
|
-
|
14
|
-
payload['info']['ifsc'] = ifsc
|
15
|
-
payload
|
16
|
+
super(payload)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SynapsePayRest
|
2
2
|
# Represents a Nepali bank account for EFT credits.
|
3
|
-
class EftNpNode <
|
3
|
+
class EftNpNode < BaseNode
|
4
4
|
class << self
|
5
5
|
private
|
6
6
|
|
@@ -8,11 +8,10 @@ module SynapsePayRest
|
|
8
8
|
args = {
|
9
9
|
type: 'EFT-NP',
|
10
10
|
nickname: nickname,
|
11
|
+
bank_name: bank_name,
|
11
12
|
account_number: account_number
|
12
13
|
}.merge(options)
|
13
|
-
|
14
|
-
payload['info']['bank_name'] = bank_name
|
15
|
-
payload
|
14
|
+
super(args)
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
@@ -6,21 +6,12 @@ module SynapsePayRest
|
|
6
6
|
private
|
7
7
|
|
8
8
|
def payload_for_create(nickname:, currency:, **options)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
}
|
16
|
-
}
|
17
|
-
}
|
18
|
-
# optional payload fields
|
19
|
-
extra = {}
|
20
|
-
extra['supp_id'] = options[:supp_id] if options[:supp_id]
|
21
|
-
extra['gateway_restricted'] = options[:gateway_restricted] if options[:gateway_restricted]
|
22
|
-
payload['extra'] = extra if extra.any?
|
23
|
-
payload
|
9
|
+
args = {
|
10
|
+
type: 'IOU',
|
11
|
+
nickname: nickname,
|
12
|
+
currency: currency
|
13
|
+
}.merge(options)
|
14
|
+
super(args)
|
24
15
|
end
|
25
16
|
end
|
26
17
|
end
|
@@ -6,16 +6,17 @@ module SynapsePayRest
|
|
6
6
|
|
7
7
|
# Node type to node class mappings.
|
8
8
|
NODE_TYPES_TO_CLASSES = {
|
9
|
-
'ACH-US'
|
10
|
-
'EFT-NP'
|
11
|
-
'EFT-IND'
|
12
|
-
'IOU'
|
13
|
-
'RESERVE-US'
|
14
|
-
'SYNAPSE-IND'
|
15
|
-
'SYNAPSE-NP'
|
16
|
-
'SYNAPSE-US'
|
17
|
-
'
|
18
|
-
'WIRE-
|
9
|
+
'ACH-US' => AchUsNode,
|
10
|
+
'EFT-NP' => EftNpNode,
|
11
|
+
'EFT-IND' => EftIndNode,
|
12
|
+
'IOU' => IouNode,
|
13
|
+
'RESERVE-US' => ReserveUsNode,
|
14
|
+
'SYNAPSE-IND' => SynapseIndNode,
|
15
|
+
'SYNAPSE-NP' => SynapseNpNode,
|
16
|
+
'SYNAPSE-US' => SynapseUsNode,
|
17
|
+
'TRIUMPH-SUBACCOUNT-US' => TriumphSubaccountUsNode,
|
18
|
+
'WIRE-INT' => WireIntNode,
|
19
|
+
'WIRE-US' => WireUsNode
|
19
20
|
}.freeze
|
20
21
|
|
21
22
|
class << self
|
@@ -34,7 +35,7 @@ module SynapsePayRest
|
|
34
35
|
|
35
36
|
user.authenticate
|
36
37
|
response = user.client.nodes.get(user_id: user.id, node_id: id)
|
37
|
-
|
38
|
+
from_response(user, response)
|
38
39
|
end
|
39
40
|
|
40
41
|
# Queries the API for all nodes belonging to the supplied user (with optional
|
@@ -62,7 +63,7 @@ module SynapsePayRest
|
|
62
63
|
|
63
64
|
user.authenticate
|
64
65
|
response = user.client.nodes.get(page: page, per_page: per_page, type: type)
|
65
|
-
|
66
|
+
multiple_from_response(user, response['nodes'])
|
66
67
|
end
|
67
68
|
|
68
69
|
# Queries the API for all nodes belonging to the supplied user (with optional
|
@@ -85,14 +86,14 @@ module SynapsePayRest
|
|
85
86
|
|
86
87
|
# determines the proper node type to instantiate from the response
|
87
88
|
# implemented differently in each BaseNode subclass
|
88
|
-
def
|
89
|
-
klass = NODE_TYPES_TO_CLASSES.fetch(response['type'])
|
90
|
-
klass.
|
89
|
+
def from_response(user, response)
|
90
|
+
klass = NODE_TYPES_TO_CLASSES.fetch(response['type']) || BaseNode
|
91
|
+
klass.from_response(user, response)
|
91
92
|
end
|
92
93
|
|
93
|
-
def
|
94
|
+
def multiple_from_response(user, response)
|
94
95
|
return [] if response.empty?
|
95
|
-
response.map { |node_data|
|
96
|
+
response.map { |node_data| from_response(user, node_data)}
|
96
97
|
end
|
97
98
|
end
|
98
99
|
end
|
@@ -6,17 +6,11 @@ module SynapsePayRest
|
|
6
6
|
private
|
7
7
|
|
8
8
|
def payload_for_create(nickname:, **options)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
extra = {}
|
16
|
-
extra['supp_id'] = options[:supp_id] if options[:supp_id]
|
17
|
-
extra['gateway_restricted'] = options[:gateway_restricted] if options[:gateway_restricted]
|
18
|
-
payload['extra'] = extra if extra.any?
|
19
|
-
payload
|
9
|
+
args = {
|
10
|
+
type: 'RESERVE-US',
|
11
|
+
nickname: nickname
|
12
|
+
}.merge(options)
|
13
|
+
super(args)
|
20
14
|
end
|
21
15
|
end
|
22
16
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module SynapsePayRest
|
2
2
|
# Represents a Synapse node allowing any user to hold Indian Rupees.
|
3
|
-
|
3
|
+
#
|
4
|
+
# @deprecated
|
5
|
+
class SynapseIndNode < BaseNode
|
4
6
|
class << self
|
5
7
|
private
|
6
8
|
|
@@ -9,13 +11,7 @@ module SynapsePayRest
|
|
9
11
|
type: 'SYNAPSE-IND',
|
10
12
|
nickname: nickname
|
11
13
|
}.merge(options)
|
12
|
-
|
13
|
-
# optional payload fields
|
14
|
-
extra = {}
|
15
|
-
extra['supp_id'] = options[:supp_id] if options[:supp_id]
|
16
|
-
extra['gateway_restricted'] = options[:gateway_restricted] if options[:gateway_restricted]
|
17
|
-
payload['extra'] = extra if extra.any?
|
18
|
-
payload
|
14
|
+
super(args)
|
19
15
|
end
|
20
16
|
end
|
21
17
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SynapsePayRest
|
2
2
|
# Represents a Synapse node allowing any user to hold Nepali Rupees.
|
3
|
-
class SynapseNpNode <
|
3
|
+
class SynapseNpNode < BaseNode
|
4
4
|
class << self
|
5
5
|
private
|
6
6
|
|
@@ -9,13 +9,7 @@ module SynapsePayRest
|
|
9
9
|
type: 'SYNAPSE-NP',
|
10
10
|
nickname: nickname
|
11
11
|
}.merge(options)
|
12
|
-
|
13
|
-
# optional payload fields
|
14
|
-
extra = {}
|
15
|
-
extra['supp_id'] = options[:supp_id] if options[:supp_id]
|
16
|
-
extra['gateway_restricted'] = options[:gateway_restricted] if options[:gateway_restricted]
|
17
|
-
payload['extra'] = extra if extra.any?
|
18
|
-
payload
|
12
|
+
super(args)
|
19
13
|
end
|
20
14
|
end
|
21
15
|
end
|