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

Commit

Permalink
JavaScript version 0_1_14
Browse files Browse the repository at this point in the history
-------

* Clean up inconsistencies between the nodom Encryption and the UI
engine 

* Only validate fields that are only there. Removing CVC from the HTML
(in case of mister cash) no longer fails validation.

* Don't require zero padding on the expiryMonth
  • Loading branch information
ArnoudAdyen committed Sep 14, 2015
1 parent fb2f736 commit 4181cdd
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 50 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ In case the HTML integration is troublesome in your setup, the library has been

# Version History

JavaScript version 0_1_14
-------

* Clean up inconsistencies between the nodom Encryption and the UI engine

* Only validate fields that are only there. Removing CVC from the HTML (in case of mister cash) no longer fails validation.

* Don't require zero padding on the expiryMonth

JavaScript version 0_1_13
-------

Expand Down
2 changes: 1 addition & 1 deletion adyen.encrypt.nodom.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!-- How to use the Adyen encryption client-side JS library -->
<!-- N.B. Make sure the library is *NOT* loaded in the "head" of the HTML document -->

<script type="text/javascript" src="js/adyen.encrypt.nodom.min.js?0_1_13"></script>
<script type="text/javascript" src="js/adyen.encrypt.nodom.min.js?0_1_14"></script>
<script type="text/javascript">

// the public key
Expand Down
2 changes: 1 addition & 1 deletion adyen.encrypt.simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

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

<script type="text/javascript">

Expand Down
2 changes: 1 addition & 1 deletion js/addOns/adyen.cardtype.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
};

adyen.CardTypeDetection = {
version : '0_1_13',
version : '0_1_14',
getHandler : function ( cardTypeElement ) {
return function ( ev ) {

Expand Down
2 changes: 1 addition & 1 deletion js/addOns/adyen.cardtype.min.js

Large diffs are not rendered by default.

101 changes: 70 additions & 31 deletions js/adyen.encrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* * Stanford Javascript Crypto Library | http://crypto.stanford.edu/sjcl/
* * JSON in JavaScript | http://www.JSON.org/
*
* Version: 0_1_13
* Version: 0_1_14
* Author: ADYEN (c) 2014
<!DOCTYPE html>
Expand Down Expand Up @@ -61,7 +61,7 @@
<!-- How to use the Adyen encryption client-side JS library -->
<!-- N.B. Make sure the library is *NOT* loaded in the "head" of the HTML document -->
<script type="text/javascript" src="js/adyen.encrypt.min.js?0_1_13"></script>
<script type="text/javascript" src="js/adyen.encrypt.min.js?0_1_14"></script>
<script type="text/javascript">
Expand Down Expand Up @@ -232,7 +232,7 @@
}


encrypt.version = '0_1_13';
encrypt.version = '0_1_14';


/*
Expand Down Expand Up @@ -346,6 +346,10 @@
};
})();

validations.numberCheck = function ( val ) {
return validations.luhnCheck(val);
};

validations.cvcCheck = function ( val ) {
return (val && val.match && val.match( /^\d{3,4}$/ )) ? true : false;
};
Expand All @@ -355,7 +359,10 @@
};

validations.monthCheck = function ( val ) {
return (val && val.match && val.match( /^\d{2}$/ ) && parseInt( val, 10 ) >= 1 && parseInt( val, 10 ) <= 12) ? true : false;

var myVal = (val || '').replace(/^0(\d)$/, '$1');

return (myVal.match( /^([1-9]|10|11|12)$/ ) && parseInt( myVal, 10 ) >= 1 && parseInt( myVal, 10 ) <= 12) ? true : false;
};

validations.holderNameCheck = function ( val ) {
Expand Down Expand Up @@ -448,10 +455,10 @@
Encryption.prototype.encrypt = function ( data ) {

var rsa, aes, cipher, keybytes, encrypted, prefix, validationObject = {
number : data.number,
cvc : data.cvc,
month: data.expiryMonth,
year : data.expiryYear
number : data.number || '',
cvc : data.cvc || '',
month: data.expiryMonth || '',
year : data.expiryYear || ''
};

if ( this.options.enableValidations !== false && this.validate(validationObject).valid === false) {
Expand All @@ -464,7 +471,7 @@

rsa = this.createRSAKey();
aes = this.createAESKey();

cipher = aes.encrypt( JSON.stringify( data ) );
keybytes = sjcl.codec.bytes.fromBits( aes.key );
encrypted = rsa.encrypt_b64( keybytes );
Expand Down Expand Up @@ -495,7 +502,7 @@

var possibleOption = this.options[field + 'IgnoreFor' + relatedField] ;

if ( possibleOption && val && data[relatedField].match(possibleOption)) {
if ( possibleOption && data[relatedField].match(possibleOption)) {
shouldIgnore = true;
}
}
Expand All @@ -510,18 +517,23 @@
switch ( field ) {
case 'number':
result.number = validations.luhnCheck( val );
result.luhn = result.number;
result.valid = result.valid && result.number;
break;
case 'expiryYear':
case 'year':
result.year = validations.yearCheck( val );
result.expiryYear = result.year;
result.valid = result.valid && result.year;
break;
case 'cvc':
result.cvc = validations.cvcCheck( val );
result.valid = result.valid && result.cvc;
break;
case 'expiryMonth':
case 'month':
result.month = validations.monthCheck( val );
result.expiryMonth = result.month;
result.valid = result.valid && result.month;
break;
case 'holderName':
Expand All @@ -544,9 +556,9 @@
};


validations.createChangeHandler = function ( cse, type, allowEmpty ) {
validations.createChangeHandler = function ( cse, field, allowEmpty ) {
return function ( ev ) {
var node = ev.target || ev.srcElement, val = ( node || {} ).value || '', field = getAttribute( node, 'data-encrypted-name' );
var node = ev.target || ev.srcElement, val = ( node || {} ).value || '';

var isInitializing = (typeof ev.isInitializing === "boolean" && ev.isInitializing);

Expand All @@ -557,38 +569,65 @@
if ( cse.options[ field + 'IgnoreNonNumeric' ] ) {
val = val.replace( /\D/g, '' );
}

if ( validations[ type + 'Check' ]( val ) ) {
cse.validity[ type ] = true;
removeClass( node, 'invalid-' + type );
addClass( node, 'valid-' + type );

// Prepare to run it through the encryption engine's validation. No longer use double validation
var fieldData = cse.toJSON(cse.getEncryptedFields(cse.element));

var validationData = {
year : fieldData.expiryYear,
month: fieldData.expiryMonth,
number : fieldData.number,
cvc : fieldData.cvc,
holderName : fieldData.holderName
};

var validationResult = cse.encryption.validate(validationData);

if ( validationResult[field] ) {
cse.validity[ field ] = true;
removeClass( node, 'invalid-' + field );
addClass( node, 'valid-' + field );
} else {
cse.validity[ type ] = false;
cse.validity[ field ] = false;

if (!isInitializing || val !== '') {
addClass( node, 'invalid-' + type );
addClass( node, 'invalid-' + field );
}
removeClass( node, 'valid-' + type );
removeClass( node, 'valid-' + field );
}

// Backwards compatibility
cse.validity.luhn = cse.validity.number;

if ( ( node.className || '' ).match( /invalid-number/ ) ) {
addClass(node, 'invalid-luhn');
removeClass(node, 'valid-luhn');
} else if ( ( node.className || '' ).match( /valid-number/ ) ) {
removeClass(node, 'invalid-luhn');
addClass(node, 'valid-luhn');
}

// Continue with regular code

if ( allowEmpty && val === '' ) {
removeClass( node, 'valid-' + type );
removeClass( node, 'invalid-' + type );
removeClass( node, 'valid-' + field );
removeClass( node, 'invalid-' + field );
}

if ( ( node.className || '' ).match( /invalid-/ ) ) {
addClass( node, 'invalid' );
} else {
removeClass( node, 'invalid' );
}

if ( cse.options.disabledValidClass !== true) {
if ( ( node.className || '' ).match( /valid-/ ) ) {
addClass( node, 'valid' );
} else {
if ( ( node.className || '' ).match( /invalid-/ ) ) {
removeClass( node, 'valid' );
}
} else {
addClass( node, 'valid' );
}
}

cse.toggleSubmit();
};
};
Expand Down Expand Up @@ -706,7 +745,7 @@
*/

handleSubmit : function ( e ) {

if ( this.options.enableValidations !== false ) {
if ( !this.isValid() ) {
if ( e.preventDefault ) {
Expand All @@ -724,7 +763,7 @@
return false;
}
}

this.createEncryptedField( this.encrypt() );

this.onsubmit( e );
Expand Down Expand Up @@ -797,7 +836,7 @@
data[ key ] = value;

}

return data;

},
Expand Down Expand Up @@ -849,7 +888,7 @@
if ( !element || !element.getAttribute ) {
continue;
} else if ( element.getAttribute( this.fieldNameAttribute ) === 'number' ) {
handlers.luhnHandler = handlers.luhnHandler || validations.createChangeHandler( cse, 'luhn', true );
handlers.luhnHandler = handlers.luhnHandler || validations.createChangeHandler( cse, 'number', true );
addEvent( element, 'change', handlers.luhnHandler, false );
addEvent( element, 'keyup', handlers.luhnHandler, false );
addEvent( element, 'blur', handlers.luhnHandler, false );
Expand Down
6 changes: 3 additions & 3 deletions js/adyen.encrypt.min.js

Large diffs are not rendered by default.

32 changes: 22 additions & 10 deletions js/adyen.encrypt.nodom.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/adyen.encrypt.nodom.min.js

Large diffs are not rendered by default.

0 comments on commit 4181cdd

Please sign in to comment.