Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit 886841b

Browse files
committed
JavaScript version 0_1_17
Add the fourDigitCvcForBins option to validate 4 digit are used for the CVC field on selected bins. The default value is '34,37' for the amex bins.
1 parent bbb382b commit 886841b

9 files changed

+131
-32
lines changed

Options.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ The `createEncryption ( key , `*`options`*` )` and `createEncryptedForm ( form,
4343
A comma separated string of bins for which the CVC code validation should be ignored.
4444

4545
For example `cvcIgnoreBins = '6703'`) to ignore CVC validation for BCMC.
46+
47+
* **string `[fourDigitCvcForBins = '34,37']`** - *since version: 0_1_17*
48+
49+
A comma separated string of bins for which a four digit CVC is required.
50+
51+
For example `fourDigitCvcForBins = '34,37'`) to require four digit CVC for Amex cards.
4652

4753
## Option in createEncryptedForm()
48-
Supported fields: `enabledValidations`, `numberIgnoreNonNumeric`, `cvcIgnoreBins`, `submitButtonsAlwaysEnabled`, `fieldNameAttribute`, `onsubmit`
54+
Supported fields: `enabledValidations`, `numberIgnoreNonNumeric`, `cvcIgnoreBins`, `fourDigitCvcForBins`, `submitButtonsAlwaysEnabled`, `fieldNameAttribute`, `onsubmit`
4955

5056
*Example:*
5157
```Javascript
@@ -55,19 +61,21 @@ var cseForm = createEncryptedForm ( form, key , {
5561
"submitButonAlwaysEnabled": false,
5662
"numberIgnoreNonNumeric" : true,
5763
"fieldNameAttribute" : "data-encrypted-name",
58-
"cvcIgnoreBins" = "6703"
64+
"cvcIgnoreBins" : "6703",
65+
"fourDigitCvcForBins" : "34,37"
5966
} );
6067
```
6168

6269
When the card type detection addon is being enabled, the `cardTypeElement` option is also supported.
6370

6471
## Option in createEncryption()
65-
Currently `enabledValidations`, `numberIgnoreNonNumeric` and `cvcIgnoreBins` are supported.
72+
Currently `enabledValidations`, `numberIgnoreNonNumeric`, `fourDigitCvcForBins` and `cvcIgnoreBins` are supported.
6673

6774
```Javascript
6875
var cse = createEncryption ( key , {
6976
"enableValidations" : true,
7077
"numberIgnoreNonNumeric" : true,
71-
"cvcIgnoreBins" = "6703"
78+
"cvcIgnoreBins" = "6703",
79+
"fourDigitCvcForBins" : "34,37"
7280
} );
7381
```

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ In case the HTML integration is troublesome in your setup, the library has been
129129

130130
# Version History
131131

132+
JavaScript version 0_1_17
133+
-------
134+
135+
* Add the fourDigitCvcForBins option to validate 4 digit are used for the CVC field on selected bins. The default value is '34,37' for the amex bins.
136+
132137
JavaScript version 0_1_16
133138
-------
134139

adyen.encrypt.nodom.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<!-- How to use the Adyen encryption client-side JS library -->
1717
<!-- N.B. Make sure the library is *NOT* loaded in the "head" of the HTML document -->
1818

19-
<script type="text/javascript" src="js/adyen.encrypt.nodom.min.js?0_1_16"></script>
19+
<script type="text/javascript" src="js/adyen.encrypt.nodom.min.js?0_1_17"></script>
2020
<script type="text/javascript">
2121

2222
// the public key
@@ -51,6 +51,9 @@
5151
// list.
5252
// options.cvcIgnoreBins = '6703'; // Ignore CVC for BCMC
5353

54+
// Use 4digit cvc for certain bins. Supply a comma separated list.
55+
// options.fourDigitCvcForBins = '34,37'; // Set 4 digit CVC for Amex
56+
5457

5558
var cseInstance = adyen.encrypt.createEncryption(key, options);
5659

adyen.encrypt.simple.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
<!-- How to use the Adyen encryption client-side JS library -->
5151
<!-- N.B. Make sure the library is *NOT* loaded in the "head" of the HTML document -->
52-
<script type="text/javascript" src="js/adyen.encrypt.min.js?0_1_16"></script>
52+
<script type="text/javascript" src="js/adyen.encrypt.min.js?0_1_17"></script>
5353

5454
<script type="text/javascript">
5555

@@ -98,6 +98,9 @@
9898
// list.
9999
// options.cvcIgnoreBins = '6703'; // Ignore CVC for BCMC
100100

101+
// Use 4digit cvc for certain bins. Supply a comma separated list.
102+
// options.fourDigitCvcForBins = '34,37'; // Set 4 digit CVC for Amex
103+
101104

102105
// Use a different attribute to identify adyen fields
103106
// Note that the attributes needs to start with data-.

js/adyen.encrypt.js

+50-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/adyen.encrypt.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/adyen.encrypt.nodom.js

+50-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* * Stanford Javascript Crypto Library | http://crypto.stanford.edu/sjcl/
88
* * JSON in JavaScript | http://www.JSON.org/
99
*
10-
* Version: 0_1_16
10+
* Version: 0_1_17
1111
* Author: ADYEN (c) 2014
1212
1313
<!DOCTYPE html>
@@ -28,7 +28,7 @@
2828
<!-- How to use the Adyen encryption client-side JS library -->
2929
<!-- N.B. Make sure the library is *NOT* loaded in the "head" of the HTML document -->
3030
31-
<script type="text/javascript" src="js/adyen.encrypt.nodom.min.js?0_1_16"></script>
31+
<script type="text/javascript" src="js/adyen.encrypt.nodom.min.js?0_1_17"></script>
3232
<script type="text/javascript">
3333
3434
// the public key
@@ -63,6 +63,9 @@
6363
// list.
6464
// options.cvcIgnoreBins = '6703'; // Ignore CVC for BCMC
6565
66+
// Use 4digit cvc for certain bins. Supply a comma separated list.
67+
// options.fourDigitCvcForBins = '34,37'; // Set 4 digit CVC for Amex
68+
6669
6770
var cseInstance = adyen.encrypt.createEncryption(key, options);
6871
@@ -172,7 +175,7 @@
172175
encrypt.errors = encrypt.errors || {};
173176

174177

175-
encrypt.version = '0_1_16';
178+
encrypt.version = '0_1_17';
176179

177180

178181

@@ -288,6 +291,14 @@
288291
delete this.options.cvcIgnoreFornumber;
289292
}
290293

294+
if ( typeof this.options.fourDigitCvcForBins === "undefined" ) {
295+
this.options.fourDigitCvcForBins = "34,37"; // Amex by default
296+
}
297+
298+
if ( typeof this.options.cvcLengthFornumber !== "undefined" ) {
299+
delete this.options.cvcLengthFornumber;
300+
}
301+
291302
if ( typeof this.options.cvcIgnoreBins === "string" ) {
292303
var binsToIgnore = [];
293304
this.options.cvcIgnoreBins.replace(/\d+/g, function(m) {
@@ -305,6 +316,28 @@
305316
delete this.options.cvcIgnoreBins;
306317
}
307318

319+
if (typeof this.options.fourDigitCvcForBins === "string") {
320+
321+
var cvcGroups = [];
322+
323+
this.options.fourDigitCvcForBins.replace(/\d+/g, function(m) {
324+
if (m.length > 0 && !isNaN(parseInt(m, 10))) {
325+
cvcGroups.push(m);
326+
}
327+
return m;
328+
});
329+
330+
if (cvcGroups.length > 0) {
331+
this.options.cvcLengthFornumber = {
332+
matcher : new RegExp("^\\s*(" + cvcGroups.join("|") + ")"),
333+
requiredLength : 4
334+
}
335+
}
336+
337+
}
338+
339+
delete this.options.fourDigitCvcForBins;
340+
308341
evLog("initializeCount");
309342
};
310343

@@ -411,25 +444,32 @@
411444
val = val.replace( /\D/g, '' );
412445
}
413446

414-
var shouldIgnore = false;
415-
416447
for ( var relatedField in data ) {
417448
if ( data.hasOwnProperty(relatedField) ) {
418449

419450
var possibleOption = this.options[field + 'IgnoreFor' + relatedField] ;
451+
var lengthOption = this.options[field + 'LengthFor' + relatedField];
420452

421453
if ( possibleOption && data[relatedField].match(possibleOption)) {
422-
shouldIgnore = true;
454+
result[field] = true;
455+
continue;
456+
} else if (lengthOption && lengthOption.matcher && lengthOption.requiredLength && data[relatedField].match(lengthOption.matcher)) {
457+
if (val.length !== lengthOption.requiredLength ) {
458+
result[field] = false;
459+
continue;
460+
}
423461
}
462+
424463
}
425464
}
426-
427-
if (shouldIgnore) {
428-
result[field] = true;
465+
466+
// above checks are used as filters. If they set a result
467+
// other checks are irrelevant
468+
if (result.hasOwnProperty(field)) {
429469
result.valid = result.valid && result[field];
430470
continue;
431471
}
432-
472+
433473
switch ( field ) {
434474
case 'number':
435475
result.number = validations.numberCheck( val );

js/adyen.encrypt.nodom.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adyen-cse-js",
3-
"version": "0.1.16",
3+
"version": "0.1.17",
44
"description": "Adyen javascript client-side encryption library",
55
"main": "js/adyen.encrypt.nodom.js",
66
"repository": {

0 commit comments

Comments
 (0)