-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinline-example.html
209 lines (191 loc) · 8.25 KB
/
inline-example.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>PCI Proxy Web Tokenization</title>
<script src="https://pay.sandbox.datatrans.com/upp/payment/js/secure-fields-1.0.0.min.js"></script>
<link rel="stylesheet" type="text/css" href="assets/css/stylesheet.css">
<link rel="stylesheet" type="text/css" href="assets/css/inline.css">
</head>
<body style="margin: 0;">
<nav style="text-align: center; background: #213d62; padding: 10px; margin-bottom: 40px;">
<a style="color: #fff; margin: 0 10px; text-decoration: none;" href="index.html">Basic Example</a>
<a style="color: #06bd6e; margin: 0 10px; text-decoration: none;" href="inline-example.html">Inline Example</a>
<a style="color: #fff; margin: 0 10px; text-decoration: none;" href="inline-example-autotab.html">Inline Example with autojump to next field</a>
<a style="color: #fff; margin: 0 10px; text-decoration: none;" href="floating-label.html">Floating Label Example</a>
</nav>
<form style="max-width: 390px; margin: 0 auto;">
<div id="payment-container" class="inline-wrapper">
<!-- Card Number markup -->
<div id="card-number-container" class="secure-field secure-field__input secure-field__base secure-field__has-actions secure-field__has-actions-left secure-field__has-card-icon">
<div class="secure-field--input-container" style="height: 40px">
<div class="secure-field--actions">
<span class="secure-field--action secure-field--action__card-icon">
<span class="secure-field--action-card-wrap">
<img class="secure-field--card-icon secure-field--card-icon__empty" src="assets/img/card-empty.svg">
<img class="secure-field--card-icon secure-field--card-icon__error" src="assets/img/card-error.svg">
<img class="secure-field--card-icon secure-field--card-icon__recognized-card" src="assets/img/card-recognized.svg">
<img class="secure-field--card-icon secure-field--cvv-icon secure-field--card-icon__empty" src="assets/img/cvc-empty.svg">
</span>
</span>
</div>
<div class="secure-field--input" id="card-number"></div>
</div>
</div>
<div>
<input id="expiry" name="expiry" placeholder="MM/YY" type="tel" maxlength="7" />
</div>
<!-- CVV markup -->
<div id="cvv-container" class="secure-field secure-field__input secure-field__base">
<div class="secure-field--input-container" style="height: 40px">
<div class="secure-field--input" id="cvv-number"></div>
</div>
</div>
</div>
<div style="max-width: 200px; margin-top: 20px">
<button type="button" id="form-submit">
Submit
</button>
<pre id="form-result" style="margin-top: 20px; font-size: 1rem"></pre>
</div>
</form>
<script>
// Expiry date
function setInputFilter(textbox, inputFilter) {
['input', 'keydown', 'keyup', 'mousedown', 'mouseup', 'select', 'contextmenu', 'drop'].forEach(function (key) {
textbox.addEventListener(key, function (e) {
if (/^\d+$/.test(e.key)) {
this.value = formatExpriy(this.value);
}
if (inputFilter(this.value)) {
this.oldValue = this.value;
this.oldSelectionStart = this.selectionStart;
this.oldSelectionEnd = this.selectionEnd;
} else if (this.hasOwnProperty('oldValue')) {
this.value = this.oldValue;
this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
} else {
this.value = '';
}
});
});
}
setInputFilter(document.getElementById("expiry"), function(value) { return /^\d{0,2}[\/]?\d{0,2}/.test(value); });
function formatExpriy (val) {
var p1 = parseInt(val[0], 10),
p2 = parseInt(val[1], 10);
return /^\d$/.test(val) && "0" !== val && "1" !== val
? "0" + val + " / "
: /^\d\d$/.test(val)
? p2 > 2 && 0 !== p1 ? "0" + p1 + " / " + p2 : "" + val + " / "
: val
}
</script>
<script>
// Credit Card and CVV
var secureFields = new SecureFields();
secureFields.initTokenize(
'1100007006',
{
cardNumber: {
placeholderElementId: 'card-number',
inputType: 'tel'
},
cvv: {
placeholderElementId: 'cvv-number',
inputType: 'tel'
}
},
{
// options...
}
);
secureFields.on('ready', function () {
// Set styles manually as they're inside an iframe and out of the scope of the parent's stylesheets
secureFields.setStyle('cardNumber', 'font: 16px/18px system-ui, sans-serif; border-radius: 0; border:0; -webkit-appearance: none; padding: 0');
secureFields.setStyle('cvv','font: 16px/18px system-ui, sans-serif; border-radius: 0; border:0; -webkit-appearance: none; padding: 0');
secureFields.focus('cardNumber');
secureFields.setPlaceholder("cardNumber", "4242 4242 4242 4242");
secureFields.setPlaceholder("cvv", "123");
});
var cardContainer = document.getElementById('card-number-container');
var cvvContainer = document.getElementById('cvv-container');
var paymentContainer = document.getElementById('payment-container');
// Set focus to input fields when clicking containers
cardContainer.addEventListener('click', function () {
secureFields.focus('cardNumber');
});
cvvContainer.addEventListener('click', function () {
secureFields.focus('cvv');
});
// Set class names when fields change
secureFields.on('change', function (data) {
var cardImage = cardContainer.querySelector('.secure-field--card-icon__recognized-card');
paymentContainer.classList.remove('secure-field__has-focus-cvv');
paymentContainer.classList.remove('secure-field__has-focus-cardNumber');
paymentContainer.classList.remove('field__has-error');
cardContainer.classList.remove('secure-field__has-error');
cvvContainer.classList.remove('secure-field__has-error');
paymentContainer.classList.add(`secure-field__has-focus-${data.event.field}`);
if (!data.fields.cardNumber.paymentMethod) {
cardImage.src = 'assets/img/card-empty.svg';
cardContainer.classList.remove('secure-field__is-recognized');
} else {
cardImage.src = 'assets/img/brands/' + data.fields.cardNumber.paymentMethod + '.svg';
cardContainer.classList.add('secure-field__is-recognized');
}
})
// Set class names on validate
secureFields.on('validate', function (data) {
paymentContainer.classList.remove('field__has-error');
if (data.fields.cardNumber.valid) {
cardContainer.classList.remove('secure-field__has-error');
} else {
cardContainer.classList.remove('secure-field__is-recognized');
cardContainer.classList.add('secure-field__has-error');
paymentContainer.classList.add('field__has-error');
}
if (data.fields.cvv.valid) {
cvvContainer.classList.remove('secure-field__has-error');
} else {
cvvContainer.classList.add('secure-field__has-error');
paymentContainer.classList.add('field__has-error');
}
});
document.getElementById('form-submit').addEventListener('click', function () {
// validate your expiry field here
if (document.getElementById('expiry').value !== '') {
secureFields.submit();
} else {
paymentContainer.classList.add('field__has-error');
}
});
secureFields.on('success', function (data) {
if (data.transactionId) {
var result = document.getElementById('form-result');
result.innerText = 'Data submitted successfully (transactionId: ' + data.transactionId + ')';
result.style.display = 'block';
}
});
</script>
<style>
/* The following styles are NOT required */
html, body {
font-family: Arial, Helvetica, sans-serif;
}
label {
font-weight: bold;
font-size: 0.9rem;
line-height: 1.5rem;
}
button {
border: none;
background-color: #06bd6e;
color: white;
padding: 7px 12px;
font-size: 1rem;
cursor: pointer;
}
</style>
</body>