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.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +11 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +154 -0
  6. data/Rakefile +178 -0
  7. data/cardconnect.gemspec +25 -0
  8. data/lib/cardconnect.rb +49 -0
  9. data/lib/cardconnect/configuration.rb +13 -0
  10. data/lib/cardconnect/connection.rb +35 -0
  11. data/lib/cardconnect/error.rb +3 -0
  12. data/lib/cardconnect/services/authorization/authorization.rb +17 -0
  13. data/lib/cardconnect/services/authorization/authorization_request.rb +51 -0
  14. data/lib/cardconnect/services/authorization/authorization_response.rb +41 -0
  15. data/lib/cardconnect/services/capture/capture.rb +17 -0
  16. data/lib/cardconnect/services/capture/capture_request.rb +50 -0
  17. data/lib/cardconnect/services/capture/capture_response.rb +24 -0
  18. data/lib/cardconnect/services/deposit/deposit.rb +17 -0
  19. data/lib/cardconnect/services/deposit/deposit_request.rb +64 -0
  20. data/lib/cardconnect/services/deposit/deposit_response.rb +40 -0
  21. data/lib/cardconnect/services/inquire/inquire.rb +17 -0
  22. data/lib/cardconnect/services/inquire/inquire_request.rb +44 -0
  23. data/lib/cardconnect/services/inquire/inquire_response.rb +31 -0
  24. data/lib/cardconnect/services/refund/refund.rb +16 -0
  25. data/lib/cardconnect/services/refund/refund_request.rb +50 -0
  26. data/lib/cardconnect/services/refund/refund_response.rb +40 -0
  27. data/lib/cardconnect/services/service_endpoint.rb +69 -0
  28. data/lib/cardconnect/services/settlement_status/settlement_status.rb +17 -0
  29. data/lib/cardconnect/services/settlement_status/settlement_status_request.rb +64 -0
  30. data/lib/cardconnect/services/settlement_status/settlement_status_response.rb +39 -0
  31. data/lib/cardconnect/services/void/void.rb +16 -0
  32. data/lib/cardconnect/services/void/void_request.rb +50 -0
  33. data/lib/cardconnect/services/void/void_response.rb +40 -0
  34. data/lib/cardconnect/utils.rb +22 -0
  35. data/lib/cardconnect/version.rb +3 -0
  36. data/test/api_request_stubs.rb +83 -0
  37. data/test/api_response_stubs.rb +120 -0
  38. data/test/cardconnect/configuration_test.rb +28 -0
  39. data/test/cardconnect/connection_test.rb +36 -0
  40. data/test/cardconnect/services/authorization/authorization_request_test.rb +141 -0
  41. data/test/cardconnect/services/authorization/authorization_response_test.rb +93 -0
  42. data/test/cardconnect/services/authorization/authorization_test.rb +59 -0
  43. data/test/cardconnect/services/capture/capture_request_test.rb +65 -0
  44. data/test/cardconnect/services/capture/capture_response_test.rb +39 -0
  45. data/test/cardconnect/services/capture/capture_test.rb +58 -0
  46. data/test/cardconnect/services/deposit/deposit_request_test.rb +65 -0
  47. data/test/cardconnect/services/deposit/deposit_response_test.rb +75 -0
  48. data/test/cardconnect/services/deposit/deposit_test.rb +55 -0
  49. data/test/cardconnect/services/inquire/inquire_request_test.rb +45 -0
  50. data/test/cardconnect/services/inquire/inquire_response_test.rb +59 -0
  51. data/test/cardconnect/services/inquire/inquire_test.rb +56 -0
  52. data/test/cardconnect/services/refund/refund_request_test.rb +49 -0
  53. data/test/cardconnect/services/refund/refund_response_test.rb +73 -0
  54. data/test/cardconnect/services/refund/refund_test.rb +57 -0
  55. data/test/cardconnect/services/settlement_status/settlement_status_request_test.rb +65 -0
  56. data/test/cardconnect/services/settlement_status/settlement_status_response_test.rb +47 -0
  57. data/test/cardconnect/services/settlement_status/settlement_status_test.rb +55 -0
  58. data/test/cardconnect/services/void/void_request_test.rb +49 -0
  59. data/test/cardconnect/services/void/void_response_test.rb +77 -0
  60. data/test/cardconnect/services/void/void_test.rb +57 -0
  61. data/test/cardconnect_test.rb +14 -0
  62. data/test/test_helper.rb +33 -0
  63. metadata +179 -0
@@ -0,0 +1,22 @@
1
+ module CardConnect
2
+ module Utils
3
+
4
+ def set_attributes(attributes, fields)
5
+ return if attributes.empty?
6
+ attributes = symbolize_keys(attributes)
7
+ fields.each do |attr|
8
+ next unless attributes[attr]
9
+ send("#{attr}=", attributes[attr])
10
+ end
11
+ end
12
+
13
+ def symbolize_keys(hash)
14
+ symbolized_hash = {}
15
+ hash.each do |k, v|
16
+ symbolized_hash[k.to_sym] = v
17
+ end
18
+ symbolized_hash
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module CardConnect
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,83 @@
1
+ def valid_auth_request
2
+ {
3
+ "merchid" => "000000927996",
4
+ "accttype" => "VISA",
5
+ "orderid" => "AB-11-9876",
6
+ "account" => "4111111111111111",
7
+ "expiry" => "1212",
8
+ "amount" => "0",
9
+ "currency" => "USD",
10
+ "name" => "TOM JONES",
11
+ "address" => "123 MAIN STREET",
12
+ "city" => "anytown",
13
+ "region" => "NY",
14
+ "country" => "US",
15
+ "postal" => "55555",
16
+ "phone" => "3334445555",
17
+ "email" => "tom@jones.com",
18
+ "ecomind" => "E",
19
+ "cvv2" => "123",
20
+ "track" => "Y",
21
+ "tokenize" => "Y",
22
+ "capture" => "Y",
23
+ "bankaba" => "1010101",
24
+ "termid" => "12345",
25
+ "ssnl4" => "1234",
26
+ "license" => "CO:1231231234",
27
+ "profile" => "Y",
28
+ "userfields" => [
29
+ {
30
+ "name0" => "value0"
31
+ },
32
+ {
33
+ "name1" => "value1"
34
+ }
35
+ ]
36
+ }
37
+ end
38
+
39
+ def valid_capture_request
40
+ {
41
+ "retref" => "288002073633",
42
+ "amount" => "596.00",
43
+ "taxamnt" => "40.00",
44
+ "merchid" => "000000927996",
45
+ "ponumber" => "PO-0736332",
46
+ "authcode" => "046221",
47
+ "invoiceid" => "7890"
48
+ }
49
+ end
50
+
51
+ def valid_inquire_request
52
+ {
53
+ 'retref' => '288002073633',
54
+ 'merchid' => '000000927996'
55
+ }
56
+ end
57
+
58
+ def valid_settlestat_request
59
+ {
60
+ "merchid" => "000000927996",
61
+ "date" => "0110"
62
+ }
63
+ end
64
+
65
+ def valid_refund_request
66
+ {
67
+ "retref" => "288009185241",
68
+ "merchid" => "000000927996",
69
+ "amount" => "59.60"
70
+ }
71
+ end
72
+
73
+ def valid_deposit_request
74
+ valid_settlestat_request
75
+ end
76
+
77
+ def valid_void_request
78
+ {
79
+ "retref" => "288013185633",
80
+ "merchid" => "000000927996",
81
+ "amount" => "101"
82
+ }
83
+ end
@@ -0,0 +1,120 @@
1
+ def valid_auth_response
2
+ {
3
+ "respstat" => "A",
4
+ "account" => "41XXXXXXXXXX1111",
5
+ "token" => "9419786452781111",
6
+ "retref" => "343005123105",
7
+ "amount" => "111",
8
+ "merchid" => "020594000000",
9
+ "respcode" => "00",
10
+ "resptext" => "Approved",
11
+ "avsresp" => "9",
12
+ "cvvresp" => "M",
13
+ "authcode" => "046221",
14
+ "respproc" => "FNOR",
15
+ "commcard" => "N"
16
+ }
17
+ end
18
+
19
+ def valid_capture_response
20
+ {
21
+ "amount" => "596.00",
22
+ "setlstat" => "Pending",
23
+ "retref" => "288002073633",
24
+ "merchid" => "000000927996",
25
+ "account" => "41XXXXXXXXXX4113"
26
+ }
27
+ end
28
+
29
+ def valid_inquire_response
30
+ {
31
+ "amount" => "596.00",
32
+ "resptext" => "Approval",
33
+ "setlstat" => "NOTCAPTURED",
34
+ "respcode" => "00",
35
+ "retref" => "288015190411",
36
+ "merchid" => "000000927996",
37
+ "account" => "41XXXXXXXXXX4113",
38
+ "respproc" => "FNOR",
39
+ "respstat" => "A",
40
+ "currency" => "USD"
41
+ }
42
+ end
43
+
44
+ def valid_settlestat_response
45
+ [
46
+ {
47
+ "txns" => [
48
+ {
49
+ "setlstat" => "N",
50
+ "retref" => "179001161341"
51
+ },
52
+ {
53
+ "setlstat" => "Y",
54
+ "retref" => "179002161341"
55
+ }
56
+ ],
57
+ "batchid" => "71742042",
58
+ "hoststat" => "GB",
59
+ "merchid" => "000000927996",
60
+ "hostbatch" => "71742041",
61
+ "respproc" => "FNOR"
62
+ }
63
+ ]
64
+ end
65
+
66
+ def valid_refund_response
67
+ {
68
+ "amount" => "59.60",
69
+ "resptext" => "Approval",
70
+ "authcode" => "REFUND",
71
+ "respcode" => "00",
72
+ "retref" => "288010185242",
73
+ "merchid" => "000000927996",
74
+ "respproc" => "PPS",
75
+ "respstat" => "A"
76
+ }
77
+ end
78
+
79
+ def valid_deposit_response
80
+ [
81
+ {
82
+ "accttype" => "VI",
83
+ "postdate" => "20121009",
84
+ "cbakamnt" => "0.00",
85
+ "feeamnt" => "0.55",
86
+ "currency" => "USD",
87
+ "amount" => "11.00",
88
+ "respproc" => "FNOR",
89
+ "txns" => [
90
+ {
91
+ "merchbatch" => 92821429,
92
+ "retref" => "282005142924",
93
+ "hostbatch" => "1429",
94
+ "feeamnt" => "0.00",
95
+ "action" => "DEB",
96
+ "depamnt" => "11.00"
97
+ }
98
+ ],
99
+ "resptext" => "Successful or something",
100
+ "depositid" => 7,
101
+ "merchid" => "000000927996",
102
+ "action" => "DEB",
103
+ "actdate" => "20121008",
104
+ }
105
+ ]
106
+ end
107
+
108
+ def valid_void_response
109
+ {
110
+ "amount" => "1.01",
111
+ "resptext" => "Approval",
112
+ "authcode" => "REVERS",
113
+ "respcode" => "00",
114
+ "retref" => "288013185633",
115
+ "merchid" => "000000927996",
116
+ "respproc" => "FNOR",
117
+ "respstat" => "A",
118
+ "currency" => "USD"
119
+ }
120
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ describe CardConnect::Configuration do
4
+ before do
5
+ @config = CardConnect::Configuration.new
6
+ end
7
+
8
+ after do
9
+ @config = nil
10
+ end
11
+
12
+ it 'must respond to merchant id' do
13
+ @config.must_respond_to :merchant_id
14
+ end
15
+
16
+ it 'must respond to api username' do
17
+ @config.must_respond_to :api_username
18
+ end
19
+
20
+ it 'must respond to api password' do
21
+ @config.must_respond_to :api_password
22
+ end
23
+
24
+ it 'must respond to endpoint' do
25
+ @config.must_respond_to :endpoint
26
+ end
27
+
28
+ end
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ describe CardConnect::Connection do
4
+ before do
5
+ @connection = CardConnect::Connection.new.connection
6
+ end
7
+
8
+ after do
9
+ @connection = nil
10
+ end
11
+
12
+ describe '#connection' do
13
+ it 'must have user agent in the headers' do
14
+ @connection.headers['User-Agent'].must_equal "CardConnectRubyGem/#{CardConnect::VERSION}"
15
+ end
16
+
17
+ it 'must have a URL that matches the configured endpoint' do
18
+ @connection.url_prefix.host.must_equal URI.parse(CardConnect.configuration.endpoint).host
19
+ @connection.url_prefix.scheme.must_equal "https"
20
+ end
21
+
22
+ describe 'Faraday handlers' do
23
+ it 'must have a handler for basic authentication first' do
24
+ @connection.builder.handlers.first.must_be :===, Faraday::Request::BasicAuthentication
25
+ end
26
+
27
+ it 'must have a handler for encoding the request as json second' do
28
+ @connection.builder.handlers[1].must_be :===, FaradayMiddleware::EncodeJson
29
+ end
30
+
31
+ it 'must have a handler for parsing the json response third' do
32
+ @connection.builder.handlers[2].must_be :===, FaradayMiddleware::ParseJson
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,141 @@
1
+ require 'test_helper'
2
+
3
+ describe CardConnect::Service::AuthorizationRequest do
4
+ before do
5
+ @request = CardConnect::Service::AuthorizationRequest.new(valid_auth_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 account' do
18
+ @request.account.must_equal "4111111111111111"
19
+ end
20
+
21
+ it 'should have expiry' do
22
+ @request.expiry.must_equal "1212"
23
+ end
24
+
25
+ it 'should have amount' do
26
+ @request.amount.must_equal "0"
27
+ end
28
+
29
+ it 'should have currency' do
30
+ @request.currency.must_equal "USD"
31
+ end
32
+
33
+ it 'should have account type' do
34
+ @request.accttype.must_equal "VISA"
35
+ end
36
+
37
+ it 'should have name' do
38
+ @request.name.must_equal "TOM JONES"
39
+ end
40
+
41
+ it 'should have address' do
42
+ @request.address.must_equal "123 MAIN STREET"
43
+ end
44
+
45
+ it 'should have city' do
46
+ @request.city.must_equal "anytown"
47
+ end
48
+
49
+ it 'should have country' do
50
+ @request.country.must_equal "US"
51
+ end
52
+
53
+ it 'should have phone' do
54
+ @request.phone.must_equal "3334445555"
55
+ end
56
+
57
+ it 'should have postal' do
58
+ @request.postal.must_equal "55555"
59
+ end
60
+
61
+ it 'should have email' do
62
+ @request.email.must_equal "tom@jones.com"
63
+ end
64
+
65
+ it 'should have ecomind' do
66
+ @request.ecomind.must_equal "E"
67
+ end
68
+
69
+ it 'should have cvv2' do
70
+ @request.cvv2.must_equal "123"
71
+ end
72
+
73
+ it 'should have order id' do
74
+ @request.orderid.must_equal "AB-11-9876"
75
+ end
76
+
77
+ it 'should have track' do
78
+ @request.track.must_equal "Y"
79
+ end
80
+
81
+ it 'should have bankaba' do
82
+ @request.bankaba.must_equal "1010101"
83
+ end
84
+
85
+ it 'should have tokenize' do
86
+ @request.tokenize.must_equal "Y"
87
+ end
88
+
89
+ it 'should have termid' do
90
+ @request.termid.must_equal "12345"
91
+ end
92
+
93
+ it 'should have capture' do
94
+ @request.capture.must_equal "Y"
95
+ end
96
+
97
+ it 'should have ssnl4 field' do
98
+ @request.ssnl4.must_equal "1234"
99
+ end
100
+
101
+ it 'should have license field' do
102
+ @request.license.must_equal "CO:1231231234"
103
+ end
104
+
105
+ it 'should have profile field' do
106
+ @request.profile.must_equal "Y"
107
+ end
108
+
109
+ describe "userfields" do
110
+ it 'should be an array of name-value pairs' do
111
+ @request.userfields.must_be_kind_of Array
112
+ @request.userfields.first.must_be_kind_of Hash
113
+ @request.userfields.first['name0'].must_equal 'value0'
114
+ end
115
+ end
116
+ end
117
+
118
+ describe '#valid?' do
119
+ it 'should not be valid if no attributes are passed in' do
120
+ CardConnect::Service::AuthorizationRequest.new.valid?.must_equal false
121
+ end
122
+
123
+ it 'should be valid if valid attributes are passed in' do
124
+ CardConnect::Service::AuthorizationRequest.new(valid_auth_request).valid?.must_equal true
125
+ end
126
+ end
127
+
128
+ describe '#errors' do
129
+ CardConnect::Service::AuthorizationRequest::REQUIRED_FIELDS.each do |field|
130
+ it "should have an error message if #{field} is missing" do
131
+ CardConnect::Service::AuthorizationRequest.new.errors.must_include "#{field.to_s.capitalize} is missing"
132
+ end
133
+ end
134
+ end
135
+
136
+ describe '#payload' do
137
+ it 'should generate hash with all the right values' do
138
+ @request.payload.must_equal symbolize_keys(valid_auth_request)
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,93 @@
1
+ require 'test_helper'
2
+
3
+ describe CardConnect::Service::AuthorizationResponse do
4
+ before do
5
+ @response = CardConnect::Service::AuthorizationResponse.new(valid_auth_response)
6
+ end
7
+
8
+ after do
9
+ @response = nil
10
+ end
11
+
12
+ describe 'FIELDS' do
13
+ it 'should have the merchant id' do
14
+ @response.merchid.must_equal "020594000000"
15
+ end
16
+
17
+ it 'should have the status' do
18
+ @response.respstat.must_equal "A"
19
+ end
20
+
21
+ it 'should have the Retrieval Reference Number' do
22
+ @response.retref.must_equal "343005123105"
23
+ end
24
+
25
+ it 'should have the Account Number' do
26
+ @response.account.must_equal "41XXXXXXXXXX1111"
27
+ end
28
+
29
+ it 'should have the Token' do
30
+ @response.token.must_equal "9419786452781111"
31
+ end
32
+
33
+ it 'should have the Amount' do
34
+ @response.amount.must_equal "111"
35
+ end
36
+
37
+ it 'should have the Response Code' do
38
+ @response.respcode.must_equal "00"
39
+ end
40
+
41
+ it 'should have the Response text' do
42
+ @response.resptext.must_equal "Approved"
43
+ end
44
+
45
+ it 'should have the Response Processor' do
46
+ @response.respproc.must_equal "FNOR"
47
+ end
48
+
49
+ it 'should have the AVS response code' do
50
+ @response.avsresp.must_equal "9"
51
+ end
52
+
53
+ it 'should have the CVV response code' do
54
+ @response.cvvresp.must_equal "M"
55
+ end
56
+
57
+ it 'should have the Authorization code' do
58
+ @response.authcode.must_equal "046221"
59
+ end
60
+
61
+ it 'should have the Commercial Card Flag' do
62
+ @response.commcard.must_equal "N"
63
+ end
64
+ end
65
+
66
+ describe '#success?' do
67
+ it 'should be true when there are no errors' do
68
+ @response.success?.must_equal true
69
+ end
70
+
71
+ it 'should be false when there are errors' do
72
+ response = CardConnect::Service::AuthorizationResponse.new(valid_auth_response.merge!("respstat" => "B", "resptext" => "this is an error"))
73
+ response.success?.must_equal false
74
+ end
75
+ end
76
+
77
+ describe '#errors' do
78
+ it 'should be empty when there are no errors' do
79
+ @response.errors.must_be_empty
80
+ end
81
+
82
+ it 'should be an array of error messages when there are errors' do
83
+ response = CardConnect::Service::AuthorizationResponse.new(valid_auth_response.merge!("respstat" => "B", "resptext" => "this is an error"))
84
+ response.errors.must_equal ["this is an error"]
85
+ end
86
+ end
87
+
88
+ describe "#body" do
89
+ it 'should generate hash with all the right values' do
90
+ @response.body.must_equal symbolize_keys(valid_auth_response)
91
+ end
92
+ end
93
+ end