-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1176 lines (1091 loc) · 48.8 KB
/
Copy pathindex.html
File metadata and controls
1176 lines (1091 loc) · 48.8 KB
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
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Global Payments — GP-API 3DS2 Sandbox Tester</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://globalpayments-samples.github.io/css/styles.css">
<style>
/* 3DS2-specific additions — no overrides to base design */
.step-panel { display: none; }
.step-panel.active { display: block; }
.flow-steps {
display: flex;
gap: 4px;
margin-bottom: 24px;
flex-wrap: wrap;
}
.flow-step {
flex: 1;
min-width: 80px;
padding: 8px 6px;
border-radius: 6px;
background: #f5f5f5;
text-align: center;
font-size: 12px;
font-weight: 600;
color: #888;
border: 2px solid transparent;
}
.flow-step.active { background: #e8f4fd; border-color: #2196F3; color: #1565c0; }
.flow-step.done { background: #e8f5e9; border-color: #4CAF50; color: #2e7d32; }
.flow-step.error { background: #fdecea; border-color: #f44336; color: #b71c1c; }
.test-cards-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: 8px;
margin-bottom: 16px;
}
.test-card-btn {
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 10px 12px;
cursor: pointer;
text-align: left;
font-family: inherit;
transition: background 0.15s, border-color 0.15s;
}
.test-card-btn:hover { background: #e9f5fb; border-color: #90caf9; }
.test-card-btn .card-num { font-size: 13px; font-weight: 700; letter-spacing: 1px; font-family: monospace; }
.test-card-btn .card-label { font-size: 11px; color: #666; margin-top: 2px; }
.test-card-btn .card-badge {
display: inline-block;
font-size: 10px;
font-weight: 700;
padding: 2px 6px;
border-radius: 4px;
margin-top: 4px;
}
.badge-success { background: #c8e6c9; color: #1b5e20; }
.badge-challenge { background: #fff9c4; color: #f57f17; }
.badge-fail { background: #ffcdd2; color: #b71c1c; }
.badge-unavail { background: #f3e5f5; color: #6a1b9a; }
.raw-toggle {
background: none;
border: 1px solid #dee2e6;
border-radius: 6px;
padding: 4px 10px;
cursor: pointer;
font-size: 12px;
color: #666;
margin-top: 8px;
}
.raw-toggle:hover { background: #f5f5f5; }
.raw-response {
display: none;
background: #1e1e1e;
color: #d4d4d4;
border-radius: 8px;
padding: 16px;
font-family: 'Courier New', monospace;
font-size: 12px;
overflow-x: auto;
white-space: pre;
margin-top: 8px;
max-height: 300px;
overflow-y: auto;
}
.raw-response.visible { display: block; }
.acs-modal {
display: none;
position: fixed;
inset: 0;
background: rgba(0,0,0,0.6);
z-index: 9999;
align-items: center;
justify-content: center;
}
.acs-modal.open { display: flex; }
.acs-modal-inner {
background: white;
border-radius: 12px;
padding: 24px;
width: 90vw;
max-width: 520px;
max-height: 90vh;
display: flex;
flex-direction: column;
gap: 12px;
}
.acs-modal-inner iframe {
width: 100%;
height: 500px;
border: 1px solid #dee2e6;
border-radius: 6px;
}
.step-result {
padding: 12px 16px;
border-radius: 8px;
margin-top: 12px;
font-size: 13px;
}
.step-result.ok { background: #e8f5e9; border-left: 4px solid #4CAF50; }
.step-result.warn { background: #fff9c4; border-left: 4px solid #FFC107; }
.step-result.err { background: #fdecea; border-left: 4px solid #f44336; }
.step-result dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 6px 0 0; }
.step-result dt { font-weight: 600; white-space: nowrap; }
.step-result dd { margin: 0; word-break: break-all; font-family: monospace; font-size: 12px; }
.mode-switch {
display: flex;
gap: 8px;
flex-wrap: wrap;
margin-bottom: 16px;
}
.mode-switch label {
flex: 1;
min-width: 180px;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 10px 12px;
cursor: pointer;
background: #fff;
font-size: 13px;
}
.mode-switch input { margin-right: 8px; }
.mode-switch label:has(input:checked) { border-color: #2196F3; background: #e8f4fd; }
.selected-card {
display: none;
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 10px 12px;
margin-bottom: 16px;
font-size: 13px;
}
.selected-card-grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 8px;
}
.selected-card-item {
display: flex;
min-width: 0;
align-items: center;
justify-content: space-between;
gap: 8px;
border: 1px solid #dee2e6;
border-radius: 6px;
background: #fff;
padding: 8px 10px;
}
.selected-card-value {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-family: monospace;
}
.copy-card-value {
flex: 0 0 auto;
border: 1px solid #ced4da;
border-radius: 5px;
background: #f8f9fa;
color: #343a40;
cursor: pointer;
font: inherit;
font-size: 12px;
padding: 3px 7px;
}
.copy-card-value:hover {
background: #e9f5fb;
border-color: #90caf9;
}
.hosted-field {
min-height: 56px;
border: 1px solid #ced4da;
border-radius: 6px;
background: #fff;
padding: 0 12px;
box-sizing: border-box;
overflow: hidden;
position: relative;
width: 100%;
}
.hosted-field:focus-within {
border-color: #0072ce;
box-shadow: 0 0 0 3px rgba(0, 114, 206, 0.12);
}
.hosted-field iframe {
border: 0 !important;
display: block !important;
height: 54px !important;
max-width: 100% !important;
min-width: 0 !important;
width: 100% !important;
}
#hosted-card-fields .gp-form-row {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(96px, 140px);
gap: 12px;
}
#hosted-card-fields .gp-form-row:has(#hosted-card-expiration) {
grid-template-columns: minmax(120px, 0.8fr) minmax(0, 1.2fr);
}
#hosted-card-fields .gp-form-group {
min-width: 0;
}
.hosted-actions { margin-top: 8px; }
.hosted-actions iframe {
max-width: 100% !important;
width: 100% !important;
}
.diagnostic-note {
background: #fff9c4;
border-left: 4px solid #FFC107;
border-radius: 8px;
padding: 10px 12px;
margin-bottom: 16px;
font-size: 13px;
}
.diagnostic-only.hidden {
display: none !important;
}
.main-layout {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
gap: 24px;
align-items: start;
}
@media (max-width: 900px) {
.main-layout {
grid-template-columns: minmax(0, 1fr);
}
}
@media (max-width: 520px) {
#hosted-card-fields .gp-form-row,
#hosted-card-fields .gp-form-row:has(#hosted-card-expiration) {
grid-template-columns: minmax(0, 1fr);
}
#hosted-card-fields .gp-form-group[style] {
max-width: none !important;
}
.mode-switch label {
min-width: 0;
}
.selected-card-grid {
grid-template-columns: minmax(0, 1fr);
}
}
.hidden { display: none !important; }
</style>
<script src="https://js.globalpay.com/4.1.12/globalpayments.js"></script>
<script src="https://cdn.jsdelivr.net/npm/globalpayments-3ds@1.8.7/dist/globalpayments-3ds.min.js"></script>
</head>
<body>
<!-- Header -->
<header class="gp-header">
<div class="gp-container">
<div class="gp-header-content">
<div class="gp-logo">
<picture>
<source media="(min-width: 768px)" srcset="https://globalpayments-samples.github.io/assets/img/GP_logo.svg">
<img src="https://globalpayments-samples.github.io/assets/img/GP_favicon.svg" alt="Global Payments" style="height: 32px; width: auto;">
</picture>
</div>
<nav class="gp-header-nav">
<a href="https://developer.globalpay.com/">Documentation</a>
<a href="https://developer.globalpayments.com/api/references-overview">API Reference</a>
<a href="https://developer.globalpayments.com/docs/integration-options/sdk/overview">SDKs</a>
</nav>
</div>
</div>
</header>
<div class="gp-container">
<!-- Page Title -->
<h1 class="gp-page-title">GP-API 3DS2 Sandbox Tester</h1>
<p class="gp-page-subtitle">Full 3DS2 browser flow: enrollment check → authentication → challenge → payment authorisation.</p>
<!-- Backend Selector -->
<div class="gp-card" style="margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 16px; flex-wrap: wrap;">
<label for="backend-selector" class="gp-label" style="margin: 0; white-space: nowrap;">Backend:</label>
<select id="backend-selector" class="gp-select" style="width: auto; min-width: 200px;">
<option value="http://localhost:3001">Node.js (port 3001)</option>
<option value="http://localhost:8003">PHP (port 8003)</option>
<option value="http://localhost:8006">.NET (port 8006)</option>
<option value="http://localhost:8004">Java (port 8004)</option>
</select>
<span id="health-status" style="font-size: 13px; color: #888;">checking…</span>
</div>
</div>
<div class="main-layout">
<!-- LEFT COLUMN: Form -->
<div>
<!-- Test Cards -->
<div class="gp-card" style="margin-bottom: 16px;">
<div class="gp-card-header">
<h2 class="gp-card-title">Test Cards</h2>
<p class="gp-card-description">Click to select a sandbox card. Hosted Fields mode copies the card number and shows the rest for manual entry; diagnostic mode fills the raw inputs.</p>
</div>
<div class="test-cards-grid">
<button class="test-card-btn" onclick="fillCard('4263970000005262','12','2026','Frictionless Visa')">
<div class="card-num">4263 9700 0000 5262</div>
<div class="card-label">Visa</div>
<span class="card-badge badge-success">Frictionless</span>
</button>
<button class="test-card-btn" onclick="fillCard('5425230000004415','12','2026','Frictionless MC')">
<div class="card-num">5425 2300 0000 4415</div>
<div class="card-label">Mastercard</div>
<span class="card-badge badge-success">Frictionless</span>
</button>
<button class="test-card-btn" onclick="fillCard('4012001037141112','12','2026','Challenge Visa')">
<div class="card-num">4012 0010 3714 1112</div>
<div class="card-label">Visa</div>
<span class="card-badge badge-challenge">Challenge</span>
</button>
<button class="test-card-btn" onclick="fillCard('5114610000004778','12','2026','Challenge MC')">
<div class="card-num">5114 6100 0000 4778</div>
<div class="card-label">Mastercard</div>
<span class="card-badge badge-challenge">Challenge</span>
</button>
<button class="test-card-btn" onclick="fillCard('4012001036853337','12','2026','Auth Failed')">
<div class="card-num">4012 0010 3685 3337</div>
<div class="card-label">Visa</div>
<span class="card-badge badge-fail">Auth Failed</span>
</button>
<button class="test-card-btn" onclick="fillCard('4012001036273338','12','2026','Unavailable')">
<div class="card-num">4012 0010 3627 3338</div>
<div class="card-label">Visa</div>
<span class="card-badge badge-unavail">Unavailable</span>
</button>
</div>
</div>
<!-- Payment Form -->
<div class="gp-card">
<div class="gp-card-header">
<h2 class="gp-card-title">Card Details</h2>
</div>
<form id="payment-form" class="gp-form" onsubmit="runFlow(event)">
<div class="mode-switch">
<label>
<input type="radio" name="integration_mode" value="hosted" checked onchange="setIntegrationMode('hosted')">
Hosted Fields
</label>
<label>
<input type="radio" name="integration_mode" value="diagnostic" onchange="setIntegrationMode('diagnostic')">
Diagnostic raw-card API
</label>
</div>
<div id="selected-card" class="selected-card"></div>
<div id="hosted-card-fields">
<div class="gp-form-row">
<div class="gp-form-group">
<label class="gp-label">Card Number</label>
<div id="hosted-card-number" class="hosted-field"></div>
</div>
<div class="gp-form-group" style="max-width: 140px;">
<label class="gp-label">CVV</label>
<div id="hosted-card-cvv" class="hosted-field"></div>
</div>
</div>
<div class="gp-form-row">
<div class="gp-form-group">
<label class="gp-label">Expiry</label>
<div id="hosted-card-expiration" class="hosted-field"></div>
</div>
<div class="gp-form-group">
<label class="gp-label">Cardholder Name</label>
<div id="hosted-card-holder-name" class="hosted-field"></div>
</div>
</div>
<div id="hosted-status" style="font-size: 13px; color: #888; margin-bottom: 8px;">Hosted Fields initializing...</div>
</div>
<div id="diagnostic-card-fields" class="hidden">
<div class="diagnostic-note">Diagnostic mode sends sandbox card data directly to the backend API. Use Hosted Fields for the customer-facing path.</div>
<div class="gp-form-row">
<div class="gp-form-group">
<label for="card_number" class="gp-label">Card Number</label>
<input type="text" id="card_number" name="card_number" class="gp-input"
placeholder="4263970000005262" maxlength="19"
style="font-family: monospace;" autocomplete="cc-number">
</div>
<div class="gp-form-group" style="max-width: 100px;">
<label for="cvn" class="gp-label">CVV</label>
<input type="text" id="cvn" name="cvn" class="gp-input"
placeholder="123" maxlength="4" autocomplete="cc-csc">
</div>
</div>
<div class="gp-form-row">
<div class="gp-form-group">
<label for="exp_month" class="gp-label">Expiry Month</label>
<input type="text" id="exp_month" name="exp_month" class="gp-input"
placeholder="12" maxlength="2" autocomplete="cc-exp-month">
</div>
<div class="gp-form-group">
<label for="exp_year" class="gp-label">Expiry Year</label>
<input type="text" id="exp_year" name="exp_year" class="gp-input"
placeholder="2026" maxlength="4" autocomplete="cc-exp-year">
</div>
</div>
</div>
<div id="diagnostic-cardholder" class="gp-form-group diagnostic-only hidden">
<label for="cardholder_name" class="gp-label">Cardholder Name</label>
<input type="text" id="cardholder_name" name="cardholder_name" class="gp-input"
value="John Doe" required autocomplete="cc-name">
</div>
<div class="gp-form-row">
<div class="gp-form-group">
<label for="amount" class="gp-label">Amount (£)</label>
<input type="number" id="amount" name="amount" class="gp-input"
value="10.00" min="0.01" step="0.01" required>
</div>
<div class="gp-form-group">
<label for="currency" class="gp-label">Currency</label>
<select id="currency" name="currency" class="gp-select">
<option value="GBP">GBP</option>
<option value="EUR">EUR</option>
<option value="USD">USD</option>
</select>
</div>
</div>
<div id="hosted-submit" class="hosted-actions"></div>
<button type="submit" id="submit-btn" class="gp-button gp-button-primary gp-button-full hidden">
Run 3DS2 Flow
</button>
<button type="button" class="gp-button gp-button-full" style="margin-top: 8px;"
onclick="resetFlow()">Reset</button>
</form>
</div>
</div>
<!-- RIGHT COLUMN: Flow Status -->
<div>
<div class="gp-card">
<div class="gp-card-header">
<h2 class="gp-card-title">3DS2 Flow</h2>
</div>
<!-- Step indicators -->
<div class="flow-steps">
<div class="flow-step" id="step-ind-1">1. Enroll</div>
<div class="flow-step" id="step-ind-2">2. Method</div>
<div class="flow-step" id="step-ind-3">3. Auth</div>
<div class="flow-step" id="step-ind-4">4. Challenge</div>
<div class="flow-step" id="step-ind-5">5. Result</div>
<div class="flow-step" id="step-ind-6">6. Payment</div>
</div>
<!-- Step 1: Enrollment -->
<div id="panel-1">
<strong style="font-size: 14px;">Step 1 — Enrollment Check</strong>
<div id="result-1"></div>
<button class="raw-toggle" onclick="toggleRaw('raw-1')">Show raw</button>
<div class="raw-response" id="raw-1"></div>
</div>
<hr style="margin: 16px 0; border: none; border-top: 1px solid #eee;">
<!-- Step 2: Method URL -->
<div id="panel-2">
<strong style="font-size: 14px;">Step 2 — Device Fingerprint</strong>
<div id="result-2"></div>
</div>
<hr style="margin: 16px 0; border: none; border-top: 1px solid #eee;">
<!-- Step 3: Initiate Auth -->
<div id="panel-3">
<strong style="font-size: 14px;">Step 3 — Initiate Authentication</strong>
<div id="result-3"></div>
<button class="raw-toggle" onclick="toggleRaw('raw-3')">Show raw</button>
<div class="raw-response" id="raw-3"></div>
</div>
<hr style="margin: 16px 0; border: none; border-top: 1px solid #eee;">
<!-- Step 4: Challenge -->
<div id="panel-4">
<strong style="font-size: 14px;">Step 4 — ACS Challenge</strong>
<div id="result-4"></div>
</div>
<hr style="margin: 16px 0; border: none; border-top: 1px solid #eee;">
<!-- Step 5: Auth Result -->
<div id="panel-5">
<strong style="font-size: 14px;">Step 5 — Authentication Result</strong>
<div id="result-5"></div>
<button class="raw-toggle" onclick="toggleRaw('raw-5')">Show raw</button>
<div class="raw-response" id="raw-5"></div>
</div>
<hr style="margin: 16px 0; border: none; border-top: 1px solid #eee;">
<!-- Step 6: Payment -->
<div id="panel-6">
<strong style="font-size: 14px;">Step 6 — Payment Authorisation</strong>
<div id="result-6"></div>
<button class="raw-toggle" onclick="toggleRaw('raw-6')">Show raw</button>
<div class="raw-response" id="raw-6"></div>
</div>
</div>
</div>
</div>
</div>
<!-- ACS Challenge Modal -->
<div id="acs-modal" class="acs-modal">
<div class="acs-modal-inner">
<div style="display: flex; justify-content: space-between; align-items: center;">
<strong>ACS Challenge</strong>
<button class="raw-toggle" onclick="closeAcsModal()">✕ Close</button>
</div>
<iframe id="acs-iframe" name="acs-iframe" title="ACS Challenge" allowfullscreen></iframe>
<p style="font-size: 12px; color: #888; margin: 0;">
Complete the issuer challenge above. The modal will close automatically once done.
</p>
</div>
</div>
<!-- Hidden method URL iframe (device fingerprinting) -->
<iframe id="method-iframe" name="method-iframe" style="display:none;" title="3DS Method URL"></iframe>
<form id="method-form" target="method-iframe" method="POST" style="display:none;">
<input type="hidden" id="method-data-input" name="threeDSMethodData">
</form>
<!-- Footer -->
<footer class="gp-footer">
<div class="gp-container">
<div class="gp-footer-content">
<div class="gp-footer-section">
<p class="gp-footer-copyright">
© 2024-<span id="footer-year">2026</span> Global Payments. All rights reserved.
</p>
</div>
<div class="gp-footer-section">
<nav class="gp-footer-nav">
<a href="https://developer.globalpay.com/" class="gp-footer-link">Developer Portal</a>
<a href="https://developer.globalpayments.com/api/references-overview" class="gp-footer-link">API Reference</a>
</nav>
</div>
</div>
</div>
</footer>
<script>
// ─── State ────────────────────────────────────────────────────────────────────
const state = {
serverTransId: null,
messageVersion: null,
authData: null,
selectedCard: null,
hostedForm: null,
hostedReady: false,
integrationMode: 'hosted',
};
document.getElementById('footer-year').textContent = new Date().getFullYear();
// ─── Backend URL ─────────────────────────────────────────────────────────────
function backendUrl() {
return document.getElementById('backend-selector').value;
}
// ─── Health check ─────────────────────────────────────────────────────────────
async function checkHealth() {
const el = document.getElementById('health-status');
el.textContent = 'checking…';
el.style.color = '#888';
try {
const r = await fetch(`${backendUrl()}/api/health`);
const d = await r.json();
el.textContent = `✓ ${d.backend || 'backend'} online`;
el.style.color = '#2e7d32';
await initHostedFields();
} catch {
el.textContent = '✗ backend unreachable';
el.style.color = '#b71c1c';
}
}
document.getElementById('backend-selector').addEventListener('change', checkHealth);
checkHealth();
// ─── Test card fill ───────────────────────────────────────────────────────────
async function copyText(value, label) {
try {
await navigator.clipboard.writeText(value);
const selected = document.getElementById('selected-card');
selected.dataset.copyStatus = `${label} copied`;
} catch {
const selected = document.getElementById('selected-card');
selected.dataset.copyStatus = `Select and copy ${label.toLowerCase()}`;
}
renderSelectedCard();
}
function renderSelectedCard() {
const selected = document.getElementById('selected-card');
const card = state.selectedCard;
if (!card) {
selected.style.display = 'none';
selected.innerHTML = '';
return;
}
const status = selected.dataset.copyStatus || 'Card selected';
selected.style.display = 'block';
selected.innerHTML = `
<div style="margin-bottom: 8px; color: #495057;">${card.name} · ${status}</div>
<div class="selected-card-grid">
${selectedCardItem('Number', card.num)}
${selectedCardItem('Expiry', `${card.month}/${card.year}`)}
${selectedCardItem('CVV', card.cvn)}
${selectedCardItem('Name', card.name)}
</div>`;
}
function selectedCardItem(label, value) {
return `
<div class="selected-card-item">
<span class="selected-card-value" title="${value}">${value}</span>
<button type="button" class="copy-card-value" onclick="copyText('${value}', '${label}')">Copy</button>
</div>`;
}
function fillCard(num, month, year, name) {
state.selectedCard = { num, month, year, name, cvn: '123' };
const selected = document.getElementById('selected-card');
selected.dataset.copyStatus = state.integrationMode === 'hosted' ? 'Card number copied' : 'Diagnostic fields filled';
renderSelectedCard();
if (state.integrationMode === 'hosted') {
copyText(num, 'Card number');
}
document.getElementById('card_number').value = num;
document.getElementById('exp_month').value = month;
document.getElementById('exp_year').value = year;
document.getElementById('cvn').value = '123';
document.getElementById('cardholder_name').value = name;
}
function setIntegrationMode(mode) {
state.integrationMode = mode;
document.getElementById('hosted-card-fields').classList.toggle('hidden', mode !== 'hosted');
document.getElementById('hosted-submit').classList.toggle('hidden', mode !== 'hosted');
document.getElementById('diagnostic-card-fields').classList.toggle('hidden', mode !== 'diagnostic');
document.getElementById('diagnostic-cardholder').classList.toggle('hidden', mode !== 'diagnostic');
document.getElementById('submit-btn').classList.toggle('hidden', mode !== 'diagnostic');
}
// ─── Flow step UI helpers ─────────────────────────────────────────────────────
function setStep(n, state) { // state: 'active' | 'done' | 'error' | ''
const el = document.getElementById(`step-ind-${n}`);
el.className = `flow-step ${state}`;
}
function showResult(panel, html, type) { // type: 'ok' | 'warn' | 'err'
document.getElementById(`result-${panel}`).innerHTML =
`<div class="step-result ${type}">${html}</div>`;
}
function showRaw(panel, obj) {
const el = document.getElementById(`raw-${panel}`);
if (el) el.textContent = JSON.stringify(obj, null, 2);
}
function toggleRaw(id) {
const el = document.getElementById(id);
if (el) el.classList.toggle('visible');
}
function setLoading(loading) {
const btn = document.getElementById('submit-btn');
btn.disabled = loading;
btn.textContent = loading ? 'Processing…' : 'Run 3DS2 Flow';
const hosted = document.getElementById('hosted-submit');
hosted.style.pointerEvents = loading ? 'none' : '';
hosted.style.opacity = loading ? '0.6' : '';
}
function resetFlow() {
for (let i = 1; i <= 6; i++) {
setStep(i, '');
const r = document.getElementById(`result-${i}`);
if (r) r.innerHTML = '';
const rw = document.getElementById(`raw-${i}`);
if (rw) { rw.textContent = ''; rw.classList.remove('visible'); }
}
state.serverTransId = null;
state.authData = null;
setLoading(false);
}
// ─── API calls ────────────────────────────────────────────────────────────────
async function api(endpoint, body) {
const r = await fetch(`${backendUrl()}${endpoint}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
return r.json();
}
async function apiGet(endpoint) {
const r = await fetch(`${backendUrl()}${endpoint}`);
return r.json();
}
function tokenPaymentReference(resp) {
return resp?.paymentReference || resp?.payment_reference || resp?.id ||
resp?.payment_method?.id || resp?.paymentMethod?.id || resp?.token;
}
async function initHostedFields() {
const status = document.getElementById('hosted-status');
state.hostedReady = false;
if (!window.GlobalPayments?.configure || !window.GlobalPayments?.ui?.form) {
status.textContent = 'Hosted Fields library unavailable. Use diagnostic mode while offline.';
status.style.color = '#b71c1c';
return;
}
try {
status.textContent = 'Hosted Fields initializing...';
status.style.color = '#888';
document.getElementById('hosted-submit').innerHTML = '';
['hosted-card-number', 'hosted-card-cvv', 'hosted-card-expiration', 'hosted-card-holder-name']
.forEach((id) => { document.getElementById(id).innerHTML = ''; });
const config = await apiGet('/api/tokenization-config');
if (!config.success) throw new Error(config.error || 'Tokenization config failed');
state.hostedForm = GlobalPayments.ui.form({
fields: {
'card-number': {
target: '#hosted-card-number',
placeholder: '•••• •••• •••• ••••',
},
'card-expiration': {
target: '#hosted-card-expiration',
placeholder: 'MM / YYYY',
},
'card-cvv': {
target: '#hosted-card-cvv',
placeholder: '•••',
},
'card-holder-name': {
target: '#hosted-card-holder-name',
placeholder: 'John Doe',
},
submit: {
target: '#hosted-submit',
text: 'Tokenize + Run 3DS2 Flow',
value: 'Tokenize + Run 3DS2 Flow',
},
},
styles: {
input: {
'font-family': 'DM Sans, Arial, sans-serif',
'font-size': '15px',
color: '#212529',
border: '0',
'box-shadow': 'none',
outline: 'none',
background: 'transparent',
margin: '0',
padding: '0',
width: '100%',
height: '54px',
'line-height': '54px',
},
'input[type=text]': {
border: '0',
'box-shadow': 'none',
outline: 'none',
background: 'transparent',
margin: '0',
padding: '0',
width: '100%',
height: '54px',
'line-height': '54px',
},
'input[type=tel]': {
border: '0',
'box-shadow': 'none',
outline: 'none',
background: 'transparent',
margin: '0',
padding: '0',
width: '100%',
height: '54px',
'line-height': '54px',
},
'#secure-payment-field': {
border: '0',
'box-shadow': 'none',
outline: 'none',
background: 'transparent',
margin: '0',
padding: '0',
width: '100%',
height: '54px',
},
'#secure-payment-field[type=button]': {
'background-color': '#0072ce',
color: '#fff',
border: '0',
'border-radius': '6px',
cursor: 'pointer',
'font-weight': '700',
width: '100%',
},
},
});
GlobalPayments.configure({
accessToken: config.data.accessToken,
env: config.data.env || 'sandbox',
accountName: config.data.accountName,
apiVersion: config.data.apiVersion || '2021-03-22',
requireCardHolderName: true,
});
state.hostedForm.ready(() => {
state.hostedReady = true;
status.textContent = 'Hosted Fields ready.';
status.style.color = '#2e7d32';
});
state.hostedForm.on('token-success', async (resp) => {
const paymentMethodId = tokenPaymentReference(resp);
const tokenCardholderName = resp?.details?.cardholderName || resp?.details?.cardholder_name || resp?.cardholderName;
if (tokenCardholderName) {
document.getElementById('cardholder_name').value = tokenCardholderName;
}
resetFlow();
setLoading(true);
showResult(1, `<strong>Tokenized:</strong> ${paymentMethodId || 'token received'}`, 'ok');
showRaw(1, resp);
if (!paymentMethodId) {
showResult(1, 'Tokenization succeeded but no payment method reference was returned.', 'err');
setStep(1, 'error');
setLoading(false);
return;
}
await runApiFlow({ payment_method_id: paymentMethodId, token_raw: resp });
});
state.hostedForm.on('token-error', (resp) => {
resetFlow();
showResult(1, `<strong>Tokenization error:</strong> ${JSON.stringify(resp)}`, 'err');
showRaw(1, resp);
setStep(1, 'error');
setLoading(false);
});
} catch (err) {
status.textContent = `Hosted Fields unavailable: ${err.message}`;
status.style.color = '#b71c1c';
}
}
// ─── Method URL (device fingerprinting) ──────────────────────────────────────
function runMethodUrl(methodUrl, methodData) {
return new Promise(resolve => {
document.getElementById('method-data-input').value = methodData;
const form = document.getElementById('method-form');
form.action = methodUrl;
form.submit();
// Wait up to 10 seconds, then continue
setTimeout(resolve, 10000);
});
}
// ─── ACS Challenge iframe ─────────────────────────────────────────────────────
function openAcsModal(challengeUrl) {
document.getElementById('acs-iframe').src = challengeUrl;
document.getElementById('acs-modal').classList.add('open');
}
function closeAcsModal() {
document.getElementById('acs-modal').classList.remove('open');
document.getElementById('acs-iframe').src = 'about:blank';
}
// ─── Main flow ────────────────────────────────────────────────────────────────
async function runFlow(event) {
event.preventDefault();
if (state.integrationMode === 'hosted') {
showResult(1, state.hostedReady
? 'Use the Hosted Fields button to tokenize and start the flow.'
: 'Hosted Fields are not ready yet. Check tokenization credentials or use diagnostic mode.', state.hostedReady ? 'warn' : 'err');
return;
}
resetFlow();
setLoading(true);
await runApiFlow({});
}
async function runApiFlow({ payment_method_id = null, token_raw = null }) {
if (token_raw) showRaw(1, token_raw);
const card_number = document.getElementById('card_number').value.replace(/\s/g, '');
const exp_month = document.getElementById('exp_month').value.trim();
const exp_year = document.getElementById('exp_year').value.trim();
const cvn = document.getElementById('cvn').value.trim();
const cardholder_name = document.getElementById('cardholder_name').value.trim();
const amount = document.getElementById('amount').value.trim();
const currency = document.getElementById('currency').value;
// ── Step 1: Enrollment check ──────────────────────────────────────────────
setStep(1, 'active');
try {
const r1 = await api('/api/check-enrollment', payment_method_id
? { payment_method_id }
: { card_number, exp_month, exp_year });
if (!r1.success) {
showResult(1, `<strong>Error:</strong> ${r1.error || 'Check-enrollment failed'}`, 'err');
showRaw(1, r1);
setStep(1, 'error');
setLoading(false);
return;
}
state.serverTransId = r1.data.server_trans_id;
state.messageVersion = r1.data.message_version;
const enrolledOk = ['Y', 'ENROLLED'].includes(r1.data.enrolled);
showResult(1, `
<dl>
<dt>Enrolled</dt><dd>${r1.data.enrolled}</dd>
<dt>Server Trans ID</dt><dd>${r1.data.server_trans_id}</dd>
<dt>Method URL</dt><dd>${r1.data.method_url || 'N/A'}</dd>
</dl>`, enrolledOk ? 'ok' : 'warn');
showRaw(1, r1.raw);
setStep(1, 'done');
// ── Step 2: Method URL ─────────────────────────────────────────────────
setStep(2, 'active');
let methodCompletion = 'UNAVAILABLE';
if (r1.data.method_url && r1.data.method_data) {
showResult(2, 'Running device fingerprint (10s timeout)…', 'ok');
await runMethodUrl(r1.data.method_url, r1.data.method_data);
methodCompletion = 'YES';
showResult(2, 'Device fingerprint complete.', 'ok');
} else {
showResult(2, 'No Method URL — skipped.', 'warn');
}
setStep(2, 'done');
// ── Step 3: Initiate Auth ──────────────────────────────────────────────
setStep(3, 'active');
const browserData = {
accept_header: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
color_depth: screen.colorDepth || 24,
ip: '123.123.123.123',
java_enabled: false,
javascript_enabled: true,
language: navigator.language || 'en-GB',
screen_height: screen.height,
screen_width: screen.width,
challenge_window_size: 'FULL_SCREEN',
timezone: String(new Date().getTimezoneOffset()),