hps 1.0.1

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 (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE.txt +32 -0
  5. data/PRIVACY.txt +66 -0
  6. data/README.md +41 -0
  7. data/Rakefile +15 -0
  8. data/hps.gemspec +26 -0
  9. data/lib/hps.rb +45 -0
  10. data/lib/hps/configuration.rb +17 -0
  11. data/lib/hps/entities/hps_account_verify.rb +9 -0
  12. data/lib/hps/entities/hps_address.rb +7 -0
  13. data/lib/hps/entities/hps_authorization.rb +13 -0
  14. data/lib/hps/entities/hps_batch.rb +7 -0
  15. data/lib/hps/entities/hps_cardholder.rb +7 -0
  16. data/lib/hps/entities/hps_charge.rb +9 -0
  17. data/lib/hps/entities/hps_charge_exceptions.rb +7 -0
  18. data/lib/hps/entities/hps_credit_card.rb +33 -0
  19. data/lib/hps/entities/hps_refund.rb +9 -0
  20. data/lib/hps/entities/hps_report_transaction_details.rb +11 -0
  21. data/lib/hps/entities/hps_report_transaction_summary.rb +7 -0
  22. data/lib/hps/entities/hps_reversal.rb +11 -0
  23. data/lib/hps/entities/hps_token_data.rb +11 -0
  24. data/lib/hps/entities/hps_transaction.rb +161 -0
  25. data/lib/hps/entities/hps_transaction_details.rb +7 -0
  26. data/lib/hps/entities/hps_transaction_header.rb +9 -0
  27. data/lib/hps/entities/hps_transaction_type.rb +17 -0
  28. data/lib/hps/entities/hps_void.rb +9 -0
  29. data/lib/hps/infrastructure/api_connection_exception.rb +11 -0
  30. data/lib/hps/infrastructure/authentication_exception.rb +11 -0
  31. data/lib/hps/infrastructure/card_exception.rb +15 -0
  32. data/lib/hps/infrastructure/exceptions.json +469 -0
  33. data/lib/hps/infrastructure/hps_exception.rb +25 -0
  34. data/lib/hps/infrastructure/hps_exception_mapper.rb +135 -0
  35. data/lib/hps/infrastructure/hps_sdk_codes.rb +49 -0
  36. data/lib/hps/infrastructure/invalid_request_exception.rb +15 -0
  37. data/lib/hps/services/hps_batch_service.rb +30 -0
  38. data/lib/hps/services/hps_charge_service.rb +635 -0
  39. data/lib/hps/services/hps_service.rb +128 -0
  40. data/lib/hps/version.rb +3 -0
  41. data/tests/amex_tests.rb +231 -0
  42. data/tests/cert_tests.rb +81 -0
  43. data/tests/discover_tests.rb +325 -0
  44. data/tests/exception_mapper_tests.rb +245 -0
  45. data/tests/general_tests.rb +58 -0
  46. data/tests/hps_token_service.rb +56 -0
  47. data/tests/mastercard_tests.rb +326 -0
  48. data/tests/secret_key.rb +12 -0
  49. data/tests/test_data.rb +128 -0
  50. data/tests/test_helper.rb +92 -0
  51. data/tests/token_tests.rb +513 -0
  52. data/tests/visa_tests.rb +378 -0
  53. metadata +165 -0
@@ -0,0 +1,128 @@
1
+ require 'active_support/core_ext/hash/conversions'
2
+
3
+ module Hps
4
+ class HpsService
5
+
6
+ attr_accessor :exception_mapper
7
+
8
+ attr_accessor *Configuration::VALID_CONFIG_KEYS
9
+
10
+ def initialize(options={})
11
+
12
+ merged_options = Hps.options.merge(options)
13
+
14
+ Configuration::VALID_CONFIG_KEYS.each do |key|
15
+ send("#{key}=", merged_options[key])
16
+ end
17
+
18
+ @exception_mapper = Hps::ExceptionMapper.new
19
+ end
20
+
21
+ #protected
22
+
23
+ def doTransaction(transaction)
24
+
25
+ if configuration_invalid
26
+ raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_transaction_id)
27
+ end
28
+
29
+ xml = Builder::XmlMarkup.new
30
+ xml.instruct!(:xml, :encoding => "UTF-8")
31
+ xml.SOAP :Envelope, {
32
+ 'xmlns:SOAP' => 'http://schemas.xmlsoap.org/soap/envelope/',
33
+ 'xmlns:hps' => 'http://Hps.Exchange.PosGateway' } do
34
+ xml.SOAP :Body do
35
+ xml.hps :PosRequest do
36
+ xml.hps 'Ver1.0'.to_sym do
37
+ xml.hps :Header do
38
+ if self.secret_api_key
39
+ self.service_uri = gateway_url_for_key self.secret_api_key
40
+ xml.hps :SecretAPIKey, self.secret_api_key
41
+ else
42
+ xml.hps :UserName, self.user_name
43
+ xml.hps :Password, self.password
44
+ xml.hps :DeviceId, self.device_id
45
+ xml.hps :LicenseId, self.license_id
46
+ xml.hps :SiteId, self.site_id
47
+ end
48
+ xml.hps :DeveloperID, self.developer_id if self.developer_id
49
+ xml.hps :VersionNbr, self.version_number if self.version_number
50
+ xml.hps :SiteTrace, self.site_trace if self.site_trace
51
+ end
52
+
53
+ xml << transaction
54
+
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ begin
61
+
62
+ uri = URI.parse(self.service_uri)
63
+ http = Net::HTTP.new uri.host, uri.port
64
+ http.use_ssl = true
65
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
66
+ data = xml.target!
67
+
68
+ response = http.post(uri.path, data, 'Content-type' => 'text/xml')
69
+
70
+ # NOTE: If the HTTP request was successful
71
+ if response.is_a? Net::HTTPOK
72
+
73
+ # NOTE: Convert XML to a Hash
74
+ soap_hash = Hash.from_xml(response.body)
75
+ # NOTE: Peel away the layers and return only the PosRespose
76
+ soap_hash["Envelope"]["Body"]["PosResponse"]["Ver1.0"]
77
+
78
+ else
79
+ raise @exception_mapper.map_sdk_exception(SdkCodes.unable_to_process_transaction)
80
+ end
81
+
82
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
83
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
84
+ raise @exception_mapper.map_sdk_exception(SdkCodes.unable_to_process_transaction, e)
85
+ end
86
+
87
+ end
88
+
89
+ def gateway_url_for_key(api_key)
90
+
91
+ gateway_url = "https://posgateway.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx?wsdl"
92
+
93
+ if api_key.include? "_uat_"
94
+
95
+ gateway_url = "https://posgateway.uat.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx?wsdl"
96
+
97
+ elsif api_key.include? "_cert_"
98
+
99
+ gateway_url = "https://posgateway.cert.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx?wsdl"
100
+ end
101
+
102
+ gateway_url
103
+ end
104
+
105
+ def hydrate_transaction_header(header)
106
+ result = HpsTransactionHeader.new
107
+ result.gateway_response_code = header["GatewayRspCode"]
108
+ result.gateway_response_message = header["GatewayRspMsg"]
109
+ result.response_dt = header["RspDT"]
110
+ result.client_txn_id = header["GatewayTxnId"]
111
+ result
112
+ end
113
+
114
+ private
115
+
116
+ def configuration_invalid
117
+ self.secret_api_key.nil? and (
118
+ self.service_uri.nil? or
119
+ self.user_name.nil? or
120
+ self.password.nil? or
121
+ self.license_id.nil? or
122
+ self.device_id.nil? or
123
+ self.site_id.nil?
124
+ )
125
+ end
126
+
127
+ end
128
+ end
@@ -0,0 +1,3 @@
1
+ module Hps
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,231 @@
1
+ require File.join( File.dirname(__FILE__), "test_helper" )
2
+
3
+
4
+ describe "Amex Tests" do
5
+
6
+ it "Amex when card is ok, should return valid result" do
7
+ charge = Hps::TestHelper.charge_valid_amex(50)
8
+ expect(charge.response_code).to eql("00")
9
+ end
10
+
11
+ # avs tests
12
+
13
+ it "Amex avs result code should equal A" do
14
+ charge = Hps::TestHelper.charge_valid_amex(90.01)
15
+ expect(charge.avs_result_code).to eql("A")
16
+ end
17
+
18
+ it "Amex avs result code should equal N" do
19
+ charge = Hps::TestHelper.charge_valid_amex(90.02)
20
+ expect(charge.avs_result_code).to eql("N")
21
+ end
22
+
23
+ it "Amex avs result code should equal R" do
24
+ charge = Hps::TestHelper.charge_valid_amex(90.03)
25
+ expect(charge.avs_result_code).to eql("R")
26
+ end
27
+
28
+ it "Amex avs result code should equal S" do
29
+ charge = Hps::TestHelper.charge_valid_amex(90.04)
30
+ expect(charge.avs_result_code).to eql("S")
31
+ end
32
+
33
+ it "Amex avs result code should equal U" do
34
+ charge = Hps::TestHelper.charge_valid_amex(90.05)
35
+ expect(charge.avs_result_code).to eql("U")
36
+ end
37
+
38
+ it "Amex avs result code should equal W" do
39
+ charge = Hps::TestHelper.charge_valid_amex(90.06)
40
+ expect(charge.avs_result_code).to eql("W")
41
+ end
42
+
43
+ it "Amex avs result code should equal X" do
44
+ charge = Hps::TestHelper.charge_valid_amex(90.07)
45
+ expect(charge.avs_result_code).to eql("X")
46
+ end
47
+
48
+ it "Amex avs result code should equal Y" do
49
+ charge = Hps::TestHelper.charge_valid_amex(90.08)
50
+ expect(charge.avs_result_code).to eql("Y")
51
+ end
52
+
53
+ it "Amex avs result code should equal Z" do
54
+ charge = Hps::TestHelper.charge_valid_amex(90.09)
55
+ expect(charge.avs_result_code).to eql("Z")
56
+ end
57
+
58
+ # cvv tests
59
+
60
+ # TODO: Gateway code changed, returning Y
61
+ it "Amex cvv result code should equal M" do
62
+ charge = Hps::TestHelper.charge_valid_amex(97.01)
63
+ #expect(charge.cvv_result_code).to eql("M")
64
+ end
65
+
66
+ it "Amex cvv result code should equal N" do
67
+ charge = Hps::TestHelper.charge_valid_amex(97.02)
68
+ expect(charge.cvv_result_code).to eql("N")
69
+ end
70
+
71
+ it "Amex cvv result code should equal P" do
72
+ charge = Hps::TestHelper.charge_valid_amex(97.03)
73
+ expect(charge.cvv_result_code).to eql("P")
74
+ end
75
+
76
+ # amex to visa 2nd
77
+ it "Amex response code should indicate denied" do
78
+ expect {
79
+ Hps::TestHelper.charge_valid_amex(10.08)
80
+ }.to raise_error(Hps::CardException) { |error|
81
+ expect(error.code).to eql("card_declined")
82
+ expect(error.response_code).to eql("51")
83
+ expect(error.response_text).to eql("DECLINE")
84
+ }
85
+ end
86
+
87
+ it "Amex response code should card expired" do
88
+ expect {
89
+ Hps::TestHelper.charge_valid_amex(10.32)
90
+ }.to raise_error(Hps::CardException) { |error|
91
+ expect(error.code).to eql("expired_card")
92
+ expect(error.response_code).to eql("54")
93
+ expect(error.response_text).to eql("EXPIRED CARD")
94
+ }
95
+ end
96
+
97
+ it "Amex response code should indicate please call" do
98
+ expect {
99
+ Hps::TestHelper.charge_valid_amex(10.34)
100
+ }.to raise_error(Hps::CardException) { |error|
101
+ expect(error.code).to eql("card_declined")
102
+ expect(error.response_code).to eql("02")
103
+ expect(error.response_text).to eql("CALL")
104
+ }
105
+ end
106
+
107
+ it "Amex response code should indicate invalid merchant" do
108
+ expect {
109
+ Hps::TestHelper.charge_valid_amex(10.22)
110
+ }.to raise_error(Hps::CardException) { |error|
111
+ expect(error.code).to eql("card_declined")
112
+ expect(error.response_code).to eql("03")
113
+ expect(error.response_text).to eql("TERM ID ERROR")
114
+ }
115
+ end
116
+
117
+ it "Amex response code should indicate invalid amount" do
118
+ expect {
119
+ Hps::TestHelper.charge_valid_amex(10.27)
120
+ }.to raise_error(Hps::CardException) { |error|
121
+ expect(error.code).to eql("invalid_amount")
122
+ expect(error.response_code).to eql("13")
123
+ expect(error.response_text).to eql("AMOUNT ERROR")
124
+ }
125
+ end
126
+
127
+ it "Amex response code should indicate no action taken" do
128
+ expect {
129
+ Hps::TestHelper.charge_valid_amex(10.14)
130
+ }.to raise_error(Hps::CardException) { |error|
131
+ # TODO: Gateway response changed
132
+ # expect(error.code).to eql("processing_error")
133
+ # expect(error.response_code).to eql("76")
134
+ # expect(error.response_text).to eql("NO ACTION TAKEN")
135
+ expect(error.code).to eql("incorrect_number")
136
+ expect(error.response_code).to eql("14")
137
+ expect(error.response_text).to eql("CARD NO. ERROR")
138
+ }
139
+ end
140
+
141
+ it "Amex response code should indicate invalid cvv2" do
142
+ expect {
143
+ Hps::TestHelper.charge_valid_amex(10.23)
144
+ }.to raise_error(Hps::CardException) { |error|
145
+ expect(error.code).to eql("incorrect_cvc")
146
+ expect(error.response_code).to eql("N7")
147
+ expect(error.response_text).to eql("CVV2 MISMATCH")
148
+ }
149
+ end
150
+
151
+ it "Amex response code should indicate invalid originator" do
152
+ expect {
153
+ Hps::TestHelper.charge_valid_amex(10.30)
154
+ }.to raise_error(Hps::CardException) { |error|
155
+ expect(error.code).to eql("processing_error")
156
+ expect(error.response_code).to eql("58")
157
+ expect(error.response_text).to eql("SERV NOT ALLOWED")
158
+ }
159
+ end
160
+
161
+ it "Amex response code should indicate card declined" do
162
+ expect {
163
+ Hps::TestHelper.charge_valid_amex(10.25)
164
+ }.to raise_error(Hps::CardException) { |error|
165
+ expect(error.code).to eql("card_declined")
166
+ expect(error.response_code).to eql("05")
167
+ expect(error.response_text).to eql("DECLINE")
168
+ }
169
+ end
170
+
171
+ it "Amex response code should indicate account canceled" do
172
+ expect {
173
+ Hps::TestHelper.charge_valid_amex(10.13)
174
+ }.to raise_error(Hps::CardException) { |error|
175
+ expect(error.code).to eql("card_declined")
176
+ expect(error.response_code).to eql("78")
177
+ expect(error.response_text).to eql("NO ACCOUNT")
178
+ }
179
+ end
180
+
181
+ it "Amex response code should indicate merchant close" do
182
+ expect {
183
+ Hps::TestHelper.charge_valid_amex(10.12)
184
+ }.to raise_error(Hps::CardException) { |error|
185
+ expect(error.code).to eql("processing_error")
186
+ expect(error.response_code).to eql("06")
187
+ expect(error.response_text).to eql("ERROR")
188
+ }
189
+ end
190
+
191
+ it "Amex response code should indicate pickup card" do
192
+ expect {
193
+ Hps::TestHelper.charge_valid_amex(10.04)
194
+ }.to raise_error(Hps::CardException) { |error|
195
+ expect(error.code).to eql("card_declined")
196
+ expect(error.response_code).to eql("44")
197
+ expect(error.response_text).to eql("HOLD-CALL")
198
+ }
199
+ end
200
+
201
+ # verify, authorize & capture
202
+
203
+ it "Amex verify should return OK" do
204
+ service = Hps::HpsChargeService.new()
205
+ result = service.verify(Hps::TestData.valid_amex, Hps::TestData.valid_cardholder)
206
+ expect(result.response_code).to eql("00")
207
+ end
208
+
209
+ it "Amex authorize should return OK" do
210
+ service = Hps::HpsChargeService.new()
211
+ result = service.authorize(50.00, "usd", Hps::TestData.valid_amex, Hps::TestData.valid_cardholder)
212
+ expect(result.response_code).to eql("00")
213
+ end
214
+
215
+ it "Amex authorize and request token should return OK" do
216
+ service = Hps::HpsChargeService.new()
217
+ result = service.authorize(50.00, "usd", Hps::TestData.valid_amex, Hps::TestData.valid_cardholder, true)
218
+ expect(result.token_data.response_code).to eql("0")
219
+ expect(result.response_code).to eql("00")
220
+ end
221
+
222
+ it "Amex authorize and capture should return OK" do
223
+ service = Hps::HpsChargeService.new()
224
+ result = service.authorize(50.00, "usd", Hps::TestData.valid_amex, Hps::TestData.valid_cardholder)
225
+ expect(result.response_code).to eql("00")
226
+
227
+ capture_result = service.capture(result.transaction_id)
228
+ expect(capture_result.response_code).to eql("00")
229
+ end
230
+
231
+ end
@@ -0,0 +1,81 @@
1
+ require File.join( File.dirname(__FILE__), "test_helper" )
2
+
3
+ describe "Certification Tests" do
4
+
5
+ RSpec.configure do |config|
6
+ config.order_groups_and_examples do |tests|
7
+ tests.sort_by { |test| test.description }
8
+ end
9
+ end
10
+
11
+ before(:each) do
12
+ Hps::TestHelper.configure_hps_module_for_certification()
13
+ @service = Hps::HpsChargeService.new()
14
+ end
15
+
16
+ it "A batch should close OK" do
17
+ begin
18
+ service = Hps::HpsBatchService.new
19
+ batch = service.close_batch
20
+ expect(batch).not_to be_nil
21
+ rescue => e
22
+ expect(e.code).to eql("no_open_batch")
23
+ end
24
+ end
25
+
26
+ it "B visa should charge OK" do
27
+ result = @service.charge(17.01, "usd", Hps::TestData.valid_visa, Hps::TestData.cert_cardholder_shortzip)
28
+ expect(result.response_code).to eql("00")
29
+ end
30
+
31
+ it "C mastercard should charge OK" do
32
+ result = @service.charge(17.02, "usd", Hps::TestData.valid_mastercard, Hps::TestData.cert_cardholder_shortzip_no_street)
33
+ expect(result.response_code).to eql("00")
34
+ end
35
+
36
+ it "D discover should charge OK" do
37
+ result = @service.charge(17.03, "usd", Hps::TestData.valid_discover, Hps::TestData.cert_cardholder_longzip_no_street)
38
+ expect(result.response_code).to eql("00")
39
+ end
40
+
41
+ it "E amex should charge OK" do
42
+ result = @service.charge(17.04, "usd", Hps::TestData.valid_amex, Hps::TestData.cert_cardholder_shortzip)
43
+ expect(result.response_code).to eql("00")
44
+ end
45
+
46
+ it "F jcb should charge OK" do
47
+ result = @service.charge(17.05, "usd", Hps::TestData.valid_jcb, Hps::TestData.cert_cardholder_longzip)
48
+ expect(result.response_code).to eql("00")
49
+ end
50
+
51
+ it "G visa should verify OK" do
52
+ result = @service.verify(Hps::TestData.valid_visa)
53
+ expect(result.response_code).to eql("85")
54
+ end
55
+
56
+ it "H mastercard should verify OK" do
57
+ result = @service.verify(Hps::TestData.valid_mastercard)
58
+ expect(result.response_code).to eql("85")
59
+ end
60
+
61
+ it "I discover should verify OK" do
62
+ result = @service.verify(Hps::TestData.valid_discover)
63
+ expect(result.response_code).to eql("85")
64
+ end
65
+
66
+ it "J amex should avs should be OK" do
67
+ result = @service.verify(Hps::TestData.valid_amex, Hps::TestData.cert_cardholder_shortzip_no_street)
68
+ expect(result.response_code).to eql("00")
69
+ end
70
+
71
+ it "K mastercard return should be OK" do
72
+ result = @service.refund(15.15, "usd", Hps::TestData.valid_mastercard, Hps::TestData.cert_cardholder_shortzip)
73
+ expect(result.response_code).to eql("00")
74
+ end
75
+
76
+ it "L visa should reverse OK" do
77
+ result = @service.reverse(Hps::TestData.valid_visa, 17.01, "usd")
78
+ expect(result.response_code).to eql("00")
79
+ end
80
+
81
+ end
@@ -0,0 +1,325 @@
1
+ require File.join( File.dirname(__FILE__), "test_helper" )
2
+
3
+ describe "Discover Tests" do
4
+
5
+ it "Discover when card is ok should return valid result" do
6
+ charge = Hps::TestHelper.charge_valid_discover(50)
7
+ expect(charge.response_code).to eql("00")
8
+ end
9
+
10
+ it "Discover avs result code should equal A" do
11
+ charge = Hps::TestHelper.charge_valid_discover(91.01)
12
+ expect(charge.avs_result_code).to eql("A")
13
+ end
14
+
15
+ it "Discover avs result code should equal N" do
16
+ charge = Hps::TestHelper.charge_valid_discover(91.02)
17
+ expect(charge.avs_result_code).to eql("N")
18
+ end
19
+
20
+ it "Discover avs result code should equal U" do
21
+ charge = Hps::TestHelper.charge_valid_discover(91.05)
22
+ expect(charge.avs_result_code).to eql("U")
23
+ end
24
+
25
+ it "Discover avs result code should equal Y" do
26
+ charge = Hps::TestHelper.charge_valid_discover(91.06)
27
+ expect(charge.avs_result_code).to eql("Y")
28
+ end
29
+
30
+ it "Discover avs result code should equal Z" do
31
+ charge = Hps::TestHelper.charge_valid_discover(91.07)
32
+ expect(charge.avs_result_code).to eql("Z")
33
+ end
34
+
35
+ # discover to 2nd visa
36
+
37
+ it "Discover response code should indicate refer card issuer" do
38
+ expect {
39
+ Hps::TestHelper.charge_valid_discover(10.34)
40
+ }.to raise_error(Hps::CardException) { |error|
41
+ expect(error.code).to eql("card_declined")
42
+ expect(error.response_code).to eql("02")
43
+ expect(error.response_text).to eql("CALL")
44
+ }
45
+ end
46
+
47
+ it "Discover response code should indicate invalid merchant" do
48
+ expect {
49
+ Hps::TestHelper.charge_valid_discover(10.22)
50
+ }.to raise_error(Hps::CardException) { |error|
51
+ expect(error.code).to eql("card_declined")
52
+ expect(error.response_code).to eql("03")
53
+ expect(error.response_text).to eql("TERM ID ERROR")
54
+ }
55
+ end
56
+
57
+ it "Discover response code should indicate pickup card" do
58
+ expect {
59
+ Hps::TestHelper.charge_valid_discover(10.04)
60
+ }.to raise_error(Hps::CardException) { |error|
61
+ expect(error.code).to eql("card_declined")
62
+ expect(error.response_code).to eql("44")
63
+ expect(error.response_text).to eql("HOLD-CALL")
64
+ }
65
+ end
66
+
67
+ it "Discover response code should indicate do not honor" do
68
+ expect {
69
+ Hps::TestHelper.charge_valid_discover(10.25)
70
+ }.to raise_error(Hps::CardException) { |error|
71
+ expect(error.code).to eql("card_declined")
72
+ expect(error.response_code).to eql("05")
73
+ expect(error.response_text).to eql("DECLINE")
74
+ }
75
+ end
76
+
77
+ it "Discover response code should indicate invalid transaction" do
78
+ expect {
79
+ Hps::TestHelper.charge_valid_discover(10.26)
80
+ }.to raise_error(Hps::CardException) { |error|
81
+ expect(error.code).to eql("processing_error")
82
+ expect(error.response_code).to eql("12")
83
+ expect(error.response_text).to eql("INVALID TRANS")
84
+ }
85
+ end
86
+
87
+ it "Discover response code should indicate invalid amount" do
88
+ expect {
89
+ Hps::TestHelper.charge_valid_discover(10.27)
90
+ }.to raise_error(Hps::CardException) { |error|
91
+ expect(error.code).to eql("invalid_amount")
92
+ expect(error.response_code).to eql("13")
93
+ expect(error.response_text).to eql("AMOUNT ERROR")
94
+ }
95
+ end
96
+
97
+ it "Discover response code should indicate invalid card" do
98
+ expect {
99
+ Hps::TestHelper.charge_valid_discover(10.28)
100
+ }.to raise_error(Hps::CardException) { |error|
101
+ expect(error.code).to eql("incorrect_number")
102
+ expect(error.response_code).to eql("14")
103
+ expect(error.response_text).to eql("CARD NO. ERROR")
104
+ }
105
+ end
106
+
107
+ # TODO: Gateway change, used to raise exception but doesn't now
108
+ # it "Discover response code should indicate invalid issuer" do
109
+ # expect {
110
+ # Hps::TestHelper.charge_valid_discover(10.18)
111
+ # }.to raise_error(Hps::CardException) { |error|
112
+ # expect(error.code).to eql("processing_error")
113
+ # expect(error.response_code).to eql("15")
114
+ # expect(error.response_text).to eql("NO SUCH ISSUER")
115
+ # }
116
+ # end
117
+
118
+ it "Discover response code should indicate system error re-enter" do
119
+ expect {
120
+ Hps::TestHelper.charge_valid_discover(10.29)
121
+ }.to raise_error(Hps::CardException) { |error|
122
+ expect(error.code).to eql("processing_error")
123
+ expect(error.response_code).to eql("19")
124
+ expect(error.response_text).to eql("RE ENTER")
125
+ }
126
+ end
127
+
128
+ it "Discover response code should indicate message format error" do
129
+ expect {
130
+ Hps::TestHelper.charge_valid_discover(10.06)
131
+ }.to raise_error(Hps::CardException) { |error|
132
+ expect(error.code).to eql("processing_error")
133
+ expect(error.response_code).to eql("EC")
134
+ expect(error.response_text).to eql("CID FORMAT ERROR")
135
+ }
136
+ end
137
+
138
+ it "Discover response code should indicate lost card" do
139
+ expect {
140
+ Hps::TestHelper.charge_valid_discover(10.31)
141
+ }.to raise_error(Hps::CardException) { |error|
142
+ expect(error.code).to eql("card_declined")
143
+ expect(error.response_code).to eql("41")
144
+ expect(error.response_text).to eql("HOLD-CALL")
145
+ }
146
+ end
147
+
148
+ it "Discover response code should indicate insufficient funds" do
149
+ expect {
150
+ Hps::TestHelper.charge_valid_discover(10.08)
151
+ }.to raise_error(Hps::CardException) { |error|
152
+ expect(error.code).to eql("card_declined")
153
+ expect(error.response_code).to eql("05")
154
+ expect(error.response_text).to eql("DECLINE")
155
+ }
156
+ end
157
+
158
+ it "Discover response code should indicate no saving account" do
159
+ expect {
160
+ Hps::TestHelper.charge_valid_discover(10.17)
161
+ }.to raise_error(Hps::CardException) { |error|
162
+ expect(error.code).to eql("processing_error")
163
+ expect(error.response_code).to eql("53")
164
+ expect(error.response_text).to eql("NO SAVE ACCOUNT")
165
+ }
166
+ end
167
+
168
+ it "Discover response code should indicate expired card" do
169
+ expect {
170
+ Hps::TestHelper.charge_valid_discover(10.32)
171
+ }.to raise_error(Hps::CardException) { |error|
172
+ expect(error.code).to eql("expired_card")
173
+ expect(error.response_code).to eql("54")
174
+ expect(error.response_text).to eql("EXPIRED CARD")
175
+ }
176
+ end
177
+
178
+ it "Discover response code should indicate no card record" do
179
+ expect {
180
+ Hps::TestHelper.charge_valid_discover(10.24)
181
+ }.to raise_error(Hps::CardException) { |error|
182
+ expect(error.code).to eql("card_declined")
183
+ expect(error.response_code).to eql("56")
184
+ expect(error.response_text).to eql("INVALID TRANS")
185
+ }
186
+ end
187
+
188
+ it "Discover response code should indicate txn not permitted on card" do
189
+ expect {
190
+ Hps::TestHelper.charge_valid_discover(10.20)
191
+ }.to raise_error(Hps::CardException) { |error|
192
+ expect(error.code).to eql("processing_error")
193
+ expect(error.response_code).to eql("57")
194
+ expect(error.response_text).to eql("SERV NOT ALLOWED")
195
+ }
196
+ end
197
+
198
+ it "Discover response code should indicate invalid aquirer" do
199
+ expect {
200
+ Hps::TestHelper.charge_valid_discover(10.30)
201
+ }.to raise_error(Hps::CardException) { |error|
202
+ expect(error.code).to eql("processing_error")
203
+ expect(error.response_code).to eql("58")
204
+ expect(error.response_text).to eql("SERV NOT ALLOWED")
205
+ }
206
+ end
207
+
208
+ it "Discover response code should indicate exceeds limit" do
209
+ expect {
210
+ Hps::TestHelper.charge_valid_discover(10.09)
211
+ }.to raise_error(Hps::CardException) { |error|
212
+ expect(error.code).to eql("card_declined")
213
+ expect(error.response_code).to eql("61")
214
+ expect(error.response_text).to eql("DECLINE")
215
+ }
216
+ end
217
+
218
+ it "Discover response code should indicate restricted card" do
219
+ expect {
220
+ Hps::TestHelper.charge_valid_discover(10.10)
221
+ }.to raise_error(Hps::CardException) { |error|
222
+ expect(error.code).to eql("card_declined")
223
+ expect(error.response_code).to eql("62")
224
+ expect(error.response_text).to eql("DECLINE")
225
+ }
226
+ end
227
+
228
+ it "Discover response code should indicate security violation" do
229
+ expect {
230
+ Hps::TestHelper.charge_valid_discover(10.19)
231
+ }.to raise_error(Hps::CardException) { |error|
232
+ expect(error.code).to eql("card_declined")
233
+ expect(error.response_code).to eql("63")
234
+ expect(error.response_text).to eql("SEC VIOLATION")
235
+ }
236
+ end
237
+
238
+ it "Discover response code should indicate exceeds freq limit" do
239
+ expect {
240
+ Hps::TestHelper.charge_valid_discover(10.11)
241
+ }.to raise_error(Hps::CardException) { |error|
242
+ expect(error.code).to eql("card_declined")
243
+ expect(error.response_code).to eql("65")
244
+ expect(error.response_text).to eql("DECLINE")
245
+ }
246
+ end
247
+
248
+ it "Discover response code should indicate no account" do
249
+ expect {
250
+ Hps::TestHelper.charge_valid_discover(10.13)
251
+ }.to raise_error(Hps::CardException) { |error|
252
+ expect(error.code).to eql("card_declined")
253
+ expect(error.response_code).to eql("78")
254
+ expect(error.response_text).to eql("NO ACCOUNT")
255
+ }
256
+ end
257
+
258
+ it "Discover response code should indicate invalid account" do
259
+ expect {
260
+ Hps::TestHelper.charge_valid_discover(10.14)
261
+ }.to raise_error(Hps::CardException) { |error|
262
+ expect(error.code).to eql("incorrect_number")
263
+ expect(error.response_code).to eql("14")
264
+ expect(error.response_text).to eql("CARD NO. ERROR")
265
+ }
266
+ end
267
+
268
+ # TODO: Gateway change, used to throw exception but now it doesn't
269
+ # it "Discover response code should indicate switch not available" do
270
+ # expect {
271
+ # Hps::TestHelper.charge_valid_discover(10.33)
272
+ # }.to raise_error(Hps::HpsException) { |error|
273
+ # #}.to raise_error(Hps::CardException) { |error|
274
+ # #expect(error.code).to eql("processing_error")
275
+ # #expect(error.response_code).to eql("14")
276
+ # expect(error.code).to eql("issuer_timeout")
277
+ # expect(error.response_code).to eql("91")
278
+ # expect(error.response_text).to eql("NO REPLY")
279
+ # }
280
+ # end
281
+
282
+ it "Discover response code should indicate system error" do
283
+ expect {
284
+ Hps::TestHelper.charge_valid_discover(10.26)
285
+ }.to raise_error(Hps::CardException) { |error|
286
+ expect(error.code).to eql("processing_error")
287
+ # TODO: Gateway change
288
+ #expect(error.response_code).to eql("96")
289
+ #expect(error.response_text).to eql("SYSTEM ERROR")
290
+ expect(error.response_code).to eql("12")
291
+ expect(error.response_text).to eql("INVALID TRANS")
292
+ }
293
+ end
294
+
295
+ # Verify, Authorize, and Capture
296
+
297
+ it "Discover verify should return OK" do
298
+ service = Hps::HpsChargeService.new()
299
+ result = service.verify(Hps::TestData.valid_discover, Hps::TestData.valid_cardholder)
300
+ expect(result.response_code).to eql("85")
301
+ end
302
+
303
+ it "Discover authorize should return OK" do
304
+ service = Hps::HpsChargeService.new()
305
+ result = service.authorize(50.00, "usd", Hps::TestData.valid_discover, Hps::TestData.valid_cardholder)
306
+ expect(result.response_code).to eql("00")
307
+ end
308
+
309
+ it "Discover authorize and request token should return OK" do
310
+ service = Hps::HpsChargeService.new()
311
+ result = service.authorize(50.00, "usd", Hps::TestData.valid_discover, Hps::TestData.valid_cardholder, true)
312
+ expect(result.token_data.response_code).to eql("0")
313
+ expect(result.response_code).to eql("00")
314
+ end
315
+
316
+ it "Discover authorize and capture should return OK" do
317
+ service = Hps::HpsChargeService.new()
318
+ result = service.authorize(50.00, "usd", Hps::TestData.valid_discover, Hps::TestData.valid_cardholder)
319
+ expect(result.response_code).to eql("00")
320
+
321
+ capture_result = service.capture(result.transaction_id)
322
+ expect(capture_result.response_code).to eql("00")
323
+ end
324
+
325
+ end