cardconnect 1.0.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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +154 -0
- data/Rakefile +178 -0
- data/cardconnect.gemspec +25 -0
- data/lib/cardconnect.rb +49 -0
- data/lib/cardconnect/configuration.rb +13 -0
- data/lib/cardconnect/connection.rb +35 -0
- data/lib/cardconnect/error.rb +3 -0
- data/lib/cardconnect/services/authorization/authorization.rb +17 -0
- data/lib/cardconnect/services/authorization/authorization_request.rb +51 -0
- data/lib/cardconnect/services/authorization/authorization_response.rb +41 -0
- data/lib/cardconnect/services/capture/capture.rb +17 -0
- data/lib/cardconnect/services/capture/capture_request.rb +50 -0
- data/lib/cardconnect/services/capture/capture_response.rb +24 -0
- data/lib/cardconnect/services/deposit/deposit.rb +17 -0
- data/lib/cardconnect/services/deposit/deposit_request.rb +64 -0
- data/lib/cardconnect/services/deposit/deposit_response.rb +40 -0
- data/lib/cardconnect/services/inquire/inquire.rb +17 -0
- data/lib/cardconnect/services/inquire/inquire_request.rb +44 -0
- data/lib/cardconnect/services/inquire/inquire_response.rb +31 -0
- data/lib/cardconnect/services/refund/refund.rb +16 -0
- data/lib/cardconnect/services/refund/refund_request.rb +50 -0
- data/lib/cardconnect/services/refund/refund_response.rb +40 -0
- data/lib/cardconnect/services/service_endpoint.rb +69 -0
- data/lib/cardconnect/services/settlement_status/settlement_status.rb +17 -0
- data/lib/cardconnect/services/settlement_status/settlement_status_request.rb +64 -0
- data/lib/cardconnect/services/settlement_status/settlement_status_response.rb +39 -0
- data/lib/cardconnect/services/void/void.rb +16 -0
- data/lib/cardconnect/services/void/void_request.rb +50 -0
- data/lib/cardconnect/services/void/void_response.rb +40 -0
- data/lib/cardconnect/utils.rb +22 -0
- data/lib/cardconnect/version.rb +3 -0
- data/test/api_request_stubs.rb +83 -0
- data/test/api_response_stubs.rb +120 -0
- data/test/cardconnect/configuration_test.rb +28 -0
- data/test/cardconnect/connection_test.rb +36 -0
- data/test/cardconnect/services/authorization/authorization_request_test.rb +141 -0
- data/test/cardconnect/services/authorization/authorization_response_test.rb +93 -0
- data/test/cardconnect/services/authorization/authorization_test.rb +59 -0
- data/test/cardconnect/services/capture/capture_request_test.rb +65 -0
- data/test/cardconnect/services/capture/capture_response_test.rb +39 -0
- data/test/cardconnect/services/capture/capture_test.rb +58 -0
- data/test/cardconnect/services/deposit/deposit_request_test.rb +65 -0
- data/test/cardconnect/services/deposit/deposit_response_test.rb +75 -0
- data/test/cardconnect/services/deposit/deposit_test.rb +55 -0
- data/test/cardconnect/services/inquire/inquire_request_test.rb +45 -0
- data/test/cardconnect/services/inquire/inquire_response_test.rb +59 -0
- data/test/cardconnect/services/inquire/inquire_test.rb +56 -0
- data/test/cardconnect/services/refund/refund_request_test.rb +49 -0
- data/test/cardconnect/services/refund/refund_response_test.rb +73 -0
- data/test/cardconnect/services/refund/refund_test.rb +57 -0
- data/test/cardconnect/services/settlement_status/settlement_status_request_test.rb +65 -0
- data/test/cardconnect/services/settlement_status/settlement_status_response_test.rb +47 -0
- data/test/cardconnect/services/settlement_status/settlement_status_test.rb +55 -0
- data/test/cardconnect/services/void/void_request_test.rb +49 -0
- data/test/cardconnect/services/void/void_response_test.rb +77 -0
- data/test/cardconnect/services/void/void_test.rb +57 -0
- data/test/cardconnect_test.rb +14 -0
- data/test/test_helper.rb +33 -0
- metadata +179 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CardConnect::Service::Authorization do
|
4
|
+
before do
|
5
|
+
@connection = CardConnect::Connection.new.connection do |stubs|
|
6
|
+
stubs.put(@service.path) { [200, {}, valid_auth_response] }
|
7
|
+
end
|
8
|
+
@service = CardConnect::Service::Authorization.new(@connection)
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
@service = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'must have the right path' do
|
16
|
+
@service.path.must_equal '/cardconnect/rest/auth'
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#build_request' do
|
20
|
+
before do
|
21
|
+
@valid_params = valid_auth_request
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
@valid_params = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'uses the default merchant id if it is not passed in' do
|
29
|
+
@service.build_request(@valid_params.reject!{|k,v| k == 'merchid' })
|
30
|
+
@service.request.merchid.must_equal 'merchant123'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'creates an Authorization request object with the right params' do
|
34
|
+
@service.build_request(@valid_params)
|
35
|
+
|
36
|
+
@service.request.must_be_kind_of CardConnect::Service::AuthorizationRequest
|
37
|
+
|
38
|
+
@service.request.merchid.must_equal '000000927996'
|
39
|
+
@service.request.account.must_equal '4111111111111111'
|
40
|
+
@service.request.expiry.must_equal '1212'
|
41
|
+
@service.request.amount.must_equal '0'
|
42
|
+
@service.request.currency.must_equal 'USD'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#submit' do
|
47
|
+
it 'raises an error when there is no request' do
|
48
|
+
@service.request.nil?.must_equal true
|
49
|
+
proc { @service.submit }.must_raise CardConnect::Error
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'creates a response when a valid request is processed' do
|
53
|
+
@service.build_request(valid_auth_request)
|
54
|
+
@service.submit
|
55
|
+
@service.response.must_be_kind_of CardConnect::Service::AuthorizationResponse
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CardConnect::Service::CaptureRequest do
|
4
|
+
before do
|
5
|
+
@request = CardConnect::Service::CaptureRequest.new(valid_capture_request)
|
6
|
+
end
|
7
|
+
|
8
|
+
after do
|
9
|
+
@request = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'FIELDS' do
|
13
|
+
it 'should have merchant id' do
|
14
|
+
@request.merchid.must_equal "000000927996"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have retrieval reference number' do
|
18
|
+
@request.retref.must_equal "288002073633"
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have authorization code' do
|
22
|
+
@request.authcode.must_equal "046221"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should have amount' do
|
26
|
+
@request.amount.must_equal "596.00"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should have invoice id' do
|
30
|
+
@request.invoiceid.must_equal "7890"
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should have PO number' do
|
34
|
+
@request.ponumber.must_equal "PO-0736332"
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should have tax amount' do
|
38
|
+
@request.taxamnt.must_equal "40.00"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#valid?' do
|
43
|
+
it 'should not be valid if no attributes are passed in' do
|
44
|
+
CardConnect::Service::CaptureRequest.new.valid?.must_equal false
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should be valid if valid attributes are passed in' do
|
48
|
+
CardConnect::Service::CaptureRequest.new(valid_capture_request).valid?.must_equal true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#errors' do
|
53
|
+
CardConnect::Service::CaptureRequest::REQUIRED_FIELDS.each do |field|
|
54
|
+
it "should have an error message if #{field} is missing" do
|
55
|
+
CardConnect::Service::CaptureRequest.new.errors.must_include "#{field.to_s.capitalize} is missing"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#payload" do
|
61
|
+
it 'should generate hash with all the right values' do
|
62
|
+
@request.payload.must_equal symbolize_keys(valid_capture_request)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CardConnect::Service::CaptureResponse do
|
4
|
+
before do
|
5
|
+
@response = CardConnect::Service::CaptureResponse.new(valid_capture_response)
|
6
|
+
end
|
7
|
+
|
8
|
+
after do
|
9
|
+
@response = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'FIELDS' do
|
13
|
+
it 'should have merchant id' do
|
14
|
+
@response.merchid.must_equal "000000927996"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have account' do
|
18
|
+
@response.account.must_equal "41XXXXXXXXXX4113"
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have amount' do
|
22
|
+
@response.amount.must_equal "596.00"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should have retrieval reference number' do
|
26
|
+
@response.retref.must_equal "288002073633"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should have settlement status' do
|
30
|
+
@response.setlstat.must_equal "Pending"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#body" do
|
35
|
+
it 'should generate hash with all the right values' do
|
36
|
+
@response.body.must_equal symbolize_keys(valid_capture_response)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CardConnect::Service::Capture do
|
4
|
+
before do
|
5
|
+
@connection = CardConnect::Connection.new.connection do |stubs|
|
6
|
+
stubs.put(@service.path) { [200, {}, valid_capture_response] }
|
7
|
+
end
|
8
|
+
@service = CardConnect::Service::Capture.new(@connection)
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
@service = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'must have the right path' do
|
16
|
+
@service.path.must_equal '/cardconnect/rest/capture'
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#build_request' do
|
20
|
+
before do
|
21
|
+
@valid_params = valid_capture_request
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
@valid_params = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'creates a Capture request object with the passed in params' do
|
29
|
+
@service.build_request(@valid_params)
|
30
|
+
|
31
|
+
@service.request.must_be_kind_of CardConnect::Service::CaptureRequest
|
32
|
+
|
33
|
+
@service.request.merchid.must_equal '000000927996'
|
34
|
+
@service.request.retref.must_equal '288002073633'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'uses default merchant ID if merchid is not passed in' do
|
38
|
+
@service.build_request(@valid_params.reject!{|k,v| k == 'merchid' })
|
39
|
+
|
40
|
+
@service.request.must_be_kind_of CardConnect::Service::CaptureRequest
|
41
|
+
|
42
|
+
@service.request.merchid.must_equal 'merchant123'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#submit' do
|
47
|
+
it 'raises an error when there is no request' do
|
48
|
+
@service.request.nil?.must_equal true
|
49
|
+
proc { @service.submit }.must_raise CardConnect::Error
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'creates a response when a valid request is processed' do
|
53
|
+
@service.build_request(valid_capture_request)
|
54
|
+
@service.submit
|
55
|
+
@service.response.must_be_kind_of CardConnect::Service::CaptureResponse
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CardConnect::Service::DepositRequest do
|
4
|
+
before do
|
5
|
+
@request = CardConnect::Service::DepositRequest.new(valid_deposit_request)
|
6
|
+
end
|
7
|
+
|
8
|
+
after do
|
9
|
+
@request = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'FIELDS' do
|
13
|
+
it 'should have merchant id' do
|
14
|
+
@request.merchid.must_equal "000000927996"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have date' do
|
18
|
+
@request.date.must_equal "0110"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#valid?' do
|
23
|
+
it 'should not be valid if no attributes are passed in' do
|
24
|
+
CardConnect::Service::DepositRequest.new.valid?.must_equal false
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should be valid if valid attributes are passed in' do
|
28
|
+
CardConnect::Service::DepositRequest.new(valid_deposit_request).valid?.must_equal true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#errors' do
|
33
|
+
CardConnect::Service::DepositRequest::REQUIRED_FIELDS.each do |field|
|
34
|
+
it "should have an error message if #{field} is missing" do
|
35
|
+
CardConnect::Service::DepositRequest.new.errors.must_include "#{field.to_s.capitalize} is missing"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#validate_date_format' do
|
40
|
+
it 'should have an error when date is less than 4 characters long' do
|
41
|
+
request = CardConnect::Service::DepositRequest.new({date: '123'})
|
42
|
+
request.valid?.must_equal false
|
43
|
+
request.errors.must_include "Date format is invalid. Please use MMDD format"
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should have an error when date is more than 4 characters long' do
|
47
|
+
request = CardConnect::Service::DepositRequest.new({date: '12345'})
|
48
|
+
request.valid?.must_equal false
|
49
|
+
request.errors.must_include "Date format is invalid. Please use MMDD format"
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should have an error when date is not parseable in MMDD format' do
|
53
|
+
request = CardConnect::Service::DepositRequest.new({date: '0000'})
|
54
|
+
request.valid?.must_equal false
|
55
|
+
request.errors.must_include "Date format is invalid. Please use MMDD format"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#payload" do
|
61
|
+
it 'should generate the correct path params' do
|
62
|
+
@request.payload.must_equal "?merchid=#{@request.merchid}&date=#{@request.date}&"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CardConnect::Service::DepositResponse do
|
4
|
+
before do
|
5
|
+
@response = CardConnect::Service::DepositResponse.new(valid_deposit_response)
|
6
|
+
end
|
7
|
+
|
8
|
+
after do
|
9
|
+
@response = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have the deposit id' do
|
13
|
+
@response.depositid.must_equal 7
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should have the merchant id' do
|
17
|
+
@response.merchid.must_equal "000000927996"
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have the respproc' do
|
21
|
+
@response.respproc.must_equal "FNOR"
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have the accttype' do
|
25
|
+
@response.accttype.must_equal "VI"
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have the action' do
|
29
|
+
@response.action.must_equal "DEB"
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should have the actdate' do
|
33
|
+
@response.actdate.must_equal "20121008"
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should have the postdate' do
|
37
|
+
@response.postdate.must_equal "20121009"
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should have the currency' do
|
41
|
+
@response.currency.must_equal "USD"
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should have the amount' do
|
45
|
+
@response.amount.must_equal "11.00"
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should have the feeamnt' do
|
49
|
+
@response.feeamnt.must_equal "0.55"
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should have the cbakamnt' do
|
53
|
+
@response.cbakamnt.must_equal "0.00"
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should have the resptext' do
|
57
|
+
@response.resptext.must_equal "Successful or something"
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should have the transactions' do
|
61
|
+
@response.txns.must_equal [{merchbatch: 92821429, retref: "282005142924", hostbatch: "1429", feeamnt: "0.00", action: "DEB", depamnt: "11.00"}]
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#body' do
|
65
|
+
it 'should have all the right fields in the body' do
|
66
|
+
@response.body.keys.must_equal [:depositid, :merchid, :respproc, :accttype, :action, :actdate, :postdate, :currency, :amount, :feeamnt, :cbakamnt, :resptext, :txns]
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should generate hash with all the right values' do
|
70
|
+
valid_payload = symbolize_keys(valid_deposit_response.first)
|
71
|
+
valid_payload[:txns] = valid_payload[:txns].map{|txn| symbolize_keys(txn)}
|
72
|
+
@response.body.must_equal valid_payload
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CardConnect::Service::Deposit do
|
4
|
+
before do
|
5
|
+
@connection = CardConnect::Connection.new.connection do |stubs|
|
6
|
+
stubs.get(@service.path) { [200, {}, valid_deposit_response] }
|
7
|
+
end
|
8
|
+
@service = CardConnect::Service::Deposit.new(@connection)
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
@service = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'must have the right path' do
|
16
|
+
@service.path.must_equal '/cardconnect/rest/deposit'
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#build_request' do
|
20
|
+
before do
|
21
|
+
@valid_params = valid_deposit_request
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
@valid_params = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'creates a Capture request object with the passed in params' do
|
29
|
+
@service.build_request(@valid_params)
|
30
|
+
|
31
|
+
@service.request.must_be_kind_of CardConnect::Service::DepositRequest
|
32
|
+
@service.request.merchid.must_equal "000000927996"
|
33
|
+
@service.request.date.must_equal "0110"
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'uses default merchant ID if merchid is not passed in' do
|
37
|
+
@service.build_request(@valid_params.reject!{|k,v| k == 'merchid' })
|
38
|
+
@service.request.must_be_kind_of CardConnect::Service::DepositRequest
|
39
|
+
@service.request.merchid.must_equal "merchant123"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#submit' do
|
44
|
+
it 'raises an error when there is no request' do
|
45
|
+
@service.request.nil?.must_equal true
|
46
|
+
proc { @service.submit }.must_raise CardConnect::Error
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'creates a response when a valid request is processed' do
|
50
|
+
@service.build_request(valid_deposit_request)
|
51
|
+
@service.submit
|
52
|
+
@service.response.must_be_kind_of CardConnect::Service::DepositResponse
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CardConnect::Service::InquireRequest do
|
4
|
+
before do
|
5
|
+
@request = CardConnect::Service::InquireRequest.new(valid_inquire_request)
|
6
|
+
end
|
7
|
+
|
8
|
+
after do
|
9
|
+
@request = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'FIELDS' do
|
13
|
+
it 'should have merchant id' do
|
14
|
+
@request.merchid.must_equal "000000927996"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have retrieval reference number' do
|
18
|
+
@request.retref.must_equal "288002073633"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#valid?' do
|
23
|
+
it 'should not be valid if no attributes are passed in' do
|
24
|
+
CardConnect::Service::InquireRequest.new.valid?.must_equal false
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should be valid if valid attributes are passed in' do
|
28
|
+
CardConnect::Service::InquireRequest.new(valid_inquire_request).valid?.must_equal true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#errors' do
|
33
|
+
CardConnect::Service::InquireRequest::REQUIRED_FIELDS.each do |field|
|
34
|
+
it "should have an error message if #{field} is missing" do
|
35
|
+
CardConnect::Service::InquireRequest.new.errors.must_include "#{field.to_s.capitalize} is missing"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#payload" do
|
41
|
+
it 'should generate the correct path params' do
|
42
|
+
@request.payload.must_equal '/288002073633/000000927996'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|