|
5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> |
6 | 6 | <title>PCI Proxy Web Tokenization</title> |
7 | 7 | <script src="https://pay.sandbox.datatrans.com/upp/payment/js/secure-fields-2.0.0.min.js"></script> |
| 8 | + <script src="../assets/js/expirationdate.js"></script> |
8 | 9 | <link rel="stylesheet" type="text/css" href="../assets/css/stylesheet.css"> |
9 | 10 | <link rel="stylesheet" type="text/css" href="../assets/css/inline.css"> |
10 | 11 | </head> |
11 | 12 | <body style="margin: 0;"> |
12 | 13 | <nav style="text-align: center; background: #213d62; padding: 10px; margin-bottom: 40px;"> |
13 | | - <a href="index.html">Basic Example</a> |
14 | | - <a style="text-decoration: underline;" href="inline-example.html">Inline Example</a> |
15 | | - <a href="floating-label.html">Floating Label Example</a> |
16 | | - <a href="iban.html">IBAN Example</a> |
17 | | - <a href="account.html">Account Number Example</a> |
| 14 | + <a href="index.html">Basic</a> |
| 15 | + <a style="text-decoration: underline;" href="inline-example.html">Inline</a> |
| 16 | + <a href="floating-label.html">Floating Label</a> |
| 17 | + <a href="iban.html">IBAN</a> |
| 18 | + <a href="account.html">Account Number</a> |
18 | 19 | <a href="show.html">Reveal Card (Show API)</a> |
19 | 20 | </nav> |
20 | 21 | <form style="max-width: 390px; margin: 0 auto;"> |
|
36 | 37 | </div> |
37 | 38 | </div> |
38 | 39 | <div> |
39 | | - <input id="expiry" name="expiry" placeholder="MM/YY" type="tel" maxlength="7" /> |
| 40 | + <input id="expiry" name="expiry" placeholder="MM/YY" type="tel" maxlength="7" autocomplete="off" /> |
40 | 41 | </div> |
41 | 42 | <!-- CVV markup --> |
42 | 43 | <div id="cvv-container" class="secure-field secure-field__input secure-field__base"> |
|
55 | 56 | <footer> |
56 | 57 | <a href="https://github.com/datatrans/secure-fields-sample/blob/master/pciproxy-examples/inline-example.html">View this page on GitHub</a> |
57 | 58 | </footer> |
58 | | - <script> |
59 | | - // Expiry date |
60 | | - function setInputFilter(textbox, inputFilter) { |
61 | | - ['input', 'keydown', 'keyup', 'mousedown', 'mouseup', 'select', 'contextmenu', 'drop'].forEach(function (key) { |
62 | | - textbox.addEventListener(key, function (e) { |
63 | | - if (/^\d+$/.test(e.key)) { |
64 | | - this.value = formatExpriy(this.value); |
65 | | - } |
66 | | - |
67 | | - if (inputFilter(this.value)) { |
68 | | - this.oldValue = this.value; |
69 | | - this.oldSelectionStart = this.selectionStart; |
70 | | - this.oldSelectionEnd = this.selectionEnd; |
71 | | - } else if (this.hasOwnProperty('oldValue')) { |
72 | | - this.value = this.oldValue; |
73 | | - this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd); |
74 | | - } else { |
75 | | - this.value = ''; |
76 | | - } |
77 | | - if (this.oldSelectionEnd === 7 && key === 'keyup' && e.key.match(/^[0-9]$/)) { |
78 | | - secureFields.focus('cvv'); |
79 | | - } |
80 | | - }); |
81 | | - }); |
82 | | - } |
83 | | - |
84 | | - setInputFilter(document.getElementById("expiry"), function(value) { return /^\d{0,2}[\/]?\d{0,2}/.test(value); }); |
85 | | - |
86 | | - function formatExpriy (val) { |
87 | | - var p1 = parseInt(val[0], 10), |
88 | | - p2 = parseInt(val[1], 10); |
89 | | - |
90 | | - return /^\d$/.test(val) && "0" !== val && "1" !== val |
91 | | - ? "0" + val + " / " |
92 | | - : /^\d\d$/.test(val) |
93 | | - ? p2 > 2 && 0 !== p1 ? "0" + p1 + " / " + p2 : "" + val + " / " |
94 | | - : val |
95 | | - } |
96 | | - </script> |
97 | 59 | <script> |
98 | 60 | // Credit Card and CVV |
99 | 61 | var secureFields = new SecureFields(); |
|
138 | 100 | }); |
139 | 101 |
|
140 | 102 | secureFields.on('change', function (data) { |
141 | | - // Fill epxiry date on card autocomplete |
| 103 | + // Fill expiration date date on card autocomplete |
142 | 104 | if (data.event.type === 'autocomplete') { |
143 | 105 | if (data.event.field === 'expiryYear') { |
144 | 106 | var value = (expiryInput.value || '/') |
|
170 | 132 | cardImage.src = '../assets/img/brands/' + data.fields.cardNumber.paymentMethod + '.svg'; |
171 | 133 | cardContainer.classList.add('secure-field__is-recognized'); |
172 | 134 | } |
173 | | - if (data.event.type === 'keyUp' && data.event.field === 'cardNumber' && data.event.eventData.isNumber && data.fields.cardNumber.valid) { |
| 135 | + if (data.event.type === 'keyUp' && data.event.field === 'cardNumber' && data.event.eventData && data.event.eventData.isNumber && data.fields.cardNumber.valid) { |
174 | 136 | document.getElementById('expiry').focus(); |
175 | 137 | } |
176 | 138 | }) |
|
196 | 158 | }); |
197 | 159 |
|
198 | 160 | document.getElementById('form-submit').addEventListener('click', function () { |
199 | | - // validate your expiry field here |
200 | | - if (document.getElementById('expiry').value !== '') { |
201 | | - secureFields.submit(); |
202 | | - } else { |
203 | | - paymentContainer.classList.add('field__has-error'); |
| 161 | + // validate your expiration date field here |
| 162 | + var result |
| 163 | + try { |
| 164 | + result = getExpirationDateObject(document.getElementById('expiry').value) |
| 165 | + } catch { |
| 166 | + // nothing to catch here |
204 | 167 | } |
| 168 | + if (result) { |
| 169 | + secureFields.submit({ |
| 170 | + expm: result.expm, |
| 171 | + expy: result.expy |
| 172 | + }); |
| 173 | + return; |
| 174 | + } |
| 175 | + paymentContainer.classList.add('field__has-error'); |
205 | 176 | }); |
206 | 177 |
|
207 | 178 | secureFields.on('success', function (data) { |
|
211 | 182 | result.style.display = 'block'; |
212 | 183 | } |
213 | 184 | }); |
| 185 | + |
| 186 | + handleExpirationDate(document.getElementById("expiry"), "cvv"); |
214 | 187 | </script> |
215 | 188 | <style> |
216 | 189 | /* The following styles are NOT required */ |
|
0 commit comments