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

1 line
8.2 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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,x,y=[].slice,z=[].indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1};a=window.jQuery||window.Zepto||window.$,a.payment={},a.payment.fn={},a.fn.payment=function(){var b,c;return c=arguments[0],b=2<=arguments.length?y.call(arguments,1):[],a.payment.fn[c].apply(this,b)},e=/(\d{1,4})/g,a.payment.cards=d=[{type:"maestro",patterns:[5018,502,503,506,56,58,639,6220,67],format:e,length:[12,13,14,15,16,17,18,19],cvcLength:[3],luhn:!0},{type:"forbrugsforeningen",patterns:[600],format:e,length:[16],cvcLength:[3],luhn:!0},{type:"dankort",patterns:[5019],format:e,length:[16],cvcLength:[3],luhn:!0},{type:"visa",patterns:[4],format:e,length:[13,16],cvcLength:[3],luhn:!0},{type:"mastercard",patterns:[51,52,53,54,55,22,23,24,25,26,27],format:e,length:[16],cvcLength:[3],luhn:!0},{type:"amex",patterns:[34,37],format:/(\d{1,4})(\d{1,6})?(\d{1,5})?/,length:[15],cvcLength:[3,4],luhn:!0},{type:"dinersclub",patterns:[30,36,38,39],format:/(\d{1,4})(\d{1,6})?(\d{1,4})?/,length:[14],cvcLength:[3],luhn:!0},{type:"discover",patterns:[60,64,65,622],format:e,length:[16],cvcLength:[3],luhn:!0},{type:"unionpay",patterns:[62,88],format:e,length:[16,17,18,19],cvcLength:[3],luhn:!1},{type:"jcb",patterns:[35],format:e,length:[16],cvcLength:[3],luhn:!0}],b=function(a){var b,c,e,f,g,h,i,j;for(a=(a+"").replace(/\D/g,""),f=0,h=d.length;f<h;f++)for(b=d[f],j=b.patterns,g=0,i=j.length;g<i;g++)if(e=j[g],c=e+"",a.substr(0,c.length)===c)return b},c=function(a){var b,c,e;for(c=0,e=d.length;c<e;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;f<g;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")||!(null==("undefined"!=typeof document&&null!==document&&null!=(b=document.selection)?b.createRange:void 0)||!document.selection.createRange().text)},w=function(a,b){var c,d,e,f,g,h;try{d=b.prop("selectionStart")}catch(a){f=a,d=null}if(g=b.val(),b.val(a),null!==d&&b.is(":focus"))return d===g.length&&(d=a.length),g!==a&&(h=g.slice(d-1,+d+1||9e9),c=a.slice(d-1,+d+1||9e9),e=a[d],/\d/.test(e)&&h===""+e+" "&&c===" "+e&&(d+=1)),b.prop("selectionStart",d),b.prop("selectionEnd",d)},r=function(a){var b,c,d,e,f,g,h,i;for(null==a&&(a=""),d="",e="0123456789",g="",b=a.split(""),h=0,i=b.length;h<i;h++)c=b[h],f=d.indexOf(c),f>-1&&(c=e[f]),g+=c;return g},q=function(b){var c;return c=a(b.currentTarget),setTimeout(function(){var a;return a=c.val(),a=r(a),a=a.replace(/\D/g,""),w(a,c)})},o=function(b){var c;return c=a(b.currentTarget),setTimeout(function(){var b;return b=c.val(),b=r(b),b=a.payment.formatCardNumber(b),w(b,c)})},h=function(c){var d,e,f,g,h,i,j;if(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)))return 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;if(c=a(b.currentTarget),d=c.val(),8===b.which&&(null==c.prop("selectionStart")||c.prop("selectionStart")===d.length))return/\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){var c;return c=a(b.currentTarget),setTimeout(function(){var b;return b=c.val(),b=r(b),b=a.payment.formatExpiry(b),w(b,c)})},i=function(b){var c,d,e;if(d=String.fromCharCode(b.which),/^\d+$/.test(d))return 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(){var a,b;return a=parseInt(e[0],10),b=parseInt(e[1],10),b>2&&0!==a?c.val("0"+a+" / "+b):c.val(""+e+" / ")})):void 0},j=function(b){var c,d,e;if(d=String.fromCharCode(b.which),/^\d+$/.test(d))return c=a(b.currentTarget),e=c.val(),/^\d\d$/.test(e)?c.val(""+e+" / "):void 0},k=function(b){var c,d,e;if(e=String.fromCharCode(b.which),"/"===e||" "===e)return c=a(b.currentTarget),d=c.val(),/^\d$/.test(d)&&"0"!==d?c.val("0"+d+" / "):void 0},g=function(b){var c,d;if(c=a(b.currentTarget),d=c.val(),8===b.which&&(null==c.prop("selectionStart")||c.prop("selectionStart")===d.length))return/\d\s\/\s$/.test(d)?(b.preventDefault(),setTimeout(function(){return c.val(d.replace(/\d\s\/\s$/,""))})):void 0},n=function(b){var c;return c=a(b.currentTarget),setTimeout(function(){var a;return a=c.val(),a=r(a),a=a.replace(/\D/g,"").slice(0,4),w(a,c)})},v=function(a){var b;return!(!a.metaKey&&!a.ctrlKey)||32!==a.which&&(0===a.which||(a.which<33||(b=String.fromCharCode(a.which),!!/[\d\s]/.test(b))))},t=function(c){var d,e,f,g;if(d=a(c.currentTarget),f=String.fromCharCode(c.which),/^\d+$/.test(f)&&!l(d))return g=(d.val()+f).replace(/\D/g,""),e=b(g),e?g.length<=e.length[e.length.length-1]:g.length<=16},u=function(b){var c,d,e;if(c=a(b.currentTarget),d=String.fromCharCode(b.which),/^\d+$/.test(d)&&!l(c))return e=c.val()+d,e=e.replace(/\D/g,""),!(e.length>6)&&void 0},s=function(b){var c,d,e;if(c=a(b.currentTarget),d=String.fromCharCode(b.which),/^\d+$/.test(d)&&!l(c))return e=c.val()+d,e.length<=4},x=function(b){var c,e,f,g,h;if(c=a(b.currentTarget),h=c.val(),g=a.payment.cardType(h)||"unknown",!c.hasClass(g))return e=function(){var a,b,c;for(c=[],a=0,b=d.length;a<b;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",v),this.on("keypress",s),this.on("paste",n),this.on("change",n),this.on("input",n),this},a.payment.fn.formatCardExpiry=function(){return this.on("keypress",v),this.on("keypress",u),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",v),this.on("keypress",t),this.on("keypress",h),this.on("keydown",f),this.on("keyup",x),this.on("paste",o),this.on("change",o),this.on("input",o),this.on("input",x),this},a.payment.fn.restrictNumeric=function(){return this.on("keypress",v),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 e=a.split(/[\s\/]+/,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,z.call(c.length,d)>=0&&(c.luhn===!1||m(a))))},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)&&(1<=b&&b<=12&&(2===c.length&&(c=c<70?"20"+c:"19"+c),4===c.length&&(e=new Date(c,b),d=new Date,e.setMonth(e.getMonth()-1),e.setMonth(e.getMonth()+1,1),e>d)))))},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,z.call(e.cvcLength,f)>=0):b.length>=3&&b.length<=4)},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=" / ":" /"===d?(b=b.substring(0,1),d=""):2===b.length||d.length>0?d=" / ":1===b.length&&"0"!==b&&"1"!==b&&(b="0"+b,d=" / "),b+d+e):""}}).call(this)});