woocommerce/assets/js/jquery-payment/jquery.payment.min.js

1 line
7.6 KiB
JavaScript

jQuery(function(a){(function(){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w=[].slice,x=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};a=jQuery,a.payment={},a.payment.fn={},a.fn.payment=function(){var b,c;return c=arguments[0],b=2<=arguments.length?w.call(arguments,1):[],a.payment.fn[c].apply(this,b)},e=/(\d{1,4})/g,a.payment.cards=d=[{type:"visaelectron",pattern:/^4(026|17500|405|508|844|91[37])/,format:e,length:[16],cvcLength:[3],luhn:!0},{type:"maestro",pattern:/^(5(018|0[23]|[68])|6(39|7))/,format:e,length:[12,13,14,15,16,17,18,19],cvcLength:[3],luhn:!0},{type:"forbrugsforeningen",pattern:/^600/,format:e,length:[16],cvcLength:[3],luhn:!0},{type:"dankort",pattern:/^5019/,format:e,length:[16],cvcLength:[3],luhn:!0},{type:"visa",pattern:/^4/,format:e,length:[13,16],cvcLength:[3],luhn:!0},{type:"mastercard",pattern:/^5[0-5]/,format:e,length:[16],cvcLength:[3],luhn:!0},{type:"amex",pattern:/^3[47]/,format:/(\d{1,4})(\d{1,6})?(\d{1,5})?/,length:[15],cvcLength:[3,4],luhn:!0},{type:"dinersclub",pattern:/^3[0689]/,format:e,length:[14],cvcLength:[3],luhn:!0},{type:"discover",pattern:/^6([045]|22)/,format:e,length:[16],cvcLength:[3],luhn:!0},{type:"unionpay",pattern:/^(62|88)/,format:e,length:[16,17,18,19],cvcLength:[3],luhn:!1},{type:"jcb",pattern:/^35/,format:e,length:[16],cvcLength:[3],luhn:!0}],b=function(a){var b,c,e;for(a=(a+"").replace(/\D/g,""),c=0,e=d.length;e>c;c++)if(b=d[c],b.pattern.test(a))return b},c=function(a){var b,c,e;for(c=0,e=d.length;e>c;c++)if(b=d[c],b.type===a)return b},m=function(a){var b,c,d,e,f,g;for(d=!0,e=0,c=(a+"").split("").reverse(),f=0,g=c.length;g>f;f++)b=c[f],b=parseInt(b,10),(d=!d)&&(b*=2),b>9&&(b-=9),e+=b;return e%10===0},l=function(a){var b;return null!=a.prop("selectionStart")&&a.prop("selectionStart")!==a.prop("selectionEnd")?!0:null!=("undefined"!=typeof document&&null!==document&&null!=(b=document.selection)?b.createRange:void 0)&&document.selection.createRange().text?!0:!1},q=function(b){return setTimeout(function(){var c,d;return c=a(b.currentTarget),d=c.val(),d=d.replace(/\D/g,""),c.val(d)})},o=function(b){return setTimeout(function(){var c,d;return c=a(b.currentTarget),d=c.val(),d=a.payment.formatCardNumber(d),c.val(d)})},h=function(c){var d,e,f,g,h,i,j;return f=String.fromCharCode(c.which),!/^\d+$/.test(f)||(d=a(c.currentTarget),j=d.val(),e=b(j+f),g=(j.replace(/\D/g,"")+f).length,i=16,e&&(i=e.length[e.length.length-1]),g>=i||null!=d.prop("selectionStart")&&d.prop("selectionStart")!==j.length)?void 0:(h=e&&"amex"===e.type?/^(\d{4}|\d{4}\s\d{6})$/:/(?:^|\s)(\d{4})$/,h.test(j)?(c.preventDefault(),setTimeout(function(){return d.val(j+" "+f)})):h.test(j+f)?(c.preventDefault(),setTimeout(function(){return d.val(j+f+" ")})):void 0)},f=function(b){var c,d;return c=a(b.currentTarget),d=c.val(),8!==b.which||null!=c.prop("selectionStart")&&c.prop("selectionStart")!==d.length?void 0:/\d\s$/.test(d)?(b.preventDefault(),setTimeout(function(){return c.val(d.replace(/\d\s$/,""))})):/\s\d?$/.test(d)?(b.preventDefault(),setTimeout(function(){return c.val(d.replace(/\d$/,""))})):void 0},p=function(b){return setTimeout(function(){var c,d;return c=a(b.currentTarget),d=c.val(),d=a.payment.formatExpiry(d),c.val(d)})},i=function(b){var c,d,e;return d=String.fromCharCode(b.which),/^\d+$/.test(d)?(c=a(b.currentTarget),e=c.val()+d,/^\d$/.test(e)&&"0"!==e&&"1"!==e?(b.preventDefault(),setTimeout(function(){return c.val("0"+e+" / ")})):/^\d\d$/.test(e)?(b.preventDefault(),setTimeout(function(){return c.val(""+e+" / ")})):void 0):void 0},j=function(b){var c,d,e;return d=String.fromCharCode(b.which),/^\d+$/.test(d)?(c=a(b.currentTarget),e=c.val(),/^\d\d$/.test(e)?c.val(""+e+" / "):void 0):void 0},k=function(b){var c,d,e;return e=String.fromCharCode(b.which),"/"===e||" "===e?(c=a(b.currentTarget),d=c.val(),/^\d$/.test(d)&&"0"!==d?c.val("0"+d+" / "):void 0):void 0},g=function(b){var c,d;return c=a(b.currentTarget),d=c.val(),8!==b.which||null!=c.prop("selectionStart")&&c.prop("selectionStart")!==d.length?void 0:/\d\s\/\s$/.test(d)?(b.preventDefault(),setTimeout(function(){return c.val(d.replace(/\d\s\/\s$/,""))})):void 0},n=function(b){return setTimeout(function(){var c,d;return c=a(b.currentTarget),d=c.val(),d=d.replace(/\D/g,"").slice(0,4),c.val(d)})},u=function(a){var b;return a.metaKey||a.ctrlKey?!0:32===a.which?!1:0===a.which?!0:a.which<33?!0:(b=String.fromCharCode(a.which),!!/[\d\s]/.test(b))},s=function(c){var d,e,f,g;return d=a(c.currentTarget),f=String.fromCharCode(c.which),/^\d+$/.test(f)&&!l(d)?(g=(d.val()+f).replace(/\D/g,""),e=b(g),e?g.length<=e.length[e.length.length-1]:g.length<=16):void 0},t=function(b){var c,d,e;return c=a(b.currentTarget),d=String.fromCharCode(b.which),/^\d+$/.test(d)&&!l(c)?(e=c.val()+d,e=e.replace(/\D/g,""),e.length>6?!1:void 0):void 0},r=function(b){var c,d,e;return c=a(b.currentTarget),d=String.fromCharCode(b.which),/^\d+$/.test(d)&&!l(c)?(e=c.val()+d,e.length<=4):void 0},v=function(b){var c,e,f,g,h;return c=a(b.currentTarget),h=c.val(),g=a.payment.cardType(h)||"unknown",c.hasClass(g)?void 0:(e=function(){var a,b,c;for(c=[],a=0,b=d.length;b>a;a++)f=d[a],c.push(f.type);return c}(),c.removeClass("unknown"),c.removeClass(e.join(" ")),c.addClass(g),c.toggleClass("identified","unknown"!==g),c.trigger("payment.cardType",g))},a.payment.fn.formatCardCVC=function(){return this.on("keypress",u),this.on("keypress",r),this.on("paste",n),this.on("change",n),this.on("input",n),this},a.payment.fn.formatCardExpiry=function(){return this.on("keypress",u),this.on("keypress",t),this.on("keypress",i),this.on("keypress",k),this.on("keypress",j),this.on("keydown",g),this.on("change",p),this.on("input",p),this},a.payment.fn.formatCardNumber=function(){return this.on("keypress",u),this.on("keypress",s),this.on("keypress",h),this.on("keydown",f),this.on("keyup",v),this.on("paste",o),this.on("change",o),this.on("input",o),this.on("input",v),this},a.payment.fn.restrictNumeric=function(){return this.on("keypress",u),this.on("paste",q),this.on("change",q),this.on("input",q),this},a.payment.fn.cardExpiryVal=function(){return a.payment.cardExpiryVal(a(this).val())},a.payment.cardExpiryVal=function(a){var b,c,d,e;return a=a.replace(/\s/g,""),e=a.split("/",2),b=e[0],d=e[1],2===(null!=d?d.length:void 0)&&/^\d+$/.test(d)&&(c=(new Date).getFullYear(),c=c.toString().slice(0,2),d=c+d),b=parseInt(b,10),d=parseInt(d,10),{month:b,year:d}},a.payment.validateCardNumber=function(a){var c,d;return a=(a+"").replace(/\s+|-/g,""),/^\d+$/.test(a)?(c=b(a),c?(d=a.length,x.call(c.length,d)>=0&&(c.luhn===!1||m(a))):!1):!1},a.payment.validateCardExpiry=function(b,c){var d,e,f;return"object"==typeof b&&"month"in b&&(f=b,b=f.month,c=f.year),b&&c?(b=a.trim(b),c=a.trim(c),/^\d+$/.test(b)&&/^\d+$/.test(c)&&b>=1&&12>=b?(2===c.length&&(c=70>c?"20"+c:"19"+c),4!==c.length?!1:(e=new Date(c,b),d=new Date,e.setMonth(e.getMonth()-1),e.setMonth(e.getMonth()+1,1),e>d)):!1):!1},a.payment.validateCardCVC=function(b,d){var e,f;return b=a.trim(b),/^\d+$/.test(b)?(e=c(d),null!=e?(f=b.length,x.call(e.cvcLength,f)>=0):b.length>=3&&b.length<=4):!1},a.payment.cardType=function(a){var c;return a?(null!=(c=b(a))?c.type:void 0)||null:null},a.payment.formatCardNumber=function(c){var d,e,f,g;return c=c.replace(/\D/g,""),(d=b(c))?(f=d.length[d.length.length-1],c=c.slice(0,f),d.format.global?null!=(g=c.match(d.format))?g.join(" "):void 0:(e=d.format.exec(c),null!=e?(e.shift(),e=a.grep(e,function(a){return a}),e.join(" ")):void 0)):c},a.payment.formatExpiry=function(a){var b,c,d,e;return(c=a.match(/^\D*(\d{1,2})(\D+)?(\d{1,4})?/))?(b=c[1]||"",d=c[2]||"",e=c[3]||"",(e.length>0||d.length>0&&!/\ \/?\ ?/.test(d))&&(d=" / "),1===b.length&&"0"!==b&&"1"!==b&&(b="0"+b,d=" / "),b+d+e):""}}).call(this)});