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

Commit

Permalink
Version 0_1_13
Browse files Browse the repository at this point in the history
* Add validation for the card holder name
* Remove window dependency from the `nodom` variant
* Add `valid` class for valid fields ( can be disabled by setting
`options.disabledValidClass` )
  • Loading branch information
ArnoudAdyen committed Jun 29, 2015
1 parent 373e146 commit fb2f736
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 35 deletions.
21 changes: 16 additions & 5 deletions Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,43 @@

The `createEncryption ( key , `*`options`*` )` and `createEncryptedForm ( form, key, `*`options`*` )` methods currently support the following fields.

* **string `[name = 'adyen-encrypted-data'] `**

The field name of the field that should contain the adyen encrypted data block.

* **string `[fieldNameAttribute = 'data-encrypted-name']`** - *since version: 0_1_10*

Configure the attribute to identify fields to be encrypted. Useful when you have multiple payment options within the same form, and want to bind each set to it's own CSE handler.

* **boolean `[enableValidations = true] `**

Enable basic field validations. Disable the submit button when the form is not valid

* **boolean `[submitButtonAlwaysEnabled = false]`**

Force the submit button to be enabled, even when the front-end validation fails.

* **boolean `[disabledValidClass = false]`** - *since version: 0_1_13*

The validation will add a `valid` class for valid fields, next to the `invalid` css class.

This flag can be used to disable the addition of the `valid` class to the input elements

* **boolean `[numberIgnoreNonNumeric = true]`**

When validating the credit card number, ignore non numeric characters like spaces

* **string `[fieldNameAttribute = 'data-encrypted-name']`**

Configure the attribute to identify fields to be encrypted. Useful when you have multiple payment options within the same form, and want to bind each set to it's own CSE handler.

* **function `[onsubmit]`**

Custom handler to be called on submit of the form.

The callback function will be executed after encryption has taken place, and will receive the original submit event as it's first argument.

* **HTMLElement `[cardTypeElement]`**

Placeholder element to place card type detection results on, when the card type detection addon is enabled.

* **string `[cvcIgnoreBins = '']`**
* **string `[cvcIgnoreBins = '']`** - *since version: 0_1_11*

A comma separated string of bins for which the CVC code validation should be ignored.

Expand Down
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_13
-------

* Add validation for the card holder name

* Remove window dependency from the `nodom` variant

* Add `valid` class for valid fields ( can be disabled by setting `options.disabledValidClass` )

JavaScript version 0_1_12
-------

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_12"></script>
<script type="text/javascript" src="js/adyen.encrypt.nodom.min.js?0_1_13"></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_12"></script>
<script type="text/javascript" src="js/adyen.encrypt.min.js?0_1_13"></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_11',
version : '0_1_13',
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.

67 changes: 53 additions & 14 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_12
* Version: 0_1_13
* 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_12"></script>
<script type="text/javascript" src="js/adyen.encrypt.min.js?0_1_13"></script>
<script type="text/javascript">
Expand Down Expand Up @@ -164,7 +164,7 @@
(function(a){var b=a.codec.bytes=a.codec.bytes||{};b.fromBits=b.fromBits||function(c){var d=[],g=a.bitArray.bitLength(c),f,e;for(f=0;f<g/8;f++){if((f&3)===0){e=c[f/4]}d.push(e>>>24);e<<=8}return d};b.toBits=b.toBits||function(c){var d=[],f,e=0;for(f=0;f<c.length;f++){e=e<<8|c[f];if((f&3)===3){d.push(e);e=0}}if(f&3){d.push(a.bitArray.partial(8*(f&3),e))}return d}}(sjcl));

/* adyen.eventlog.js */
var evLog;(function(){function a(c,d,e,b){if(typeof c.addEventListener==="function"){c.addEventListener(d,e,b)}else{if(c.attachEvent){c.attachEvent("on"+d,e)}else{throw new Error(encrypt.errors.UNABLETOBIND+": Unable to bind "+d+"-event")}}}evLog=evLog||(function(){var b={};return function(f,e,c){if(f==="bind"){evLog(c+"Bind");a(e,"change",function(){evLog(c+"FieldChangeCount");evLog("log",c,"ch")},true);a(e,"click",function(){evLog(c+"FieldClickCount");evLog("log",c,"cl")},true);a(e,"focus",function(){evLog(c+"FieldFocusCount");evLog("log",c,"fo")},true);a(e,"blur",function(){evLog(c+"FieldBlurCount");evLog("log",c,"bl")},true);a(e,"keyup",function(h){if(h.keyCode==16){evLog("log",c,"Su")}else{if(h.keyCode==17){evLog("log",c,"Cu")}else{if(h.keyCode==18){evLog("log",c,"Au")}}}});a(e,"keydown",function(h){evLog(c+"FieldKeyCount");switch(h&&h.keyCode){case 8:evLog("log",c,"Kb");break;case 16:evLog("log",c,"Sd");break;case 17:evLog("log",c,"Cd");break;case 18:evLog("log",c,"Ad");break;case 37:evLog("log",c,"Kl");break;case 39:evLog("log",c,"Kr");break;case 46:evLog("log",c,"Kd");break;case 32:evLog("log",c,"Ks");break;default:if(h.keyCode>=48&&h.keyCode<=57||h.keyCode>=96&&h.keyCode<=105){evLog("log",c,"KN")}else{if(h.keyCode>=65&&h.keyCode<=90){evLog("log",c,"KL")}}break}},true);return}if(f==="set"){b[e]=c;return}if(f==="log"){var g=e+"FieldLog";if(!b.hasOwnProperty(g)){b[g]=c}else{b[g]+=","+c}if(b[g].length>1500){b[g]=b[g].substring(b[g].length-1500)}return}if(f==="extend"){for(var d in b){if(d==="number"||d==="expiryMonth"||d==="expiryYear"||d==="generationtime"||d==="holderName"||d==="cvc"){continue}if(b.hasOwnProperty(d)){e[d]=""+b[d]}}return}if(!b.hasOwnProperty(f)){b[f]=1}else{b[f]++}}})();a(window,"focus",function(){evLog("activate")});a(window,"blur",function(){evLog("deactivate")})}());
var evLog;(function(){function a(c,d,e,b){if(typeof c.addEventListener==="function"){c.addEventListener(d,e,b)}else{if(c.attachEvent){c.attachEvent("on"+d,e)}else{throw new Error(encrypt.errors.UNABLETOBIND+": Unable to bind "+d+"-event")}}}evLog=evLog||(function(){var b={};return function(f,e,c){if(f==="bind"){evLog(c+"Bind");a(e,"change",function(){evLog(c+"FieldChangeCount");evLog("log",c,"ch")},true);a(e,"click",function(){evLog(c+"FieldClickCount");evLog("log",c,"cl")},true);a(e,"focus",function(){evLog(c+"FieldFocusCount");evLog("log",c,"fo")},true);a(e,"blur",function(){evLog(c+"FieldBlurCount");evLog("log",c,"bl")},true);a(e,"keyup",function(h){if(h.keyCode==16){evLog("log",c,"Su")}else{if(h.keyCode==17){evLog("log",c,"Cu")}else{if(h.keyCode==18){evLog("log",c,"Au")}}}});a(e,"keydown",function(h){evLog(c+"FieldKeyCount");switch(h&&h.keyCode){case 8:evLog("log",c,"Kb");break;case 16:evLog("log",c,"Sd");break;case 17:evLog("log",c,"Cd");break;case 18:evLog("log",c,"Ad");break;case 37:evLog("log",c,"Kl");break;case 39:evLog("log",c,"Kr");break;case 46:evLog("log",c,"Kd");break;case 32:evLog("log",c,"Ks");break;default:if(h.keyCode>=48&&h.keyCode<=57||h.keyCode>=96&&h.keyCode<=105){evLog("log",c,"KN")}else{if(h.keyCode>=65&&h.keyCode<=90){evLog("log",c,"KL")}}break}},true);return}if(f==="set"){b[e]=c;return}if(f==="log"){var g=e+"FieldLog";if(!b.hasOwnProperty(g)){b[g]=c}else{b[g]+=","+c}if(b[g].length>1500){b[g]=b[g].substring(b[g].length-1500)}return}if(f==="extend"){for(var d in b){if(d==="number"||d==="expiryMonth"||d==="expiryYear"||d==="generationtime"||d==="holderName"||d==="cvc"){continue}if(b.hasOwnProperty(d)){e[d]=""+b[d]}}return}if(!b.hasOwnProperty(f)){b[f]=1}else{b[f]++}}})();if(window&&(window.attachEvent||window.addEventListener)){a(window,"focus",function(){evLog("activate")});a(window,"blur",function(){evLog("deactivate")})}}());

/* adyen */
var adyen = root.adyen = root.adyen || {};
Expand Down Expand Up @@ -232,7 +232,7 @@
}


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


/*
Expand Down Expand Up @@ -357,6 +357,10 @@
validations.monthCheck = function ( val ) {
return (val && val.match && val.match( /^\d{2}$/ ) && parseInt( val, 10 ) >= 1 && parseInt( val, 10 ) <= 12) ? true : false;
};

validations.holderNameCheck = function ( val ) {
return (val && val.match && val.match(/\S/)) ? true : false;
};

var Encryption = function ( key, options ) {
try {
Expand Down Expand Up @@ -391,8 +395,8 @@
this.options.cvcIgnoreFornumber = new RegExp("^\\s*(" + binsToIgnore.join("|") + ")");
}

} else if (typeof this.options.ignoreCvcBins !== "undefined" ) {
delete this.options.ignoreCvcBins;
} else if (typeof this.options.cvcIgnoreBins !== "undefined" ) {
delete this.options.cvcIgnoreBins;
}

evLog("initializeCount");
Expand Down Expand Up @@ -421,7 +425,7 @@

return rsa;

}
};

/*
* Creates an AES key.
Expand Down Expand Up @@ -520,6 +524,10 @@
result.month = validations.monthCheck( val );
result.valid = result.valid && result.month;
break;
case 'holderName':
result.holderName = validations.holderNameCheck(val)
result.valid = result.valid && result.holderName;
break;
default:
result.unknown = result.unknown || [];
result.unknown.push( field );
Expand All @@ -539,7 +547,9 @@
validations.createChangeHandler = function ( cse, type, allowEmpty ) {
return function ( ev ) {
var node = ev.target || ev.srcElement, val = ( node || {} ).value || '', field = getAttribute( node, 'data-encrypted-name' );


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

if ( node.options && typeof node.selectedIndex !== 'undefined' ) {
val = node.options[ node.selectedIndex ].value;
}
Expand All @@ -554,9 +564,13 @@
addClass( node, 'valid-' + type );
} else {
cse.validity[ type ] = false;
addClass( node, 'invalid-' + type );

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

if ( allowEmpty && val === '' ) {
removeClass( node, 'valid-' + type );
removeClass( node, 'invalid-' + type );
Expand All @@ -567,6 +581,14 @@
} else {
removeClass( node, 'invalid' );
}

if ( cse.options.disabledValidClass !== true) {
if ( ( node.className || '' ).match( /valid-/ ) ) {
addClass( node, 'valid' );
} else {
removeClass( node, 'valid' );
}
}
cse.toggleSubmit();
};
};
Expand Down Expand Up @@ -666,7 +688,7 @@
* @param node {DOMNode} @param attrName {String}
*
*/
hasAttribute : document.documentElement.hasAttribute ? function ( node, attrName ) {
hasAttribute : (document && document.documentElement && document.documentElement.hasAttribute) ? function ( node, attrName ) {
// Native support
return node.hasAttribute( attrName );
} : function ( node, attrName ) {
Expand Down Expand Up @@ -830,29 +852,46 @@
handlers.luhnHandler = handlers.luhnHandler || validations.createChangeHandler( cse, 'luhn', true );
addEvent( element, 'change', handlers.luhnHandler, false );
addEvent( element, 'keyup', handlers.luhnHandler, false );
addEvent( element, 'blur', handlers.luhnHandler, false );
handlers.luhnHandler( {
target : element
target : element,
isInitializing : true
} );
} else if ( element.getAttribute( this.fieldNameAttribute ) === 'cvc' ) {
handlers.cvcHandler = handlers.cvcHandler || validations.createChangeHandler( cse, 'cvc', true );
addEvent( element, 'change', handlers.cvcHandler, false );
addEvent( element, 'keyup', handlers.cvcHandler, false );
addEvent( element, 'blur', handlers.cvcHandler, false );
handlers.cvcHandler( {
target : element
target : element,
isInitializing : true
} );
} else if ( element.getAttribute( this.fieldNameAttribute ) === 'expiryYear' ) {
handlers.expiryYearHandler = handlers.expiryYearHandler || validations.createChangeHandler( cse, 'year', true );
addEvent( element, 'change', handlers.expiryYearHandler, false );
addEvent( element, 'keyup', handlers.expiryYearHandler, false );
addEvent( element, 'blur', handlers.expiryYearHandler, false );
handlers.expiryYearHandler( {
target : element
target : element,
isInitializing : true
} );
} else if ( element.getAttribute( this.fieldNameAttribute ) === 'expiryMonth' ) {
handlers.expiryMonthHandler = handlers.expiryMonthHandler || validations.createChangeHandler( cse, 'month', true );
addEvent( element, 'change', handlers.expiryMonthHandler, false );
addEvent( element, 'keyup', handlers.expiryMonthHandler, false );
addEvent( element, 'blur', handlers.expiryMonthHandler, false );
handlers.expiryMonthHandler( {
target : element
target : element,
isInitializing : true
} );
} else if ( element.getAttribute( this.fieldNameAttribute ) === 'holderName' ) {
handlers.holderNameHandler = handlers.holderNameHandler || validations.createChangeHandler( cse, 'holderName', false );
addEvent( element, 'change', handlers.holderNameHandler, false );
addEvent( element, 'keyup', handlers.holderNameHandler, false );
addEvent( element, 'blur', handlers.holderNameHandler, false );
handlers.holderNameHandler( {
target : element,
isInitializing : true
} );
}
}
Expand Down
6 changes: 3 additions & 3 deletions js/adyen.encrypt.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit fb2f736

Please sign in to comment.