-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimulator.html
More file actions
451 lines (421 loc) · 18.3 KB
/
simulator.html
File metadata and controls
451 lines (421 loc) · 18.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3DS Optimization Playground</title>
<!-- Tailwind CSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Inter', sans-serif;
background-color: #f3f4f6;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
}
.container {
background-color: #ffffff;
border-radius: 12px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
padding: 32px;
max-width: 800px;
width: 100%;
display: flex;
flex-direction: column;
gap: 24px;
}
.input-group label {
font-weight: 500;
color: #374151;
margin-bottom: 8px;
display: block;
}
.input-group input[type="number"],
.input-group select {
width: 100%;
padding: 10px 14px;
border: 1px solid #d1d5db;
border-radius: 8px;
font-size: 1rem;
color: #4b5563;
transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
.input-group input[type="number"]:focus,
.input-group select:focus {
outline: none;
border-color: #4f46e5;
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}
.checkbox-group {
display: flex;
align-items: center;
gap: 10px;
}
.checkbox-group input[type="checkbox"] {
width: 20px;
height: 20px;
border-radius: 6px;
border: 1px solid #d1d5db;
accent-color: #4f46e5;
}
.checkbox-group label {
font-weight: 400;
color: #374151;
}
.button-primary {
background-color: #4f46e5;
color: #ffffff;
padding: 12px 20px;
border-radius: 8px;
font-weight: 600;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
border: none;
box-shadow: 0 4px 10px rgba(79, 70, 229, 0.2);
}
.button-primary:hover {
background-color: #4338ca;
box-shadow: 0 6px 15px rgba(79, 70, 229, 0.3);
}
.output-section {
background-color: #f9fafb;
border: 1px solid #e5e7eb;
border-radius: 8px;
padding: 24px;
}
.output-section h3 {
font-size: 1.25rem;
font-weight: 600;
color: #1f2937;
margin-bottom: 16px;
}
.output-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 0;
border-bottom: 1px dashed #e5e7eb;
}
.output-item:last-child {
border-bottom: none;
}
.output-item span:first-child {
color: #4b5563;
font-weight: 500;
}
.output-item span:last-child {
font-weight: 600;
color: #1f2937;
}
.exemption-info {
margin-top: 16px;
padding: 12px;
background-color: #ecfdf5;
border: 1px solid #d1fae5;
border-radius: 8px;
color: #065f46;
font-size: 0.9rem;
}
.failure-info {
margin-top: 16px;
padding: 12px;
background-color: #fee2e2;
border: 1px solid #fecaca;
border-radius: 8px;
color: #991b1b;
font-size: 0.9rem;
}
.ai-toggle-group {
display: flex;
align-items: center;
justify-content: flex-end; /* Align to the right */
gap: 10px;
margin-bottom: 16px;
}
.ai-toggle-group label {
font-weight: 500;
color: #374151;
}
/* Custom toggle switch styling */
.switch {
position: relative;
display: inline-block;
width: 48px;
height: 28px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
border-radius: 28px;
}
.slider:before {
position: absolute;
content: "";
height: 20px;
width: 20px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #4f46e5;
}
input:focus + .slider {
box-shadow: 0 0 1px #4f46e5;
}
input:checked + .slider:before {
-webkit-transform: translateX(20px);
-ms-transform: translateX(20px);
transform: translateX(20px);
}
</style>
</head>
<body>
<div class="container">
<h1 class="text-3xl font-bold text-center text-gray-800">3DS Optimization Playground</h1>
<p class="text-center text-gray-600">Simulate 3DS flow and exemption impacts.</p>
<div class="ai-toggle-group">
<label for="aiModelToggle">Enable AI Model (Auto-tune parameters)</label>
<label class="switch">
<input type="checkbox" id="aiModelToggle">
<span class="slider"></span>
</label>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="input-group">
<label for="amount">Transaction Amount ($)</label>
<input type="number" id="amount" value="100.00" min="0.01" step="0.01">
</div>
<div class="input-group">
<label for="cofStatus">Credential on File (CoF) Status</label>
<select id="cofStatus">
<option value="none">Not CoF</option>
<option value="merchantInitiated">Merchant Initiated Transaction (MIT)</option>
<option value="customerInitiated">Customer Initiated Transaction (CIT)</option>
</select>
</div>
<div class="input-group">
<label for="challengeIndicator">Challenge Indicator</label>
<select id="challengeIndicator">
<option value="noPreference">No Preference</option>
<option value="noChallenge">No Challenge Requested</option>
<option value="challengeMandated">Challenge Mandated</option>
</select>
</div>
<div class="input-group checkbox-group">
<input type="checkbox" id="piiPresence">
<label for="piiPresence">PII (Personally Identifiable Information) Present?</label>
</div>
</div>
<button id="simulateBtn" class="button-primary">Simulate 3DS Flow</button>
<div id="outputSection" class="output-section hidden">
<h3 class="text-xl font-semibold text-gray-800 mb-4">Simulation Results</h3>
<div class="output-item">
<span>Outcome:</span>
<span id="outcome"></span>
</div>
<div class="output-item">
<span>Frictionless Rate:</span>
<span id="frictionlessRate"></span>
</div>
<div class="output-item">
<span>Challenge Rate:</span>
<span id="challengeRate"></span>
</div>
<div class="output-item">
<span>Failure Rate:</span>
<span id="failureRate"></span>
</div>
<div id="exemptionReason" class="exemption-info hidden"></div>
<div id="failureReason" class="failure-info hidden"></div>
</div>
</div>
<script>
// DOM Elements
const amountInput = document.getElementById('amount');
const cofStatusSelect = document.getElementById('cofStatus');
const challengeIndicatorSelect = document.getElementById('challengeIndicator');
const piiPresenceCheckbox = document.getElementById('piiPresence');
const aiModelToggle = document.getElementById('aiModelToggle');
const simulateBtn = document.getElementById('simulateBtn');
const outputSection = document.getElementById('outputSection');
const outcomeSpan = document.getElementById('outcome');
const frictionlessRateSpan = document.getElementById('frictionlessRate');
const challengeRateSpan = document.getElementById('challengeRate');
const failureRateSpan = document.getElementById('failureRate');
const exemptionReasonDiv = document.getElementById('exemptionReason');
const failureReasonDiv = document.getElementById('failureReason');
// --- Global Rates for AI Model Persistence ---
// These rates will now persist across multiple simulations when AI model is enabled.
let currentFrictionlessRate = 0.60;
let currentChallengeRate = 0.30;
let currentFailureRate = 0.10;
// Event Listener for Simulate Button
simulateBtn.addEventListener('click', simulate3DS);
/**
* Simulates the 3DS flow based on user inputs and internal logic.
*/
function simulate3DS() {
// Get input values
const amount = parseFloat(amountInput.value);
const cofStatus = cofStatusSelect.value;
const challengeIndicator = challengeIndicatorSelect.value;
const piiPresent = piiPresenceCheckbox.checked;
const aiModelEnabled = aiModelToggle.checked;
// Initialize outcome and reason variables for the current run
let outcome = 'Unknown';
let exemptionReason = '';
let failureReason = '';
// Reset previous outputs
exemptionReasonDiv.classList.add('hidden');
failureReasonDiv.classList.add('hidden');
exemptionReasonDiv.innerHTML = '';
failureReasonDiv.innerHTML = '';
// --- 3DS Logic and Exemption Evaluation ---
// 1. Transaction Risk Analysis (TRA) Exemption (Simplified)
let traExemptionEligible = false;
if (amount <= 50 && cofStatus !== 'none' && piiPresent) {
traExemptionEligible = true;
} else if (amount <= 30 && cofStatus !== 'none') {
traExemptionEligible = true;
}
// 2. Low Value Exemption (LVE)
let lveEligible = false;
if (amount <= 30) { // Example threshold for LVE
lveEligible = true;
}
// 3. Recurring Payments / Merchant Initiated Transactions (MIT) Exemption
let recurringExemptionEligible = false;
if (cofStatus === 'merchantInitiated' || cofStatus === 'customerInitiated') {
recurringExemptionEligible = true;
}
let exemptionApplied = false;
if (lveEligible) {
exemptionApplied = true;
exemptionReason = 'Low Value Exemption (LVE): Transaction amount is below the low value threshold.';
} else if (recurringExemptionEligible) {
exemptionApplied = true;
exemptionReason = 'Recurring Payments/MIT Exemption: Transaction is a Credential on File (CoF) payment.';
} else if (traExemptionEligible) {
exemptionApplied = true;
exemptionReason = 'Transaction Risk Analysis (TRA) Exemption: Low amount, CoF, and PII present indicate lower risk.';
}
// --- ACS Random Challenge Logic ---
let acsMandatedChallenge = false;
// Only consider random challenge if no exemption was applied and challenge indicator is 'noPreference' or 'noChallenge'
if (!exemptionApplied && (challengeIndicator === 'noPreference' || challengeIndicator === 'noChallenge')) {
const randomChallengeRoll = Math.random();
if (randomChallengeRoll < 0.25) { // 1 in 4 chance (25%)
acsMandatedChallenge = true;
}
}
// Determine final outcome based on challenge indicator, exemptions, and ACS random challenge
if (challengeIndicator === 'challengeMandated') {
outcome = 'Challenge (Mandated)';
exemptionApplied = false; // A mandated challenge overrides any exemption logic
exemptionReason = ''; // Clear exemption reason if challenge is mandated
} else { // 'noPreference' or 'noChallenge'
if (exemptionApplied) {
// Explicitly set outcome when an exemption applies
outcome = 'Frictionless (Exempted)';
} else if (acsMandatedChallenge) {
// ACS randomly mandated a challenge
outcome = `Challenge (ACS Mandated - ${challengeIndicator === 'noChallenge' ? 'No Challenge Requested' : 'No Preference'})`;
} else {
// Default behavior if no exemption and no ACS mandated challenge
if (challengeIndicator === 'noChallenge') {
outcome = 'Frictionless (No Challenge Requested)';
} else { // 'noPreference'
// Simulate a random outcome based on the current (potentially AI-tuned) rates
const random = Math.random();
if (random < currentFrictionlessRate) {
outcome = 'Frictionless';
} else if (random < currentFrictionlessRate + currentChallengeRate) {
outcome = 'Challenge';
} else {
outcome = 'Failure';
failureReason = 'Simulated failure due to high risk or technical issue.';
}
}
}
}
// AI Model Impact (Simplified)
if (aiModelEnabled) {
// AI model "tunes" parameters to optimize frictionless flow
// These changes now persist because currentFrictionlessRate, etc., are global
// Note: this is a simplified representation of the fine-tuning AI does for demo purposes only.
// It is however not real AI.
if (outcome.includes('Frictionless')) {
currentFrictionlessRate = Math.min(0.95, currentFrictionlessRate + 0.05); // Increase frictionless
currentChallengeRate = Math.max(0.01, currentChallengeRate - 0.03); // Decrease challenge
currentFailureRate = Math.max(0.01, currentFailureRate - 0.02); // Decrease failure
if (!exemptionApplied) { // If AI helped achieve frictionless without explicit exemption
exemptionReason = exemptionReason || 'AI Model Optimization: Transaction identified as low risk for frictionless flow.';
exemptionReasonDiv.classList.remove('hidden');
}
} else if (outcome.includes('Challenge')) {
// AI tries to reduce future challenges for similar transactions
currentFrictionlessRate = Math.min(0.90, currentFrictionlessRate + 0.02);
currentChallengeRate = Math.max(0.05, currentChallengeRate - 0.02);
exemptionReason = exemptionReason || 'AI Model Optimization: Future transactions of this type may see increased frictionless rates.';
exemptionReasonDiv.classList.remove('hidden');
} else if (outcome.includes('Failure')) {
// AI tries to reduce future failures
currentFailureRate = Math.max(0.01, currentFailureRate - 0.01);
exemptionReason = exemptionReason || 'AI Model Optimization: Future transactions of this type may see reduced failure rates.';
exemptionReasonDiv.classList.remove('hidden');
}
} else {
// If AI model is disabled, ensure rates revert to base or remain static
// For this simulation, we'll reset them if AI is turned off
currentFrictionlessRate = 0.60;
currentChallengeRate = 0.30;
currentFailureRate = 0.10;
}
// Ensure rates sum to 100% (with some tolerance for floating point)
const totalRate = currentFrictionlessRate + currentChallengeRate + currentFailureRate;
if (totalRate > 1.001 || totalRate < 0.999) {
// Normalize if they drift significantly
const factor = 1 / totalRate;
currentFrictionlessRate *= factor;
currentChallengeRate *= factor;
currentFailureRate *= factor;
}
// Display Results
outcomeSpan.textContent = outcome;
frictionlessRateSpan.textContent = `${(currentFrictionlessRate * 100).toFixed(2)}%`;
challengeRateSpan.textContent = `${(currentChallengeRate * 100).toFixed(2)}%`;
failureRateSpan.textContent = `${(currentFailureRate * 100).toFixed(2)}%`;
if (exemptionReason) {
exemptionReasonDiv.innerHTML = `<strong>Exemption/Optimization Info:</strong> ${exemptionReason}`;
exemptionReasonDiv.classList.remove('hidden');
}
if (failureReason) {
failureReasonDiv.innerHTML = `<strong>Failure Reason:</strong> ${failureReason}`;
failureReasonDiv.classList.remove('hidden');
}
outputSection.classList.remove('hidden');
}
</script>
</body>
</html>