cardconnect 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/README.md +18 -5
  4. data/Rakefile +34 -10
  5. data/lib/cardconnect.rb +7 -3
  6. data/lib/cardconnect/services/authorization/authorization_response.rb +1 -1
  7. data/lib/cardconnect/services/profile/profile.rb +25 -0
  8. data/lib/cardconnect/services/profile/profile_delete_request.rb +49 -0
  9. data/lib/cardconnect/services/profile/profile_delete_response.rb +39 -0
  10. data/lib/cardconnect/services/profile/profile_get_request.rb +49 -0
  11. data/lib/cardconnect/services/profile/profile_get_response.rb +40 -0
  12. data/lib/cardconnect/services/{deposit/deposit_request.rb → profile/profile_put_request.rb} +11 -21
  13. data/lib/cardconnect/services/profile/profile_put_response.rb +42 -0
  14. data/lib/cardconnect/services/service_endpoint.rb +7 -0
  15. data/lib/cardconnect/utils.rb +1 -0
  16. data/lib/cardconnect/version.rb +1 -1
  17. data/test/api_request_stubs.rb +32 -4
  18. data/test/api_response_stubs.rb +62 -30
  19. data/test/cardconnect/services/inquire/inquire_test.rb +1 -1
  20. data/test/cardconnect/services/profile/profile_delete_request_test.rb +50 -0
  21. data/test/cardconnect/services/profile/profile_delete_response_test.rb +67 -0
  22. data/test/cardconnect/services/profile/profile_get_request_test.rb +50 -0
  23. data/test/cardconnect/services/profile/profile_get_response_test.rb +127 -0
  24. data/test/cardconnect/services/profile/profile_put_request_test.rb +114 -0
  25. data/test/cardconnect/services/profile/profile_test.rb +168 -0
  26. metadata +22 -12
  27. data/lib/cardconnect/services/deposit/deposit.rb +0 -15
  28. data/lib/cardconnect/services/deposit/deposit_response.rb +0 -39
  29. data/test/cardconnect/services/deposit/deposit_request_test.rb +0 -65
  30. data/test/cardconnect/services/deposit/deposit_response_test.rb +0 -77
  31. data/test/cardconnect/services/deposit/deposit_test.rb +0 -55
@@ -0,0 +1,114 @@
1
+ require 'test_helper'
2
+
3
+ describe CardConnect::Service::ProfilePutRequest do
4
+ before do
5
+ @request = CardConnect::Service::ProfilePutRequest.new(valid_profile_put_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 profile id' do
18
+ @request.profileid.must_equal '12345678901234567890'
19
+ end
20
+
21
+ it 'should have region' do
22
+ @request.region.must_equal 'AK'
23
+ end
24
+
25
+ it 'should have phone' do
26
+ @request.phone.must_equal '7778789999'
27
+ end
28
+
29
+ it 'should have accttype' do
30
+ @request.accttype.must_equal 'VISA'
31
+ end
32
+
33
+ it 'should have postal' do
34
+ @request.postal.must_equal '19090'
35
+ end
36
+
37
+ it 'should have ssnl4' do
38
+ @request.ssnl4.must_equal '3655'
39
+ end
40
+
41
+ it 'should have expiry' do
42
+ @request.expiry.must_equal '0214'
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 address' do
54
+ @request.address.must_equal '123 MAIN STREET'
55
+ end
56
+
57
+ it 'should have name' do
58
+ @request.name.must_equal 'TOM JONES'
59
+ end
60
+
61
+ it 'should have account' do
62
+ @request.account.must_equal '4444333322221111'
63
+ end
64
+
65
+ it 'should have license' do
66
+ @request.license.must_equal '123451254'
67
+ end
68
+
69
+ it 'should have defaultacct' do
70
+ @request.defaultacct.must_equal 'N'
71
+ end
72
+
73
+ it 'should have profileupdate' do
74
+ @request.profileupdate.must_equal 'Y'
75
+ end
76
+
77
+ it 'should have profile' do
78
+ @request.profile.must_equal '12345678901234567890acctid'
79
+ end
80
+
81
+ it 'should have bankaba' do
82
+ @request.bankaba.must_equal '1234567'
83
+ end
84
+
85
+ it 'should have email' do
86
+ @request.email.must_equal 'test@email.com'
87
+ end
88
+ end
89
+
90
+ describe '#valid?' do
91
+ it 'should not be valid if no attributes are passed in' do
92
+ CardConnect::Service::ProfilePutRequest.new.valid?.must_equal false
93
+ end
94
+
95
+ it 'should be valid if valid attributes are passed in' do
96
+ CardConnect::Service::ProfilePutRequest.new(valid_profile_put_request).valid?.must_equal true
97
+ end
98
+ end
99
+
100
+ describe '#errors' do
101
+ CardConnect::Service::ProfilePutRequest::REQUIRED_FIELDS.each do |field|
102
+ field_name = field.to_s.capitalize
103
+ it "should have an error message if #{field_name} is missing" do
104
+ CardConnect::Service::ProfilePutRequest.new.errors.must_include "#{field_name} is missing"
105
+ end
106
+ end
107
+ end
108
+
109
+ describe '#payload' do
110
+ it 'should generate hash with all the right values' do
111
+ @request.payload.must_equal symbolize_keys(valid_profile_put_request)
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,168 @@
1
+ require 'test_helper'
2
+
3
+ describe CardConnect::Service::Profile do
4
+
5
+ describe 'GET profile' do
6
+ before do
7
+ @connection = CardConnect::Connection.new.connection do |stubs|
8
+ path = "#{@service.path}/#{valid_profile_request['profileid']}/#{valid_profile_request['acctid']}/#{valid_profile_request['merchid']}"
9
+ stubs.get(path) { [200, {}, valid_profile_get_response] }
10
+ end
11
+ @service = CardConnect::Service::Profile.new('get', @connection)
12
+ end
13
+
14
+ after do
15
+ @service = nil
16
+ end
17
+
18
+ it 'must have the right path' do
19
+ @service.path.must_equal '/cardconnect/rest/profile'
20
+ end
21
+
22
+ describe '#build_request' do
23
+ before do
24
+ @valid_params = valid_profile_request
25
+ end
26
+
27
+ after do
28
+ @valid_params = nil
29
+ end
30
+
31
+ it 'creates a profile request object with the passed in params' do
32
+ @service.build_request(@valid_params)
33
+
34
+ @service.request.must_be_kind_of CardConnect::Service::ProfileGetRequest
35
+ @service.request.acctid.must_equal '1'
36
+ @service.request.merchid.must_equal '000000927996'
37
+ end
38
+
39
+ it 'uses default merchant ID if merchid is not passed in' do
40
+ @service.build_request(@valid_params.reject! { |k, _| k == 'merchid' })
41
+ @service.request.must_be_kind_of CardConnect::Service::ProfileGetRequest
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_profile_request)
54
+ @service.submit
55
+ @service.response.must_be_kind_of CardConnect::Service::ProfileGetResponse
56
+ end
57
+ end
58
+ end
59
+
60
+ describe 'DELETE profile' do
61
+ before do
62
+ @connection = CardConnect::Connection.new.connection do |stubs|
63
+ path = "#{@service.path}/#{valid_profile_request['profileid']}/#{valid_profile_request['acctid']}/#{valid_profile_request['merchid']}"
64
+ stubs.delete(path) { [200, {}, valid_profile_delete_response] }
65
+ end
66
+ @service = CardConnect::Service::Profile.new('delete', @connection)
67
+ end
68
+
69
+ after do
70
+ @service = nil
71
+ end
72
+
73
+ it 'must have the right path' do
74
+ @service.path.must_equal '/cardconnect/rest/profile'
75
+ end
76
+
77
+ describe '#build_request' do
78
+ before do
79
+ @valid_params = valid_profile_request
80
+ end
81
+
82
+ after do
83
+ @valid_params = nil
84
+ end
85
+
86
+ it 'creates a profile request object with the passed in params' do
87
+ @service.build_request(@valid_params)
88
+
89
+ @service.request.must_be_kind_of CardConnect::Service::ProfileDeleteRequest
90
+ @service.request.acctid.must_equal '1'
91
+ @service.request.merchid.must_equal '000000927996'
92
+ end
93
+
94
+ it 'uses default merchant ID if merchid is not passed in' do
95
+ @service.build_request(@valid_params.reject! { |k, _| k == 'merchid' })
96
+ @service.request.must_be_kind_of CardConnect::Service::ProfileDeleteRequest
97
+ @service.request.merchid.must_equal 'merchant123'
98
+ end
99
+ end
100
+
101
+ describe '#submit' do
102
+ it 'raises an error when there is no request' do
103
+ @service.request.nil?.must_equal true
104
+ proc { @service.submit }.must_raise CardConnect::Error
105
+ end
106
+
107
+ it 'creates a response when a valid request is processed' do
108
+ @service.build_request(valid_profile_request)
109
+ @service.submit
110
+ @service.response.must_be_kind_of CardConnect::Service::ProfileDeleteResponse
111
+ end
112
+ end
113
+ end
114
+
115
+ describe 'CREATE/UPDATE profile' do
116
+ before do
117
+ @connection = CardConnect::Connection.new.connection do |stubs|
118
+ stubs.put(@service.path) { [200, {}, valid_profile_put_response] }
119
+ end
120
+ @service = CardConnect::Service::Profile.new('put', @connection)
121
+ end
122
+
123
+ after do
124
+ @service = nil
125
+ end
126
+
127
+ it 'must have the right path' do
128
+ @service.path.must_equal '/cardconnect/rest/profile'
129
+ end
130
+
131
+ describe '#build_request' do
132
+ before do
133
+ @valid_params = valid_profile_request
134
+ end
135
+
136
+ after do
137
+ @valid_params = nil
138
+ end
139
+
140
+ it 'creates a profile request object with the passed in params' do
141
+ @service.build_request(@valid_params)
142
+
143
+ @service.request.must_be_kind_of CardConnect::Service::ProfilePutRequest
144
+ @service.request.merchid.must_equal '000000927996'
145
+ @service.request.profileid.must_equal '12345678901234567890'
146
+ end
147
+
148
+ it 'uses default merchant ID if merchid is not passed in' do
149
+ @service.build_request(@valid_params.reject! { |k, _| k == 'merchid' })
150
+ @service.request.must_be_kind_of CardConnect::Service::ProfilePutRequest
151
+ @service.request.merchid.must_equal 'merchant123'
152
+ end
153
+ end
154
+
155
+ describe '#submit' do
156
+ it 'raises an error when there is no request' do
157
+ @service.request.nil?.must_equal true
158
+ proc { @service.submit }.must_raise CardConnect::Error
159
+ end
160
+
161
+ it 'creates a response when a valid request is processed' do
162
+ @service.build_request(valid_profile_request)
163
+ @service.submit
164
+ @service.response.must_be_kind_of CardConnect::Service::ProfilePutResponse
165
+ end
166
+ end
167
+ end
168
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cardconnect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim McKenzie
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-11-09 00:00:00.000000000 Z
13
+ date: 2017-05-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -82,12 +82,16 @@ files:
82
82
  - lib/cardconnect/services/capture/capture.rb
83
83
  - lib/cardconnect/services/capture/capture_request.rb
84
84
  - lib/cardconnect/services/capture/capture_response.rb
85
- - lib/cardconnect/services/deposit/deposit.rb
86
- - lib/cardconnect/services/deposit/deposit_request.rb
87
- - lib/cardconnect/services/deposit/deposit_response.rb
88
85
  - lib/cardconnect/services/inquire/inquire.rb
89
86
  - lib/cardconnect/services/inquire/inquire_request.rb
90
87
  - lib/cardconnect/services/inquire/inquire_response.rb
88
+ - lib/cardconnect/services/profile/profile.rb
89
+ - lib/cardconnect/services/profile/profile_delete_request.rb
90
+ - lib/cardconnect/services/profile/profile_delete_response.rb
91
+ - lib/cardconnect/services/profile/profile_get_request.rb
92
+ - lib/cardconnect/services/profile/profile_get_response.rb
93
+ - lib/cardconnect/services/profile/profile_put_request.rb
94
+ - lib/cardconnect/services/profile/profile_put_response.rb
91
95
  - lib/cardconnect/services/refund/refund.rb
92
96
  - lib/cardconnect/services/refund/refund_request.rb
93
97
  - lib/cardconnect/services/refund/refund_response.rb
@@ -110,12 +114,15 @@ files:
110
114
  - test/cardconnect/services/capture/capture_request_test.rb
111
115
  - test/cardconnect/services/capture/capture_response_test.rb
112
116
  - test/cardconnect/services/capture/capture_test.rb
113
- - test/cardconnect/services/deposit/deposit_request_test.rb
114
- - test/cardconnect/services/deposit/deposit_response_test.rb
115
- - test/cardconnect/services/deposit/deposit_test.rb
116
117
  - test/cardconnect/services/inquire/inquire_request_test.rb
117
118
  - test/cardconnect/services/inquire/inquire_response_test.rb
118
119
  - test/cardconnect/services/inquire/inquire_test.rb
120
+ - test/cardconnect/services/profile/profile_delete_request_test.rb
121
+ - test/cardconnect/services/profile/profile_delete_response_test.rb
122
+ - test/cardconnect/services/profile/profile_get_request_test.rb
123
+ - test/cardconnect/services/profile/profile_get_response_test.rb
124
+ - test/cardconnect/services/profile/profile_put_request_test.rb
125
+ - test/cardconnect/services/profile/profile_test.rb
119
126
  - test/cardconnect/services/refund/refund_request_test.rb
120
127
  - test/cardconnect/services/refund/refund_response_test.rb
121
128
  - test/cardconnect/services/refund/refund_test.rb
@@ -147,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
154
  version: '0'
148
155
  requirements: []
149
156
  rubyforge_project:
150
- rubygems_version: 2.5.1
157
+ rubygems_version: 2.6.8
151
158
  signing_key:
152
159
  specification_version: 4
153
160
  summary: CardConnect API Ruby Client
@@ -162,12 +169,15 @@ test_files:
162
169
  - test/cardconnect/services/capture/capture_request_test.rb
163
170
  - test/cardconnect/services/capture/capture_response_test.rb
164
171
  - test/cardconnect/services/capture/capture_test.rb
165
- - test/cardconnect/services/deposit/deposit_request_test.rb
166
- - test/cardconnect/services/deposit/deposit_response_test.rb
167
- - test/cardconnect/services/deposit/deposit_test.rb
168
172
  - test/cardconnect/services/inquire/inquire_request_test.rb
169
173
  - test/cardconnect/services/inquire/inquire_response_test.rb
170
174
  - test/cardconnect/services/inquire/inquire_test.rb
175
+ - test/cardconnect/services/profile/profile_delete_request_test.rb
176
+ - test/cardconnect/services/profile/profile_delete_response_test.rb
177
+ - test/cardconnect/services/profile/profile_get_request_test.rb
178
+ - test/cardconnect/services/profile/profile_get_response_test.rb
179
+ - test/cardconnect/services/profile/profile_put_request_test.rb
180
+ - test/cardconnect/services/profile/profile_test.rb
171
181
  - test/cardconnect/services/refund/refund_request_test.rb
172
182
  - test/cardconnect/services/refund/refund_response_test.rb
173
183
  - test/cardconnect/services/refund/refund_test.rb
@@ -1,15 +0,0 @@
1
- module CardConnect
2
- module Service
3
- class Deposit < ServiceEndpoint
4
- # Initializes a Deposit Service
5
- #
6
- # @param connection [CardConnect::Connection]
7
- # @return CardConnect::Service::Deposit
8
- def initialize(connection = CardConnect.connection)
9
- super(connection)
10
- @resource_name = '/deposit'
11
- @rest_method = 'get'
12
- end
13
- end
14
- end
15
- end
@@ -1,39 +0,0 @@
1
- module CardConnect
2
- module Service
3
- class DepositResponse
4
- include Utils
5
-
6
- FIELDS = [:depositid, :merchid, :respproc, :accttype, :action, :actdate,
7
- :postdate, :currency, :amount, :feeamnt, :cbakamnt, :resptext, :txns].freeze
8
-
9
- attr_accessor(*FIELDS)
10
- attr_reader :errors
11
-
12
- def initialize(response)
13
- response = response.empty? ? response : response.first
14
- set_attributes(response, FIELDS)
15
- parse_transactions
16
- @errors = []
17
- end
18
-
19
- def success?
20
- errors.empty?
21
- end
22
-
23
- def body
24
- body = {}
25
- FIELDS.each do |attr|
26
- body.merge!(attr => send(attr))
27
- end
28
- body
29
- end
30
-
31
- private
32
-
33
- def parse_transactions
34
- return if txns.nil?
35
- txns.each_with_index { |txn, i| txns[i] = symbolize_keys(txn) }
36
- end
37
- end
38
- end
39
- end
@@ -1,65 +0,0 @@
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