blockchyp 1.24.14 → 2.0.0.pre.alpha7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +1 -41
- data/README.md +441 -3551
- data/lib/blockchyp/version.rb +1 -1
- data/lib/blockchyp.rb +41 -366
- data/lib/blockchyp_client.rb +125 -207
- data/test/boolean_prompt_test.rb +18 -32
- data/test/heartbeat_test.rb +10 -10
- data/test/new_transaction_display_test.rb +50 -44
- data/test/pan_charge_test.rb +27 -44
- data/test/pan_enroll_test.rb +25 -45
- data/test/pan_preauth_test.rb +26 -43
- data/test/simple_batch_close_test.rb +23 -37
- data/test/simple_capture_test.rb +21 -38
- data/test/simple_gift_activate_test.rb +15 -30
- data/test/simple_message_test.rb +15 -29
- data/test/simple_ping_test.rb +14 -28
- data/test/simple_refund_test.rb +22 -40
- data/test/simple_reversal_test.rb +22 -39
- data/test/simple_void_test.rb +22 -39
- data/test/terminal_charge_test.rb +25 -40
- data/test/terminal_clear_test.rb +14 -28
- data/test/terminal_ebt_balance_test.rb +16 -30
- data/test/terminal_ebt_charge_test.rb +27 -42
- data/test/terminal_enroll_test.rb +24 -39
- data/test/terminal_gift_card_balance_test.rb +15 -29
- data/test/terminal_keyed_charge_test.rb +26 -41
- data/test/terminal_manual_ebt_charge_test.rb +28 -43
- data/test/terminal_preauth_test.rb +25 -40
- data/test/terms_and_conditions_test.rb +19 -33
- data/test/test_helper.rb +10 -9
- data/test/text_prompt_test.rb +15 -29
- data/test/update_transaction_display_test.rb +50 -44
- metadata +5 -64
- data/test/activate_terminal_test.rb +0 -45
- data/test/add_test_merchant_test.rb +0 -56
- data/test/batch_history_test.rb +0 -54
- data/test/cancel_payment_link_test.rb +0 -72
- data/test/capture_signature_test.rb +0 -46
- data/test/deactivate_terminal_test.rb +0 -42
- data/test/delete_branding_asset_test.rb +0 -50
- data/test/delete_customer_test.rb +0 -55
- data/test/delete_media_asset_test.rb +0 -53
- data/test/delete_queued_transaction_test.rb +0 -56
- data/test/delete_slide_show_test.rb +0 -50
- data/test/delete_survey_question_test.rb +0 -51
- data/test/delete_test_merchant_test.rb +0 -59
- data/test/delete_token_test.rb +0 -55
- data/test/empty_branding_asset_test.rb +0 -44
- data/test/empty_slide_show_test.rb +0 -45
- data/test/gateway_timeout_test.rb +0 -49
- data/test/get_customer_test.rb +0 -55
- data/test/get_merchants_test.rb +0 -52
- data/test/invite_merchant_user_test.rb +0 -45
- data/test/link_token_test.rb +0 -56
- data/test/list_queued_transactions_test.rb +0 -55
- data/test/list_terminals_test.rb +0 -42
- data/test/media_asset_test.rb +0 -57
- data/test/media_test.rb +0 -42
- data/test/media_upload_test.rb +0 -52
- data/test/merchant_platforms_test.rb +0 -59
- data/test/merchant_profile_test.rb +0 -43
- data/test/merchant_users_test.rb +0 -42
- data/test/partial_refund_test.rb +0 -58
- data/test/search_customer_test.rb +0 -55
- data/test/send_payment_link_test.rb +0 -67
- data/test/simple_locate_test.rb +0 -44
- data/test/slide_show_test.rb +0 -51
- data/test/slide_shows_test.rb +0 -49
- data/test/survey_question_test.rb +0 -48
- data/test/survey_questions_test.rb +0 -50
- data/test/survey_results_test.rb +0 -48
- data/test/tc_delete_template_test.rb +0 -51
- data/test/tc_entry_test.rb +0 -56
- data/test/tc_log_test.rb +0 -42
- data/test/tc_template_test.rb +0 -53
- data/test/tc_template_update_test.rb +0 -48
- data/test/tc_templates_test.rb +0 -42
- data/test/terminal_branding_test.rb +0 -42
- data/test/terminal_queued_transaction_test.rb +0 -51
- data/test/terminal_status_test.rb +0 -45
- data/test/terminal_timeout_test.rb +0 -46
- data/test/testdata/aviato.png +0 -0
- data/test/token_metadata_test.rb +0 -55
- data/test/transaction_history_test.rb +0 -54
- data/test/unlink_token_test.rb +0 -56
- data/test/update_branding_asset_test.rb +0 -62
- data/test/update_customer_test.rb +0 -49
- data/test/update_merchant_platforms_test.rb +0 -61
- data/test/update_merchant_test.rb +0 -60
- data/test/update_slide_show_test.rb +0 -60
- data/test/update_survey_question_test.rb +0 -47
- data/test/upload_status_test.rb +0 -53
data/lib/blockchyp_client.rb
CHANGED
@@ -21,7 +21,6 @@ module BlockChyp
|
|
21
21
|
@signing_key = signing_key
|
22
22
|
@gateway_host = 'https://api.blockchyp.com'
|
23
23
|
@test_gateway_host = 'https://test.blockchyp.com'
|
24
|
-
@dashboard_host = 'https://dashboard.blockchyp.com'
|
25
24
|
@https = false
|
26
25
|
@route_cache_location = File.join(Dir.tmpdir, '.blockchyp_route')
|
27
26
|
@route_cache_ttl = 60
|
@@ -39,7 +38,6 @@ module BlockChyp
|
|
39
38
|
attr_reader :offline_fixed_key
|
40
39
|
attr_accessor :gateway_host
|
41
40
|
attr_accessor :test_gateway_host
|
42
|
-
attr_accessor :dashboard_host
|
43
41
|
attr_accessor :https
|
44
42
|
attr_accessor :route_cache_ttl
|
45
43
|
attr_accessor :gateway_timeout
|
@@ -47,7 +45,25 @@ module BlockChyp
|
|
47
45
|
attr_accessor :offline_cache_enabled
|
48
46
|
attr_accessor :terminal_connect_timeout
|
49
47
|
attr_accessor :route_cache_location
|
50
|
-
|
48
|
+
|
49
|
+
def gateway_get(path, test)
|
50
|
+
path = resolve_gateway_url(path, test)
|
51
|
+
puts 'GET: ' + path
|
52
|
+
uri = URI(path)
|
53
|
+
req = Net::HTTP::Get.new(uri)
|
54
|
+
headers = generate_gateway_headers
|
55
|
+
headers.each do |key, value|
|
56
|
+
req[key] = value
|
57
|
+
end
|
58
|
+
res = Net::HTTP.new(uri.host, uri.port).start do |inner_http|
|
59
|
+
inner_http.request(req)
|
60
|
+
end
|
61
|
+
if res.is_a?(Net::HTTPSuccess)
|
62
|
+
JSON.parse(res.body)
|
63
|
+
else
|
64
|
+
raise res.message
|
65
|
+
end
|
66
|
+
end
|
51
67
|
|
52
68
|
def generate_gateway_headers
|
53
69
|
nonce = CryptoUtils.generate_nonce
|
@@ -68,213 +84,134 @@ module BlockChyp
|
|
68
84
|
OpenSSL::HMAC.hexdigest('SHA256', CryptoUtils.hex2bin(signing_key), canonical_string)
|
69
85
|
end
|
70
86
|
|
71
|
-
def
|
72
|
-
url =
|
73
|
-
|
74
|
-
|
75
|
-
|
87
|
+
def resolve_gateway_url(path, test)
|
88
|
+
url = if test
|
89
|
+
test_gateway_host
|
90
|
+
else
|
91
|
+
gateway_host
|
92
|
+
end
|
76
93
|
|
77
|
-
|
78
|
-
URI.parse(dashboard_host + path)
|
94
|
+
url + path
|
79
95
|
end
|
80
96
|
|
81
97
|
def generate_error_response(msg)
|
82
|
-
|
83
|
-
success
|
84
|
-
error
|
85
|
-
responseDescription
|
86
|
-
|
98
|
+
[
|
99
|
+
'success' => false,
|
100
|
+
'error' => msg,
|
101
|
+
'responseDescription' => msg
|
102
|
+
]
|
87
103
|
end
|
88
104
|
|
89
|
-
def route_terminal_request(
|
90
|
-
|
91
|
-
return gateway_request(
|
105
|
+
def route_terminal_request(request, terminal_path, gateway_path, method)
|
106
|
+
if request['terminalName'].nil?
|
107
|
+
return gateway_request(gateway_path, request, method)
|
92
108
|
end
|
93
109
|
|
94
|
-
route = resolve_terminal_route(request[
|
110
|
+
route = resolve_terminal_route(request['terminalName'])
|
95
111
|
if !route
|
96
112
|
return generate_error_response('Unkown Terminal')
|
97
|
-
elsif route[
|
98
|
-
return gateway_request(
|
113
|
+
elsif route['cloudRelayEnabled']
|
114
|
+
return gateway_request(gateway_path, request, method)
|
99
115
|
end
|
100
116
|
|
101
|
-
terminal_request(
|
117
|
+
terminal_request(route, terminal_path, request, method, true)
|
102
118
|
end
|
103
119
|
|
104
|
-
def terminal_request(
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
wrapped_request = {
|
115
|
-
apiKey: tx_creds[:apiKey],
|
116
|
-
bearerToken: tx_creds[:bearerToken],
|
117
|
-
signingKey: tx_creds[:signingKey],
|
118
|
-
request: request
|
120
|
+
def terminal_request(route, path, request, method, open_retry)
|
121
|
+
url = resolve_terminal_url(route, path)
|
122
|
+
|
123
|
+
tx_creds = route['transientCredentials']
|
124
|
+
|
125
|
+
terminal_request = {
|
126
|
+
'apiKey' => tx_creds['apiKey'],
|
127
|
+
'bearerToken' => tx_creds['bearerToken'],
|
128
|
+
'signingKey' => tx_creds['signingKey'],
|
129
|
+
'request' => request
|
119
130
|
}
|
120
131
|
|
121
|
-
|
132
|
+
puts method + ': ' + url
|
133
|
+
puts terminal_request.to_json
|
122
134
|
|
123
|
-
|
124
|
-
|
135
|
+
uri = URI(url)
|
136
|
+
req = if method == 'PUT'
|
137
|
+
Net::HTTP::Put.new(uri)
|
138
|
+
else
|
139
|
+
Net::HTTP::Post.new(uri)
|
140
|
+
end
|
141
|
+
json = terminal_request.to_json
|
125
142
|
req['Content-Type'] = 'application/json'
|
126
143
|
req['Content-Length'] = json.length
|
127
144
|
req.body = json
|
128
|
-
|
145
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
146
|
+
http.open_timeout = terminal_connect_timeout
|
147
|
+
http.read_timeout = terminal_timeout
|
129
148
|
begin
|
130
|
-
|
149
|
+
res = http.start do |inner_http|
|
150
|
+
inner_http.request(req)
|
151
|
+
end
|
131
152
|
rescue Net::OpenTimeout, Errno::EHOSTDOWN, Errno::EHOSTUNREACH, Errno::ETIMEDOUT, Errno::ENETUNREACH
|
132
153
|
if open_retry
|
133
|
-
evict(route[
|
134
|
-
route = resolve_terminal_route(route[
|
135
|
-
return terminal_request(
|
154
|
+
evict(route['terminalName'])
|
155
|
+
route = resolve_terminal_route(route['terminalName'])
|
156
|
+
return terminal_request(route, path, request, method, false)
|
136
157
|
end
|
137
|
-
raise
|
138
158
|
end
|
139
|
-
if
|
140
|
-
|
159
|
+
if res.is_a?(Net::HTTPSuccess)
|
160
|
+
puts 'Response: ' + res.body
|
161
|
+
JSON.parse(res.body)
|
141
162
|
else
|
142
|
-
raise
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def get_http_request(method, uri)
|
147
|
-
case method
|
148
|
-
when 'GET'
|
149
|
-
Net::HTTP::Get.new(uri.request_uri)
|
150
|
-
when 'PUT'
|
151
|
-
Net::HTTP::Put.new(uri.request_uri)
|
152
|
-
when 'POST'
|
153
|
-
Net::HTTP::Post.new(uri.request_uri)
|
154
|
-
when 'DELETE'
|
155
|
-
Net::HTTP::Delete.new(uri.request_uri)
|
163
|
+
raise res.message
|
156
164
|
end
|
157
165
|
end
|
158
166
|
|
159
|
-
def
|
167
|
+
def resolve_terminal_url(route, path)
|
160
168
|
url = if https
|
161
169
|
'https://'
|
162
170
|
else
|
163
171
|
'http://'
|
164
172
|
end
|
165
|
-
url += route[
|
173
|
+
url += route['ipAddress']
|
166
174
|
port = if https
|
167
175
|
':8443'
|
168
176
|
else
|
169
177
|
':8080'
|
170
178
|
end
|
171
|
-
|
172
|
-
end
|
173
|
-
|
174
|
-
def dashboard_request(method, path, request = nil)
|
175
|
-
uri = resolve_dashboard_uri(path, request)
|
176
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
177
|
-
http.use_ssl = uri.instance_of?(URI::HTTPS)
|
178
|
-
timeout = get_timeout(request, gateway_timeout)
|
179
|
-
http.open_timeout = timeout
|
180
|
-
http.read_timeout = timeout
|
181
|
-
|
182
|
-
req = get_http_request(method, uri)
|
183
|
-
|
184
|
-
req['User-Agent'] = user_agent
|
185
|
-
unless request.nil?
|
186
|
-
json = request.to_json
|
187
|
-
req['Content-Type'] = 'application/json'
|
188
|
-
req['Content-Length'] = json.length
|
189
|
-
req.body = json
|
190
|
-
end
|
191
|
-
|
192
|
-
headers = generate_gateway_headers
|
193
|
-
headers.each do |key, value|
|
194
|
-
req[key] = value
|
195
|
-
end
|
196
|
-
|
197
|
-
response = http.request(req)
|
198
|
-
|
199
|
-
if response.is_a?(Net::HTTPSuccess)
|
200
|
-
JSON.parse(response.body, symbolize_names: true)
|
201
|
-
else
|
202
|
-
raise response.message
|
203
|
-
end
|
179
|
+
url + port + path
|
204
180
|
end
|
205
181
|
|
206
|
-
def
|
207
|
-
|
208
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
209
|
-
http.use_ssl = uri.instance_of?(URI::HTTPS)
|
210
|
-
timeout = get_timeout(request, gateway_timeout)
|
211
|
-
http.open_timeout = timeout
|
212
|
-
http.read_timeout = timeout
|
213
|
-
|
214
|
-
req = get_http_request("POST", uri)
|
215
|
-
req.body = content
|
216
|
-
req['User-Agent'] = user_agent
|
217
|
-
req['Content-Type'] = 'application/octet-stream'
|
218
|
-
|
219
|
-
if request[:fileName]
|
220
|
-
req['X-Upload-File-Name'] = request[:fileName]
|
221
|
-
end
|
222
|
-
|
223
|
-
if request[:uploadId]
|
224
|
-
req['X-Upload-ID'] = request[:uploadId]
|
225
|
-
end
|
182
|
+
def gateway_request(path, request, method)
|
183
|
+
url = resolve_gateway_url(path, request['test'])
|
226
184
|
|
227
|
-
|
228
|
-
|
229
|
-
req['Content-Length'] = request[:fileSize]
|
230
|
-
end
|
185
|
+
puts method + ': ' + url
|
186
|
+
puts request.to_json
|
231
187
|
|
188
|
+
uri = URI(url)
|
189
|
+
req = if method == 'PUT'
|
190
|
+
Net::HTTP::Put.new(uri)
|
191
|
+
else
|
192
|
+
Net::HTTP::Post.new(uri)
|
193
|
+
end
|
194
|
+
json = request.to_json
|
195
|
+
req['Content-Type'] = 'application/json'
|
196
|
+
req['Content-Length'] = json.length
|
232
197
|
headers = generate_gateway_headers
|
233
198
|
headers.each do |key, value|
|
234
199
|
req[key] = value
|
235
200
|
end
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
if response.is_a?(Net::HTTPSuccess)
|
240
|
-
JSON.parse(response.body, symbolize_names: true)
|
241
|
-
else
|
242
|
-
raise response.message
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
def gateway_request(method, path, request = nil, relay = false)
|
247
|
-
uri = resolve_gateway_uri(path, request)
|
248
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
249
|
-
http.use_ssl = uri.instance_of?(URI::HTTPS)
|
250
|
-
timeout = get_timeout(request, relay ? terminal_timeout : gateway_timeout)
|
251
|
-
http.open_timeout = timeout
|
252
|
-
http.read_timeout = timeout
|
253
|
-
|
254
|
-
req = get_http_request(method, uri)
|
255
|
-
|
256
|
-
req['User-Agent'] = user_agent
|
257
|
-
unless request.nil?
|
258
|
-
json = request.to_json
|
259
|
-
req['Content-Type'] = 'application/json'
|
260
|
-
req['Content-Length'] = json.length
|
261
|
-
req.body = json
|
262
|
-
end
|
263
|
-
|
264
|
-
headers = generate_gateway_headers
|
265
|
-
headers.each do |key, value|
|
266
|
-
req[key] = value
|
201
|
+
req.body = json
|
202
|
+
res = Net::HTTP.new(uri.host, uri.port).start do |http|
|
203
|
+
http.request(req)
|
267
204
|
end
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
if response.is_a?(Net::HTTPSuccess)
|
272
|
-
JSON.parse(response.body, symbolize_names: true)
|
205
|
+
if res.is_a?(Net::HTTPSuccess)
|
206
|
+
puts 'Response: ' + res.body
|
207
|
+
JSON.parse(res.body)
|
273
208
|
else
|
274
|
-
raise
|
209
|
+
raise res.message
|
275
210
|
end
|
276
211
|
end
|
277
212
|
|
213
|
+
attr_accessor :routeCache
|
214
|
+
|
278
215
|
def resolve_terminal_route(terminal_name)
|
279
216
|
route = route_cache_get(terminal_name, false)
|
280
217
|
|
@@ -286,8 +223,8 @@ module BlockChyp
|
|
286
223
|
|
287
224
|
ttl = Time.now.utc + (route_cache_ttl * 60)
|
288
225
|
route_cache_entry = {}
|
289
|
-
route_cache_entry[
|
290
|
-
route_cache_entry[
|
226
|
+
route_cache_entry['route'] = route
|
227
|
+
route_cache_entry['ttl'] = ttl
|
291
228
|
@route_cache[api_key + terminal_name] = route_cache_entry
|
292
229
|
update_offline_cache(route_cache_entry)
|
293
230
|
end
|
@@ -298,21 +235,19 @@ module BlockChyp
|
|
298
235
|
if offline_cache_enabled
|
299
236
|
offline_cache = read_offline_cache
|
300
237
|
offline_entry = route_cache_entry.clone
|
301
|
-
route = route_cache_entry[
|
302
|
-
tx_creds = route[
|
303
|
-
tx_creds[
|
304
|
-
tx_creds[
|
305
|
-
tx_creds[
|
306
|
-
route[
|
307
|
-
offline_entry[
|
308
|
-
offline_cache[
|
238
|
+
route = route_cache_entry['route'].clone
|
239
|
+
tx_creds = route['transientCredentials'].clone
|
240
|
+
tx_creds['apiKey'] = encrypt(tx_creds['api_key'])
|
241
|
+
tx_creds['bearerToken'] = encrypt(tx_creds['bearerToken'])
|
242
|
+
tx_creds['signingKey'] = encrypt(tx_creds['signingKey'])
|
243
|
+
route['transientCredentials'] = tx_creds
|
244
|
+
offline_entry['route'] = route
|
245
|
+
offline_cache[apiKey + route['terminalName']] = offline_entry
|
309
246
|
File.write(route_cache_location, offline_cache.to_json)
|
310
247
|
end
|
311
248
|
end
|
312
249
|
|
313
250
|
def encrypt(plain_text)
|
314
|
-
return plain_text if plain_text.nil? || plain_text.empty?
|
315
|
-
|
316
251
|
cipher = OpenSSL::Cipher::AES256.new(:CBC)
|
317
252
|
cipher.encrypt
|
318
253
|
cipher.key = derive_offline_key
|
@@ -322,12 +257,8 @@ module BlockChyp
|
|
322
257
|
end
|
323
258
|
|
324
259
|
def decrypt(cipher_text)
|
325
|
-
return cipher_text if cipher_text.nil? || cipher_text.empty?
|
326
|
-
|
327
260
|
tokens = cipher_text.split(':')
|
328
261
|
|
329
|
-
return cipher_text if tokens[0].nil? || tokens[1].nil?
|
330
|
-
|
331
262
|
iv = Base64.decode64(tokens[0])
|
332
263
|
cp = Base64.decode64(tokens[1])
|
333
264
|
|
@@ -344,9 +275,9 @@ module BlockChyp
|
|
344
275
|
end
|
345
276
|
|
346
277
|
def request_route_from_gateway(terminal_name)
|
347
|
-
route =
|
348
|
-
if !route.nil? && !route[
|
349
|
-
route[
|
278
|
+
route = gateway_get('/api/terminal-route?terminal=' + CGI.escape(terminal_name), false)
|
279
|
+
if !route.nil? && !route['ipAddress'].empty?
|
280
|
+
route['exists'] = true
|
350
281
|
end
|
351
282
|
route
|
352
283
|
end
|
@@ -368,49 +299,36 @@ module BlockChyp
|
|
368
299
|
end
|
369
300
|
|
370
301
|
if route_cache_entry
|
371
|
-
route = route_cache_entry[
|
372
|
-
tx_creds = route[
|
373
|
-
tx_creds[
|
374
|
-
tx_creds[
|
375
|
-
tx_creds[
|
376
|
-
route[
|
377
|
-
|
378
|
-
|
379
|
-
raw_ttl = route_cache_entry[:ttl]
|
380
|
-
|
381
|
-
ttl = raw_ttl.instance_of?(Time) ? raw_ttl : Time.parse(route_cache_entry[:ttl])
|
302
|
+
route = route_cache_entry['route']
|
303
|
+
tx_creds = route['transientCredentials']
|
304
|
+
tx_creds['apiKey'] = decrypt(tx_creds['apiKey'])
|
305
|
+
tx_creds['bearerToken'] = decrypt(tx_creds['bearerToken'])
|
306
|
+
tx_creds['signingKey'] = decrypt(tx_creds['signingKey'])
|
307
|
+
route['transientCredentials'] = tx_creds
|
308
|
+
routeCacheEntry['route'] = route
|
309
|
+
end
|
382
310
|
|
383
|
-
|
384
|
-
|
311
|
+
if route_cache_entry
|
312
|
+
now = Time.new
|
313
|
+
ttl = Time.parse(route_cache_entry['ttl'])
|
314
|
+
if stale || now < ttl
|
315
|
+
puts 'Cache Hit ' + route_cache_entry.to_json
|
316
|
+
route_cache_entry['route']
|
385
317
|
end
|
386
318
|
end
|
387
319
|
end
|
388
320
|
|
389
321
|
def read_offline_cache
|
322
|
+
puts route_cache_location
|
323
|
+
|
390
324
|
if File.file?(route_cache_location)
|
391
325
|
|
392
326
|
config_file = File.open(route_cache_location)
|
393
327
|
content = config_file.read
|
394
328
|
|
395
|
-
return JSON.parse(content
|
329
|
+
return JSON.parse(content)
|
396
330
|
end
|
397
331
|
{}
|
398
332
|
end
|
399
|
-
|
400
|
-
def user_agent
|
401
|
-
if defined? VERSION
|
402
|
-
"BlockChyp-Ruby/#{VERSION}"
|
403
|
-
else
|
404
|
-
'BlockChyp-Ruby'
|
405
|
-
end
|
406
|
-
end
|
407
|
-
|
408
|
-
def get_timeout(request, default)
|
409
|
-
if request.nil? || !request.key?(:timeout) || request[:timeout].zero?
|
410
|
-
return default
|
411
|
-
end
|
412
|
-
|
413
|
-
request[:timeout]
|
414
|
-
end
|
415
333
|
end
|
416
334
|
end
|
data/test/boolean_prompt_test.rb
CHANGED
@@ -1,49 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2019-2022 BlockChyp, Inc. All rights reserved. Use of this code is
|
4
|
-
# governed by a license that can be found in the LICENSE file.
|
5
|
-
#
|
6
|
-
# This file was generated automatically by the BlockChyp SDK Generator.
|
7
|
-
# Changes to this file will be lost every time the code is regenerated.
|
8
|
-
|
9
3
|
require ::File.expand_path('test_helper', __dir__)
|
10
4
|
|
11
5
|
module BlockChyp
|
12
6
|
class BooleanPromptTest < TestCase
|
13
7
|
def test_boolean_prompt
|
14
|
-
|
15
|
-
puts "Running test_boolean_prompt..."
|
16
|
-
|
17
8
|
config = load_test_config
|
18
9
|
|
19
10
|
blockchyp = BlockChyp.new(
|
20
|
-
config[
|
21
|
-
config[
|
22
|
-
config[
|
11
|
+
config['apiKey'],
|
12
|
+
config['bearerToken'],
|
13
|
+
config['signingKey']
|
23
14
|
)
|
24
|
-
blockchyp.gateway_host = config[
|
25
|
-
blockchyp.test_gateway_host = config[
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
blockchyp.gateway_host = config['gatewayHost']
|
16
|
+
blockchyp.test_gateway_host = config['testGatewayHost']
|
17
|
+
|
18
|
+
test_delay(blockchyp, 'BooleanPromptTest')
|
19
|
+
# setup request object
|
20
|
+
request = {}
|
21
|
+
request['test'] = true
|
22
|
+
request['terminalName'] = 'Test Terminal'
|
23
|
+
request['prompt'] = 'Would you like to become a member?'
|
24
|
+
request['yesCaption'] = 'Yes'
|
25
|
+
request['noCaption'] = 'No'
|
26
|
+
response = blockchyp.booleanPrompt(request)
|
30
27
|
|
31
|
-
|
32
|
-
|
33
|
-
# Set request parameters
|
34
|
-
request = {
|
35
|
-
test: true,
|
36
|
-
terminalName: config[:defaultTerminalName],
|
37
|
-
prompt: 'Would you like to become a member?',
|
38
|
-
yesCaption: 'Yes',
|
39
|
-
noCaption: 'No'
|
40
|
-
}
|
41
|
-
|
42
|
-
response = blockchyp.boolean_prompt(request)
|
43
28
|
assert_not_nil(response)
|
44
29
|
# response assertions
|
45
|
-
assert(response[
|
46
|
-
assert(response[
|
30
|
+
assert(response['success'])
|
31
|
+
assert(response['response'])
|
47
32
|
end
|
33
|
+
|
48
34
|
end
|
49
35
|
end
|
data/test/heartbeat_test.rb
CHANGED
@@ -8,20 +8,20 @@ module BlockChyp
|
|
8
8
|
config = load_test_config
|
9
9
|
|
10
10
|
blockchyp = BlockChyp.new(
|
11
|
-
config[
|
12
|
-
config[
|
13
|
-
config[
|
11
|
+
config['apiKey'],
|
12
|
+
config['bearerToken'],
|
13
|
+
config['signingKey']
|
14
14
|
)
|
15
|
-
blockchyp.
|
16
|
-
blockchyp.
|
15
|
+
blockchyp.gatewayHost = config['gatewayHost']
|
16
|
+
blockchyp.testGatewayHost = config['testGatewayHost']
|
17
17
|
|
18
18
|
response = blockchyp.heartbeat(true)
|
19
19
|
assert_not_nil(response)
|
20
|
-
assert(response[
|
21
|
-
assert(!response[
|
22
|
-
assert(!response[
|
23
|
-
assert(!response[
|
24
|
-
assert(!response[
|
20
|
+
assert(response['success'])
|
21
|
+
assert(!response['timestamp'].empty?)
|
22
|
+
assert(!response['clockchain'].empty?)
|
23
|
+
assert(!response['latestTick'].empty?)
|
24
|
+
assert(!response['merchantPk'].empty?)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -1,64 +1,70 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2019-2022 BlockChyp, Inc. All rights reserved. Use of this code is
|
4
|
-
# governed by a license that can be found in the LICENSE file.
|
5
|
-
#
|
6
|
-
# This file was generated automatically by the BlockChyp SDK Generator.
|
7
|
-
# Changes to this file will be lost every time the code is regenerated.
|
8
|
-
|
9
3
|
require ::File.expand_path('test_helper', __dir__)
|
10
4
|
|
11
5
|
module BlockChyp
|
12
6
|
class NewTransactionDisplayTest < TestCase
|
13
7
|
def test_new_transaction_display
|
14
|
-
|
15
|
-
puts "Running test_new_transaction_display..."
|
16
|
-
|
17
8
|
config = load_test_config
|
18
9
|
|
19
10
|
blockchyp = BlockChyp.new(
|
20
|
-
config[
|
21
|
-
config[
|
22
|
-
config[
|
11
|
+
config['apiKey'],
|
12
|
+
config['bearerToken'],
|
13
|
+
config['signingKey']
|
23
14
|
)
|
24
|
-
blockchyp.gateway_host = config[
|
25
|
-
blockchyp.test_gateway_host = config[
|
26
|
-
blockchyp.dashboard_host = config[:dashboardHost]
|
15
|
+
blockchyp.gateway_host = config['gatewayHost']
|
16
|
+
blockchyp.test_gateway_host = config['testGatewayHost']
|
27
17
|
|
28
|
-
test_delay(blockchyp, '
|
18
|
+
test_delay(blockchyp, 'NewTransactionDisplayTest')
|
19
|
+
# setup request object
|
20
|
+
request = {}
|
21
|
+
request['test'] = true
|
22
|
+
request['terminalName'] = 'Test Terminal'
|
23
|
+
request['transaction'] = new_transaction_display_transaction
|
24
|
+
response = blockchyp.newTransactionDisplay(request)
|
29
25
|
|
26
|
+
assert_not_nil(response)
|
27
|
+
# response assertions
|
28
|
+
assert(response['success'])
|
29
|
+
end
|
30
30
|
|
31
|
+
def new_transaction_display_transaction
|
32
|
+
val = {}
|
33
|
+
val['subtotal'] = '35.00'
|
34
|
+
val['tax'] = '5.00'
|
35
|
+
val['total'] = '70.00'
|
36
|
+
val['items'] = new_transaction_display_items
|
37
|
+
val
|
38
|
+
end
|
31
39
|
|
40
|
+
def new_transaction_display_items
|
41
|
+
val = []
|
42
|
+
val.push(new_transaction_display_item_2)
|
43
|
+
val
|
44
|
+
end
|
32
45
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
{
|
49
|
-
description: 'memberDiscount',
|
50
|
-
amount: '10.00'
|
51
|
-
}
|
52
|
-
]
|
53
|
-
}
|
54
|
-
]
|
55
|
-
}
|
56
|
-
}
|
46
|
+
def new_transaction_display_item_2
|
47
|
+
val = {}
|
48
|
+
val['description'] = 'Leki Trekking Poles'
|
49
|
+
val['price'] = '35.00'
|
50
|
+
val['quantity'] = 2
|
51
|
+
val['extended'] = '70.00'
|
52
|
+
val['discounts'] = new_transaction_display_discounts
|
53
|
+
val
|
54
|
+
end
|
55
|
+
|
56
|
+
def new_transaction_display_discounts
|
57
|
+
val = []
|
58
|
+
val.push(new_transaction_display_discount_2)
|
59
|
+
val
|
60
|
+
end
|
57
61
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
+
def new_transaction_display_discount_2
|
63
|
+
val = {}
|
64
|
+
val['description'] = 'memberDiscount'
|
65
|
+
val['amount'] = '10.00'
|
66
|
+
val
|
62
67
|
end
|
68
|
+
|
63
69
|
end
|
64
70
|
end
|