-
Notifications
You must be signed in to change notification settings - Fork 0
/
atoms.app.payments.js
executable file
·1 lines (1 loc) · 9.38 KB
/
atoms.app.payments.js
1
(function(){"use strict";var __loadScript,__hasProp={}.hasOwnProperty,__extends=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)__hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},__bind=function(fn,me){return function(){return fn.apply(me,arguments)}};Atoms.Molecule.AccountNumber=function(_super){function AccountNumber(){return AccountNumber.__super__.constructor.apply(this,arguments)}var CODE_LENGTHS,mod97;return __extends(AccountNumber,_super),CODE_LENGTHS={AD:24,AE:23,AT:20,AZ:28,BA:20,BE:16,BG:22,BH:22,BR:29,CH:21,CR:21,CY:28,CZ:24,DE:22,DK:18,DO:28,EE:20,ES:24,FI:18,FO:18,FR:27,GB:22,GI:23,GL:18,GR:27,GT:28,HR:21,HU:28,IE:22,IL:23,IS:26,IT:27,JO:30,KW:30,KZ:20,LB:28,LI:21,LT:20,LU:20,LV:21,MC:27,MD:24,ME:22,MK:19,MR:27,MT:31,MU:30,NL:18,NO:15,PK:24,PL:28,PS:29,PT:25,QA:29,RO:24,RS:22,SA:24,SE:24,SI:19,SK:24,SM:27,TN:24,TR:26},AccountNumber["extends"]=!0,AccountNumber.events=["submit"],AccountNumber["default"]={events:["submit"],children:[{"Atom.Input":{id:"countrycode",type:"text",maxlength:2,placeholder:"Country code",events:["keyup"],required:!0}},{"Atom.Input":{id:"checkdigits",type:"number",maxlength:2,placeholder:"Check digits",events:["keyup"],required:!0}},{"Atom.Input":{id:"bankandoffice",type:"text",maxlength:30,placeholder:"Bank and office",events:["keyup"],required:!0}},{"Atom.Button":{id:"submit",text:"Pay",events:["touch"],style:"fluid accept",disabled:!0}}]},AccountNumber.prototype.setValues=function(attributes){var item,_results;null==attributes&&(attributes={}),_results=[];for(item in attributes)_results.push(this[item].value(attributes[item]));return _results},AccountNumber.prototype.onInputKeyup=function(event,atom){var checked,child,code,digits,iban,_i,_len,_ref;for(checked=!0,_ref=this.children,_i=0,_len=_ref.length;_len>_i;_i++)child=_ref[_i],"Input"===child.constructor.base&&child.error(!1);return atom.value().trim(),atom.value().replace(/\s+/g,""),this.countrycode.value().length>0&&this.checkdigits.value().length>0&&this.bankandoffice.value().length>0&&(iban=this.countrycode.value()+this.checkdigits.value()+this.bankandoffice.value(),iban=String(iban).toUpperCase().replace(/[^A-Z0-9]/g,""),code=iban.match(/^([A-Z]{2})(\d{2})([A-Z\d]+)$/),digits=(code[3]+code[1]+code[2]).replace(/[A-Z]/g,function(letter){return String(letter.charCodeAt(0)-55)})),2!==this.countrycode.value().length?(checked=!1,this.countrycode.value().length>0&&this.countrycode.error(!0)):2!==this.checkdigits.value().length?(checked=!1,this.checkdigits.value().length>0&&this.checkdigits.error(!0)):code&&iban.length===CODE_LENGTHS[code[1]]&&1===mod97(digits)||(checked=!1,this.bankandoffice.value().length>0&&this.bankandoffice.error(!0)),2===this.countrycode.value().length&&CODE_LENGTHS[this.countrycode.value()]&&this.bankandoffice.refresh({maxlength:CODE_LENGTHS[this.countrycode.value()]}),checked?this.submit.el.removeAttr("disabled"):this.submit.el.attr("disabled",!0)},mod97=function(string){var checksum,fragment,offset;if(!string)return 0;for(checksum=string.slice(0,2),offset=2;offset<string.length;)fragment=String(checksum)+string.substring(offset,offset+7),checksum=parseInt(fragment,10)%97,offset+=7;return checksum},AccountNumber}(Atoms.Molecule.Form),Atoms.Molecule.CreditCard=function(_super){function CreditCard(){return CreditCard.__super__.constructor.apply(this,arguments)}var isNumber;return __extends(CreditCard,_super),CreditCard["extends"]=!0,CreditCard.events=["submit"],CreditCard["default"]={events:["submit"],children:[{"Atom.Input":{id:"name",name:"name",type:"text",placeholder:"Credit card name",events:["keyup"],required:!0}},{"Atom.Input":{id:"number",name:"number",type:"tel",maxlength:16,placeholder:"Credit card number",events:["keyup"],required:!0}},{"Atom.Input":{id:"month",name:"month",type:"tel",placeholder:"MM",min:1,max:12,events:["keyup"],required:!0}},{"Atom.Input":{id:"year",name:"year",type:"tel",placeholder:"YYYY",minlength:4,maxlength:4,events:["keyup"],required:!0}},{"Atom.Input":{id:"cvc",name:"cvc",type:"tel",placeholder:"CVC",maxlength:4,events:["keyup"],required:!0}},{"Atom.Button":{id:"submit",text:"Send Payment",events:["touch"],style:"fluid accept",disabled:!0}}]},CreditCard.prototype.setValues=function(attributes){var item,_results;null==attributes&&(attributes={}),_results=[];for(item in attributes)_results.push(this[item].value(attributes[item]));return _results},CreditCard.prototype.onInputKeyup=function(event,atom){var checked,child,_i,_len,_ref,_ref1,_ref2;for(checked=!0,_ref=this.children,_i=0,_len=_ref.length;_len>_i;_i++)child=_ref[_i],"Input"===child.constructor.base&&child.error(!1);return atom.value().trim,atom.value().replace(/\s+/g,""),16===this.number.value().length&&this.validateCreditCard(this.number.value())?isNumber(this.month.value())&&1<=(_ref1=this.month.value())&&12>=_ref1?isNumber(this.year.value())&&(new Date).getFullYear()<=this.year.value()?new Date>=new Date(this.year.value(),this.month.value(),1)?(checked=!1,this.year.value().length>0&&this.year.error(!0),this.month.value().length>0&&this.month.error(!0)):isNumber(this.cvc.value())&&0<=(_ref2=this.cvc.value())&&999>=_ref2?this.name.value().length<4&&(checked=!1,this.name.value().length>0&&this.name.error(!0)):(checked=!1,this.cvc.value().length>0&&this.cvc.error(!0)):(checked=!1,this.year.value().length>0&&this.year.error(!0)):(checked=!1,this.month.value().length>0&&this.month.error(!0)):(checked=!1,this.number.value().length>0&&this.number.error(!0)),checked?this.submit.el.removeAttr("disabled"):this.submit.el.attr("disabled",!0)},CreditCard.prototype.validateCreditCard=function(ccNumb){var bResult,calc,i,iCCN,iTotal,len,sCCN,valid;if(valid="0123456789",len=ccNumb.length,iCCN=parseInt(ccNumb),sCCN=ccNumb.toString(),sCCN=sCCN.replace(/^\s+|\s+$/g,"").trim(),iTotal=0,bResult=!1,isNumber(ccNumb)||(bResult=!1),0===len)bResult=!1;else if(len>=15){for(i=len;i>0;){switch(calc=parseInt(iCCN)%10,calc=parseInt(calc),iTotal+=calc,i--,iCCN/=10,calc=parseInt(iCCN)%10,calc=2*calc){case 10:calc=1;break;case 12:calc=3;break;case 14:calc=5;break;case 16:calc=7;break;case 18:calc=9;break;default:calc=calc}iCCN/=10,iTotal+=calc,i--}bResult=iTotal%10===0?!0:!1}return bResult},isNumber=function(n){return!isNaN(parseFloat(n))&&isFinite(n)},CreditCard}(Atoms.Molecule.Form),Atoms.Molecule.StripeCreditCard=function(_super){function StripeCreditCard(){this.post=__bind(this.post,this),StripeCreditCard.__super__.constructor.apply(this,arguments),0===Atoms.$("[data-extension=stripe]").length&&__loadScript(),this.attributes.amount&&this.submit.el.html((this.attributes.concept||"Pay")+(" "+this.attributes.amount))}return __extends(StripeCreditCard,_super),StripeCreditCard["extends"]=!0,StripeCreditCard.events=["submit","error"],StripeCreditCard["default"]={events:["submit","error"],children:[{"Atom.Input":{id:"number",type:"tel",placeholder:"Credit card number",required:!0,events:["keyup"],maxlength:16}},{"Atom.Input":{id:"month",type:"tel",placeholder:"MM",events:["keyup"],maxlength:2}},{"Atom.Input":{id:"year",type:"tel",placeholder:"YYYY",events:["keyup"],maxlength:4}},{"Atom.Input":{id:"cvc",type:"tel",placeholder:"CVC",events:["keyup"],maxlength:3}},{"Atom.Button":{id:"submit",text:"Send Payment",style:"fluid accept",disabled:!0}}]},StripeCreditCard.prototype.post=function(token){var parameters;return parameters={token:token,amount:this.attributes.amount,reference:this.attributes.reference},$$.ajax({url:this.attributes.url,type:"POST",dataType:"json",data:parameters,contentType:"application/x-www-form-urlencoded",success:function(_this){return function(xhr){return _this.bubble("submit",xhr),"undefined"!=typeof __&&null!==__?__.Dialog.Loading.hide():void 0}}(this),error:function(_this){return function(xhr,error){return _this.bubble("error",error),"undefined"!=typeof __&&null!==__?__.Dialog.Loading.hide():void 0}}(this)})},StripeCreditCard.prototype.onButtonTouch=function(){var parameters;return"undefined"!=typeof __&&null!==__&&__.Dialog.Loading.show(),Stripe.setPublishableKey(this.attributes.key),parameters={number:this.number.value(),cvc:this.cvc.value(),exp_month:this.month.value(),exp_year:this.year.value()},window.Stripe.createToken(parameters,function(_this){return function(status,response){return response.error?("undefined"!=typeof __&&null!==__&&__.Dialog.Loading.hide(),_this.bubble("error",response.error)):_this.post(response.id)}}(this)),!1},StripeCreditCard.prototype.onInputKeyup=function(){var child,valid,_i,_len,_ref;for(valid=!0,_ref=this.children,_i=0,_len=_ref.length;_len>_i;_i++)child=_ref[_i],"Input"===child.constructor.base&&child.error(!1);return this.attributes.url&&this.attributes.key?Stripe.validateCardNumber(this.number.value())?!this.month.value()||isNaN(parseInt(this.month.value()))||this.month.value().length<2||parseInt(this.month.value())>12?(valid=!1,this.month.error(!0)):!this.year.value()||isNaN(parseInt(this.year.value()))||parseInt(this.year.value())<(new Date).getFullYear()?(valid=!1,this.year.error(!0)):Stripe.validateCVC(this.cvc.value())||(valid=!1,this.cvc.error(!0)):(valid=!1,this.number.error(!0)):valid=!1,valid?this.submit.el.removeAttr("disabled"):this.submit.el.attr("disabled",!0),!1},StripeCreditCard}(Atoms.Molecule.Form),__loadScript=function(){var script;return script=document.createElement("script"),script.type="text/javascript",script.src="https://js.stripe.com/v1/",script.setAttribute("data-extension","stripe"),document.body.appendChild(script)}}).call(this);