blockchyp 2.0.0.pre.alpha7

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.
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ require 'date'
5
+
6
+ module BlockChyp
7
+ # crypto and encoding utilities
8
+ class CryptoUtils
9
+ def self.generate_nonce
10
+ bin2hex(SecureRandom.bytes(32))
11
+ end
12
+
13
+ def self.timestamp
14
+ Time.now.utc.to_datetime.rfc3339
15
+ end
16
+
17
+ def self.bin2hex(val)
18
+ val.each_byte.map { |b| b.to_s(16) }.join
19
+ end
20
+
21
+ def self.hex2bin(val)
22
+ val.scan(/../).map { |x| x.hex.chr }.join
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path('test_helper', __dir__)
4
+
5
+ module BlockChyp
6
+ class BooleanPromptTest < TestCase
7
+ def test_boolean_prompt
8
+ config = load_test_config
9
+
10
+ blockchyp = BlockChyp.new(
11
+ config['apiKey'],
12
+ config['bearerToken'],
13
+ config['signingKey']
14
+ )
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)
27
+
28
+ assert_not_nil(response)
29
+ # response assertions
30
+ assert(response['success'])
31
+ assert(response['response'])
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path('test_helper', __dir__)
4
+
5
+ module BlockChyp
6
+ class HeartbeatTest < TestCase
7
+ def test_heartbeat
8
+ config = load_test_config
9
+
10
+ blockchyp = BlockChyp.new(
11
+ config['apiKey'],
12
+ config['bearerToken'],
13
+ config['signingKey']
14
+ )
15
+ blockchyp.gatewayHost = config['gatewayHost']
16
+ blockchyp.testGatewayHost = config['testGatewayHost']
17
+
18
+ response = blockchyp.heartbeat(true)
19
+ assert_not_nil(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
+ end
26
+ end
27
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path('test_helper', __dir__)
4
+
5
+ module BlockChyp
6
+ class NewTransactionDisplayTest < TestCase
7
+ def test_new_transaction_display
8
+ config = load_test_config
9
+
10
+ blockchyp = BlockChyp.new(
11
+ config['apiKey'],
12
+ config['bearerToken'],
13
+ config['signingKey']
14
+ )
15
+ blockchyp.gateway_host = config['gatewayHost']
16
+ blockchyp.test_gateway_host = config['testGatewayHost']
17
+
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)
25
+
26
+ assert_not_nil(response)
27
+ # response assertions
28
+ assert(response['success'])
29
+ end
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
39
+
40
+ def new_transaction_display_items
41
+ val = []
42
+ val.push(new_transaction_display_item_2)
43
+ val
44
+ end
45
+
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
61
+
62
+ def new_transaction_display_discount_2
63
+ val = {}
64
+ val['description'] = 'memberDiscount'
65
+ val['amount'] = '10.00'
66
+ val
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path('test_helper', __dir__)
4
+
5
+ module BlockChyp
6
+ class PANChargeTest < TestCase
7
+ def test_pan_charge
8
+ config = load_test_config
9
+
10
+ blockchyp = BlockChyp.new(
11
+ config['apiKey'],
12
+ config['bearerToken'],
13
+ config['signingKey']
14
+ )
15
+ blockchyp.gateway_host = config['gatewayHost']
16
+ blockchyp.test_gateway_host = config['testGatewayHost']
17
+
18
+ test_delay(blockchyp, 'PANChargeTest')
19
+ # setup request object
20
+ request = {}
21
+ request['pan'] = '4111111111111111'
22
+ request['amount'] = '25.55'
23
+ request['test'] = true
24
+ request['transactionRef'] = uuid
25
+ response = blockchyp.charge(request)
26
+
27
+ assert_not_nil(response)
28
+ # response assertions
29
+ assert(response['approved'])
30
+ assert(response['test'])
31
+ assert_equal(response['authCode'].length, 6)
32
+ assert(!response['transactionId'].empty?)
33
+ assert(!response['timestamp'].empty?)
34
+ assert(!response['tickBlock'].empty?)
35
+ assert_equal('Approved', response['responseDescription'])
36
+ assert(!response['paymentType'].empty?)
37
+ assert(!response['maskedPan'].empty?)
38
+ assert(!response['entryMethod'].empty?)
39
+ assert_equal('25.55', response['authorizedAmount'])
40
+ assert_equal('KEYED', response['entryMethod'])
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path('test_helper', __dir__)
4
+
5
+ module BlockChyp
6
+ class PANEnrollTest < TestCase
7
+ def test_pan_enroll
8
+ config = load_test_config
9
+
10
+ blockchyp = BlockChyp.new(
11
+ config['apiKey'],
12
+ config['bearerToken'],
13
+ config['signingKey']
14
+ )
15
+ blockchyp.gateway_host = config['gatewayHost']
16
+ blockchyp.test_gateway_host = config['testGatewayHost']
17
+
18
+ test_delay(blockchyp, 'PANEnrollTest')
19
+ # setup request object
20
+ request = {}
21
+ request['pan'] = '4111111111111111'
22
+ request['test'] = true
23
+ response = blockchyp.enroll(request)
24
+
25
+ assert_not_nil(response)
26
+ # response assertions
27
+ assert(response['approved'])
28
+ assert(response['test'])
29
+ assert_equal(response['authCode'].length, 6)
30
+ assert(!response['transactionId'].empty?)
31
+ assert(!response['timestamp'].empty?)
32
+ assert(!response['tickBlock'].empty?)
33
+ assert_equal('Approved', response['responseDescription'])
34
+ assert(!response['paymentType'].empty?)
35
+ assert(!response['maskedPan'].empty?)
36
+ assert(!response['entryMethod'].empty?)
37
+ assert_equal('KEYED', response['entryMethod'])
38
+ assert(!response['token'].empty?)
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path('test_helper', __dir__)
4
+
5
+ module BlockChyp
6
+ class PANPreauthTest < TestCase
7
+ def test_pan_preauth
8
+ config = load_test_config
9
+
10
+ blockchyp = BlockChyp.new(
11
+ config['apiKey'],
12
+ config['bearerToken'],
13
+ config['signingKey']
14
+ )
15
+ blockchyp.gateway_host = config['gatewayHost']
16
+ blockchyp.test_gateway_host = config['testGatewayHost']
17
+
18
+ test_delay(blockchyp, 'PANPreauthTest')
19
+ # setup request object
20
+ request = {}
21
+ request['pan'] = '4111111111111111'
22
+ request['amount'] = '25.55'
23
+ request['test'] = true
24
+ response = blockchyp.preauth(request)
25
+
26
+ assert_not_nil(response)
27
+ # response assertions
28
+ assert(response['approved'])
29
+ assert(response['test'])
30
+ assert_equal(response['authCode'].length, 6)
31
+ assert(!response['transactionId'].empty?)
32
+ assert(!response['timestamp'].empty?)
33
+ assert(!response['tickBlock'].empty?)
34
+ assert_equal('Approved', response['responseDescription'])
35
+ assert(!response['paymentType'].empty?)
36
+ assert(!response['maskedPan'].empty?)
37
+ assert(!response['entryMethod'].empty?)
38
+ assert_equal('25.55', response['authorizedAmount'])
39
+ assert_equal('KEYED', response['entryMethod'])
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path('test_helper', __dir__)
4
+
5
+ module BlockChyp
6
+ class SimpleBatchCloseTest < TestCase
7
+ def test_simple_batch_close
8
+ config = load_test_config
9
+
10
+ blockchyp = BlockChyp.new(
11
+ config['apiKey'],
12
+ config['bearerToken'],
13
+ config['signingKey']
14
+ )
15
+ blockchyp.gateway_host = config['gatewayHost']
16
+ blockchyp.test_gateway_host = config['testGatewayHost']
17
+
18
+ test_delay(blockchyp, 'SimpleBatchCloseTest')
19
+ # setup request object
20
+ request = {}
21
+ request['pan'] = '4111111111111111'
22
+ request['amount'] = '25.55'
23
+ request['test'] = true
24
+ request['transactionRef'] = uuid
25
+ response = blockchyp.charge(request)
26
+
27
+ # setup request object
28
+ request = {}
29
+ request['test'] = true
30
+ response = blockchyp.closeBatch(request)
31
+
32
+ assert_not_nil(response)
33
+ # response assertions
34
+ assert(response['success'])
35
+ assert(!response['capturedTotal'].empty?)
36
+ assert(!response['openPreauths'].empty?)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path('test_helper', __dir__)
4
+
5
+ module BlockChyp
6
+ class SimpleCaptureTest < TestCase
7
+ def test_simple_capture
8
+ config = load_test_config
9
+
10
+ blockchyp = BlockChyp.new(
11
+ config['apiKey'],
12
+ config['bearerToken'],
13
+ config['signingKey']
14
+ )
15
+ blockchyp.gateway_host = config['gatewayHost']
16
+ blockchyp.test_gateway_host = config['testGatewayHost']
17
+
18
+ test_delay(blockchyp, 'SimpleCaptureTest')
19
+ # setup request object
20
+ request = {}
21
+ request['pan'] = '4111111111111111'
22
+ request['amount'] = '25.55'
23
+ request['test'] = true
24
+ response = blockchyp.preauth(request)
25
+
26
+ # setup request object
27
+ request = {}
28
+ request['transactionId'] = response['transactionId']
29
+ request['test'] = true
30
+ response = blockchyp.capture(request)
31
+
32
+ assert_not_nil(response)
33
+ # response assertions
34
+ assert(response['approved'])
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path('test_helper', __dir__)
4
+
5
+ module BlockChyp
6
+ class SimpleGiftActivateTest < TestCase
7
+ def test_simple_gift_activate
8
+ config = load_test_config
9
+
10
+ blockchyp = BlockChyp.new(
11
+ config['apiKey'],
12
+ config['bearerToken'],
13
+ config['signingKey']
14
+ )
15
+ blockchyp.gateway_host = config['gatewayHost']
16
+ blockchyp.test_gateway_host = config['testGatewayHost']
17
+
18
+ test_delay(blockchyp, 'SimpleGiftActivateTest')
19
+ # setup request object
20
+ request = {}
21
+ request['test'] = true
22
+ request['terminalName'] = 'Test Terminal'
23
+ request['amount'] = '50.00'
24
+ response = blockchyp.giftActivate(request)
25
+
26
+ assert_not_nil(response)
27
+ # response assertions
28
+ assert(response['approved'])
29
+ assert(!response['publicKey'].empty?)
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path('test_helper', __dir__)
4
+
5
+ module BlockChyp
6
+ class SimpleMessageTest < TestCase
7
+ def test_simple_message
8
+ config = load_test_config
9
+
10
+ blockchyp = BlockChyp.new(
11
+ config['apiKey'],
12
+ config['bearerToken'],
13
+ config['signingKey']
14
+ )
15
+ blockchyp.gateway_host = config['gatewayHost']
16
+ blockchyp.test_gateway_host = config['testGatewayHost']
17
+
18
+ test_delay(blockchyp, 'SimpleMessageTest')
19
+ # setup request object
20
+ request = {}
21
+ request['test'] = true
22
+ request['terminalName'] = 'Test Terminal'
23
+ request['message'] = 'Thank You For Your Business'
24
+ response = blockchyp.message(request)
25
+
26
+ assert_not_nil(response)
27
+ # response assertions
28
+ assert(response['success'])
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path('test_helper', __dir__)
4
+
5
+ module BlockChyp
6
+ class SimplePingTest < TestCase
7
+ def test_simple_ping
8
+ config = load_test_config
9
+
10
+ blockchyp = BlockChyp.new(
11
+ config['apiKey'],
12
+ config['bearerToken'],
13
+ config['signingKey']
14
+ )
15
+ blockchyp.gateway_host = config['gatewayHost']
16
+ blockchyp.test_gateway_host = config['testGatewayHost']
17
+
18
+ test_delay(blockchyp, 'SimplePingTest')
19
+ # setup request object
20
+ request = {}
21
+ request['test'] = true
22
+ request['terminalName'] = 'Test Terminal'
23
+ response = blockchyp.ping(request)
24
+
25
+ assert_not_nil(response)
26
+ # response assertions
27
+ assert(response['success'])
28
+ end
29
+
30
+ end
31
+ end