blockchyp 2.3.5 → 2.6.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +155 -117
  3. data/lib/blockchyp.rb +6 -1
  4. data/lib/blockchyp/version.rb +1 -1
  5. data/lib/blockchyp_client.rb +50 -60
  6. data/test/batch_history_test.rb +11 -11
  7. data/test/boolean_prompt_test.rb +12 -12
  8. data/test/capture_signature_test.rb +9 -9
  9. data/test/gateway_timeout_test.rb +10 -10
  10. data/test/get_customer_test.rb +13 -13
  11. data/test/heartbeat_test.rb +10 -10
  12. data/test/merchant_profile_test.rb +38 -0
  13. data/test/new_transaction_display_test.rb +20 -20
  14. data/test/pan_charge_test.rb +22 -22
  15. data/test/pan_enroll_test.rb +20 -20
  16. data/test/pan_preauth_test.rb +21 -21
  17. data/test/partial_refund_test.rb +51 -0
  18. data/test/search_customer_test.rb +13 -13
  19. data/test/send_payment_link_test.rb +26 -26
  20. data/test/simple_batch_close_test.rb +11 -13
  21. data/test/simple_capture_test.rb +12 -12
  22. data/test/simple_gift_activate_test.rb +11 -11
  23. data/test/simple_message_test.rb +9 -9
  24. data/test/simple_ping_test.rb +8 -8
  25. data/test/simple_refund_test.rb +13 -13
  26. data/test/simple_reversal_test.rb +13 -13
  27. data/test/simple_void_test.rb +13 -13
  28. data/test/terminal_charge_test.rb +20 -20
  29. data/test/terminal_clear_test.rb +8 -8
  30. data/test/terminal_ebt_balance_test.rb +10 -10
  31. data/test/terminal_ebt_charge_test.rb +22 -22
  32. data/test/terminal_enroll_test.rb +19 -19
  33. data/test/terminal_gift_card_balance_test.rb +9 -9
  34. data/test/terminal_keyed_charge_test.rb +21 -21
  35. data/test/terminal_manual_ebt_charge_test.rb +23 -23
  36. data/test/terminal_preauth_test.rb +20 -20
  37. data/test/terminal_status_test.rb +8 -8
  38. data/test/terminal_timeout_test.rb +9 -9
  39. data/test/terms_and_conditions_test.rb +13 -13
  40. data/test/test_helper.rb +7 -6
  41. data/test/text_prompt_test.rb +10 -10
  42. data/test/transaction_history_test.rb +11 -11
  43. data/test/update_customer_test.rb +12 -12
  44. data/test/update_transaction_display_test.rb +20 -20
  45. metadata +4 -2
@@ -47,7 +47,7 @@ module BlockChyp
47
47
  class BlockChyp < BlockChypClient
48
48
 
49
49
  def heartbeat(test)
50
- gateway_request('GET', '/api/heartbeat', {'test' => test})
50
+ gateway_request('GET', '/api/heartbeat', { test: test })
51
51
  end
52
52
 
53
53
  # Tests connectivity with a payment terminal.
@@ -206,5 +206,10 @@ module BlockChyp
206
206
  gateway_request('POST', '/api/tx-history', request)
207
207
  end
208
208
 
209
+ # Returns profile information for a merchant.
210
+ def merchant_profile(request)
211
+ gateway_request('POST', '/api/public-merchant-profile', request)
212
+ end
213
+
209
214
  end
210
215
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlockChyp
4
- VERSION = '2.3.5'
4
+ VERSION = '2.6.0'
5
5
  end
@@ -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 = if request.nil? || !request['test']
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
- 'success' => false,
81
- 'error' => msg,
82
- 'responseDescription' => msg
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
- if request['terminalName'].nil?
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['terminalName'])
88
+ route = resolve_terminal_route(request[:terminalName])
92
89
  if !route
93
90
  return generate_error_response('Unkown Terminal')
94
- elsif route['cloudRelayEnabled']
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['transientCredentials']
106
+ tx_creds = route[:transientCredentials]
110
107
 
111
108
  wrapped_request = {
112
- 'apiKey' => tx_creds['apiKey'],
113
- 'bearerToken' => tx_creds['bearerToken'],
114
- 'signingKey' => tx_creds['signingKey'],
115
- 'request' => request
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['terminalName'])
131
- route = resolve_terminal_route(route['terminalName'])
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['ipAddress']
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['route'] = route
215
- route_cache_entry['ttl'] = ttl
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['route'].clone
227
- tx_creds = route['transientCredentials'].clone
228
- tx_creds['apiKey'] = encrypt(tx_creds['apiKey'])
229
- tx_creds['bearerToken'] = encrypt(tx_creds['bearerToken'])
230
- tx_creds['signingKey'] = encrypt(tx_creds['signingKey'])
231
- route['transientCredentials'] = tx_creds
232
- offline_entry['route'] = route
233
- offline_cache[api_key + route['terminalName']] = offline_entry
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['ipAddress'].empty?
274
- route['exists'] = true
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['route']
297
- tx_creds = route['transientCredentials']
298
- tx_creds['apiKey'] = decrypt(tx_creds['apiKey'])
299
- tx_creds['bearerToken'] = decrypt(tx_creds['bearerToken'])
300
- tx_creds['signingKey'] = decrypt(tx_creds['signingKey'])
301
- route['transientCredentials'] = tx_creds
302
- route_cache_entry['route'] = route
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
- if route_cache_entry
306
- now = Time.new
307
- raw_ttl = route_cache_entry['ttl']
308
- if raw_ttl.instance_of?(Time)
309
- ttl = raw_ttl
310
- else
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
- "BlockChyp-Ruby"
324
+ 'BlockChyp-Ruby'
335
325
  end
336
326
  end
337
327
 
338
328
  def get_timeout(request, default)
339
- if request.nil? || request['timeout'].nil? || request['timeout'].zero?
329
+ if request.nil? || !request.key?(:timeout) || request[:timeout].zero?
340
330
  return default
341
331
  end
342
332
 
343
- request['timeout']
333
+ request[:timeout]
344
334
  end
345
335
  end
346
336
  end
@@ -14,35 +14,35 @@ module BlockChyp
14
14
  config = load_test_config
15
15
 
16
16
  blockchyp = BlockChyp.new(
17
- config['apiKey'],
18
- config['bearerToken'],
19
- config['signingKey']
17
+ config[:apiKey],
18
+ config[:bearerToken],
19
+ config[:signingKey]
20
20
  )
21
- blockchyp.gateway_host = config['gatewayHost']
22
- blockchyp.test_gateway_host = config['testGatewayHost']
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
- "pan": '4111111111111111',
29
- "amount": '25.55',
30
- "test": true,
31
- "transactionRef": uuid
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
- "maxResults": 10
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['success'])
45
+ assert(response[:success])
46
46
  end
47
47
  end
48
48
  end
@@ -14,30 +14,30 @@ module BlockChyp
14
14
  config = load_test_config
15
15
 
16
16
  blockchyp = BlockChyp.new(
17
- config['apiKey'],
18
- config['bearerToken'],
19
- config['signingKey']
17
+ config[:apiKey],
18
+ config[:bearerToken],
19
+ config[:signingKey]
20
20
  )
21
- blockchyp.gateway_host = config['gatewayHost']
22
- blockchyp.test_gateway_host = config['testGatewayHost']
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
- "test": true,
29
- "terminalName": 'Test Terminal',
30
- "prompt": 'Would you like to become a member?',
31
- "yesCaption": 'Yes',
32
- "noCaption": 'No'
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['success'])
40
- assert(response['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['apiKey'],
18
- config['bearerToken'],
19
- config['signingKey']
17
+ config[:apiKey],
18
+ config[:bearerToken],
19
+ config[:signingKey]
20
20
  )
21
- blockchyp.gateway_host = config['gatewayHost']
22
- blockchyp.test_gateway_host = config['testGatewayHost']
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
- "terminalName": 'Test Terminal',
29
- "sigFormat": SignatureFormat::PNG,
30
- "sigWidth": 200
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['success'])
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['apiKey'],
18
- config['bearerToken'],
19
- config['signingKey']
17
+ config[:apiKey],
18
+ config[:bearerToken],
19
+ config[:signingKey]
20
20
  )
21
- blockchyp.gateway_host = config['gatewayHost']
22
- blockchyp.test_gateway_host = config['testGatewayHost']
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
- "timeout": 1,
29
- "pan": '5555555555554444',
30
- "amount": '25.55',
31
- "test": true,
32
- "transactionRef": uuid
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
@@ -14,23 +14,23 @@ module BlockChyp
14
14
  config = load_test_config
15
15
 
16
16
  blockchyp = BlockChyp.new(
17
- config['apiKey'],
18
- config['bearerToken'],
19
- config['signingKey']
17
+ config[:apiKey],
18
+ config[:bearerToken],
19
+ config[:signingKey]
20
20
  )
21
- blockchyp.gateway_host = config['gatewayHost']
22
- blockchyp.test_gateway_host = config['testGatewayHost']
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
- "customer": {
29
- "firstName": 'Test',
30
- "lastName": 'Customer',
31
- "companyName": 'Test Company',
32
- "emailAddress": 'support@blockchyp.com',
33
- "smsNumber": '(123) 123-1234'
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
- "customerId": response['customer']['id']
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['success'])
48
+ assert(response[:success])
49
49
  end
50
50
  end
51
51
  end