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,245 @@
1
+ require 'hps'
2
+
3
+
4
+ describe "ExceptionMapper Tests" do
5
+
6
+ before(:all) do
7
+ @mapper = Hps::ExceptionMapper.new
8
+ end
9
+
10
+
11
+ it "mapping version number accessible" do
12
+ expect(@mapper.version_number).to eq("1.0.0")
13
+ end
14
+
15
+ # Issuer Exceptions
16
+
17
+ it "issuer card declined test codes" do
18
+
19
+ [ "02", "03", "04", "05", "41", "43", "44", "51", "56", "61", "62", "63", "65", "78" ].each { |code|
20
+
21
+ result = @mapper.map_issuer_exception(1, code, "")
22
+ expect(result.transaction_id).to eq(1)
23
+ expect(result.code).to eq("card_declined")
24
+ expect(result.message).to eq(message_for_code("Exception_Message_CardDeclined"))
25
+ }
26
+
27
+ end
28
+
29
+ it "issuer processing error test codes" do
30
+
31
+ [ "06", "07", "12", "15", "19", "12", "52", "53", "57", "58", "76", "77", "91", "96", "EC" ].each { |code|
32
+
33
+ result = @mapper.map_issuer_exception(2, code, "")
34
+ expect(result.transaction_id).to eq(2)
35
+ expect(result.code).to eq("processing_error")
36
+ expect(result.message).to eq(message_for_code("Exception_Message_ProcessingError"))
37
+ }
38
+
39
+ end
40
+
41
+ it "issuer invalid amount test" do
42
+ result = @mapper.map_issuer_exception(3, "13", "")
43
+ expect(result.transaction_id).to eq(3)
44
+ expect(result.code).to eq("invalid_amount")
45
+ expect(result.message).to eq(message_for_code("Exception_Message_ChargeAmount"))
46
+ end
47
+
48
+ it "issuer incorrect number test" do
49
+ result = @mapper.map_issuer_exception(4, "14", "")
50
+ expect(result.transaction_id).to eq(4)
51
+ expect(result.code).to eq("incorrect_number")
52
+ expect(result.message).to eq(message_for_code("Exception_Message_IncorrectNumber"))
53
+ end
54
+
55
+ it "issuer expired card test" do
56
+ result = @mapper.map_issuer_exception(5, "54", "")
57
+ expect(result.transaction_id).to eq(5)
58
+ expect(result.code).to eq("expired_card")
59
+ expect(result.message).to eq(message_for_code("Exception_Message_CardExpired"))
60
+ end
61
+
62
+ it "issuer invalid pin test" do
63
+ result = @mapper.map_issuer_exception(6, "55", "")
64
+ expect(result.transaction_id).to eq(6)
65
+ expect(result.code).to eq("invalid_pin")
66
+ expect(result.message).to eq(message_for_code("Exception_Message_InvalidPin"))
67
+ end
68
+
69
+ it "issuer pin retries exceeded test" do
70
+ result = @mapper.map_issuer_exception(7, "75", "")
71
+ expect(result.transaction_id).to eq(7)
72
+ expect(result.code).to eq("pin_retries_exceeded")
73
+ expect(result.message).to eq(message_for_code("Exception_Message_PinExceeded"))
74
+ end
75
+
76
+ it "issuer invalid expiry test" do
77
+ result = @mapper.map_issuer_exception(8, "80", "")
78
+ expect(result.transaction_id).to eq(8)
79
+ expect(result.code).to eq("invalid_expiry")
80
+ expect(result.message).to eq(message_for_code("Exception_Message_InvalidExpiry"))
81
+ end
82
+
83
+ it "issuer pin verification test" do
84
+ result = @mapper.map_issuer_exception(9, "86", "")
85
+ expect(result.transaction_id).to eq(9)
86
+ expect(result.code).to eq("pin_verification")
87
+ expect(result.message).to eq(message_for_code("Exception_Message_PinVerification"))
88
+ end
89
+
90
+ it "issuer incorrect cvc test" do
91
+ [ "EB", "N7" ].each { |code|
92
+ result = @mapper.map_issuer_exception(10, code, "")
93
+ expect(result.transaction_id).to eq(10)
94
+ expect(result.code).to eq("incorrect_cvc")
95
+ expect(result.message).to eq(message_for_code("Exception_Message_IncorrectCvc"))
96
+ }
97
+ end
98
+
99
+ it "issuer unknown test" do
100
+ result = @mapper.map_issuer_exception(11, "Foo", "Foo")
101
+ expect(result.transaction_id).to eq(11)
102
+ expect(result.code).to eq("unknown_card_exception")
103
+ expect(result.message).to eq("Foo")
104
+ end
105
+
106
+ it "issuer nil test" do
107
+ result = @mapper.map_issuer_exception(0, nil, nil)
108
+ expect(result.transaction_id).to eq(0)
109
+ expect(result.code).to eq("unknown_card_exception")
110
+ expect(result.message).to eq("Hps::CardException")
111
+ end
112
+
113
+ # Gateway exceptions
114
+
115
+ it "gateway authentication exception test" do
116
+ result = @mapper.map_gateway_exception(0, "-2", nil)
117
+ expect(result.code).to eq("unknown")
118
+ expect(result.message).to eq(message_for_code("Exception_Message_AuthenticationError"))
119
+ end
120
+
121
+ it "gateway invalid request exception cpc test" do
122
+ result = @mapper.map_gateway_exception(0, "12", nil)
123
+ expect(result.param).to eq("card")
124
+ expect(result.code).to eq("invalid_cpc_data")
125
+ expect(result.message).to eq(message_for_code("Exception_Message_InvalidCpcData"))
126
+ end
127
+
128
+ it "gateway invalid request exception card data test" do
129
+ result = @mapper.map_gateway_exception(0, "13", nil)
130
+ expect(result.param).to eq("card")
131
+ expect(result.code).to eq("invalid_card_data")
132
+ expect(result.message).to eq(message_for_code("Exception_Message_InvalidCardData"))
133
+ end
134
+
135
+ it "gateway card exception test" do
136
+ result = @mapper.map_gateway_exception(0, "14", nil)
137
+ expect(result.code).to eq("invalid_number")
138
+ expect(result.message).to eq(message_for_code("Exception_Message_InvalidNumber"))
139
+ end
140
+
141
+ it "gateway message passthrough test" do
142
+ result = @mapper.map_gateway_exception(0, "1", "Foo")
143
+ expect(result.code).to eq("unknown")
144
+ expect(result.message).to eq("Foo")
145
+ end
146
+
147
+ it "gateway invalid original transaction test" do
148
+ result = @mapper.map_gateway_exception(0, "3", "Foo")
149
+ expect(result.code).to eq("invalid_original_transaction")
150
+ expect(result.message).to eq("Foo")
151
+ end
152
+
153
+ it "gateway no open batch test" do
154
+ result = @mapper.map_gateway_exception(0, "5", "Foo")
155
+ expect(result.code).to eq("no_open_batch")
156
+ expect(result.message).to eq("Foo")
157
+ end
158
+
159
+ it "gateway timeout test" do
160
+ result = @mapper.map_gateway_exception(0, "30", nil)
161
+ expect(result.code).to eq("unknown")
162
+ expect(result.message).to eq(message_for_code("Exception_Message_GatewayTimedOut"))
163
+ end
164
+
165
+ it "gateway unknown test" do
166
+ result = @mapper.map_gateway_exception(0, "Foo", "Foo")
167
+ expect(result.code).to eq("unknown")
168
+ expect(result.message).to eq("Foo")
169
+ end
170
+
171
+ # Sdk Exceptions
172
+
173
+ it "sdk invalid transaction id test" do
174
+ result = @mapper.map_sdk_exception(Hps::SdkCodes.invalid_transaction_id, nil)
175
+ expect(result.param).to eq("gatewayTransactionId")
176
+ expect(result.code).to eq("invalid_transaction_id")
177
+ expect(result.message).to eq(message_for_code("Exception_Message_TransactionIdLessThanEqualZero"))
178
+ end
179
+
180
+ it "sdk invalid gateway url test" do
181
+ result = @mapper.map_sdk_exception(Hps::SdkCodes.invalid_gateway_url, nil)
182
+ expect(result.param).to eq("HpsServiceUri")
183
+ expect(result.code).to eq("sdk_exception")
184
+ expect(result.message).to eq(message_for_code("Exception_Message_InvalidGatewayUrl"))
185
+ end
186
+
187
+ it "sdk unable to process transaction test" do
188
+ result = @mapper.map_sdk_exception(Hps::SdkCodes.invalid_gateway_url, nil)
189
+ expect(result.param).to eq("HpsServiceUri")
190
+ expect(result.code).to eq("sdk_exception")
191
+ expect(result.message).to eq(message_for_code("Exception_Message_InvalidGatewayUrl"))
192
+ end
193
+
194
+ it "sdk missing currency" do
195
+ result = @mapper.map_sdk_exception(Hps::SdkCodes.missing_currency, nil)
196
+ expect(result.param).to eq("currency")
197
+ expect(result.code).to eq("missing_currency")
198
+ expect(result.message).to eq(message_for_code("Exception_Message_ArgumentNull"))
199
+ end
200
+
201
+ it "sdk invalid currency" do
202
+ result = @mapper.map_sdk_exception(Hps::SdkCodes.invalid_currency, nil)
203
+ expect(result.param).to eq("currency")
204
+ expect(result.code).to eq("invalid_currency")
205
+ expect(result.message).to eq(message_for_code("Exception_Message_InvalidCurrency"))
206
+ end
207
+
208
+ it "sdk invalid amount" do
209
+ result = @mapper.map_sdk_exception(Hps::SdkCodes.invalid_amount, nil)
210
+ expect(result.param).to eq("amount")
211
+ expect(result.code).to eq("invalid_amount")
212
+ expect(result.message).to eq(message_for_code("Exception_Message_ChargeAmount"))
213
+ end
214
+
215
+ it "sdk reversal error after gateway timeout" do
216
+ result = @mapper.map_sdk_exception(Hps::SdkCodes.reversal_error_after_gateway_timeout, nil)
217
+ expect(result.code).to eq("gateway_timeout")
218
+ expect(result.message).to eq(message_for_code("Exception_Message_UnableToReverseTransactionAfterGatewayTimeout"))
219
+ end
220
+
221
+ it "sdk reversal error after issuer timeout" do
222
+ result = @mapper.map_sdk_exception(Hps::SdkCodes.reversal_error_after_issuer_timeout, nil)
223
+ expect(result.code).to eq("issuer_timeout")
224
+ expect(result.message).to eq(message_for_code("Exception_Message_UnableToReverseTransactionAfterIssuerTimeout"))
225
+ end
226
+
227
+ it "sdk processing error" do
228
+ result = @mapper.map_sdk_exception(Hps::SdkCodes.processing_error, nil)
229
+ expect(result.code).to eq("processing_error")
230
+ expect(result.message).to eq(message_for_code("Exception_Message_ProcessingError"))
231
+ end
232
+
233
+ # Helper methods
234
+
235
+ def message_for_code(code)
236
+
237
+ mapping = @mapper.exceptions["exception_messages"].detect { |message|
238
+ message["code"] == code
239
+ }
240
+
241
+ mapping["message"] unless mapping.nil?
242
+
243
+ end
244
+
245
+ end
@@ -0,0 +1,58 @@
1
+ require File.join( File.dirname(__FILE__), "test_helper.rb" )
2
+
3
+ describe "General Tests" do
4
+
5
+ before(:each) do
6
+ Hps::TestHelper.configure_hps_module()
7
+ @service = Hps::HpsChargeService.new()
8
+ end
9
+
10
+ it "charge when amount is less than zero should throw invalid request exception" do
11
+ expect {
12
+ @service.charge(-5, "usd", Hps::TestData::valid_visa, Hps::TestData::valid_cardholder)
13
+ }.to raise_error(Hps::InvalidRequestException)
14
+ end
15
+
16
+ it "charge when currency is empty should throw invalid request exception" do
17
+ expect {
18
+ @service.charge(50, "", Hps::TestData::valid_visa, Hps::TestData::valid_cardholder)
19
+ }.to raise_error(Hps::InvalidRequestException)
20
+ end
21
+
22
+ it "charge when currency is not usd should throw invalid request exception" do
23
+ expect {
24
+ @service.charge(50, "eur", Hps::TestData::valid_visa, Hps::TestData::valid_cardholder)
25
+ }.to raise_error(Hps::InvalidRequestException)
26
+ end
27
+
28
+ it "charge when configuration is invalid should throw hps exception" do
29
+ expect {
30
+ @service = Hps::HpsChargeService.new :service_uri => nil
31
+ @service.charge(50, "usd", Hps::TestData::valid_visa, Hps::TestData::valid_cardholder)
32
+ }.to raise_error(Hps::HpsException)
33
+ end
34
+
35
+ it "charge when license_id is invalid should throw authentication exception" do
36
+ expect {
37
+ @service = Hps::HpsChargeService.new :secret_api_key => nil
38
+ @service.charge(50, "usd", Hps::TestData::valid_visa, Hps::TestData::valid_cardholder)
39
+ }.to raise_error(Hps::InvalidRequestException)
40
+ end
41
+
42
+ it "charge when card number is invalid should throw hps exception" do
43
+ expect {
44
+ @service.charge(50, "usd", Hps::TestData::invalid_card, Hps::TestData::valid_cardholder)
45
+ }.to raise_error(Hps::HpsException)
46
+ end
47
+
48
+ it "list when charge is in filter range should show in list" do
49
+ start_date = DateTime.now - 12.hours
50
+ charge = @service.charge(50, "usd", Hps::TestData::valid_visa, Hps::TestData::valid_cardholder)
51
+ end_date = DateTime.now
52
+
53
+ charges = @service.list(start_date, end_date)
54
+ expect(charges).to have_at_least(1).items
55
+ expect(charges.any? { |c| c.transaction_id = charge.transaction_id }).to be_true
56
+ end
57
+
58
+ end
@@ -0,0 +1,56 @@
1
+ require 'net/http'
2
+
3
+ require 'rubygems'
4
+ require 'json'
5
+
6
+ module Hps
7
+ class HpsTokenService
8
+ attr_accessor :public_api_key, :url
9
+
10
+ def initialize(public_api_key)
11
+ @public_api_key = public_api_key
12
+ if @public_api_key.nil? || @public_api_key.eql?('')
13
+ raise HpsException.new('Public Key Not Found', '0')
14
+ end
15
+
16
+ components = @public_api_key.split '_'
17
+ if components.size < 3
18
+ raise HpsException.new('Public API Key must contain at least two underscores','0')
19
+ end
20
+
21
+ if components[1].downcase.eql? 'prod'
22
+ @url = 'https://api.heartlandportico.com/SecureSubmit.v1/api/token'
23
+ else
24
+ @url = 'https://posgateway.cert.secureexchange.net/Hps.Exchange.PosGateway.Hpf.v1/api/token'
25
+ end
26
+
27
+ end
28
+
29
+ def get_token(card_data)
30
+ data = {
31
+ 'api_key' => @public_api_key,
32
+ 'object' => 'token',
33
+ 'token_type' => 'supt',
34
+ '_method' => 'post',
35
+ 'card[number]' => card_data.number,
36
+ 'card[cvv]' => card_data.cvv,
37
+ 'card[exp_month]' => card_data.exp_month,
38
+ 'card[exp_year]' => card_data.exp_year
39
+ }
40
+ get_result = get(data)
41
+ JSON.parse(get_result)
42
+ end
43
+
44
+ def get(data)
45
+ begin
46
+ uri = URI(@url)
47
+ uri.query = URI.encode_www_form(data)
48
+ res = Net::HTTP.get_response(uri)
49
+ res.body
50
+
51
+ rescue Exception => e
52
+ raise HpsException.new(e.message,'0')
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,326 @@
1
+ require File.join( File.dirname(__FILE__), "test_helper" )
2
+
3
+ describe "Mastercard Tests" do
4
+
5
+ it "Mastercard when card is ok, should return valid result" do
6
+ charge = Hps::TestHelper.charge_valid_mastercard(50)
7
+ expect(charge.response_code).to eql("00")
8
+ end
9
+
10
+ # avs tests
11
+
12
+ it "Mastercard avs result code should equal A" do
13
+ charge = Hps::TestHelper.charge_valid_mastercard(90.01)
14
+ expect(charge.avs_result_code).to eql("A")
15
+ end
16
+
17
+ it "Mastercard avs result code should equal N" do
18
+ charge = Hps::TestHelper.charge_valid_mastercard(90.02)
19
+ expect(charge.avs_result_code).to eql("N")
20
+ end
21
+
22
+ it "Mastercard avs result code should equal R" do
23
+ charge = Hps::TestHelper.charge_valid_mastercard(90.03)
24
+ expect(charge.avs_result_code).to eql("R")
25
+ end
26
+
27
+ it "Mastercard avs result code should equal S" do
28
+ charge = Hps::TestHelper.charge_valid_mastercard(90.04)
29
+ expect(charge.avs_result_code).to eql("S")
30
+ end
31
+
32
+ it "Mastercard avs result code should equal U" do
33
+ charge = Hps::TestHelper.charge_valid_mastercard(90.05)
34
+ expect(charge.avs_result_code).to eql("U")
35
+ end
36
+
37
+ it "Mastercard avs result code should equal W" do
38
+ charge = Hps::TestHelper.charge_valid_mastercard(90.06)
39
+ expect(charge.avs_result_code).to eql("W")
40
+ end
41
+
42
+ it "Mastercard avs result code should equal X" do
43
+ charge = Hps::TestHelper.charge_valid_mastercard(90.07)
44
+ expect(charge.avs_result_code).to eql("X")
45
+ end
46
+
47
+ it "Mastercard avs result code should equal Y" do
48
+ charge = Hps::TestHelper.charge_valid_mastercard(90.08)
49
+ expect(charge.avs_result_code).to eql("Y")
50
+ end
51
+
52
+ it "Mastercard avs result code should equal Z" do
53
+ charge = Hps::TestHelper.charge_valid_mastercard(90.09)
54
+ expect(charge.avs_result_code).to eql("Z")
55
+ end
56
+
57
+ # cvv tests
58
+
59
+ it "Mastercard cvv result code should equal M" do
60
+ charge = Hps::TestHelper.charge_valid_mastercard(95.01)
61
+ expect(charge.cvv_result_code).to eql("M")
62
+ end
63
+
64
+ it "Mastercard cvv result code should equal N" do
65
+ charge = Hps::TestHelper.charge_valid_mastercard(95.02)
66
+ expect(charge.cvv_result_code).to eql("N")
67
+ end
68
+
69
+ it "Mastercard cvv result code should equal P" do
70
+ charge = Hps::TestHelper.charge_valid_mastercard(95.03)
71
+ expect(charge.cvv_result_code).to eql("P")
72
+ end
73
+
74
+ it "Mastercard cvv result code should equal U" do
75
+ charge = Hps::TestHelper.charge_valid_mastercard(95.04)
76
+ expect(charge.cvv_result_code).to eql("U")
77
+ end
78
+
79
+ # mastercard to 8583
80
+
81
+ it "Mastercard response code should indicate refer card issuer" do
82
+ expect {
83
+ Hps::TestHelper.charge_valid_mastercard(10.34)
84
+ }.to raise_error(Hps::CardException) { |error|
85
+ expect(error.code).to eql("card_declined")
86
+ expect(error.response_code).to eql("02")
87
+ expect(error.response_text).to eql("CALL")
88
+ }
89
+ end
90
+
91
+ it "Mastercard response code should indicate term id error" do
92
+ expect {
93
+ Hps::TestHelper.charge_valid_mastercard(10.22)
94
+ }.to raise_error(Hps::CardException) { |error|
95
+ expect(error.code).to eql("card_declined")
96
+ expect(error.response_code).to eql("03")
97
+ expect(error.response_text).to eql("TERM ID ERROR")
98
+ }
99
+ end
100
+
101
+ # TODO: Gateway not throwing error
102
+ # it "Mastercard response code should indicate invalid merchant" do
103
+ # expect {
104
+ # Hps::TestHelper.charge_valid_mastercard(10.01)
105
+ # }.to raise_error(Hps::CardException) { |error|
106
+ # expect(error.code).to eql("card_declined")
107
+ # expect(error.response_code).to eql("04")
108
+ # expect(error.response_text).to eql("HOLD-CALL")
109
+ # }
110
+ # end
111
+
112
+ it "Mastercard response code should indicate do not honor" do
113
+ expect {
114
+ Hps::TestHelper.charge_valid_mastercard(10.25)
115
+ }.to raise_error(Hps::CardException) { |error|
116
+ expect(error.code).to eql("card_declined")
117
+ expect(error.response_code).to eql("05")
118
+ expect(error.response_text).to eql("DECLINE")
119
+ }
120
+ end
121
+
122
+ # TODO: Gateway not throwing error
123
+ # it "Mastercard response code should indicate invalid transaction" do
124
+ # expect {
125
+ # Hps::TestHelper.charge_valid_amex(10.26)
126
+ # }.to raise_error(Hps::CardException) { |error|
127
+ # expect(error.code).to eql("processing_error")
128
+ # expect(error.response_code).to eql("12")
129
+ # expect(error.response_text).to eql("INVALID TRANS")
130
+ # }
131
+ # end
132
+
133
+ it "Mastercard response code should indicate invalid amount" do
134
+ expect {
135
+ Hps::TestHelper.charge_valid_mastercard(10.27)
136
+ }.to raise_error(Hps::CardException) { |error|
137
+ expect(error.code).to eql("invalid_amount")
138
+ expect(error.response_code).to eql("13")
139
+ expect(error.response_text).to eql("AMOUNT ERROR")
140
+ }
141
+ end
142
+
143
+ it "Mastercard response code should indicate invalid card" do
144
+ expect {
145
+ Hps::TestHelper.charge_valid_mastercard(10.28)
146
+ }.to raise_error(Hps::CardException) { |error|
147
+ expect(error.code).to eql("incorrect_number")
148
+ expect(error.response_code).to eql("14")
149
+ expect(error.response_text).to eql("CARD NO. ERROR")
150
+ }
151
+ end
152
+
153
+ it "Mastercard response code should indicate invalid issuer" do
154
+ expect {
155
+ Hps::TestHelper.charge_valid_mastercard(10.18)
156
+ }.to raise_error(Hps::CardException) { |error|
157
+ expect(error.code).to eql("processing_error")
158
+ expect(error.response_code).to eql("15")
159
+ expect(error.response_text).to eql("NO SUCH ISSUER")
160
+ }
161
+ end
162
+
163
+ it "Mastercard response code should indicate lost card" do
164
+ expect {
165
+ Hps::TestHelper.charge_valid_mastercard(10.31)
166
+ }.to raise_error(Hps::CardException) { |error|
167
+ expect(error.code).to eql("card_declined")
168
+ expect(error.response_code).to eql("41")
169
+ expect(error.response_text).to eql("HOLD-CALL")
170
+ }
171
+ end
172
+
173
+ it "Mastercard response code should indicate hold call" do
174
+ expect {
175
+ Hps::TestHelper.charge_valid_mastercard(10.03)
176
+ }.to raise_error(Hps::CardException) { |error|
177
+ expect(error.code).to eql("card_declined")
178
+ expect(error.response_code).to eql("43")
179
+ expect(error.response_text).to eql("HOLD-CALL")
180
+ }
181
+ end
182
+
183
+ it "Mastercard response code should indicate decline" do
184
+ expect {
185
+ Hps::TestHelper.charge_valid_mastercard(10.08)
186
+ }.to raise_error(Hps::CardException) { |error|
187
+ expect(error.code).to eql("card_declined")
188
+ expect(error.response_code).to eql("51")
189
+ expect(error.response_text).to eql("DECLINE")
190
+ }
191
+ end
192
+
193
+ it "Mastercard response code should indicate expired card" do
194
+ expect {
195
+ Hps::TestHelper.charge_valid_mastercard(10.32)
196
+ }.to raise_error(Hps::CardException) { |error|
197
+ expect(error.code).to eql("expired_card")
198
+ expect(error.response_code).to eql("54")
199
+ expect(error.response_text).to eql("EXPIRED CARD")
200
+ }
201
+ end
202
+
203
+ it "Mastercard response code should indicate exceeds limit" do
204
+ expect {
205
+ Hps::TestHelper.charge_valid_mastercard(10.09)
206
+ }.to raise_error(Hps::CardException) { |error|
207
+ expect(error.code).to eql("card_declined")
208
+ expect(error.response_code).to eql("61")
209
+ expect(error.response_text).to eql("DECLINE")
210
+ }
211
+ end
212
+
213
+ it "Mastercard response code should indicate restricted card" do
214
+ expect {
215
+ Hps::TestHelper.charge_valid_mastercard(10.10)
216
+ }.to raise_error(Hps::CardException) { |error|
217
+ expect(error.code).to eql("card_declined")
218
+ expect(error.response_code).to eql("62")
219
+ expect(error.response_text).to eql("DECLINE")
220
+ }
221
+ end
222
+
223
+ it "Mastercard response code should indicate security violation" do
224
+ expect {
225
+ Hps::TestHelper.charge_valid_mastercard(10.19)
226
+ }.to raise_error(Hps::CardException) { |error|
227
+ expect(error.code).to eql("card_declined")
228
+ expect(error.response_code).to eql("63")
229
+ expect(error.response_text).to eql("SEC VIOLATION")
230
+ }
231
+ end
232
+
233
+ it "Mastercard response code should indicate exceeds freq limit" do
234
+ expect {
235
+ Hps::TestHelper.charge_valid_mastercard(10.11)
236
+ }.to raise_error(Hps::CardException) { |error|
237
+ expect(error.code).to eql("card_declined")
238
+ expect(error.response_code).to eql("65")
239
+ expect(error.response_text).to eql("DECLINE")
240
+ }
241
+ end
242
+
243
+ it "Mastercard response code should indicate card no error" do
244
+ expect {
245
+ Hps::TestHelper.charge_valid_mastercard(10.14)
246
+ }.to raise_error(Hps::CardException) { |error|
247
+ expect(error.code).to eql("incorrect_number")
248
+ expect(error.response_code).to eql("14")
249
+ expect(error.response_text).to eql("CARD NO. ERROR")
250
+ }
251
+ end
252
+
253
+ it "Mastercard response code should indicate invalid account" do
254
+ expect {
255
+ Hps::TestHelper.charge_valid_mastercard(10.06)
256
+ }.to raise_error(Hps::CardException) { |error|
257
+ expect(error.code).to eql("processing_error")
258
+ # TODO: Gateway change
259
+ #expect(error.response_code).to eql("79")
260
+ expect(error.response_code).to eql("EC")
261
+ expect(error.response_text).to eql("CID FORMAT ERROR")
262
+ }
263
+ end
264
+
265
+ # TODO: Gateway change, used to throw exception but now it doesn't
266
+ it "Mastercard response code should indicate switch not available" do
267
+ expect {
268
+ Hps::TestHelper.charge_valid_mastercard(10.33)
269
+ }.to raise_error(Hps::HpsException) { |error|
270
+ #}.to raise_error(Hps::CardException) { |error|
271
+ #expect(error.code).to eql("processing_error")
272
+ #expect(error.response_code).to eql("14")
273
+ expect(error.code).to eql("issuer_timeout")
274
+ expect(error.response_code).to eql("91")
275
+ expect(error.response_text).to eql("NO REPLY")
276
+ }
277
+ end
278
+
279
+ it "Mastercard response code should indicate system error" do
280
+ expect {
281
+ Hps::TestHelper.charge_valid_mastercard(10.21)
282
+ }.to raise_error(Hps::CardException) { |error|
283
+ expect(error.code).to eql("processing_error")
284
+ expect(error.response_code).to eql("96")
285
+ expect(error.response_text).to eql("SYSTEM ERROR")
286
+ }
287
+ end
288
+
289
+ # verify, authorize, refund, and capture
290
+
291
+ it "Mastercard verify should return OK" do
292
+ service = Hps::HpsChargeService.new()
293
+ result = service.verify(Hps::TestData.valid_mastercard, Hps::TestData.valid_cardholder)
294
+ expect(result.response_code).to eql("85")
295
+ end
296
+
297
+ it "Mastercard authorize should return OK" do
298
+ service = Hps::HpsChargeService.new()
299
+ result = service.authorize(50.00, "usd", Hps::TestData.valid_mastercard, Hps::TestData.valid_cardholder)
300
+ expect(result.response_code).to eql("00")
301
+ end
302
+
303
+ it "Mastercard authorize and request token should return OK" do
304
+ service = Hps::HpsChargeService.new()
305
+ result = service.authorize(50.00, "usd", Hps::TestData.valid_mastercard, Hps::TestData.valid_cardholder, true)
306
+ expect(result.token_data.response_code).to eql("0")
307
+ expect(result.response_code).to eql("00")
308
+ end
309
+
310
+ it "Mastercard should refund OK" do
311
+ service = Hps::HpsChargeService.new()
312
+ charge = service.charge(25.00, "usd", Hps::TestData.valid_mastercard, Hps::TestData.valid_cardholder)
313
+ refund = service.refund_transaction(25.00, "usd", charge.transaction_id)
314
+ expect(refund.response_code).to eql("00")
315
+ end
316
+
317
+ it "Mastercard authorize and capture should return OK" do
318
+ service = Hps::HpsChargeService.new()
319
+ result = service.authorize(50.00, "usd", Hps::TestData.valid_mastercard, Hps::TestData.valid_cardholder)
320
+ expect(result.response_code).to eql("00")
321
+
322
+ capture_result = service.capture(result.transaction_id)
323
+ expect(capture_result.response_code).to eql("00")
324
+ end
325
+
326
+ end