cardconnect 1.1.1 → 2.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 (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
@@ -28,6 +28,7 @@ module CardConnect
28
28
 
29
29
  def submit
30
30
  raise CardConnect::Error, 'Request has not been built' if request.nil?
31
+ raise CardConnect::Error, 'Rest method is required' if rest_method.nil?
31
32
  @response = send(rest_method)
32
33
  end
33
34
 
@@ -43,6 +44,12 @@ module CardConnect
43
44
  puts e.message
44
45
  end
45
46
 
47
+ def delete
48
+ response_class.new(connection.delete(path + request.payload).body)
49
+ rescue Faraday::ResourceNotFound => e
50
+ puts e.message
51
+ end
52
+
46
53
  def put
47
54
  response_class.new(connection.put(path, request.payload).body)
48
55
  rescue Faraday::ResourceNotFound => e
@@ -2,6 +2,7 @@ module CardConnect
2
2
  module Utils
3
3
  def set_attributes(attributes, fields)
4
4
  return if attributes.empty?
5
+ attributes = attributes[0] if attributes.is_a? Array
5
6
  attributes = symbolize_keys(attributes)
6
7
  fields.each do |attr|
7
8
  next unless attributes[attr]
@@ -1,3 +1,3 @@
1
1
  module CardConnect
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -74,10 +74,6 @@ def valid_refund_request
74
74
  }
75
75
  end
76
76
 
77
- def valid_deposit_request
78
- valid_settlestat_request
79
- end
80
-
81
77
  def valid_void_request
82
78
  {
83
79
  'retref' => '288013185633',
@@ -85,3 +81,35 @@ def valid_void_request
85
81
  'amount' => '101'
86
82
  }
87
83
  end
84
+
85
+ def valid_profile_request
86
+ {
87
+ 'profileid' => '12345678901234567890',
88
+ 'acctid' => '1',
89
+ 'merchid' => '000000927996'
90
+ }
91
+ end
92
+
93
+ def valid_profile_put_request
94
+ {
95
+ "region" => "AK",
96
+ "phone" => "7778789999",
97
+ "accttype" => "VISA",
98
+ "postal" => "19090",
99
+ "ssnl4" => "3655",
100
+ "expiry" => "0214",
101
+ "city" => "ANYTOWN",
102
+ "country" => "US",
103
+ "address" => "123 MAIN STREET",
104
+ "merchid" => '000000927996',
105
+ "profileid" => '12345678901234567890',
106
+ "profile" => '12345678901234567890acctid',
107
+ "bankaba" => '1234567',
108
+ "email" => 'test@email.com',
109
+ "name" => "TOM JONES",
110
+ "account" => "4444333322221111",
111
+ "license" => "123451254",
112
+ "defaultacct" => "N",
113
+ "profileupdate" => "Y"
114
+ }
115
+ end
@@ -13,7 +13,8 @@ def valid_auth_response # rubocop:disable Metrics/MethodLength
13
13
  'authcode' => '046221',
14
14
  'respproc' => 'FNOR',
15
15
  'commcard' => 'N',
16
- 'profileid' => '12345678'
16
+ 'profileid' => '12345678',
17
+ 'acctid' => nil
17
18
  }
18
19
  end
19
20
 
@@ -71,35 +72,6 @@ def valid_refund_response
71
72
  }
72
73
  end
73
74
 
74
- def valid_deposit_response # rubocop:disable Metrics/MethodLength
75
- [
76
- {
77
- 'accttype' => 'VI',
78
- 'postdate' => '20121009',
79
- 'cbakamnt' => '0.00',
80
- 'feeamnt' => '0.55',
81
- 'currency' => 'USD',
82
- 'amount' => '11.00',
83
- 'respproc' => 'FNOR',
84
- 'txns' => [
85
- {
86
- 'merchbatch' => 92821429,
87
- 'retref' => '282005142924',
88
- 'hostbatch' => '1429',
89
- 'feeamnt' => '0.00',
90
- 'action' => 'DEB',
91
- 'depamnt' => '11.00'
92
- }
93
- ],
94
- 'resptext' => 'Successful or something',
95
- 'depositid' => 7,
96
- 'merchid' => '000000927996',
97
- 'action' => 'DEB',
98
- 'actdate' => '20121008'
99
- }
100
- ]
101
- end
102
-
103
75
  def valid_void_response # rubocop:disable Metrics/MethodLength
104
76
  {
105
77
  'amount' => '1.01',
@@ -113,3 +85,63 @@ def valid_void_response # rubocop:disable Metrics/MethodLength
113
85
  'currency' => 'USD'
114
86
  }
115
87
  end
88
+
89
+ def valid_profile_get_response #rubocop:disable Metrics/MethodLength
90
+ {
91
+ "resptext" => 'Profile found',
92
+ "respcode" => 'A',
93
+ "respstat" => 'B',
94
+ "respproc" => "PPS",
95
+ "account" => '41XXXXXXXXXX1111',
96
+ "defaultacct" => "12345",
97
+ "ssnl4" => "1234",
98
+ "email" => 'test@test.com',
99
+ "phone" => "7778789999",
100
+ "region" => "AK",
101
+ "postal" => "19090",
102
+ "address" => "123 MAIN STREET",
103
+ "accttype" => "VISA",
104
+ "token" => "9440670166031111",
105
+ "name" => "TOM JONES",
106
+ "license" => "123451254",
107
+ "country" => "US",
108
+ "city" => "ANYTOWN",
109
+ "expiry" => "0214",
110
+ "profileid" => "12345678901234567890",
111
+ "acctid" => "1"
112
+ }
113
+ end
114
+
115
+ def valid_profile_delete_response #rubocop:disable Metrics/MethodLength
116
+ {
117
+ "resptext" => "Profile Deleted",
118
+ "respcode" => "08",
119
+ "profileid" => "12345678901234567890",
120
+ "acctid" => "1",
121
+ "respproc" => "PPS",
122
+ "respstat" => "A"
123
+ }
124
+ end
125
+
126
+ def valid_profile_put_response #rubocop:disable Metrics/MethodLength
127
+ {
128
+ "region" => "AK",
129
+ "phone" => "7778789999",
130
+ "accttype" => "VISA",
131
+ "postal" => "19090",
132
+ "ssnl4" => "3655",
133
+ "respproc" => "PPS",
134
+ "expiry" => "0214",
135
+ "city" => "ANYTOWN",
136
+ "country" => "US",
137
+ "resptext" => "Profile Saved",
138
+ "token" => "9440670166031111",
139
+ "respcode" => "09",
140
+ "address" => "123 MAIN STREET",
141
+ "name" => "TOM JONES",
142
+ "license" => "123451254",
143
+ "respstat" => "A",
144
+ "profileid" => "12345678901234567890",
145
+ "acctid" => "1"
146
+ }
147
+ end
@@ -26,7 +26,7 @@ describe CardConnect::Service::Inquire do
26
26
  @valid_params = nil
27
27
  end
28
28
 
29
- it 'creates a Capture request object with the passed in params' do
29
+ it 'creates a inquire request object with the passed in params' do
30
30
  @service.build_request(@valid_params)
31
31
 
32
32
  @service.request.must_be_kind_of CardConnect::Service::InquireRequest
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ describe CardConnect::Service::ProfileDeleteRequest do
4
+ before do
5
+ @request = CardConnect::Service::ProfileDeleteRequest.new(valid_profile_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 account id' do
22
+ @request.acctid.must_equal '1'
23
+ end
24
+ end
25
+
26
+ describe '#valid?' do
27
+ it 'should not be valid if no attributes are passed in' do
28
+ CardConnect::Service::ProfileDeleteRequest.new.valid?.must_equal false
29
+ end
30
+
31
+ it 'should be valid if valid attributes are passed in' do
32
+ CardConnect::Service::ProfileDeleteRequest.new(valid_profile_request).valid?.must_equal true
33
+ end
34
+ end
35
+
36
+ describe '#errors' do
37
+ CardConnect::Service::ProfileDeleteRequest::REQUIRED_FIELDS.each do |field|
38
+ field_name = field.to_s.capitalize
39
+ it "should have an error message if #{field_name} is missing" do
40
+ CardConnect::Service::ProfileDeleteRequest.new.errors.must_include "#{field_name} is missing"
41
+ end
42
+ end
43
+ end
44
+
45
+ describe '#payload' do
46
+ it 'should generate hash with all the right values' do
47
+ @request.payload.must_equal "/12345678901234567890/1/000000927996"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,67 @@
1
+ require 'test_helper'
2
+
3
+ describe CardConnect::Service::ProfileDeleteResponse do
4
+ before do
5
+ @response = CardConnect::Service::ProfileDeleteResponse.new(valid_profile_delete_response)
6
+ end
7
+
8
+ after do
9
+ @response = nil
10
+ end
11
+
12
+ describe 'FIELDS' do
13
+ it 'should have response text' do
14
+ @response.resptext.must_equal 'Profile Deleted'
15
+ end
16
+
17
+ it 'should have the response code' do
18
+ @response.respcode.must_equal '08'
19
+ end
20
+
21
+ it 'should have the respproc' do
22
+ @response.respproc.must_equal 'PPS'
23
+ end
24
+
25
+ it 'should have response status' do
26
+ @response.respstat.must_equal 'A'
27
+ end
28
+
29
+ it 'should have profileid' do
30
+ @response.profileid.must_equal '12345678901234567890'
31
+ end
32
+
33
+ it 'should have acctid' do
34
+ @response.acctid.must_equal '1'
35
+ end
36
+ end
37
+
38
+ describe '#success?' do
39
+ it 'should be true when there are no errors' do
40
+ @response.success?.must_equal true
41
+ end
42
+
43
+ it 'should be false when there are errors' do
44
+ prof_response = valid_profile_delete_response.merge!('respstat' => 'C', 'resptext' => 'this is an error')
45
+ response = CardConnect::Service::ProfileDeleteResponse.new(prof_response)
46
+ response.success?.must_equal false
47
+ end
48
+ end
49
+
50
+ describe '#errors' do
51
+ it 'should be empty when there are no errors' do
52
+ @response.errors.must_be_empty
53
+ end
54
+
55
+ it 'should be an array of error messages when there are errors' do
56
+ prof_response = valid_profile_delete_response.merge!('respstat' => 'C', 'resptext' => 'this is an error')
57
+ response = CardConnect::Service::ProfileDeleteResponse.new(prof_response)
58
+ response.errors.must_equal ['this is an error']
59
+ end
60
+ end
61
+
62
+ describe '#body' do
63
+ it 'should generate hash with all the right values' do
64
+ @response.body.must_equal symbolize_keys(valid_profile_delete_response)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ describe CardConnect::Service::ProfileGetRequest do
4
+ before do
5
+ @request = CardConnect::Service::ProfileGetRequest.new(valid_profile_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 account id' do
22
+ @request.acctid.must_equal '1'
23
+ end
24
+ end
25
+
26
+ describe '#valid?' do
27
+ it 'should not be valid if no attributes are passed in' do
28
+ CardConnect::Service::ProfileGetRequest.new.valid?.must_equal false
29
+ end
30
+
31
+ it 'should be valid if valid attributes are passed in' do
32
+ CardConnect::Service::ProfileGetRequest.new(valid_profile_request).valid?.must_equal true
33
+ end
34
+ end
35
+
36
+ describe '#errors' do
37
+ CardConnect::Service::ProfileGetRequest::REQUIRED_FIELDS.each do |field|
38
+ field_name = field.to_s.capitalize
39
+ it "should have an error message if #{field_name} is missing" do
40
+ CardConnect::Service::ProfileGetRequest.new.errors.must_include "#{field_name} is missing"
41
+ end
42
+ end
43
+ end
44
+
45
+ describe '#payload' do
46
+ it 'should generate hash with all the right values' do
47
+ @request.payload.must_equal "/12345678901234567890/1/000000927996"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,127 @@
1
+ require 'test_helper'
2
+
3
+ describe CardConnect::Service::ProfileGetResponse do
4
+ before do
5
+ @response = CardConnect::Service::ProfileGetResponse.new(valid_profile_get_response)
6
+ end
7
+
8
+ after do
9
+ @response = nil
10
+ end
11
+
12
+ describe 'FIELDS' do
13
+ it 'should have profile id' do
14
+ @response.profileid.must_equal '12345678901234567890'
15
+ end
16
+
17
+ it 'should have account id' do
18
+ @response.acctid.must_equal '1'
19
+ end
20
+
21
+ it 'should have response status' do
22
+ @response.respstat.must_equal 'B'
23
+ end
24
+
25
+ it 'should have account' do
26
+ @response.account.must_equal '41XXXXXXXXXX1111'
27
+ end
28
+
29
+ it 'should have response code' do
30
+ @response.respcode.must_equal 'A'
31
+ end
32
+
33
+ it 'should have response text' do
34
+ @response.resptext.must_equal 'Profile found'
35
+ end
36
+
37
+ it 'should have respproc' do
38
+ @response.respproc.must_equal 'PPS'
39
+ end
40
+
41
+ it 'should have accttype' do
42
+ @response.accttype.must_equal 'VISA'
43
+ end
44
+
45
+ it 'should have expiry' do
46
+ @response.expiry.must_equal '0214'
47
+ end
48
+
49
+ it 'should have name' do
50
+ @response.name.must_equal 'TOM JONES'
51
+ end
52
+
53
+ it 'should have address' do
54
+ @response.address.must_equal '123 MAIN STREET'
55
+ end
56
+
57
+ it 'should have city' do
58
+ @response.city.must_equal 'ANYTOWN'
59
+ end
60
+
61
+ it 'should have region' do
62
+ @response.region.must_equal 'AK'
63
+ end
64
+
65
+ it 'should have country' do
66
+ @response.country.must_equal 'US'
67
+ end
68
+
69
+ it 'should have phone' do
70
+ @response.phone.must_equal '7778789999'
71
+ end
72
+
73
+ it 'should have postal' do
74
+ @response.postal.must_equal '19090'
75
+ end
76
+
77
+ it 'should have ssnl4' do
78
+ @response.ssnl4.must_equal '1234'
79
+ end
80
+
81
+ it 'should have email' do
82
+ @response.email.must_equal 'test@test.com'
83
+ end
84
+
85
+ it 'should have defaultacct' do
86
+ @response.defaultacct.must_equal '12345'
87
+ end
88
+
89
+ it 'should have license' do
90
+ @response.license.must_equal '123451254'
91
+ end
92
+
93
+ it 'should have token' do
94
+ @response.token.must_equal '9440670166031111'
95
+ end
96
+ end
97
+
98
+ describe '#success?' do
99
+ it 'should be true when there are no errors' do
100
+ @response.success?.must_equal true
101
+ end
102
+
103
+ it 'should be false when there are errors' do
104
+ prof_response = valid_profile_get_response.merge!('respstat' => 'C', 'resptext' => 'this is an error')
105
+ response = CardConnect::Service::ProfileGetResponse.new(prof_response)
106
+ response.success?.must_equal false
107
+ end
108
+ end
109
+
110
+ describe '#errors' do
111
+ it 'should be empty when there are no errors' do
112
+ @response.errors.must_be_empty
113
+ end
114
+
115
+ it 'should be an array of error messages when there are errors' do
116
+ prof_response = valid_profile_get_response.merge!('respstat' => 'C', 'resptext' => 'this is an error')
117
+ response = CardConnect::Service::ProfileGetResponse.new(prof_response)
118
+ response.errors.must_equal ['this is an error']
119
+ end
120
+ end
121
+
122
+ describe '#body' do
123
+ it 'should generate hash with all the right values' do
124
+ @response.body.must_equal symbolize_keys(valid_profile_get_response)
125
+ end
126
+ end
127
+ end