forked from activemerchant/active_merchant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote_cyber_source_test.rb
405 lines (341 loc) · 14.3 KB
/
remote_cyber_source_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
require 'test_helper'
class RemoteCyberSourceTest < Test::Unit::TestCase
def setup
Base.mode = :test
@gateway = CyberSourceGateway.new({nexus: "NC"}.merge(fixtures(:cyber_source)))
@credit_card = credit_card('4111111111111111', verification_value: '321')
@declined_card = credit_card('801111111111111')
@pinless_debit_card = credit_card('4002269999999999')
@three_ds_enrolled_card = credit_card('4000000000000002',
verification_value: '321',
month: "12",
year: "#{Time.now.year + 2}",
brand: :visa
)
@amount = 100
@options = {
:order_id => generate_unique_id,
:line_items => [
{
:declared_value => 100,
:quantity => 2,
:code => 'default',
:description => 'Giant Walrus',
:sku => 'WA323232323232323'
},
{
:declared_value => 100,
:quantity => 2,
:description => 'Marble Snowcone',
:sku => 'FAKE1232132113123'
}
],
:currency => 'USD',
:ignore_avs => 'true',
:ignore_cvv => 'true'
}
@subscription_options = {
:order_id => generate_unique_id,
:credit_card => @credit_card,
:subscription => {
:frequency => "weekly",
:start_date => Date.today.next_week,
:occurrences => 4,
:auto_renew => true,
:amount => 100
}
}
end
def test_transcript_scrubbing
transcript = capture_transcript(@gateway) do
@gateway.purchase(@amount, @credit_card, @options)
end
transcript = @gateway.scrub(transcript)
assert_scrubbed(@credit_card.number, transcript)
assert_scrubbed(@credit_card.verification_value, transcript)
assert_scrubbed(@gateway.options[:password], transcript)
end
def test_network_tokenization_transcript_scrubbing
credit_card = network_tokenization_credit_card('4111111111111111',
:brand => 'visa',
:eci => "05",
:payment_cryptogram => "EHuWW9PiBkWvqE5juRwDzAUFBAk="
)
transcript = capture_transcript(@gateway) do
@gateway.authorize(@amount, credit_card, @options)
end
transcript = @gateway.scrub(transcript)
assert_scrubbed(credit_card.number, transcript)
assert_scrubbed(credit_card.payment_cryptogram, transcript)
assert_scrubbed(@gateway.options[:password], transcript)
end
def test_successful_authorization
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
assert !response.authorization.blank?
end
def test_unsuccessful_authorization
assert response = @gateway.authorize(@amount, @declined_card, @options)
assert response.test?
assert_equal 'Invalid account number', response.message
assert_equal false, response.success?
end
def test_authorize_and_void
assert auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
assert void = @gateway.void(auth.authorization, @options)
assert_equal 'Successful transaction', void.message
assert_success void
assert void.test?
end
def test_capture_and_void
assert auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
assert capture = @gateway.capture(@amount, auth.authorization, @options)
assert_success capture
assert void = @gateway.void(capture.authorization, @options)
assert_equal 'Successful transaction', void.message
assert_success void
assert void.test?
end
def test_successful_tax_calculation
assert response = @gateway.calculate_tax(@credit_card, @options)
assert_equal 'Successful transaction', response.message
assert response.params['totalTaxAmount']
assert_not_equal "0", response.params['totalTaxAmount']
assert_success response
end
def test_successful_purchase
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
end
def test_successful_purchase_sans_options
assert response = @gateway.purchase(@amount, @credit_card)
assert_equal 'Successful transaction', response.message
assert_success response
end
def test_successful_purchase_with_billing_address_override
@options[:billing_address] = address
@options[:email] = 'override@example.com'
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'Successful transaction', response.message
assert_success response
end
def test_successful_purchase_with_long_country_name
@options[:billing_address] = address(country: "united states", state: "NC")
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'Successful transaction', response.message
assert_success response
end
def test_successful_purchase_without_decision_manager
@options[:decision_manager_enabled] = 'false'
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
end
def test_successful_purchase_with_decision_manager_profile
@options[:decision_manager_enabled] = 'true'
@options[:decision_manager_profile] = 'Regular'
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
end
def test_successful_pinless_debit_card_puchase
assert response = @gateway.purchase(@amount, @pinless_debit_card, @options.merge(:pinless_debit_card => true))
assert_equal 'Successful transaction', response.message
assert_success response
end
def test_unsuccessful_purchase
assert response = @gateway.purchase(@amount, @declined_card, @options)
assert_equal 'Invalid account number', response.message
assert_failure response
end
def test_authorize_and_capture
assert auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
assert_equal 'Successful transaction', auth.message
assert capture = @gateway.capture(@amount, auth.authorization)
assert_success capture
end
def test_successful_authorization_and_failed_capture
assert auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
assert_equal 'Successful transaction', auth.message
assert capture = @gateway.capture(@amount + 10, auth.authorization, @options)
assert_failure capture
assert_equal "The requested amount exceeds the originally authorized amount", capture.message
end
def test_failed_capture_bad_auth_info
assert auth = @gateway.authorize(@amount, @credit_card, @options)
assert capture = @gateway.capture(@amount, "a;b;c", @options)
assert_failure capture
end
def test_invalid_login
gateway = CyberSourceGateway.new( :login => 'asdf', :password => 'qwer' )
assert response = gateway.purchase(@amount, @credit_card, @options)
assert_failure response
assert_equal "wsse:FailedCheck: \nSecurity Data : UsernameToken authentication failed.\n", response.message
end
def test_successful_refund
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
assert response = @gateway.refund(@amount, response.authorization)
assert_equal 'Successful transaction', response.message
assert_success response
end
def test_successful_validate_pinless_debit_card
assert response = @gateway.validate_pinless_debit_card(@pinless_debit_card, @options)
assert response.test?
assert_equal 'Y', response.params["status"]
assert_equal true, response.success?
end
def test_network_tokenization_authorize_and_capture
credit_card = network_tokenization_credit_card('4111111111111111',
:brand => 'visa',
:eci => "05",
:payment_cryptogram => "EHuWW9PiBkWvqE5juRwDzAUFBAk="
)
assert auth = @gateway.authorize(@amount, credit_card, @options)
assert_success auth
assert_equal 'Successful transaction', auth.message
assert capture = @gateway.capture(@amount, auth.authorization)
assert_success capture
end
def test_successful_authorize_with_mdd_fields
(1..20).each { |e| @options["mdd_field_#{e}".to_sym] = "value #{e}" }
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_success response
end
def test_successful_purchase_with_mdd_fields
(1..20).each { |e| @options["mdd_field_#{e}".to_sym] = "value #{e}" }
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response
end
def test_successful_authorize_with_nonfractional_currency
assert response = @gateway.authorize(100, @credit_card, @options.merge(:currency => 'JPY'))
assert_equal "1", response.params['amount']
assert_success response
end
def test_successful_subscription_authorization
assert response = @gateway.store(@credit_card, @subscription_options)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
assert response = @gateway.authorize(@amount, response.authorization, :order_id => generate_unique_id)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
assert !response.authorization.blank?
end
def test_successful_subscription_purchase
assert response = @gateway.store(@credit_card, @subscription_options)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
assert response = @gateway.purchase(@amount, response.authorization, :order_id => generate_unique_id)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
end
def test_successful_subscription_credit
assert response = @gateway.store(@credit_card, @subscription_options)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
assert response = @gateway.credit(@amount, response.authorization, :order_id => generate_unique_id)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
end
def test_successful_create_subscription
assert response = @gateway.store(@credit_card, @subscription_options)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
end
def test_successful_create_subscription_with_setup_fee
assert response = @gateway.store(@credit_card, @subscription_options.merge(:setup_fee => 100))
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
end
def test_successful_create_subscription_with_monthly_options
response = @gateway.store(@credit_card, @subscription_options.merge(:setup_fee => 99.0, :subscription => {:amount => 49.0, :automatic_renew => false, frequency: 'monthly'}))
assert_equal 'Successful transaction', response.message
response = @gateway.retrieve(";#{response.params['subscriptionID']};", :order_id => @subscription_options[:order_id])
assert_equal "0.49", response.params['recurringAmount']
assert_equal 'monthly', response.params['frequency']
end
def test_successful_update_subscription_creditcard
assert response = @gateway.store(@credit_card, @subscription_options)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
assert response = @gateway.update(response.authorization, @credit_card, {:order_id => generate_unique_id, :setup_fee => 100})
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
end
def test_successful_update_subscription_billing_address
assert response = @gateway.store(@credit_card, @subscription_options)
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
assert response = @gateway.update(response.authorization, nil,
{:order_id => generate_unique_id, :setup_fee => 100, billing_address: address, email: 'someguy1232@fakeemail.net'})
assert_equal 'Successful transaction', response.message
assert_success response
assert response.test?
end
def test_successful_delete_subscription
assert response = @gateway.store(@credit_card, @subscription_options)
assert response.success?
assert response.test?
assert response = @gateway.unstore(response.authorization, :order_id => generate_unique_id)
assert response.success?
assert response.test?
end
def test_successful_retrieve_subscription
assert response = @gateway.store(@credit_card, @subscription_options)
assert response.success?
assert response.test?
assert response = @gateway.retrieve(response.authorization, :order_id => generate_unique_id)
assert response.success?
assert response.test?
end
def test_3ds_purchase_request
assert response = @gateway.purchase(1202, @three_ds_enrolled_card, @options.merge(payer_auth_enroll_service: true))
assert_equal "475", response.params["reasonCode"]
assert !response.params["acsURL"].blank?
assert !response.params["paReq"].blank?
assert !response.params["xid"].blank?
assert !response.success?
end
def test_3ds_authorize_request
assert response = @gateway.authorize(1202, @three_ds_enrolled_card, @options.merge(payer_auth_enroll_service: true))
assert_equal "475", response.params["reasonCode"]
assert !response.params["acsURL"].blank?
assert !response.params["paReq"].blank?
assert !response.params["xid"].blank?
assert !response.success?
end
def test_3ds_transactions_with_unenrolled_card
assert response = @gateway.purchase(1202, @credit_card, @options.merge(payer_auth_enroll_service: true))
assert response.success?
assert response = @gateway.authorize(1202, @credit_card, @options.merge(payer_auth_enroll_service: true))
assert response.success?
end
def test_verify_credentials
assert @gateway.verify_credentials
gateway = CyberSourceGateway.new(login: "an_unknown_login", password: "unknown_password")
assert !gateway.verify_credentials
end
end