-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
cyber_source_rest_test.rb
723 lines (654 loc) · 36.8 KB
/
cyber_source_rest_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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
require 'test_helper'
class CyberSourceRestTest < Test::Unit::TestCase
include CommStub
def setup
@gateway = CyberSourceRestGateway.new(
merchant_id: 'abc123',
public_key: 'def345',
private_key: "NYlM1sgultLjvgaraWvDCXykdz1buqOW8yXE3pMlmxQ=\n"
)
@bank_account = check(account_number: '4100', routing_number: '121042882')
@credit_card = credit_card(
'4111111111111111',
verification_value: '987',
month: 12,
year: 2031
)
@master_card = credit_card('2222420000001113', brand: 'master')
@visa_network_token = network_tokenization_credit_card(
'4111111111111111',
brand: 'visa',
eci: '05',
payment_cryptogram: 'EHuWW9PiBkWvqE5juRwDzAUFBAk=',
source: :network_token
)
@mastercard_network_token = network_tokenization_credit_card(
'5555555555554444',
brand: 'master',
eci: '05',
payment_cryptogram: 'EHuWW9PiBkWvqE5juRwDzAUFBAk=',
source: :network_token
)
@apple_pay = network_tokenization_credit_card(
'4111111111111111',
payment_cryptogram: 'AceY+igABPs3jdwNaDg3MAACAAA=',
month: '11',
year: Time.now.year + 1,
source: :apple_pay,
verification_value: 569
)
@google_pay_mc = network_tokenization_credit_card(
'5555555555554444',
payment_cryptogram: 'AceY+igABPs3jdwNaDg3MAACAAA=',
month: '11',
year: Time.now.year + 1,
source: :google_pay,
verification_value: 569,
brand: 'master'
)
@apple_pay_jcb = network_tokenization_credit_card(
'3566111111111113',
payment_cryptogram: 'AceY+igABPs3jdwNaDg3MAACAAA=',
month: '11',
year: Time.now.year + 1,
source: :apple_pay,
verification_value: 569,
brand: 'jcb'
)
@amount = 100
@options = {
order_id: '1',
description: 'Store Purchase',
billing_address: {
name: 'John Doe',
address1: '1 Market St',
city: 'san francisco',
state: 'CA',
zip: '94105',
country: 'US',
phone: '4158880000'
},
email: 'test@cybs.com'
}
@gmt_time = Time.now.httpdate
@digest = 'SHA-256=gXWufV4Zc7VkN9Wkv9jh/JuAVclqDusx3vkyo3uJFWU='
@resource = '/pts/v2/payments/'
end
def test_required_merchant_id_and_secret
error = assert_raises(ArgumentError) { CyberSourceRestGateway.new }
assert_equal 'Missing required parameter: merchant_id', error.message
end
def test_supported_card_types
assert_equal CyberSourceRestGateway.supported_cardtypes, %i[visa master american_express discover diners_club jcb maestro elo union_pay cartes_bancaires mada]
end
def test_properly_format_on_zero_decilmal
stub_comms do
@gateway.authorize(1000, @credit_card, @options)
end.check_request do |_endpoint, data, _headers|
request = JSON.parse(data)
card = request['paymentInformation']['card']
amount_details = request['orderInformation']['amountDetails']
assert_equal '1', request['clientReferenceInformation']['code']
assert_equal '2031', card['expirationYear']
assert_equal '12', card['expirationMonth']
assert_equal '987', card['securityCode']
assert_equal '001', card['type']
assert_equal 'USD', amount_details['currency']
assert_equal '10.00', amount_details['totalAmount']
end.respond_with(successful_purchase_response)
end
def test_should_create_an_http_signature_for_a_post
signature = @gateway.send :get_http_signature, @resource, @digest, 'post', @gmt_time
parsed = parse_signature(signature)
assert_equal 'def345', parsed['keyid']
assert_equal 'HmacSHA256', parsed['algorithm']
assert_equal 'host date request-target digest v-c-merchant-id', parsed['headers']
assert_equal %w[algorithm headers keyid signature], signature.split(', ').map { |v| v.split('=').first }.sort
end
def test_should_create_an_http_signature_for_a_get
signature = @gateway.send :get_http_signature, @resource, nil, 'get', @gmt_time
parsed = parse_signature(signature)
assert_equal 'host date request-target v-c-merchant-id', parsed['headers']
end
def test_scrub
assert @gateway.supports_scrubbing?
assert_equal @gateway.scrub(pre_scrubbed), post_scrubbed
end
def test_including_customer_if_customer_id_present
post = { paymentInformation: {} }
@gateway.send :add_customer_id, post, {}
assert_nil post[:paymentInformation][:customer]
@gateway.send :add_customer_id, post, { customer_id: 10 }
assert_equal 10, post[:paymentInformation][:customer][:customerId]
end
def test_add_ammount_and_currency
post = { orderInformation: {} }
@gateway.send :add_amount, post, 10221, {}
assert_equal '102.21', post.dig(:orderInformation, :amountDetails, :totalAmount)
assert_equal 'USD', post.dig(:orderInformation, :amountDetails, :currency)
end
def test_add_credit_card_data
post = { paymentInformation: {} }
@gateway.send :add_credit_card, post, @credit_card
card = post[:paymentInformation][:card]
assert_equal @credit_card.number, card[:number]
assert_equal '2031', card[:expirationYear]
assert_equal '12', card[:expirationMonth]
assert_equal '987', card[:securityCode]
assert_equal '001', card[:type]
end
def test_add_ach
post = { paymentInformation: {} }
@gateway.send :add_ach, post, @bank_account
bank = post[:paymentInformation][:bank]
assert_equal @bank_account.account_number, bank[:account][:number]
assert_equal @bank_account.routing_number, bank[:routingNumber]
end
def test_add_billing_address
post = { orderInformation: {} }
@gateway.send :add_address, post, @credit_card, @options[:billing_address], @options, :billTo
address = post[:orderInformation][:billTo]
assert_equal 'John', address[:firstName]
assert_equal 'Doe', address[:lastName]
assert_equal '1 Market St', address[:address1]
assert_equal 'san francisco', address[:locality]
assert_equal 'US', address[:country]
assert_equal 'test@cybs.com', address[:email]
assert_equal '4158880000', address[:phoneNumber]
end
def test_add_shipping_address
post = { orderInformation: {} }
@options[:shipping_address] = @options.delete(:billing_address)
@gateway.send :add_address, post, @credit_card, @options[:shipping_address], @options, :shipTo
address = post[:orderInformation][:shipTo]
assert_equal 'John', address[:firstName]
assert_equal 'Doe', address[:lastName]
assert_equal '1 Market St', address[:address1]
assert_equal 'san francisco', address[:locality]
assert_equal 'US', address[:country]
assert_equal 'test@cybs.com', address[:email]
assert_equal '4158880000', address[:phoneNumber]
end
def test_authorize_network_token_visa
stub_comms do
@gateway.authorize(100, @visa_network_token, @options)
end.check_request do |_endpoint, data, _headers|
request = JSON.parse(data)
assert_equal '001', request['paymentInformation']['tokenizedCard']['type']
assert_equal '3', request['paymentInformation']['tokenizedCard']['transactionType']
assert_equal 'EHuWW9PiBkWvqE5juRwDzAUFBAk=', request['paymentInformation']['tokenizedCard']['cryptogram']
assert_nil request['paymentInformation']['tokenizedCard']['requestorId']
assert_equal '015', request['processingInformation']['paymentSolution']
assert_equal 'internet', request['processingInformation']['commerceIndicator']
end.respond_with(successful_purchase_response)
end
def test_authorize_network_token_mastercard
stub_comms do
@gateway.authorize(100, @mastercard_network_token, @options)
end.check_request do |_endpoint, data, _headers|
request = JSON.parse(data)
assert_equal '002', request['paymentInformation']['tokenizedCard']['type']
assert_equal '3', request['paymentInformation']['tokenizedCard']['transactionType']
assert_equal 'EHuWW9PiBkWvqE5juRwDzAUFBAk=', request['paymentInformation']['tokenizedCard']['cryptogram']
assert_nil request['paymentInformation']['tokenizedCard']['requestorId']
assert_equal '014', request['processingInformation']['paymentSolution']
assert_equal 'internet', request['processingInformation']['commerceIndicator']
end.respond_with(successful_purchase_response)
end
def test_authorize_apple_pay_visa
stub_comms do
@gateway.authorize(100, @apple_pay, @options)
end.check_request do |_endpoint, data, _headers|
request = JSON.parse(data)
assert_equal '001', request['paymentInformation']['tokenizedCard']['type']
assert_equal '1', request['paymentInformation']['tokenizedCard']['transactionType']
assert_equal 'AceY+igABPs3jdwNaDg3MAACAAA=', request['paymentInformation']['tokenizedCard']['cryptogram']
assert_nil request['paymentInformation']['tokenizedCard']['requestorId']
assert_equal '001', request['processingInformation']['paymentSolution']
assert_equal 'internet', request['processingInformation']['commerceIndicator']
assert_include request['consumerAuthenticationInformation'], 'cavv'
end.respond_with(successful_purchase_response)
end
def test_authorize_google_pay_master_card
stub_comms do
@gateway.authorize(100, @google_pay_mc, @options.merge(merchant_id: 'MerchantId'))
end.check_request do |_endpoint, data, headers|
request = JSON.parse(data)
assert_equal 'MerchantId', headers['V-C-Merchant-Id']
assert_equal '002', request['paymentInformation']['tokenizedCard']['type']
assert_equal '1', request['paymentInformation']['tokenizedCard']['transactionType']
assert_nil request['paymentInformation']['tokenizedCard']['requestorId']
assert_equal '012', request['processingInformation']['paymentSolution']
assert_equal 'internet', request['processingInformation']['commerceIndicator']
assert_equal request['consumerAuthenticationInformation']['ucafCollectionIndicator'], '2'
assert_include request['consumerAuthenticationInformation'], 'ucafAuthenticationData'
end.respond_with(successful_purchase_response)
end
def test_authorize_apple_pay_jcb
stub_comms do
@gateway.authorize(100, @apple_pay_jcb, @options)
end.check_request do |_endpoint, data, _headers|
request = JSON.parse(data)
assert_equal '007', request['paymentInformation']['tokenizedCard']['type']
assert_equal '1', request['paymentInformation']['tokenizedCard']['transactionType']
assert_nil request['paymentInformation']['tokenizedCard']['requestorId']
assert_equal '001', request['processingInformation']['paymentSolution']
assert_nil request['processingInformation']['commerceIndicator']
assert_include request['consumerAuthenticationInformation'], 'cavv'
end.respond_with(successful_purchase_response)
end
def test_url_building
assert_equal "#{@gateway.class.test_url}/pts/v2/action", @gateway.send(:url, 'action')
end
def test_stored_credential_cit_initial
@options[:stored_credential] = stored_credential(:cardholder, :internet, :initial)
response = stub_comms do
@gateway.authorize(@amount, @credit_card, @options)
end.check_request do |_endpoint, data, _headers|
request = JSON.parse(data)
assert_equal 'internet', request['processingInformation']['commerceIndicator']
assert_equal 'customer', request.dig('processingInformation', 'authorizationOptions', 'initiator', 'type')
end.respond_with(successful_purchase_response)
assert_success response
end
def test_stored_credential_recurring_cit
@options[:stored_credential] = stored_credential(:cardholder, :recurring)
response = stub_comms do
@gateway.authorize(@amount, @credit_card, @options)
end.check_request do |_endpoint, data, _headers|
request = JSON.parse(data)
assert_equal 'recurring', request['processingInformation']['commerceIndicator']
assert_equal 'customer', request.dig('processingInformation', 'authorizationOptions', 'initiator', 'type')
assert_equal true, request.dig('processingInformation', 'authorizationOptions', 'initiator', 'merchantInitiatedTransaction', 'storedCredentialUsed')
end.respond_with(successful_purchase_response)
assert_success response
end
def test_stored_credential_recurring_mit_ntid
@options[:stored_credential] = stored_credential(:merchant, :recurring, ntid: '123456789619999')
response = stub_comms do
@gateway.authorize(@amount, @credit_card, @options)
end.check_request do |_endpoint, data, _headers|
request = JSON.parse(data)
assert_equal 'recurring', request['processingInformation']['commerceIndicator']
assert_equal 'merchant', request.dig('processingInformation', 'authorizationOptions', 'initiator', 'type')
assert_equal true, request.dig('processingInformation', 'authorizationOptions', 'initiator', 'merchantInitiatedTransaction', 'storedCredentialUsed')
end.respond_with(successful_purchase_response)
assert_success response
end
def test_successful_credit_card_purchase_single_request_ignore_avs
stub_comms do
options = @options.merge(ignore_avs: true)
@gateway.purchase(@amount, @credit_card, options)
end.check_request do |_endpoint, request_body, _headers|
json_body = JSON.parse(request_body)
assert_equal json_body['processingInformation']['authorizationOptions']['ignoreAvsResult'], 'true'
assert_nil json_body['processingInformation']['authorizationOptions']['ignoreCvResult']
end.respond_with(successful_purchase_response)
end
def test_successful_credit_card_purchase_single_request_without_ignore_avs
stub_comms do
# globally ignored AVS for gateway instance:
options = @options.merge(ignore_avs: false)
@gateway.options[:ignore_avs] = true
@gateway.purchase(@amount, @credit_card, options)
end.check_request do |_endpoint, request_body, _headers|
json_body = JSON.parse(request_body)
assert_nil json_body['processingInformation']['authorizationOptions']['ignoreAvsResult']
assert_nil json_body['processingInformation']['authorizationOptions']['ignoreCvResult']
end.respond_with(successful_purchase_response)
end
def test_successful_credit_card_purchase_single_request_ignore_ccv
stub_comms do
@gateway.purchase(@amount, @credit_card, @options.merge(ignore_cvv: true))
end.check_request do |_endpoint, request_body, _headers|
json_body = JSON.parse(request_body)
assert_nil json_body['processingInformation']['authorizationOptions']['ignoreAvsResult']
assert_equal json_body['processingInformation']['authorizationOptions']['ignoreCvResult'], 'true'
end.respond_with(successful_purchase_response)
end
def test_successful_credit_card_purchase_single_request_without_ignore_ccv
stub_comms do
@gateway.purchase(@amount, @credit_card, @options.merge(ignore_cvv: false))
end.check_request do |_endpoint, request_body, _headers|
json_body = JSON.parse(request_body)
assert_nil json_body['processingInformation']['authorizationOptions']['ignoreAvsResult']
assert_nil json_body['processingInformation']['authorizationOptions']['ignoreCvResult']
end.respond_with(successful_purchase_response)
end
def test_authorize_includes_mdd_fields
stub_comms do
@gateway.authorize(100, @credit_card, order_id: '1', mdd_field_2: 'CustomValue2', mdd_field_3: 'CustomValue3')
end.check_request do |_endpoint, data, _headers|
json_data = JSON.parse(data)
assert_equal json_data['merchantDefinedInformation'][0]['key'], 'mdd_field_2'
assert_equal json_data['merchantDefinedInformation'][0]['value'], 'CustomValue2'
assert_equal json_data['merchantDefinedInformation'].count, 2
end.respond_with(successful_purchase_response)
end
def test_capture_includes_mdd_fields
stub_comms do
@gateway.capture(100, '1846925324700976124593', order_id: '1', mdd_field_2: 'CustomValue2', mdd_field_3: 'CustomValue3')
end.check_request do |_endpoint, data, _headers|
json_data = JSON.parse(data)
assert_equal json_data['merchantDefinedInformation'][0]['key'], 'mdd_field_2'
assert_equal json_data['merchantDefinedInformation'][0]['value'], 'CustomValue2'
assert_equal json_data['merchantDefinedInformation'].count, 2
end.respond_with(successful_capture_response)
end
def test_credit_includes_mdd_fields
stub_comms do
@gateway.credit(@amount, @credit_card, mdd_field_2: 'CustomValue2', mdd_field_3: 'CustomValue3')
end.check_request do |_endpoint, data, _headers|
json_data = JSON.parse(data)
assert_equal json_data['merchantDefinedInformation'][0]['key'], 'mdd_field_2'
assert_equal json_data['merchantDefinedInformation'][0]['value'], 'CustomValue2'
assert_equal json_data['merchantDefinedInformation'].count, 2
end.respond_with(successful_credit_response)
end
def test_authorize_includes_reconciliation_id
stub_comms do
@gateway.authorize(100, @credit_card, order_id: '1', reconciliation_id: '181537')
end.check_request do |_endpoint, data, _headers|
json_data = JSON.parse(data)
assert_equal json_data['clientReferenceInformation']['reconciliationId'], '181537'
end.respond_with(successful_purchase_response)
end
def test_bank_account_purchase_includes_sec_code
stub_comms do
@gateway.purchase(@amount, @bank_account, order_id: '1', sec_code: 'WEB')
end.check_request do |_endpoint, data, _headers|
json_data = JSON.parse(data)
assert_equal json_data['processingInformation']['bankTransferOptions']['secCode'], 'WEB'
end.respond_with(successful_purchase_response)
end
def test_purchase_includes_invoice_number
stub_comms do
@gateway.purchase(100, @credit_card, invoice_number: '1234567')
end.check_request do |_endpoint, data, _headers|
json_data = JSON.parse(data)
assert_equal json_data['orderInformation']['invoiceDetails']['invoiceNumber'], '1234567'
end.respond_with(successful_purchase_response)
end
def test_mastercard_purchase_with_3ds2
@options[:three_d_secure] = {
version: '2.2.0',
cavv: '3q2+78r+ur7erb7vyv66vv\/\/\/\/8=',
eci: '05',
ds_transaction_id: 'ODUzNTYzOTcwODU5NzY3Qw==',
enrolled: 'true',
authentication_response_status: 'Y',
cavv_algorithm: '2'
}
stub_comms do
@gateway.purchase(100, @master_card, @options)
end.check_request do |_endpoint, data, _headers|
json_data = JSON.parse(data)
assert_equal json_data['consumerAuthenticationInformation']['ucafAuthenticationData'], '3q2+78r+ur7erb7vyv66vv\/\/\/\/8='
assert_equal json_data['consumerAuthenticationInformation']['ucafCollectionIndicator'], '2'
assert_equal json_data['consumerAuthenticationInformation']['cavvAlgorithm'], '2'
assert_equal json_data['consumerAuthenticationInformation']['paSpecificationVersion'], '2.2.0'
assert_equal json_data['consumerAuthenticationInformation']['directoryServerTransactionID'], 'ODUzNTYzOTcwODU5NzY3Qw=='
assert_equal json_data['consumerAuthenticationInformation']['eciRaw'], '05'
assert_equal json_data['consumerAuthenticationInformation']['xid'], '3q2+78r+ur7erb7vyv66vv\/\/\/\/8='
assert_equal json_data['consumerAuthenticationInformation']['veresEnrolled'], 'true'
assert_equal json_data['consumerAuthenticationInformation']['paresStatus'], 'Y'
end.respond_with(successful_purchase_response)
end
def test_visa_purchase_with_3ds2
@options[:three_d_secure] = {
version: '2.2.0',
cavv: '3q2+78r+ur7erb7vyv66vv\/\/\/\/8=',
eci: '05',
ds_transaction_id: 'ODUzNTYzOTcwODU5NzY3Qw==',
enrolled: 'true',
authentication_response_status: 'Y',
cavv_algorithm: '2'
}
stub_comms do
@gateway.authorize(100, @credit_card, @options)
end.check_request do |_endpoint, data, _headers|
json_data = JSON.parse(data)
assert_equal json_data['consumerAuthenticationInformation']['cavv'], '3q2+78r+ur7erb7vyv66vv\/\/\/\/8='
assert_equal json_data['consumerAuthenticationInformation']['cavvAlgorithm'], '2'
assert_equal json_data['consumerAuthenticationInformation']['paSpecificationVersion'], '2.2.0'
assert_equal json_data['consumerAuthenticationInformation']['directoryServerTransactionID'], 'ODUzNTYzOTcwODU5NzY3Qw=='
assert_equal json_data['consumerAuthenticationInformation']['eciRaw'], '05'
assert_equal json_data['consumerAuthenticationInformation']['xid'], '3q2+78r+ur7erb7vyv66vv\/\/\/\/8='
assert_equal json_data['consumerAuthenticationInformation']['veresEnrolled'], 'true'
assert_equal json_data['consumerAuthenticationInformation']['paresStatus'], 'Y'
end.respond_with(successful_purchase_response)
end
def test_adds_application_id_as_partner_solution_id
partner_id = 'partner_id'
CyberSourceRestGateway.application_id = partner_id
stub_comms do
@gateway.authorize(100, @credit_card, @options)
end.check_request do |_endpoint, data, _headers|
json_data = JSON.parse(data)
assert_equal json_data['clientReferenceInformation']['partner']['solutionId'], partner_id
end.respond_with(successful_purchase_response)
ensure
CyberSourceRestGateway.application_id = nil
end
private
def parse_signature(signature)
signature.gsub(/=\"$/, '').delete('"').split(', ').map { |x| x.split('=') }.to_h
end
def pre_scrubbed
<<-PRE
<- "POST /pts/v2/payments/ HTTP/1.1\r\nContent-Type: application/json;charset=utf-8\r\nAccept: application/hal+json;charset=utf-8\r\nV-C-Merchant-Id: testrest\r\nDate: Sun, 29 Jan 2023 17:13:30 GMT\r\nHost: apitest.cybersource.com\r\nSignature: keyid=\"08c94330-f618-42a3-b09d-e1e43be5efda\", algorithm=\"HmacSHA256\", headers=\"host date (request-target) digest v-c-merchant-id\", signature=\"DJHeHWceVrsJydd8BCbGowr9dzQ/ry5cGN1FocLakEw=\"\r\nDigest: SHA-256=wuV1cxGzs6KpuUKJmlD7pKV6MZ/5G1wQVoYbf8cRChM=\r\nConnection: close\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nUser-Agent: Ruby\r\nContent-Length: 584\r\n\r\n"
<- "{\"clientReferenceInformation\":{\"code\":\"b8779865d140125036016a0f85db907f\"},\"paymentInformation\":{\"card\":{\"number\":\"4111111111111111\",\"expirationMonth\":\"12\",\"expirationYear\":\"2031\",\"securityCode\":\"987\",\"type\":\"001\"}},\"orderInformation\":{\"amountDetails\":{\"totalAmount\":\"102.21\",\"currency\":\"USD\"},\"billTo\":{\"firstName\":\"John\",\"lastName\":\"Doe\",\"address1\":\"1 Market St\",\"locality\":\"san francisco\",\"administrativeArea\":\"CA\",\"postalCode\":\"94105\",\"country\":\"US\",\"email\":\"test@cybs.com\",\"phoneNumber\":\"4158880000\"},\"shipTo\":{\"firstName\":\"Longbob\",\"lastName\":\"Longsen\",\"email\":\"test@cybs.com\"}}}"
-> "HTTP/1.1 201 Created\r\n"
-> "Cache-Control: no-cache, no-store, must-revalidate\r\n"
-> "Pragma: no-cache\r\n"
-> "Expires: -1\r\n"
-> "Strict-Transport-Security: max-age=31536000\r\n"
-> "Content-Type: application/hal+json\r\n"
-> "Content-Length: 905\r\n"
-> "x-response-time: 291ms\r\n"
-> "X-OPNET-Transaction-Trace: 0b1f2bd7-9545-4939-9478-4b76cf7199b6\r\n"
-> "Connection: close\r\n"
-> "v-c-correlation-id: 42969bf5-a77d-4035-9d09-58d4ca070e8c\r\n"
-> "\r\n"
reading 905 bytes...
-> "{\"_links\":{\"authReversal\":{\"method\":\"POST\",\"href\":\"/pts/v2/payments/6750124114786780104953/reversals\"},\"self\":{\"method\":\"GET\",\"href\":\"/pts/v2/payments/6750124114786780104953\"},\"capture\":{\"method\":\"POST\",\"href\":\"/pts/v2/payments/6750124114786780104953/captures\"}},\"clientReferenceInformation\":{\"code\":\"b8779865d140125036016a0f85db907f\"},\"id\":\"6750124114786780104953\",\"orderInformation\":{\"amountDetails\":{\"authorizedAmount\":\"102.21\",\"currency\":\"USD\"}},\"paymentAccountInformation\":{\"card\":{\"type\":\"001\"}},\"paymentInformation\":{\"tokenizedCard\":{\"type\":\"001\"},\"card\":{\"type\":\"001\"}},\"pointOfSaleInformation\":{\"terminalId\":\"111111\"},\"processorInformation\":{\"approvalCode\":\"888888\",\"networkTransactionId\":\"123456789619999\",\"transactionId\":\"123456789619999\",\"responseCode\":\"100\",\"avs\":{\"code\":\"X\",\"codeRaw\":\"I1\"}},\"reconciliationId\":\"78243988SD9YL291\",\"status\":\"AUTHORIZED\",\"submitTimeUtc\":\"2023-01-29T17:13:31Z\"}"
PRE
end
def post_scrubbed
<<-POST
<- "POST /pts/v2/payments/ HTTP/1.1\r\nContent-Type: application/json;charset=utf-8\r\nAccept: application/hal+json;charset=utf-8\r\nV-C-Merchant-Id: testrest\r\nDate: Sun, 29 Jan 2023 17:13:30 GMT\r\nHost: apitest.cybersource.com\r\nSignature: keyid=\"[FILTERED]\", algorithm=\"HmacSHA256\", headers=\"host date (request-target) digest v-c-merchant-id\", signature=\"[FILTERED]\"\r\nDigest: SHA-256=[FILTERED]\r\nConnection: close\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nUser-Agent: Ruby\r\nContent-Length: 584\r\n\r\n"
<- "{\"clientReferenceInformation\":{\"code\":\"b8779865d140125036016a0f85db907f\"},\"paymentInformation\":{\"card\":{\"number\":\"[FILTERED]\",\"expirationMonth\":\"12\",\"expirationYear\":\"2031\",\"securityCode\":\"[FILTERED]\",\"type\":\"001\"}},\"orderInformation\":{\"amountDetails\":{\"totalAmount\":\"102.21\",\"currency\":\"USD\"},\"billTo\":{\"firstName\":\"John\",\"lastName\":\"Doe\",\"address1\":\"1 Market St\",\"locality\":\"san francisco\",\"administrativeArea\":\"CA\",\"postalCode\":\"94105\",\"country\":\"US\",\"email\":\"test@cybs.com\",\"phoneNumber\":\"4158880000\"},\"shipTo\":{\"firstName\":\"Longbob\",\"lastName\":\"Longsen\",\"email\":\"test@cybs.com\"}}}"
-> "HTTP/1.1 201 Created\r\n"
-> "Cache-Control: no-cache, no-store, must-revalidate\r\n"
-> "Pragma: no-cache\r\n"
-> "Expires: -1\r\n"
-> "Strict-Transport-Security: max-age=31536000\r\n"
-> "Content-Type: application/hal+json\r\n"
-> "Content-Length: 905\r\n"
-> "x-response-time: 291ms\r\n"
-> "X-OPNET-Transaction-Trace: 0b1f2bd7-9545-4939-9478-4b76cf7199b6\r\n"
-> "Connection: close\r\n"
-> "v-c-correlation-id: 42969bf5-a77d-4035-9d09-58d4ca070e8c\r\n"
-> "\r\n"
reading 905 bytes...
-> "{\"_links\":{\"authReversal\":{\"method\":\"POST\",\"href\":\"/pts/v2/payments/6750124114786780104953/reversals\"},\"self\":{\"method\":\"GET\",\"href\":\"/pts/v2/payments/6750124114786780104953\"},\"capture\":{\"method\":\"POST\",\"href\":\"/pts/v2/payments/6750124114786780104953/captures\"}},\"clientReferenceInformation\":{\"code\":\"b8779865d140125036016a0f85db907f\"},\"id\":\"6750124114786780104953\",\"orderInformation\":{\"amountDetails\":{\"authorizedAmount\":\"102.21\",\"currency\":\"USD\"}},\"paymentAccountInformation\":{\"card\":{\"type\":\"001\"}},\"paymentInformation\":{\"tokenizedCard\":{\"type\":\"001\"},\"card\":{\"type\":\"001\"}},\"pointOfSaleInformation\":{\"terminalId\":\"111111\"},\"processorInformation\":{\"approvalCode\":\"888888\",\"networkTransactionId\":\"123456789619999\",\"transactionId\":\"123456789619999\",\"responseCode\":\"100\",\"avs\":{\"code\":\"X\",\"codeRaw\":\"I1\"}},\"reconciliationId\":\"78243988SD9YL291\",\"status\":\"AUTHORIZED\",\"submitTimeUtc\":\"2023-01-29T17:13:31Z\"}"
POST
end
def pre_scrubbed_nt
<<-PRE
<- "POST /pts/v2/payments/ HTTP/1.1\r\nContent-Type: application/json;charset=utf-8\r\nAccept: application/hal+json;charset=utf-8\r\nV-C-Merchant-Id: testrest\r\nDate: Sun, 29 Jan 2023 17:13:30 GMT\r\nHost: apitest.cybersource.com\r\nSignature: keyid=\"08c94330-f618-42a3-b09d-e1e43be5efda\", algorithm=\"HmacSHA256\", headers=\"host date (request-target) digest v-c-merchant-id\", signature=\"DJHeHWceVrsJydd8BCbGowr9dzQ/ry5cGN1FocLakEw=\"\r\nDigest: SHA-256=wuV1cxGzs6KpuUKJmlD7pKV6MZ/5G1wQVoYbf8cRChM=\r\nConnection: close\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nUser-Agent: Ruby\r\nContent-Length: 584\r\n\r\n"
<- "{\"clientReferenceInformation\":{\"code\":\"ba20ae354e25edd1a5ab27158c0a2955\"},\"paymentInformation\":{\"tokenizedCard\":{\"number\":\"4111111111111111\",\"expirationMonth\":9,\"expirationYear\":2025,\"cryptogram\":\"EHuWW9PiBkWvqE5juRwDzAUFBAk=\",\"type\":\"001\",\"transactionType\":\"3\"}},\"orderInformation\":{\"amountDetails\":{\"totalAmount\":\"102.21\",\"currency\":\"USD\"},\"billTo\":{\"firstName\":\"John\",\"lastName\":\"Doe\",\"address1\":\"1 Market St\",\"locality\":\"san francisco\",\"administrativeArea\":\"CA\",\"postalCode\":\"94105\",\"country\":\"US\",\"email\":\"test@cybs.com\",\"phoneNumber\":\"4158880000\"}},\"processingInformation\":{\"commerceIndicator\":\"internet\",\"paymentSolution\":\"015\",\"authorizationOptions\":{}}}"
-> "HTTP/1.1 201 Created\r\n"
-> "Cache-Control: no-cache, no-store, must-revalidate\r\n"
-> "Pragma: no-cache\r\n"
-> "Expires: -1\r\n"
-> "Strict-Transport-Security: max-age=31536000\r\n"
-> "Content-Type: application/hal+json\r\n"
-> "Content-Length: 905\r\n"
-> "x-response-time: 291ms\r\n"
-> "X-OPNET-Transaction-Trace: 0b1f2bd7-9545-4939-9478-4b76cf7199b6\r\n"
-> "Connection: close\r\n"
-> "v-c-correlation-id: 42969bf5-a77d-4035-9d09-58d4ca070e8c\r\n"
-> "\r\n"
reading 905 bytes...
-> "{\"_links\":{\"authReversal\":{\"method\":\"POST\",\"href\":\"/pts/v2/payments/7145981349676498704951/reversals\"},\"self\":{\"method\":\"GET\",\"href\":\"/pts/v2/payments/7145981349676498704951\"},\"capture\":{\"method\":\"POST\",\"href\":\"/pts/v2/payments/7145981349676498704951/captures\"}},\"clientReferenceInformation\":{\"code\":\"ba20ae354e25edd1a5ab27158c0a2955\"},\"id\":\"7145981349676498704951\",\"issuerInformation\":{\"responseRaw\":\"0110322000000E10000200000000000001022105012115353420253130383141564D334B5953323833313030303030000159008000223134573031363135303730333830323039344730363400103232415050524F56414C00065649435243200034544B54523031313132313231323132313231544C3030323636504E30303431313131\"},\"orderInformation\":{\"amountDetails\":{\"authorizedAmount\":\"102.21\",\"currency\":\"USD\"}},\"paymentAccountInformation\":{\"card\":{\"type\":\"001\"}},\"paymentInformation\":{\"tokenizedCard\":{\"requestorId\":\"12121212121\",\"assuranceLevel\":\"66\",\"type\":\"001\"},\"card\":{\"suffix\":\"1111\",\"type\":\"001\"}},\"pointOfSaleInformation\":{\"terminalId\":\"01234567\"},\"processorInformation\":{\"merchantNumber\":\"000123456789012\",\"approvalCode\":\"831000\",\"networkTransactionId\":\"016150703802094\",\"transactionId\":\"016150703802094\",\"responseCode\":\"00\",\"avs\":{\"code\":\"Y\",\"codeRaw\":\"Y\"}},\"reconciliationId\":\"1081AVM3KYS2\",\"status\":\"AUTHORIZED\",\"submitTimeUtc\":\"2024-05-01T21:15:35Z\"}"
PRE
end
def post_scrubbed_nt
<<-POST
<- "POST /pts/v2/payments/ HTTP/1.1\r\nContent-Type: application/json;charset=utf-8\r\nAccept: application/hal+json;charset=utf-8\r\nV-C-Merchant-Id: testrest\r\nDate: Sun, 29 Jan 2023 17:13:30 GMT\r\nHost: apitest.cybersource.com\r\nSignature: keyid=\"[FILTERED]\", algorithm=\"HmacSHA256\", headers=\"host date (request-target) digest v-c-merchant-id\", signature=\"[FILTERED]\"\r\nDigest: SHA-256=[FILTERED]\r\nConnection: close\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nUser-Agent: Ruby\r\nContent-Length: 584\r\n\r\n"
<- "{\"clientReferenceInformation\":{\"code\":\"ba20ae354e25edd1a5ab27158c0a2955\"},\"paymentInformation\":{\"tokenizedCard\":{\"number\":\"[FILTERED]\",\"expirationMonth\":9,\"expirationYear\":2025,\"cryptogram\":\"[FILTERED]\",\"type\":\"001\",\"transactionType\":\"3\"}},\"orderInformation\":{\"amountDetails\":{\"totalAmount\":\"102.21\",\"currency\":\"USD\"},\"billTo\":{\"firstName\":\"John\",\"lastName\":\"Doe\",\"address1\":\"1 Market St\",\"locality\":\"san francisco\",\"administrativeArea\":\"CA\",\"postalCode\":\"94105\",\"country\":\"US\",\"email\":\"test@cybs.com\",\"phoneNumber\":\"4158880000\"}},\"processingInformation\":{\"commerceIndicator\":\"internet\",\"paymentSolution\":\"015\",\"authorizationOptions\":{}}}"
-> "HTTP/1.1 201 Created\r\n"
-> "Cache-Control: no-cache, no-store, must-revalidate\r\n"
-> "Pragma: no-cache\r\n"
-> "Expires: -1\r\n"
-> "Strict-Transport-Security: max-age=31536000\r\n"
-> "Content-Type: application/hal+json\r\n"
-> "Content-Length: 905\r\n"
-> "x-response-time: 291ms\r\n"
-> "X-OPNET-Transaction-Trace: 0b1f2bd7-9545-4939-9478-4b76cf7199b6\r\n"
-> "Connection: close\r\n"
-> "v-c-correlation-id: 42969bf5-a77d-4035-9d09-58d4ca070e8c\r\n"
-> "\r\n"
reading 905 bytes...
-> "{\"_links\":{\"authReversal\":{\"method\":\"POST\",\"href\":\"/pts/v2/payments/7145981349676498704951/reversals\"},\"self\":{\"method\":\"GET\",\"href\":\"/pts/v2/payments/7145981349676498704951\"},\"capture\":{\"method\":\"POST\",\"href\":\"/pts/v2/payments/7145981349676498704951/captures\"}},\"clientReferenceInformation\":{\"code\":\"ba20ae354e25edd1a5ab27158c0a2955\"},\"id\":\"7145981349676498704951\",\"issuerInformation\":{\"responseRaw\":\"0110322000000E10000200000000000001022105012115353420253130383141564D334B5953323833313030303030000159008000223134573031363135303730333830323039344730363400103232415050524F56414C00065649435243200034544B54523031313132313231323132313231544C3030323636504E30303431313131\"},\"orderInformation\":{\"amountDetails\":{\"authorizedAmount\":\"102.21\",\"currency\":\"USD\"}},\"paymentAccountInformation\":{\"card\":{\"type\":\"001\"}},\"paymentInformation\":{\"tokenizedCard\":{\"requestorId\":\"12121212121\",\"assuranceLevel\":\"66\",\"type\":\"001\"},\"card\":{\"suffix\":\"1111\",\"type\":\"001\"}},\"pointOfSaleInformation\":{\"terminalId\":\"01234567\"},\"processorInformation\":{\"merchantNumber\":\"000123456789012\",\"approvalCode\":\"831000\",\"networkTransactionId\":\"016150703802094\",\"transactionId\":\"016150703802094\",\"responseCode\":\"00\",\"avs\":{\"code\":\"Y\",\"codeRaw\":\"Y\"}},\"reconciliationId\":\"1081AVM3KYS2\",\"status\":\"AUTHORIZED\",\"submitTimeUtc\":\"2024-05-01T21:15:35Z\"}"
POST
end
def successful_purchase_response
<<-RESPONSE
{
"_links": {
"authReversal": {
"method": "POST",
"href": "/pts/v2/payments/6750124114786780104953/reversals"
},
"self": {
"method": "GET",
"href": "/pts/v2/payments/6750124114786780104953"
},
"capture": {
"method": "POST",
"href": "/pts/v2/payments/6750124114786780104953/captures"
}
},
"clientReferenceInformation": {
"code": "b8779865d140125036016a0f85db907f"
},
"id": "6750124114786780104953",
"orderInformation": {
"amountDetails": {
"authorizedAmount": "102.21",
"currency": "USD"
}
},
"paymentAccountInformation": {
"card": {
"type": "001"
}
},
"paymentInformation": {
"tokenizedCard": {
"type": "001"
},
"card": {
"type": "001"
}
},
"pointOfSaleInformation": {
"terminalId": "111111"
},
"processorInformation": {
"approvalCode": "888888",
"networkTransactiDDDonId": "123456789619999",
"transactionId": "123456789619999",
"responseCode": "100",
"avs": {
"code": "X",
"codeRaw": "I1"
}
},
"reconciliationId": "78243988SD9YL291",
"status": "AUTHORIZED",
"submitTimeUtc": "2023-01-29T17:13:31Z"
}
RESPONSE
end
def successful_capture_response
<<-RESPONSE
{
"_links": {
"void": {
"method": "POST",
"href": "/pts/v2/captures/6799471903876585704951/voids"
},
"self": {
"method": "GET",
"href": "/pts/v2/captures/6799471903876585704951"
}
},
"clientReferenceInformation": {
"code": "TC50171_3"
},
"id": "6799471903876585704951",
"orderInformation": {
"amountDetails": {
"totalAmount": "102.21",
"currency": "USD"
}
},
"reconciliationId": "78243988SD9YL291",
"status": "PENDING",
"submitTimeUtc": "2023-03-27T19:59:50Z"
}
RESPONSE
end
def successful_credit_response
<<-RESPONSE
{
"_links": {
"void": {
"method": "POST",
"href": "/pts/v2/credits/6799499091686234304951/voids"
},
"self": {
"method": "GET",
"href": "/pts/v2/credits/6799499091686234304951"
}
},
"clientReferenceInformation": {
"code": "12345678"
},
"creditAmountDetails": {
"currency": "usd",
"creditAmount": "200.00"
},
"id": "6799499091686234304951",
"orderInformation": {
"amountDetails": {
"currency": "usd"
}
},
"paymentAccountInformation": {
"card": {
"type": "001"
}
},
"paymentInformation": {
"tokenizedCard": {
"type": "001"
},
"card": {
"type": "001"
}
},
"processorInformation": {
"approvalCode": "888888",
"responseCode": "100"
},
"reconciliationId": "70391830ZFKZI570",
"status": "PENDING",
"submitTimeUtc": "2023-03-27T20:45:09Z"
}
RESPONSE
end
end