blockchyp 2.3.7 → 2.4.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 +118 -113
- data/lib/blockchyp.rb +1 -1
- data/lib/blockchyp/version.rb +1 -1
- data/lib/blockchyp_client.rb +50 -60
- data/test/batch_history_test.rb +11 -11
- data/test/boolean_prompt_test.rb +12 -12
- data/test/capture_signature_test.rb +9 -9
- data/test/gateway_timeout_test.rb +10 -10
- data/test/get_customer_test.rb +13 -13
- data/test/heartbeat_test.rb +10 -10
- data/test/merchant_profile_test.rb +7 -7
- data/test/new_transaction_display_test.rb +20 -20
- data/test/pan_charge_test.rb +22 -22
- data/test/pan_enroll_test.rb +20 -20
- data/test/pan_preauth_test.rb +21 -21
- data/test/search_customer_test.rb +13 -13
- data/test/send_payment_link_test.rb +26 -26
- data/test/simple_batch_close_test.rb +11 -11
- data/test/simple_capture_test.rb +12 -12
- data/test/simple_gift_activate_test.rb +11 -11
- data/test/simple_message_test.rb +9 -9
- data/test/simple_ping_test.rb +8 -8
- data/test/simple_refund_test.rb +13 -13
- data/test/simple_reversal_test.rb +13 -13
- data/test/simple_void_test.rb +13 -13
- data/test/terminal_charge_test.rb +20 -20
- data/test/terminal_clear_test.rb +8 -8
- data/test/terminal_ebt_balance_test.rb +10 -10
- data/test/terminal_ebt_charge_test.rb +22 -22
- data/test/terminal_enroll_test.rb +19 -19
- data/test/terminal_gift_card_balance_test.rb +9 -9
- data/test/terminal_keyed_charge_test.rb +21 -21
- data/test/terminal_manual_ebt_charge_test.rb +23 -23
- data/test/terminal_preauth_test.rb +20 -20
- data/test/terminal_status_test.rb +8 -8
- data/test/terminal_timeout_test.rb +9 -9
- data/test/terms_and_conditions_test.rb +13 -13
- data/test/test_helper.rb +7 -6
- data/test/text_prompt_test.rb +10 -10
- data/test/transaction_history_test.rb +11 -11
- data/test/update_customer_test.rb +12 -12
- data/test/update_transaction_display_test.rb +20 -20
- metadata +2 -2
data/lib/blockchyp.rb
CHANGED
@@ -47,7 +47,7 @@ module BlockChyp
|
|
47
47
|
class BlockChyp < BlockChypClient
|
48
48
|
|
49
49
|
def heartbeat(test)
|
50
|
-
gateway_request('GET', '/api/heartbeat', {
|
50
|
+
gateway_request('GET', '/api/heartbeat', { test: test })
|
51
51
|
end
|
52
52
|
|
53
53
|
# Tests connectivity with a payment terminal.
|
data/lib/blockchyp/version.rb
CHANGED
data/lib/blockchyp_client.rb
CHANGED
@@ -45,6 +45,7 @@ module BlockChyp
|
|
45
45
|
attr_accessor :offline_cache_enabled
|
46
46
|
attr_accessor :terminal_connect_timeout
|
47
47
|
attr_accessor :route_cache_location
|
48
|
+
attr_accessor :route_cache
|
48
49
|
|
49
50
|
def generate_gateway_headers
|
50
51
|
nonce = CryptoUtils.generate_nonce
|
@@ -66,32 +67,28 @@ module BlockChyp
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def resolve_gateway_uri(path, request)
|
69
|
-
url =
|
70
|
-
gateway_host
|
71
|
-
else
|
72
|
-
test_gateway_host
|
73
|
-
end
|
70
|
+
url = request.nil? || !request[:test] ? gateway_host : test_gateway_host
|
74
71
|
|
75
|
-
URI.parse(url + path)
|
72
|
+
URI.parse(path.nil? ? url : url + path)
|
76
73
|
end
|
77
74
|
|
78
75
|
def generate_error_response(msg)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
76
|
+
{
|
77
|
+
success: false,
|
78
|
+
error: msg,
|
79
|
+
responseDescription: msg
|
80
|
+
}
|
84
81
|
end
|
85
82
|
|
86
83
|
def route_terminal_request(method, terminal_path, gateway_path, request)
|
87
|
-
|
84
|
+
unless request.key?(:terminalName)
|
88
85
|
return gateway_request(method, gateway_path, request)
|
89
86
|
end
|
90
87
|
|
91
|
-
route = resolve_terminal_route(request[
|
88
|
+
route = resolve_terminal_route(request[:terminalName])
|
92
89
|
if !route
|
93
90
|
return generate_error_response('Unkown Terminal')
|
94
|
-
elsif route[
|
91
|
+
elsif route[:cloudRelayEnabled]
|
95
92
|
return gateway_request(method, gateway_path, request, relay: true)
|
96
93
|
end
|
97
94
|
|
@@ -106,13 +103,13 @@ module BlockChyp
|
|
106
103
|
http.open_timeout = timeout
|
107
104
|
http.read_timeout = timeout
|
108
105
|
|
109
|
-
tx_creds = route[
|
106
|
+
tx_creds = route[:transientCredentials]
|
110
107
|
|
111
108
|
wrapped_request = {
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
109
|
+
apiKey: tx_creds[:apiKey],
|
110
|
+
bearerToken: tx_creds[:bearerToken],
|
111
|
+
signingKey: tx_creds[:signingKey],
|
112
|
+
request: request
|
116
113
|
}
|
117
114
|
|
118
115
|
req = get_http_request(method, uri)
|
@@ -127,14 +124,14 @@ module BlockChyp
|
|
127
124
|
response = http.request(req)
|
128
125
|
rescue Net::OpenTimeout, Errno::EHOSTDOWN, Errno::EHOSTUNREACH, Errno::ETIMEDOUT, Errno::ENETUNREACH
|
129
126
|
if open_retry
|
130
|
-
evict(route[
|
131
|
-
route = resolve_terminal_route(route[
|
127
|
+
evict(route[:terminalName])
|
128
|
+
route = resolve_terminal_route(route[:terminalName])
|
132
129
|
return terminal_request(method, route, path, request, false)
|
133
130
|
end
|
134
131
|
raise
|
135
132
|
end
|
136
133
|
if response.is_a?(Net::HTTPSuccess)
|
137
|
-
JSON.parse(response.body)
|
134
|
+
JSON.parse(response.body, symbolize_names: true)
|
138
135
|
else
|
139
136
|
raise response.message
|
140
137
|
end
|
@@ -157,7 +154,7 @@ module BlockChyp
|
|
157
154
|
else
|
158
155
|
'http://'
|
159
156
|
end
|
160
|
-
url += route[
|
157
|
+
url += route[:ipAddress]
|
161
158
|
port = if https
|
162
159
|
':8443'
|
163
160
|
else
|
@@ -192,14 +189,12 @@ module BlockChyp
|
|
192
189
|
response = http.request(req)
|
193
190
|
|
194
191
|
if response.is_a?(Net::HTTPSuccess)
|
195
|
-
JSON.parse(response.body)
|
192
|
+
JSON.parse(response.body, symbolize_names: true)
|
196
193
|
else
|
197
194
|
raise response.message
|
198
195
|
end
|
199
196
|
end
|
200
197
|
|
201
|
-
attr_accessor :routeCache
|
202
|
-
|
203
198
|
def resolve_terminal_route(terminal_name)
|
204
199
|
route = route_cache_get(terminal_name, false)
|
205
200
|
|
@@ -211,8 +206,8 @@ module BlockChyp
|
|
211
206
|
|
212
207
|
ttl = Time.now.utc + (route_cache_ttl * 60)
|
213
208
|
route_cache_entry = {}
|
214
|
-
route_cache_entry[
|
215
|
-
route_cache_entry[
|
209
|
+
route_cache_entry[:route] = route
|
210
|
+
route_cache_entry[:ttl] = ttl
|
216
211
|
@route_cache[api_key + terminal_name] = route_cache_entry
|
217
212
|
update_offline_cache(route_cache_entry)
|
218
213
|
end
|
@@ -223,14 +218,14 @@ module BlockChyp
|
|
223
218
|
if offline_cache_enabled
|
224
219
|
offline_cache = read_offline_cache
|
225
220
|
offline_entry = route_cache_entry.clone
|
226
|
-
route = route_cache_entry[
|
227
|
-
tx_creds = route[
|
228
|
-
tx_creds[
|
229
|
-
tx_creds[
|
230
|
-
tx_creds[
|
231
|
-
route[
|
232
|
-
offline_entry[
|
233
|
-
offline_cache[api_key + route[
|
221
|
+
route = route_cache_entry[:route].clone
|
222
|
+
tx_creds = route[:transientCredentials].clone
|
223
|
+
tx_creds[:apiKey] = encrypt(tx_creds[:apiKey])
|
224
|
+
tx_creds[:bearerToken] = encrypt(tx_creds[:bearerToken])
|
225
|
+
tx_creds[:signingKey] = encrypt(tx_creds[:signingKey])
|
226
|
+
route[:transientCredentials] = tx_creds
|
227
|
+
offline_entry[:route] = route
|
228
|
+
offline_cache[api_key + route[:terminalName]] = offline_entry
|
234
229
|
File.write(route_cache_location, offline_cache.to_json)
|
235
230
|
end
|
236
231
|
end
|
@@ -270,8 +265,8 @@ module BlockChyp
|
|
270
265
|
|
271
266
|
def request_route_from_gateway(terminal_name)
|
272
267
|
route = gateway_request('GET', '/api/terminal-route?terminal=' + CGI.escape(terminal_name))
|
273
|
-
if !route.nil? && !route[
|
274
|
-
route[
|
268
|
+
if !route.nil? && !route[:ipAddress].empty?
|
269
|
+
route[:exists] = true
|
275
270
|
end
|
276
271
|
route
|
277
272
|
end
|
@@ -293,25 +288,20 @@ module BlockChyp
|
|
293
288
|
end
|
294
289
|
|
295
290
|
if route_cache_entry
|
296
|
-
route = route_cache_entry[
|
297
|
-
tx_creds = route[
|
298
|
-
tx_creds[
|
299
|
-
tx_creds[
|
300
|
-
tx_creds[
|
301
|
-
route[
|
302
|
-
route_cache_entry[
|
303
|
-
end
|
291
|
+
route = route_cache_entry[:route]
|
292
|
+
tx_creds = route[:transientCredentials]
|
293
|
+
tx_creds[:apiKey] = decrypt(tx_creds[:apiKey])
|
294
|
+
tx_creds[:bearerToken] = decrypt(tx_creds[:bearerToken])
|
295
|
+
tx_creds[:signingKey] = decrypt(tx_creds[:signingKey])
|
296
|
+
route[:transientCredentials] = tx_creds
|
297
|
+
route_cache_entry[:route] = route
|
304
298
|
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
ttl = Time.parse(route_cache_entry['ttl'])
|
312
|
-
end
|
313
|
-
if stale || now < ttl
|
314
|
-
route_cache_entry['route']
|
299
|
+
raw_ttl = route_cache_entry[:ttl]
|
300
|
+
|
301
|
+
ttl = raw_ttl.instance_of?(Time) ? raw_ttl : Time.parse(route_cache_entry[:ttl])
|
302
|
+
|
303
|
+
if stale || Time.new < ttl
|
304
|
+
route_cache_entry[:route]
|
315
305
|
end
|
316
306
|
end
|
317
307
|
end
|
@@ -322,7 +312,7 @@ module BlockChyp
|
|
322
312
|
config_file = File.open(route_cache_location)
|
323
313
|
content = config_file.read
|
324
314
|
|
325
|
-
return JSON.parse(content)
|
315
|
+
return JSON.parse(content, symbolize_names: true)
|
326
316
|
end
|
327
317
|
{}
|
328
318
|
end
|
@@ -331,16 +321,16 @@ module BlockChyp
|
|
331
321
|
if defined? VERSION
|
332
322
|
"BlockChyp-Ruby/#{VERSION}"
|
333
323
|
else
|
334
|
-
|
324
|
+
'BlockChyp-Ruby'
|
335
325
|
end
|
336
326
|
end
|
337
327
|
|
338
328
|
def get_timeout(request, default)
|
339
|
-
if request.nil? || request
|
329
|
+
if request.nil? || !request.key?(:timeout) || request[:timeout].zero?
|
340
330
|
return default
|
341
331
|
end
|
342
332
|
|
343
|
-
request[
|
333
|
+
request[:timeout]
|
344
334
|
end
|
345
335
|
end
|
346
336
|
end
|
data/test/batch_history_test.rb
CHANGED
@@ -14,35 +14,35 @@ module BlockChyp
|
|
14
14
|
config = load_test_config
|
15
15
|
|
16
16
|
blockchyp = BlockChyp.new(
|
17
|
-
config[
|
18
|
-
config[
|
19
|
-
config[
|
17
|
+
config[:apiKey],
|
18
|
+
config[:bearerToken],
|
19
|
+
config[:signingKey]
|
20
20
|
)
|
21
|
-
blockchyp.gateway_host = config[
|
22
|
-
blockchyp.test_gateway_host = config[
|
21
|
+
blockchyp.gateway_host = config[:gatewayHost]
|
22
|
+
blockchyp.test_gateway_host = config[:testGatewayHost]
|
23
23
|
|
24
24
|
test_delay(blockchyp, 'batch_history_test')
|
25
25
|
|
26
26
|
# Set request parameters
|
27
27
|
setup_request = {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
pan: '4111111111111111',
|
29
|
+
amount: '25.55',
|
30
|
+
test: true,
|
31
|
+
transactionRef: uuid
|
32
32
|
}
|
33
33
|
|
34
34
|
response = blockchyp.charge(setup_request)
|
35
35
|
|
36
36
|
# Set request parameters
|
37
37
|
request = {
|
38
|
-
|
38
|
+
maxResults: 10
|
39
39
|
}
|
40
40
|
|
41
41
|
response = blockchyp.batch_history(request)
|
42
42
|
|
43
43
|
assert_not_nil(response)
|
44
44
|
# response assertions
|
45
|
-
assert(response[
|
45
|
+
assert(response[:success])
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
data/test/boolean_prompt_test.rb
CHANGED
@@ -14,30 +14,30 @@ module BlockChyp
|
|
14
14
|
config = load_test_config
|
15
15
|
|
16
16
|
blockchyp = BlockChyp.new(
|
17
|
-
config[
|
18
|
-
config[
|
19
|
-
config[
|
17
|
+
config[:apiKey],
|
18
|
+
config[:bearerToken],
|
19
|
+
config[:signingKey]
|
20
20
|
)
|
21
|
-
blockchyp.gateway_host = config[
|
22
|
-
blockchyp.test_gateway_host = config[
|
21
|
+
blockchyp.gateway_host = config[:gatewayHost]
|
22
|
+
blockchyp.test_gateway_host = config[:testGatewayHost]
|
23
23
|
|
24
24
|
test_delay(blockchyp, 'boolean_prompt_test')
|
25
25
|
|
26
26
|
# Set request parameters
|
27
27
|
request = {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
test: true,
|
29
|
+
terminalName: 'Test Terminal',
|
30
|
+
prompt: 'Would you like to become a member?',
|
31
|
+
yesCaption: 'Yes',
|
32
|
+
noCaption: 'No'
|
33
33
|
}
|
34
34
|
|
35
35
|
response = blockchyp.boolean_prompt(request)
|
36
36
|
|
37
37
|
assert_not_nil(response)
|
38
38
|
# response assertions
|
39
|
-
assert(response[
|
40
|
-
assert(response[
|
39
|
+
assert(response[:success])
|
40
|
+
assert(response[:response])
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -14,27 +14,27 @@ module BlockChyp
|
|
14
14
|
config = load_test_config
|
15
15
|
|
16
16
|
blockchyp = BlockChyp.new(
|
17
|
-
config[
|
18
|
-
config[
|
19
|
-
config[
|
17
|
+
config[:apiKey],
|
18
|
+
config[:bearerToken],
|
19
|
+
config[:signingKey]
|
20
20
|
)
|
21
|
-
blockchyp.gateway_host = config[
|
22
|
-
blockchyp.test_gateway_host = config[
|
21
|
+
blockchyp.gateway_host = config[:gatewayHost]
|
22
|
+
blockchyp.test_gateway_host = config[:testGatewayHost]
|
23
23
|
|
24
24
|
test_delay(blockchyp, 'capture_signature_test')
|
25
25
|
|
26
26
|
# Set request parameters
|
27
27
|
request = {
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
terminalName: 'Test Terminal',
|
29
|
+
sigFormat: SignatureFormat::PNG,
|
30
|
+
sigWidth: 200
|
31
31
|
}
|
32
32
|
|
33
33
|
response = blockchyp.capture_signature(request)
|
34
34
|
|
35
35
|
assert_not_nil(response)
|
36
36
|
# response assertions
|
37
|
-
assert(response[
|
37
|
+
assert(response[:success])
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -14,22 +14,22 @@ module BlockChyp
|
|
14
14
|
config = load_test_config
|
15
15
|
|
16
16
|
blockchyp = BlockChyp.new(
|
17
|
-
config[
|
18
|
-
config[
|
19
|
-
config[
|
17
|
+
config[:apiKey],
|
18
|
+
config[:bearerToken],
|
19
|
+
config[:signingKey]
|
20
20
|
)
|
21
|
-
blockchyp.gateway_host = config[
|
22
|
-
blockchyp.test_gateway_host = config[
|
21
|
+
blockchyp.gateway_host = config[:gatewayHost]
|
22
|
+
blockchyp.test_gateway_host = config[:testGatewayHost]
|
23
23
|
|
24
24
|
test_delay(blockchyp, 'gateway_timeout_test')
|
25
25
|
|
26
26
|
# Set request parameters
|
27
27
|
request = {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
timeout: 1,
|
29
|
+
pan: '5555555555554444',
|
30
|
+
amount: '25.55',
|
31
|
+
test: true,
|
32
|
+
transactionRef: uuid
|
33
33
|
}
|
34
34
|
|
35
35
|
assert_raise Net::ReadTimeout do
|
data/test/get_customer_test.rb
CHANGED
@@ -14,23 +14,23 @@ module BlockChyp
|
|
14
14
|
config = load_test_config
|
15
15
|
|
16
16
|
blockchyp = BlockChyp.new(
|
17
|
-
config[
|
18
|
-
config[
|
19
|
-
config[
|
17
|
+
config[:apiKey],
|
18
|
+
config[:bearerToken],
|
19
|
+
config[:signingKey]
|
20
20
|
)
|
21
|
-
blockchyp.gateway_host = config[
|
22
|
-
blockchyp.test_gateway_host = config[
|
21
|
+
blockchyp.gateway_host = config[:gatewayHost]
|
22
|
+
blockchyp.test_gateway_host = config[:testGatewayHost]
|
23
23
|
|
24
24
|
test_delay(blockchyp, 'get_customer_test')
|
25
25
|
|
26
26
|
# Set request parameters
|
27
27
|
setup_request = {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
customer: {
|
29
|
+
firstName: 'Test',
|
30
|
+
lastName: 'Customer',
|
31
|
+
companyName: 'Test Company',
|
32
|
+
emailAddress: 'support@blockchyp.com',
|
33
|
+
smsNumber: '(123) 123-1234'
|
34
34
|
}
|
35
35
|
}
|
36
36
|
|
@@ -38,14 +38,14 @@ module BlockChyp
|
|
38
38
|
|
39
39
|
# Set request parameters
|
40
40
|
request = {
|
41
|
-
|
41
|
+
customerId: response[:customer][:id]
|
42
42
|
}
|
43
43
|
|
44
44
|
response = blockchyp.customer(request)
|
45
45
|
|
46
46
|
assert_not_nil(response)
|
47
47
|
# response assertions
|
48
|
-
assert(response[
|
48
|
+
assert(response[:success])
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|