synapse_pay_rest 3.2.2 → 3.2.3
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/.gitignore +1 -1
- data/lib/synapse_pay_rest/api/subscriptions.rb +87 -0
- data/lib/synapse_pay_rest/client.rb +7 -4
- data/lib/synapse_pay_rest/models/node/ach_us_node.rb +2 -3
- data/lib/synapse_pay_rest/models/node/base_node.rb +19 -2
- data/lib/synapse_pay_rest/models/node/node.rb +1 -1
- data/lib/synapse_pay_rest/models/subscription/subscription.rb +138 -0
- data/lib/synapse_pay_rest/models/user/base_document.rb +81 -53
- data/lib/synapse_pay_rest/models/user/document.rb +19 -6
- data/lib/synapse_pay_rest/models/user/user.rb +45 -5
- data/lib/synapse_pay_rest/version.rb +1 -1
- data/lib/synapse_pay_rest.rb +4 -0
- data/samples.md +10 -6
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7b9318467c17d58d84b25ee16da62c521d831a3
|
4
|
+
data.tar.gz: e12ddb18f8d2cbeeea1793aa0c0994b1c7181241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29b7c4622218262bfe57afb889746f44a59f3f0a1827918de70832dcad42d7c4e1c5985e992b17241b8127854f5b0d1873854ab4508f75b8fe0e731eb8c891d4
|
7
|
+
data.tar.gz: f16edcbc0d7681811068e9a9ed2f8efcdba30e7d749f718fd53246e7a614042bf66c64288806405dc52a74b203d4ac222564cfb543518f3add979c3e4b6b1839
|
data/.gitignore
CHANGED
@@ -0,0 +1,87 @@
|
|
1
|
+
module SynapsePayRest
|
2
|
+
# Wrapper class for /subscriptions endpoints
|
3
|
+
#
|
4
|
+
# @todo Implement idempotency keys
|
5
|
+
class Subscriptions
|
6
|
+
|
7
|
+
# Valid optional args for #get
|
8
|
+
# @todo Refactor to HTTPClient
|
9
|
+
VALID_QUERY_PARAMS = [:page, :per_page].freeze
|
10
|
+
|
11
|
+
# @!attribute [rw] client
|
12
|
+
# @return [SynapsePayRest::HTTPClient]
|
13
|
+
attr_accessor :client
|
14
|
+
|
15
|
+
# @param client [SynapsePayRest::HTTPClient]
|
16
|
+
def initialize(client)
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
# Sends a POST request to /subscriptions endpoint to create a new subscription.
|
21
|
+
# Returns the response.
|
22
|
+
#
|
23
|
+
# @param url [String]
|
24
|
+
# @param scope [Array]
|
25
|
+
# @see https://docs.synapsepay.com/docs/create-subscription payload structure
|
26
|
+
#
|
27
|
+
# @raise [SynapsePayRest::Error] may return subclasses of error based on
|
28
|
+
# HTTP response from API
|
29
|
+
#
|
30
|
+
# @return [Hash] API response
|
31
|
+
def create(payload:)
|
32
|
+
path = subscription_path
|
33
|
+
client.post(path, payload)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Sends a GET request to /subscriptions endpoint. Queries a specific subscription_id
|
37
|
+
# if subs_id supplied, else queries all subscriptions. Returns the response.
|
38
|
+
#
|
39
|
+
# @param subscription_id [String,void] (optional) id of a subscription to look up
|
40
|
+
# @param page [String,Integer] (optional) response will default to 1
|
41
|
+
# @param per_page [String,Integer] (optional) response will default to 20
|
42
|
+
#
|
43
|
+
# @raise [SynapsePayRest::Error] may return subclasses of error based on
|
44
|
+
# HTTP response from API
|
45
|
+
#
|
46
|
+
# @return [Hash] API response
|
47
|
+
#
|
48
|
+
# @todo Probably should use CGI or RestClient's param builder instead of
|
49
|
+
# rolling our own, probably error-prone and untested version
|
50
|
+
# https://github.com/rest-client/rest-client#usage-raw-url
|
51
|
+
def get(subscription_id: nil, **options)
|
52
|
+
path = subscription_path(subscription_id: subscription_id)
|
53
|
+
|
54
|
+
params = VALID_QUERY_PARAMS.map do |p|
|
55
|
+
options[p] ? "#{p}=#{options[p]}" : nil
|
56
|
+
end.compact
|
57
|
+
|
58
|
+
path += '?' + params.join('&') if params.any?
|
59
|
+
client.get(path)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Sends a PATCH request to /subscriptions endpoint, updating the current subscription
|
63
|
+
# and returns the response.
|
64
|
+
#
|
65
|
+
# @param payload [Hash]
|
66
|
+
# @see https://docs.synapsepay.com/docs/update-subscription payload structure for
|
67
|
+
# updating subscription
|
68
|
+
#
|
69
|
+
# @raise [SynapsePayRest::Error] may return subclasses of error based on
|
70
|
+
# HTTP response from API
|
71
|
+
#
|
72
|
+
# @return [Hash] API response
|
73
|
+
def update(subscription_id:, payload:)
|
74
|
+
path = subscription_path(subscription_id: subscription_id)
|
75
|
+
client.patch(path, payload)
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def subscription_path(subscription_id: nil)
|
81
|
+
path = "/subscriptions"
|
82
|
+
path += "/#{subscription_id}" if subscription_id
|
83
|
+
path
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
@@ -11,7 +11,9 @@ module SynapsePayRest
|
|
11
11
|
# @return [SynapsePayRest::Nodes]
|
12
12
|
# @!attribute [rw] transactions
|
13
13
|
# @return [SynapsePayRest::Transactions]
|
14
|
-
|
14
|
+
# @!attribute [rw] subscriptions
|
15
|
+
# @return [SynapsePayRest::Subscriptions]
|
16
|
+
attr_accessor :http_client, :users, :nodes, :transactions, :subscriptions
|
15
17
|
|
16
18
|
# Alias for #transactions (legacy name)
|
17
19
|
alias_method :trans, :transactions
|
@@ -39,9 +41,10 @@ module SynapsePayRest
|
|
39
41
|
fingerprint: fingerprint,
|
40
42
|
ip_address: ip_address,
|
41
43
|
**options)
|
42
|
-
@users
|
43
|
-
@nodes
|
44
|
-
@transactions
|
44
|
+
@users = Users.new @http_client
|
45
|
+
@nodes = Nodes.new @http_client
|
46
|
+
@transactions = Transactions.new @http_client
|
47
|
+
@subscriptions = Subscriptions.new @http_client
|
45
48
|
end
|
46
49
|
end
|
47
50
|
end
|
@@ -33,15 +33,14 @@ module SynapsePayRest
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
# Creates an
|
36
|
+
# Creates an Unverified Node Class node via access token, belonging to this user
|
37
37
|
#
|
38
38
|
# @param user [SynapsePayRest::User] the user to whom the node belongs
|
39
39
|
# @param access_token [String] user's access token
|
40
40
|
#
|
41
41
|
# @raise [SynapsePayRest::Error]
|
42
42
|
#
|
43
|
-
# @return [
|
44
|
-
|
43
|
+
# @return [<SynapsePayRest::UnverifiedNode>]
|
45
44
|
def create_via_bank_login_mfa(user:, access_token:)
|
46
45
|
raise ArgumentError, 'user must be a User object' unless user.is_a?(User)
|
47
46
|
raise ArgumentError, 'access_token must be a String' unless access_token.is_a?(String)
|
@@ -88,10 +88,12 @@ module SynapsePayRest
|
|
88
88
|
account_class: response['info']['class'],
|
89
89
|
account_number: response['info']['account_num'],
|
90
90
|
routing_number: response['info']['routing_num'],
|
91
|
-
account_id: response['info']['account_id'],
|
92
91
|
address: response['info']['address'],
|
93
92
|
swift: response['info']['swift'],
|
94
|
-
ifsc: response['info']['ifsc']
|
93
|
+
ifsc: response['info']['ifsc'],
|
94
|
+
user_info: nil,
|
95
|
+
transactions: nil,
|
96
|
+
timeline: nil
|
95
97
|
}
|
96
98
|
|
97
99
|
if response['info']['correspondent_info']
|
@@ -121,6 +123,21 @@ module SynapsePayRest
|
|
121
123
|
args[:gateway_restricted] = extra['gateway_restricted']
|
122
124
|
end
|
123
125
|
|
126
|
+
if response['extra']['other']['info']
|
127
|
+
user_info = response['extra']['other']['info']
|
128
|
+
args[:user_info] = user_info
|
129
|
+
end
|
130
|
+
|
131
|
+
if response['extra']['other']['transactions']
|
132
|
+
transactions = response['extra']['transactions']
|
133
|
+
args[:transactions] = transactions
|
134
|
+
end
|
135
|
+
|
136
|
+
if response['timeline']
|
137
|
+
timeline = response['timeline']
|
138
|
+
args[:timeline] = timeline
|
139
|
+
end
|
140
|
+
|
124
141
|
self.new(**args)
|
125
142
|
end
|
126
143
|
|
@@ -30,7 +30,7 @@ module SynapsePayRest
|
|
30
30
|
# @raise [SynapsePayRest::Error] if HTTP error
|
31
31
|
#
|
32
32
|
# @return [SynapsePayRest::BaseNode] subclass depends on node type
|
33
|
-
def find(user:, id:, full_dehydrate:)
|
33
|
+
def find(user:, id:, full_dehydrate: 'no')
|
34
34
|
raise ArgumentError, 'user must be a User object' unless user.is_a?(User)
|
35
35
|
raise ArgumentError, 'id must be a String' unless id.is_a?(String)
|
36
36
|
|
@@ -0,0 +1,138 @@
|
|
1
|
+
module SynapsePayRest
|
2
|
+
# Represents a subscription record and holds methods for creating subscription instances
|
3
|
+
# from API calls. This is built on top of the SynapsePayRest::Subscription class and
|
4
|
+
# is intended to make it easier to use the API without knowing payload formats
|
5
|
+
# or knowledge of REST.
|
6
|
+
#
|
7
|
+
# @todo use mixins to remove duplication between Node and BaseNode.
|
8
|
+
class Subscription
|
9
|
+
attr_reader :id, :is_active, :scope, :url
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# Creates a new subscription in the API and returns a Subscription instance from the
|
13
|
+
# response data.
|
14
|
+
#
|
15
|
+
# @param client [SynapsePayRest::Client]
|
16
|
+
# @param scope [Array<String>]
|
17
|
+
# @param url [String]
|
18
|
+
#
|
19
|
+
# @raise [SynapsePayRest::Error] if HTTP error or invalid argument format
|
20
|
+
#
|
21
|
+
# @return [SynapsePayRest::Subscription]
|
22
|
+
def create(client:, url:, scope:, **options)
|
23
|
+
raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
|
24
|
+
raise ArgumentError, 'url must be a String' unless url.is_a? String
|
25
|
+
raise ArgumentError, 'scope must be an Array' unless scope.is_a? Array
|
26
|
+
|
27
|
+
payload = payload_for_create(url: url, scope: scope, **options)
|
28
|
+
response = client.subscriptions.create(payload: payload)
|
29
|
+
from_response(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Queries the API for a subscription by id and returns a Subscription instances if found.
|
33
|
+
#
|
34
|
+
# @param client [SynapsePayRest::Client]
|
35
|
+
# @param id [String] id of the subscription to find
|
36
|
+
#
|
37
|
+
# @raise [SynapsePayRest::Error] if user not found or invalid client credentials
|
38
|
+
#
|
39
|
+
# @return [SynapsePayRest::Subscription]
|
40
|
+
def find(client:, id:)
|
41
|
+
raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
|
42
|
+
raise ArgumentError, 'id must be a String' unless id.is_a?(String)
|
43
|
+
|
44
|
+
response = client.subscriptions.get(subscription_id: id)
|
45
|
+
from_response(response)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Queries the API for all subscriptions and returns them as Subscription instances.
|
49
|
+
#
|
50
|
+
# @param client [SynapsePayRest::Client]
|
51
|
+
# @param page [String,Integer] (optional) response will default to 1
|
52
|
+
# @param per_page [String,Integer] (optional) response will default to 20
|
53
|
+
#
|
54
|
+
# @raise [SynapsePayRest::Error] if HTTP error or invalid argument format
|
55
|
+
#
|
56
|
+
# @return [Array<SynapsePayRest::Subscription>]
|
57
|
+
def all(client:, page: nil, per_page: nil)
|
58
|
+
raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
|
59
|
+
[page, per_page].each do |arg|
|
60
|
+
if arg && (!arg.is_a?(Integer) || arg < 1)
|
61
|
+
raise ArgumentError, "#{arg} must be nil or an Integer >= 1"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
response = client.subscriptions.get(page: page, per_page: per_page)
|
65
|
+
multiple_from_response(response['subscriptions'])
|
66
|
+
end
|
67
|
+
|
68
|
+
# Updates the given key value pairs.
|
69
|
+
#
|
70
|
+
# @param is_active [boolean]
|
71
|
+
# @param url [String]
|
72
|
+
# @param scope [Array<String>]
|
73
|
+
#
|
74
|
+
# @raise [SynapsePayRest::Error] if HTTP error or invalid argument format
|
75
|
+
#
|
76
|
+
# @return [SynapsePayRest::Subscription] new instance corresponding to same API record
|
77
|
+
def update(client:, is_active:, url:, scope:, **options)
|
78
|
+
raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
|
79
|
+
|
80
|
+
payload = payload_for_update(is_active: is_active, url: url, scope: scope, **options)
|
81
|
+
response = client.subscriptions.update(payload: payload)
|
82
|
+
from_response(response)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Creates a Subscription from a response hash.
|
86
|
+
#
|
87
|
+
# @note Shouldn't need to call this directly.
|
88
|
+
def from_response(response)
|
89
|
+
args = {
|
90
|
+
id: response['_id'],
|
91
|
+
is_active: response['is_active'],
|
92
|
+
scope: response['scope'],
|
93
|
+
url: response['url']
|
94
|
+
}
|
95
|
+
self.new(args)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Calls from_response on each member of a response collection.
|
99
|
+
def multiple_from_response(response)
|
100
|
+
return [] if response.empty?
|
101
|
+
response.map { |subscription_data| from_response(subscription_data)}
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
# Converts #create args into API payload structure.
|
107
|
+
def payload_for_create(**options)
|
108
|
+
payload = {}
|
109
|
+
# must have one of these
|
110
|
+
payload['url'] = options[:url] if options[:url]
|
111
|
+
payload['scope'] = options[:scope] if options[:scope]
|
112
|
+
payload
|
113
|
+
end
|
114
|
+
|
115
|
+
# Converts #update args into API payload structure.
|
116
|
+
def payload_for_update(**options)
|
117
|
+
payload = {}
|
118
|
+
# must have one of these
|
119
|
+
payload['is_active'] = options[:is_active] if options[:is_active]
|
120
|
+
payload['url'] = options[:url] if options[:url]
|
121
|
+
payload['scope'] = options[:scope] if options[:scope]
|
122
|
+
payload
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
# @note Do not call directly. Use Subscription.create or other class method
|
128
|
+
# to instantiate via API action.
|
129
|
+
def initialize(**options)
|
130
|
+
options.each { |key, value| instance_variable_set("@#{key}", value) }
|
131
|
+
end
|
132
|
+
|
133
|
+
# Checks if two Subscription instances have same id (different instances of same record).
|
134
|
+
def ==(other)
|
135
|
+
other.instance_of?(self.class) && !id.nil? && id == other.id
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -10,10 +10,11 @@ module SynapsePayRest
|
|
10
10
|
:entity_scope, :birth_day, :birth_month, :birth_year,
|
11
11
|
:address_street, :address_city, :address_subdivision,
|
12
12
|
:address_postal_code, :address_country_code,
|
13
|
-
:physical_documents, :social_documents, :virtual_documents
|
13
|
+
:physical_documents, :social_documents, :virtual_documents,
|
14
|
+
:alias, :day, :month, :year, :screening_results
|
14
15
|
attr_reader :id, :permission_scope
|
15
16
|
|
16
|
-
class << self
|
17
|
+
class << self
|
17
18
|
# Creates a new base document in the API belonging to the provided user and
|
18
19
|
# returns a base document instance from the response data.
|
19
20
|
#
|
@@ -66,28 +67,27 @@ module SynapsePayRest
|
|
66
67
|
raise ArgumentError, 'virtual_documents be empty or contain VirtualDocument(s)'
|
67
68
|
end
|
68
69
|
|
69
|
-
base_document = BaseDocument.new(
|
70
|
-
user
|
71
|
-
email
|
72
|
-
phone_number
|
73
|
-
ip
|
74
|
-
name
|
75
|
-
aka
|
76
|
-
entity_type
|
77
|
-
entity_scope
|
78
|
-
birth_day
|
79
|
-
birth_month
|
80
|
-
birth_year
|
81
|
-
address_street
|
82
|
-
address_city
|
83
|
-
address_subdivision
|
84
|
-
address_postal_code
|
85
|
-
address_country_code
|
86
|
-
physical_documents
|
87
|
-
social_documents
|
88
|
-
virtual_documents
|
89
|
-
)
|
90
|
-
|
70
|
+
base_document = BaseDocument.new({
|
71
|
+
"user"=>user,
|
72
|
+
"email"=>email,
|
73
|
+
"phone_number"=>phone_number,
|
74
|
+
"ip"=>ip,
|
75
|
+
"name"=>name,
|
76
|
+
"aka"=>aka,
|
77
|
+
"entity_type"=>entity_type,
|
78
|
+
"entity_scope"=>entity_scope,
|
79
|
+
"birth_day"=>birth_day,
|
80
|
+
"birth_month"=>birth_month,
|
81
|
+
"birth_year"=>birth_year,
|
82
|
+
"address_street"=>address_street,
|
83
|
+
"address_city"=>address_city,
|
84
|
+
"address_subdivision"=>address_subdivision,
|
85
|
+
"address_postal_code"=>address_postal_code,
|
86
|
+
"address_country_code"=>address_country_code,
|
87
|
+
"physical_documents"=>physical_documents,
|
88
|
+
"social_documents"=>social_documents,
|
89
|
+
"virtual_documents"=>virtual_documents
|
90
|
+
})
|
91
91
|
base_document.submit
|
92
92
|
end
|
93
93
|
|
@@ -113,15 +113,42 @@ module SynapsePayRest
|
|
113
113
|
end
|
114
114
|
|
115
115
|
args = {
|
116
|
-
user
|
117
|
-
id
|
118
|
-
name
|
119
|
-
permission_scope
|
120
|
-
|
121
|
-
|
122
|
-
|
116
|
+
"user"=>user,
|
117
|
+
"id"=>base_document_data['id'],
|
118
|
+
"name"=>base_document_data['name'],
|
119
|
+
"permission_scope"=>base_document_data['permission_scope'],
|
120
|
+
"address_city"=>nil,
|
121
|
+
"address_country_code"=>nil,
|
122
|
+
"address_postal_code"=>nil,
|
123
|
+
"address_street"=>nil,
|
124
|
+
"address_subdivision"=>nil,
|
125
|
+
"alias"=>nil,
|
126
|
+
"day"=>nil,
|
127
|
+
"email"=>nil,
|
128
|
+
"entity_scope"=>nil,
|
129
|
+
"entity_type"=>nil,
|
130
|
+
"ip"=>nil,
|
131
|
+
"month"=>nil,
|
132
|
+
"phone_number"=>nil,
|
133
|
+
"year"=>nil,
|
134
|
+
"screening_results"=>nil,
|
135
|
+
"physical_documents"=>physical_docs,
|
136
|
+
"social_documents"=>social_docs,
|
137
|
+
"virtual_documents"=>virtual_docs
|
123
138
|
}
|
124
139
|
|
140
|
+
other_keys = base_document_data.keys
|
141
|
+
|
142
|
+
["physical_docs", "social_docs", "virtual_docs"].each do |item|
|
143
|
+
other_keys.delete_at(other_keys.index(item))
|
144
|
+
end
|
145
|
+
|
146
|
+
for key in other_keys do
|
147
|
+
if base_document_data.has_key?(key)
|
148
|
+
args[key] = base_document_data[key]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
125
152
|
base_doc = self.new(args)
|
126
153
|
[physical_docs, social_docs, virtual_docs].flatten.each do |doc|
|
127
154
|
doc.base_document = base_doc
|
@@ -133,28 +160,29 @@ module SynapsePayRest
|
|
133
160
|
end
|
134
161
|
|
135
162
|
# @note It should not be necessary to call this method directly.
|
136
|
-
def initialize(
|
137
|
-
@id = args[
|
138
|
-
@permission_scope = args[
|
139
|
-
@user = args[
|
140
|
-
@email = args[
|
141
|
-
@phone_number = args[
|
142
|
-
@ip = args[
|
143
|
-
@name = args[
|
144
|
-
@aka = args[
|
145
|
-
@entity_type = args[
|
146
|
-
@entity_scope = args[
|
147
|
-
@birth_day = args[
|
148
|
-
@birth_month = args[
|
149
|
-
@birth_year = args[
|
150
|
-
@address_street = args[
|
151
|
-
@address_city = args[
|
152
|
-
@address_subdivision = args[
|
153
|
-
@address_postal_code = args[
|
154
|
-
@address_country_code = args[
|
155
|
-
@
|
156
|
-
@
|
157
|
-
@
|
163
|
+
def initialize(args)
|
164
|
+
@id = args["id"]
|
165
|
+
@permission_scope = args["permission_scope"]
|
166
|
+
@user = args["user"]
|
167
|
+
@email = args["email"]
|
168
|
+
@phone_number = args["phone_number"]
|
169
|
+
@ip = args["ip"]
|
170
|
+
@name = args["name"]
|
171
|
+
@aka = args["aka"]
|
172
|
+
@entity_type = args["entity_type"]
|
173
|
+
@entity_scope = args["entity_scope"]
|
174
|
+
@birth_day = args["birth_day"]
|
175
|
+
@birth_month = args["birth_month"]
|
176
|
+
@birth_year = args["birth_year"]
|
177
|
+
@address_street = args["address_street"]
|
178
|
+
@address_city = args["address_city"]
|
179
|
+
@address_subdivision = args["address_subdivision"]
|
180
|
+
@address_postal_code = args["address_postal_code"]
|
181
|
+
@address_country_code = args["address_country_code"]
|
182
|
+
@screening_results = args["screening_results"]
|
183
|
+
@physical_documents = args["physical_documents"]
|
184
|
+
@social_documents = args["social_documents"]
|
185
|
+
@virtual_documents = args["virtual_documents"]
|
158
186
|
end
|
159
187
|
|
160
188
|
# Submits the base document to the API.
|
@@ -8,7 +8,7 @@ module SynapsePayRest
|
|
8
8
|
# @return [SynapsePayRest::BaseDocument] the base document to which the document belongs
|
9
9
|
# @!attribute [rw] status
|
10
10
|
# @return [String] https://docs.synapsepay.com/docs/user-resources#section-document-status
|
11
|
-
attr_accessor :base_document, :status, :id, :type, :value, :last_updated
|
11
|
+
attr_accessor :base_document, :status, :id, :type, :value, :last_updated, :document_value, :meta
|
12
12
|
|
13
13
|
class << self
|
14
14
|
# Creates a document instance but does not submit it to the API. Use
|
@@ -35,12 +35,23 @@ module SynapsePayRest
|
|
35
35
|
|
36
36
|
# @note Do not call this method. It is used by child classes only.
|
37
37
|
def from_response(data)
|
38
|
-
self.new(
|
39
|
-
type:
|
40
|
-
id:
|
41
|
-
status:
|
42
|
-
last_updated:
|
38
|
+
doc = self.new(
|
39
|
+
type: data['document_type'],
|
40
|
+
id: data['id'],
|
41
|
+
status: data['status'],
|
42
|
+
last_updated: data['last_updated'],
|
43
|
+
document_value: nil,
|
44
|
+
meta: nil
|
43
45
|
)
|
46
|
+
|
47
|
+
if data.has_key?('document_value')
|
48
|
+
doc.document_value = data['document_value']
|
49
|
+
end
|
50
|
+
|
51
|
+
if data.has_key?('meta')
|
52
|
+
doc.meta = data['meta']
|
53
|
+
end
|
54
|
+
doc
|
44
55
|
end
|
45
56
|
end
|
46
57
|
|
@@ -53,6 +64,8 @@ module SynapsePayRest
|
|
53
64
|
# only exist for fetched data
|
54
65
|
@status = options[:status]
|
55
66
|
@last_updated = options[:last_updated]
|
67
|
+
@document_value = options[:document_value]
|
68
|
+
@meta = options[:meta]
|
56
69
|
end
|
57
70
|
|
58
71
|
# Checks if two Document instances have same id (different instances of same record).
|
@@ -13,7 +13,7 @@ module SynapsePayRest
|
|
13
13
|
# @return [String] https://docs.synapsepay.com/docs/user-resources#section-user-permissions
|
14
14
|
attr_reader :client, :id, :logins, :phone_numbers, :legal_names, :note,
|
15
15
|
:supp_id, :is_business, :cip_tag, :permission
|
16
|
-
attr_accessor :refresh_token, :base_documents
|
16
|
+
attr_accessor :refresh_token, :base_documents, :oauth_key, :expires_in, :flag, :ips
|
17
17
|
|
18
18
|
class << self
|
19
19
|
# Creates a new user in the API and returns a User instance from the
|
@@ -69,11 +69,12 @@ module SynapsePayRest
|
|
69
69
|
# @raise [SynapsePayRest::Error] if user not found or invalid client credentials
|
70
70
|
#
|
71
71
|
# @return [SynapsePayRest::User]
|
72
|
-
def find(client:, id:, full_dehydrate:)
|
72
|
+
def find(client:, id:, full_dehydrate:'no')
|
73
73
|
raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
|
74
74
|
raise ArgumentError, 'id must be a String' unless id.is_a?(String)
|
75
75
|
|
76
76
|
response = client.users.get(user_id: id, full_dehydrate: full_dehydrate)
|
77
|
+
|
77
78
|
from_response(client, response)
|
78
79
|
end
|
79
80
|
|
@@ -157,9 +158,21 @@ module SynapsePayRest
|
|
157
158
|
note: response['extra']['note'],
|
158
159
|
supp_id: response['extra']['supp_id'],
|
159
160
|
is_business: response['extra']['is_business'],
|
160
|
-
cip_tag: response['extra']['cip_tag']
|
161
|
+
cip_tag: response['extra']['cip_tag'],
|
162
|
+
flag: nil,
|
163
|
+
ips: nil,
|
164
|
+
oauth_key: nil,
|
165
|
+
expires_in: nil
|
161
166
|
)
|
162
167
|
|
168
|
+
if response.has_key?('flag')
|
169
|
+
user.flag = response['flag']
|
170
|
+
end
|
171
|
+
|
172
|
+
if response.has_key?('ips')
|
173
|
+
user.ips = response['ips']
|
174
|
+
end
|
175
|
+
|
163
176
|
unless response['documents'].empty?
|
164
177
|
base_documents = BaseDocument.from_response(user, response)
|
165
178
|
user.base_documents = base_documents
|
@@ -186,9 +199,11 @@ module SynapsePayRest
|
|
186
199
|
#
|
187
200
|
# @raise [SynapsePayRest::Error]
|
188
201
|
#
|
189
|
-
# @return [SynapsePayRest::User] (
|
202
|
+
# @return [SynapsePayRest::User] (new instance with updated tokens)
|
190
203
|
def authenticate
|
191
|
-
client.users.refresh(user_id: id, payload: payload_for_refresh)
|
204
|
+
response = client.users.refresh(user_id: id, payload: payload_for_refresh)
|
205
|
+
self.oauth_key = response['oauth_key']
|
206
|
+
self.expires_in = response['expires_in']
|
192
207
|
self
|
193
208
|
end
|
194
209
|
|
@@ -303,6 +318,19 @@ module SynapsePayRest
|
|
303
318
|
update(phone_number: phone_number)
|
304
319
|
end
|
305
320
|
|
321
|
+
# Add a legal_name to the user.
|
322
|
+
#
|
323
|
+
# @param legal_name [String]
|
324
|
+
#
|
325
|
+
# @raise [SynapsePayRest::Error]
|
326
|
+
#
|
327
|
+
# @return [SynapsePayRest::User] new instance corresponding to same API record
|
328
|
+
def add_legal_name(legal_name)
|
329
|
+
raise ArgumentError, 'legal_name must be a String' unless legal_name.is_a? String
|
330
|
+
|
331
|
+
update(legal_name: legal_name)
|
332
|
+
end
|
333
|
+
|
306
334
|
# Removes a phone_number from the user.
|
307
335
|
#
|
308
336
|
# @param phone_number [String]
|
@@ -441,6 +469,18 @@ module SynapsePayRest
|
|
441
469
|
AchUsNode.create_via_bank_login(user: self, **options)
|
442
470
|
end
|
443
471
|
|
472
|
+
# Creates an Unverified Node Class node via access token, belonging to this user
|
473
|
+
#
|
474
|
+
# @param access_token [String]
|
475
|
+
# @see https://synapsepay.com/api/v3/institutions/show valid bank_name options
|
476
|
+
#
|
477
|
+
# @raise [SynapsePayRest::Error]
|
478
|
+
#
|
479
|
+
# @return [<SynapsePayRest::UnverifiedNode>]
|
480
|
+
def create_ach_us_nodes_via_bank_login_mfa(**options)
|
481
|
+
AchUsNode.create_via_bank_login_mfa(user: self, **options)
|
482
|
+
end
|
483
|
+
|
444
484
|
# Creates an EFT-IND node.
|
445
485
|
#
|
446
486
|
# @param nickname [String] nickname for the node
|
data/lib/synapse_pay_rest.rb
CHANGED
@@ -6,6 +6,7 @@ require 'synapse_pay_rest/http_client'
|
|
6
6
|
require 'synapse_pay_rest/api/users'
|
7
7
|
require 'synapse_pay_rest/api/nodes'
|
8
8
|
require 'synapse_pay_rest/api/transactions'
|
9
|
+
require 'synapse_pay_rest/api/subscriptions'
|
9
10
|
|
10
11
|
# general library classes
|
11
12
|
require 'synapse_pay_rest/error'
|
@@ -52,6 +53,9 @@ require 'synapse_pay_rest/models/node/node'
|
|
52
53
|
# transaction-related classes
|
53
54
|
require 'synapse_pay_rest/models/transaction/transaction'
|
54
55
|
|
56
|
+
# subscription-related classes
|
57
|
+
require 'synapse_pay_rest/models/subscription/subscription'
|
58
|
+
|
55
59
|
# Namespace for all SynapsePayRest classes and modules
|
56
60
|
module SynapsePayRest
|
57
61
|
# Modifies the default method to print a warning when deprecated constants
|
data/samples.md
CHANGED
@@ -44,9 +44,7 @@ args = {
|
|
44
44
|
# (optional) uses API default of 20 unless specified, larger values take longer
|
45
45
|
per_page: 50,
|
46
46
|
# (optional) filters by name/email match
|
47
|
-
query: nil
|
48
|
-
# (optional) returns all KYC on user
|
49
|
-
full_dehydrate: yes
|
47
|
+
query: nil
|
50
48
|
}
|
51
49
|
|
52
50
|
users = SynapsePayRest::User.all(args)
|
@@ -56,8 +54,11 @@ users = SynapsePayRest::User.all(args)
|
|
56
54
|
#### Find a User by User ID
|
57
55
|
|
58
56
|
```ruby
|
59
|
-
user = SynapsePayRest::User.find(client: client, id: '57e97ab786c2737f4ccd4dc1'
|
57
|
+
user = SynapsePayRest::User.find(client: client, id: '57e97ab786c2737f4ccd4dc1')
|
60
58
|
# => #<SynapsePayRest::User>
|
59
|
+
|
60
|
+
# full_dehydrate: 'yes' optional, see docs for response example (https://docs.synapsepay.com/docs/get-user)
|
61
|
+
user = SynapsePayRest::User.find(client: client, id: '57e97ab786c2737f4ccd4dc1', full_dehydrate: 'yes')
|
61
62
|
```
|
62
63
|
|
63
64
|
#### Search for a User by Name/Email
|
@@ -311,9 +312,12 @@ node = user.find_node(id: '1a3efa1231as2f')
|
|
311
312
|
##### b) Node#find
|
312
313
|
|
313
314
|
```ruby
|
314
|
-
|
315
|
-
node = SynapsePayRest::Node.find(user: user, id: '1a3efa1231as2f', full_dehydrate: 'no')
|
315
|
+
node = SynapsePayRest::Node.find(user: user, id: '1a3efa1231as2f')
|
316
316
|
# => #<SynapsePayRest::EftNpNode>
|
317
|
+
|
318
|
+
# full_dehydrate: 'yes' (optional) returns all trans data on node
|
319
|
+
node = SynapsePayRest::Node.find(user: user, id: '1a3efa1231as2f', full_dehydrate: 'yes')
|
320
|
+
|
317
321
|
```
|
318
322
|
|
319
323
|
#### Create ACH-US Node(s) via Bank Login
|
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.
|
4
|
+
version: 3.2.3
|
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-05-
|
12
|
+
date: 2017-05-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- bin/console
|
153
153
|
- lib/synapse_pay_rest.rb
|
154
154
|
- lib/synapse_pay_rest/api/nodes.rb
|
155
|
+
- lib/synapse_pay_rest/api/subscriptions.rb
|
155
156
|
- lib/synapse_pay_rest/api/transactions.rb
|
156
157
|
- lib/synapse_pay_rest/api/users.rb
|
157
158
|
- lib/synapse_pay_rest/client.rb
|
@@ -171,6 +172,7 @@ files:
|
|
171
172
|
- lib/synapse_pay_rest/models/node/unverified_node.rb
|
172
173
|
- lib/synapse_pay_rest/models/node/wire_int_node.rb
|
173
174
|
- lib/synapse_pay_rest/models/node/wire_us_node.rb
|
175
|
+
- lib/synapse_pay_rest/models/subscription/subscription.rb
|
174
176
|
- lib/synapse_pay_rest/models/transaction/transaction.rb
|
175
177
|
- lib/synapse_pay_rest/models/user/base_document.rb
|
176
178
|
- lib/synapse_pay_rest/models/user/document.rb
|