hps 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -8
- data/LICENSE.txt +32 -32
- data/PRIVACY.txt +65 -65
- data/README.md +40 -40
- data/Rakefile +15 -15
- data/hps.gemspec +26 -26
- data/lib/hps/configuration.rb +16 -16
- data/lib/hps/entities/hps_account_verify.rb +8 -8
- data/lib/hps/entities/hps_address.rb +6 -6
- data/lib/hps/entities/hps_authorization.rb +12 -12
- data/lib/hps/entities/hps_batch.rb +6 -6
- data/lib/hps/entities/hps_cardholder.rb +10 -6
- data/lib/hps/entities/hps_charge.rb +8 -8
- data/lib/hps/entities/hps_charge_exceptions.rb +6 -6
- data/lib/hps/entities/hps_credit_card.rb +32 -32
- data/lib/hps/entities/hps_refund.rb +8 -8
- data/lib/hps/entities/hps_report_transaction_details.rb +10 -10
- data/lib/hps/entities/hps_report_transaction_summary.rb +6 -6
- data/lib/hps/entities/hps_reversal.rb +10 -10
- data/lib/hps/entities/hps_token_data.rb +10 -10
- data/lib/hps/entities/hps_transaction.rb +161 -161
- data/lib/hps/entities/hps_transaction_details.rb +6 -6
- data/lib/hps/entities/hps_transaction_header.rb +8 -8
- data/lib/hps/entities/hps_transaction_type.rb +16 -16
- data/lib/hps/entities/hps_void.rb +8 -8
- data/lib/hps/infrastructure/api_connection_exception.rb +11 -11
- data/lib/hps/infrastructure/authentication_exception.rb +11 -11
- data/lib/hps/infrastructure/card_exception.rb +15 -15
- data/lib/hps/infrastructure/exceptions.json +468 -468
- data/lib/hps/infrastructure/hps_exception.rb +25 -25
- data/lib/hps/infrastructure/hps_exception_mapper.rb +134 -134
- data/lib/hps/infrastructure/hps_sdk_codes.rb +48 -48
- data/lib/hps/infrastructure/invalid_request_exception.rb +15 -15
- data/lib/hps/services/hps_batch_service.rb +29 -29
- data/lib/hps/services/hps_charge_service.rb +634 -634
- data/lib/hps/services/hps_service.rb +128 -128
- data/lib/hps/version.rb +3 -3
- data/lib/hps.rb +45 -45
- data/tests/amex_tests.rb +230 -230
- data/tests/cert_tests.rb +80 -80
- data/tests/discover_tests.rb +324 -324
- data/tests/exception_mapper_tests.rb +244 -244
- data/tests/general_tests.rb +58 -58
- data/tests/hps_token_service.rb +56 -56
- data/tests/mastercard_tests.rb +325 -325
- data/tests/secret_key.rb +11 -11
- data/tests/test_data.rb +127 -127
- data/tests/test_helper.rb +108 -92
- data/tests/token_tests.rb +513 -513
- data/tests/visa_tests.rb +378 -378
- metadata +4 -6
- data/.DS_Store +0 -0
- data/.gitignore +0 -24
@@ -1,245 +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
|
-
|
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
245
|
end
|
data/tests/general_tests.rb
CHANGED
@@ -1,58 +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 :
|
38
|
-
@service.charge(50, "usd", Hps::TestData::valid_visa, Hps::TestData::valid_cardholder)
|
39
|
-
}.to raise_error(Hps::
|
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
|
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 :license_id => 11111
|
38
|
+
@service.charge(50, "usd", Hps::TestData::valid_visa, Hps::TestData::valid_cardholder)
|
39
|
+
}.to raise_error(Hps::AuthenticationException)
|
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
|