-
Notifications
You must be signed in to change notification settings - Fork 0
/
atoms.app.stripe.js
1 lines (1 loc) · 3.5 KB
/
atoms.app.stripe.js
1
(function(){"use strict";var __loadScript,__bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__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};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);