@@ -24,6 +24,9 @@ def setup
24
24
billing_address: address,
25
25
return_url: 'https://example.com'
26
26
}
27
+
28
+ @stored_credential_cit_options = { initial_transaction: true, initiator: 'cardholder', reason_type: 'recurring', network_transaction_id: nil }
29
+ @stored_credential_mit_options = { initial_transaction: false, initiator: 'merchant', reason_type: 'recurring', network_transaction_id: '123456789012345' }
27
30
end
28
31
29
32
def test_gateway_has_access_token
@@ -301,68 +304,138 @@ def test_invalid_login
301
304
end
302
305
303
306
def test_successful_cit_with_stored_credential
304
- stored_credential_params = {
305
- initial_transaction: true,
306
- reason_type: 'recurring',
307
- initiator: 'cardholder',
308
- network_transaction_id: nil
309
- }
310
-
311
307
auth = stub_comms do
312
- @gateway.authorize(@amount, @credit_card, @options.merge({ stored_credential: stored_credential_params }))
308
+ @gateway.authorize(@amount, @credit_card, @options.merge! ({ stored_credential: @stored_credential_cit_options }))
313
309
end.check_request do |endpoint, data, _headers|
314
- # This conditional asserts after the initial setup call is made
315
- assert_match(/"external_recurring_data\":{\"merchant_trigger_reason\":\"scheduled\",\"original_transaction_id\":null,\"triggered_by\":\"customer\"}/, data) if endpoint != 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
310
+ # This conditional runs assertions after the initial setup call is made
311
+ unless endpoint == 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
312
+ assert_match(/"external_recurring_data\"/, data)
313
+ assert_match(/"merchant_trigger_reason\":\"scheduled\"/, data)
314
+ assert_match(/"original_transaction_id\":null,/, data)
315
+ assert_match(/"triggered_by\":\"customer\"/, data)
316
+ end
316
317
end.respond_with(successful_authorize_response)
317
318
assert_success auth
318
319
end
319
320
320
321
def test_successful_mit_with_recurring_stored_credential
321
- stored_credential_params = {
322
- initial_transaction: false,
323
- reason_type: 'recurring',
324
- initiator: 'merchant',
325
- network_transaction_id: 'MCC123ABC0101'
326
- }
327
-
328
322
auth = stub_comms do
329
- @gateway.authorize(@amount, @credit_card, @options.merge({ stored_credential: stored_credential_params }))
323
+ @gateway.authorize(@amount, @credit_card, @options.merge! ({ stored_credential: @stored_credential_cit_options }))
330
324
end.check_request do |endpoint, data, _headers|
331
- assert_match(/"external_recurring_data\":{\"merchant_trigger_reason\":\"scheduled\",\"original_transaction_id\":\"MCC123ABC0101\",\"triggered_by\":\"merchant\"}/, data) if endpoint != 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
325
+ unless endpoint == 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
326
+ assert_match(/"external_recurring_data\"/, data)
327
+ assert_match(/"merchant_trigger_reason\":\"scheduled\"/, data)
328
+ assert_match(/"original_transaction_id\":null,/, data)
329
+ assert_match(/"triggered_by\":\"customer\"/, data)
330
+ end
332
331
end.respond_with(successful_authorize_response)
333
332
assert_success auth
333
+
334
+ purchase = stub_comms do
335
+ @gateway.purchase(@amount, @credit_card, @options.merge!({ stored_credential: @stored_credential_mit_options }))
336
+ end.check_request do |endpoint, data, _headers|
337
+ unless endpoint == 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
338
+ assert_match(/"external_recurring_data\"/, data)
339
+ assert_match(/"merchant_trigger_reason\":\"scheduled\"/, data)
340
+ assert_match(/"original_transaction_id\":\"123456789012345\"/, data)
341
+ assert_match(/"triggered_by\":\"merchant\"/, data)
342
+ end
343
+ end.respond_with(successful_purchase_response)
344
+ assert_success purchase
334
345
end
335
346
336
347
def test_successful_mit_with_unscheduled_stored_credential
337
- stored_credential_params = {
338
- initial_transaction: false,
339
- reason_type: 'unscheduled',
340
- initiator: 'merchant',
341
- network_transaction_id: 'MCC123ABC0101'
342
- }
348
+ @stored_credential_cit_options[:reason_type] = 'unscheduled'
349
+ @stored_credential_mit_options[:reason_type] = 'unscheduled'
343
350
344
351
auth = stub_comms do
345
- @gateway.authorize(@amount, @credit_card, @options.merge({ stored_credential: stored_credential_params }))
352
+ @gateway.authorize(@amount, @credit_card, @options.merge! ({ stored_credential: @stored_credential_cit_options }))
346
353
end.check_request do |endpoint, data, _headers|
347
- assert_match(/"external_recurring_data\":{\"merchant_trigger_reason\":\"unscheduled\",\"original_transaction_id\":\"MCC123ABC0101\",\"triggered_by\":\"merchant\"}/, data) if endpoint != 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
354
+ unless endpoint == 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
355
+ assert_match(/"external_recurring_data\"/, data)
356
+ assert_match(/"merchant_trigger_reason\":\"unscheduled\"/, data)
357
+ assert_match(/"original_transaction_id\":null,/, data)
358
+ assert_match(/"triggered_by\":\"customer\"/, data)
359
+ end
348
360
end.respond_with(successful_authorize_response)
349
361
assert_success auth
362
+
363
+ purchase = stub_comms do
364
+ @gateway.purchase(@amount, @credit_card, @options.merge!({ stored_credential: @stored_credential_mit_options }))
365
+ end.check_request do |endpoint, data, _headers|
366
+ unless endpoint == 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
367
+ assert_match(/"external_recurring_data\"/, data)
368
+ assert_match(/"merchant_trigger_reason\":\"unscheduled\"/, data)
369
+ assert_match(/"original_transaction_id\":\"123456789012345\"/, data)
370
+ assert_match(/"triggered_by\":\"merchant\"/, data)
371
+ end
372
+ end.respond_with(successful_purchase_response)
373
+ assert_success purchase
350
374
end
351
375
352
376
def test_successful_mit_with_installment_stored_credential
353
- stored_credential_params = {
354
- initial_transaction: false,
355
- reason_type: 'installment',
356
- initiator: 'merchant',
357
- network_transaction_id: 'MCC123ABC0101'
358
- }
377
+ @stored_credential_cit_options[:reason_type] = 'installment'
378
+ @stored_credential_mit_options[:reason_type] = 'installment'
379
+
380
+ auth = stub_comms do
381
+ @gateway.authorize(@amount, @credit_card, @options.merge!({ stored_credential: @stored_credential_cit_options }))
382
+ end.check_request do |endpoint, data, _headers|
383
+ unless endpoint == 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
384
+ assert_match(/"external_recurring_data\"/, data)
385
+ assert_match(/"merchant_trigger_reason\":\"scheduled\"/, data)
386
+ assert_match(/"original_transaction_id\":null,/, data)
387
+ assert_match(/"triggered_by\":\"customer\"/, data)
388
+ end
389
+ end.respond_with(successful_authorize_response)
390
+ assert_success auth
391
+
392
+ purchase = stub_comms do
393
+ @gateway.purchase(@amount, @credit_card, @options.merge!({ stored_credential: @stored_credential_mit_options }))
394
+ end.check_request do |endpoint, data, _headers|
395
+ unless endpoint == 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
396
+ assert_match(/"external_recurring_data\"/, data)
397
+ assert_match(/"merchant_trigger_reason\":\"scheduled\"/, data)
398
+ assert_match(/"original_transaction_id\":\"123456789012345\"/, data)
399
+ assert_match(/"triggered_by\":\"merchant\"/, data)
400
+ end
401
+ end.respond_with(successful_purchase_response)
402
+ assert_success purchase
403
+ end
404
+
405
+ def test_successful_mit_with_original_transaction_id
406
+ mastercard = credit_card('2223 0000 1018 1375', { brand: 'master' })
407
+ @options[:original_transaction_id] = 'MCC123ABC0101'
359
408
360
409
auth = stub_comms do
361
- @gateway.authorize(@amount, @credit_card , @options.merge({ stored_credential: stored_credential_params }))
410
+ @gateway.authorize(@amount, mastercard , @options.merge! ({ stored_credential: @stored_credential_cit_options }))
362
411
end.check_request do |endpoint, data, _headers|
363
- assert_match(/"external_recurring_data\":{\"merchant_trigger_reason\":\"scheduled\",\"original_transaction_id\":\"MCC123ABC0101\",\"triggered_by\":\"merchant\"}/, data) if endpoint != 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
412
+ unless endpoint == 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
413
+ assert_match(/"external_recurring_data\"/, data)
414
+ assert_match(/"merchant_trigger_reason\":\"scheduled\"/, data)
415
+ assert_match(/"original_transaction_id\":null,/, data)
416
+ assert_match(/"triggered_by\":\"customer\"/, data)
417
+ end
364
418
end.respond_with(successful_authorize_response)
365
419
assert_success auth
420
+
421
+ purchase = stub_comms do
422
+ @gateway.purchase(@amount, mastercard, @options.merge!({ stored_credential: @stored_credential_mit_options }))
423
+ end.check_request do |endpoint, data, _headers|
424
+ unless endpoint == 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create'
425
+ assert_match(/"external_recurring_data\"/, data)
426
+ assert_match(/"merchant_trigger_reason\":\"scheduled\"/, data)
427
+ assert_match(/"original_transaction_id\":\"MCC123ABC0101\"/, data)
428
+ assert_match(/"triggered_by\":\"merchant\"/, data)
429
+ end
430
+ end.respond_with(successful_purchase_response)
431
+ assert_success purchase
432
+ end
433
+
434
+ def test_failed_mit_with_unapproved_ntid
435
+ @gateway.expects(:ssl_post).returns(failed_ntid_response)
436
+ assert_raise ArgumentError do
437
+ @gateway.authorize(@amount, @credit_card, @options.merge!({ stored_credential: @stored_credential_cit_options }))
438
+ end
366
439
end
367
440
368
441
def test_scrub
@@ -438,4 +511,8 @@ def successful_void_response
438
511
def failed_void_response
439
512
%({"code":"not_found","message":"The requested endpoint does not exist [/api/v1/pa/payment_intents/12345/cancel]"})
440
513
end
514
+
515
+ def failed_ntid_response
516
+ %({"code":"validation_error","source":"external_recurring_data.original_transaction_id","message":"external_recurring_data.original_transaction_id should be 13-15 characters long"})
517
+ end
441
518
end
0 commit comments