if(!Array.prototype.indexOf){Array.prototype.indexOf=function(searchElement,fromIndex){if(void 0===this||null===this){throw new TypeError('"this" is null or not defined')}var length=this.length>>>0;fromIndex=+fromIndex||0;if(Math.abs(fromIndex)===1/0){fromIndex=0}if(fromIndex<0){fromIndex+=length;if(fromIndex<0){fromIndex=0}}for(;fromIndex "+serviceName,"services":{"statusService":PagSeguro.DataFortress.statusService},"url":tokenMonitoration})};PagSeguro.DataFortress.onResolve(function(dfServices){services=dfServices;DataFortress.serviceOn=true});PagSeguro.DataFortress.onFail(function(dummyServices){services=dummyServices;DataFortress.serviceOn=false},true)};PagSeguro.DirectPaymentMediator=function(){this.vendor=window.parent;this.sessionId;this.owner="eb2e419f11f74361b337fb30adf61aa5";this.origin="ps-direct-pay";this.dnahash;this.mediator=new PagSeguro.APIMediator({vendor:this.vendor});this.listenChannels();this.setDnaHash($("#senderTrackingHash").val())};PagSeguro.DirectPaymentMediator.prototype={constructor:PagSeguro.DirectPaymentMediator,publish:function(message,channel){this.mediator.postMessage(message,channel)},subscribe:function(channel,callback){this.mediator.acceptMessage(channel,callback)},setSessionId:function(sessionId){this.sessionId=sessionId;this.additionalIframesbyVendor()},setDnaHash:function(hash){var _that=this;if(this.mediator.check("vendor")){this.dnahash=hash;this.publish({command:"setDnaHash",result:hash},"vendor")}else{setTimeout(function(){_that.setDnaHash(hash)},100)}},checkPagSeguroAccepted:function(brand){return"object"==typeof window.acceptedCreditCards&&window.acceptedCreditCards.hasOwnProperty(brand)&&"DISPONIVEL"==window.acceptedCreditCards[brand].status},getAcceptedBrandProperty:function(brand,prop){var _that=this,propValue=false;if(_that.checkPagSeguroAccepted(brand)&&window.acceptedCreditCards[brand].hasOwnProperty(prop)){propValue=window.acceptedCreditCards[brand][prop]}return propValue},getAcceptedBrandConfig:function(brand){return this.getAcceptedBrandProperty(brand,"brandViewConfig")},getBrandService:function(params,callbacks){var _that=this;var doCallback=function(name,data){if("function"==typeof callbacks[name]){callbacks[name](data)}};var treatSuccess=function(serviceData){if(_that.checkPagSeguroAccepted(serviceData.bin.brand.name)){doCallback("success",serviceData.bin)}else{doCallback("error",serviceData)}};DataFortress.callService("getCardData",{data:numberParamsToString(params),success:function(data){treatSuccess(data)},error:function(data){doCallback("error",data)},complete:function(data){doCallback("complete",data)}})},getBrand:function(config){var _that=this;var params={origin:_that.origin||"",tk:_that.sessionId||"",owner:_that.owner||"",creditCard:config.cardBin||"",internationalMode:config.internationalMode||false};var callbacks={error:function(data){_that.publish({result:{error:true},command:"getBrand"},"vendor")},success:function(data){_that.publish({result:{brand:_that.mountBrandDataToVendor(data)},command:"getBrand"},"vendor")}};_that.getBrandService(params,callbacks)},mountBrandDataToVendor:function(serviceData){var _that=this,mountedData={name:serviceData.brand.name,bin:serviceData.bin,cvvSize:serviceData.cvvSize,expirable:"y"===serviceData.expirable?true:false,international:!serviceData.country||"BR"!=serviceData.country.isoCode,validationAlgorithm:serviceData.validationAlgorithm},anchor=serviceData.brand.name;if(_that.getAcceptedBrandConfig(anchor)){mountedData.config=_that.getAcceptedBrandConfig(anchor)}return mountedData},mountErrorDataToVendor:function(serviceData){var errors={};if(serviceData.hasOwnProperty("error")&&serviceData.error.hasOwnProperty("code")&&serviceData.error.hasOwnProperty("message")&&"string"==typeof serviceData.error.message){errors[serviceData.error.code]=serviceData.error.message.toLowerCase()}return errors},createCardTokenService:function(params,callbacks){var _that=this;var doCallback=function(name,data){if("function"==typeof callbacks[name]){callbacks[name](data)}};DataFortress.callService("getTransientToken",{data:numberParamsToString(params),success:function(data){doCallback("success",data)},error:function(data){doCallback("error",data)},complete:function(data){doCallback("complete",data)}})},validateParamsAndGetTransientToken:function(params,callbacks){var _that=this;function launchError(errorData){if("function"==typeof callbacks["complete"]){callbacks["complete"]({error:errorData})}if("function"==typeof callbacks["error"]){callbacks["error"]({error:errorData})}return false}params=numberParamsToString(params);if(""==params.brand||!_that.checkPagSeguroAccepted(params.brand)){return launchError({code:"10000",message:"invalid creditcard brand",status:"invalid_data"})}if(_that.getAcceptedBrandConfig(params.brand).acceptedLengths.indexOf(params.creditCard.length)<0){return launchError({code:"10001",message:"creditcard number with invalid length",status:"invalid_data"})}params.dateMandatory=_that.getAcceptedBrandConfig(params.brand).hasDueDate;if(params.dateMandatory&&(""==params.expMonth||""==params.expYear)){return launchError({code:"10002",message:"invalid date format",status:"invalid_data"})}if(""!=params.tempCvv&&""!=params.tempPassword){return launchError({code:"10003",message:"invalid security field",status:"invalid_data"})}if(_that.getAcceptedBrandConfig(params.brand).hasCvv&&""==params.tempCvv){return launchError({code:"10004",message:"cvv is mandatory",status:"invalid_data"})}if(_that.getAcceptedBrandConfig(params.brand).hasPassword&&""==params.tempPassword){return launchError({code:"10005",message:"password is mandatory",status:"invalid_data"})}params.cvv=params.tempCvv||params.tempPassword||"";delete params.tempCvv;delete params.tempPassword;if(params.cvv.length!=_that.getAcceptedBrandConfig(params.brand).securityFieldLength){return launchError({code:"10006",message:"security field with invalid length",status:"invalid_data"})}_that.createCardTokenService(params,callbacks)},createCardToken:function(config){var _that=this;var callTokenService=function(){var params={origin:_that.origin||"",tk:_that.sessionId||"",owner:_that.owner||"",brand:config.brand||"",creditCard:config.cardNumber||"",tempCvv:config.cvv||"",tempPassword:config.password||""},callbacks={success:function(data){var resultCommand={result:{card:{token:data.token}},command:"createCardToken"};_that.publish(resultCommand,"vendor")},error:function(data){var resultCommand={result:{error:true,errors:_that.mountErrorDataToVendor(data)},command:"createCardToken"};_that.publish(resultCommand,"vendor")}};if(config.expirationMonth&&config.expirationYear){params.expMonth=1==config.expirationMonth.toString().length?"0"+config.expirationMonth:config.expirationMonth;params.expYear=config.expirationYear}else{params.expMonth="";params.expYear=""}_that.validateParamsAndGetTransientToken(params,callbacks)};if(config.brand){callTokenService()}else{var brandParams={origin:_that.origin||"",tk:_that.sessionId||"",owner:_that.owner||"",creditCard:config.cardNumber||"",internationalMode:config.internationalMode||false};this.getBrandService(brandParams,{complete:function(data){if(data.bin&&data.bin.brand){config.brand=data.bin.brand.name}callTokenService()}})}},getInstallments:function(data){var _that=this,amount="";if("NaN"==Number(data.amount).toString()){amount=data.amount}else{amount=(data.amount+"").replace(/^(\d+)\.?(.*)/,function(m,r1,r2){return r1+"."+(r2.length>=2?r2.slice(0,3):r2+new Array(3-r2.length).join("0"))})}var isFeatureEnabled="true"===$("#isFeatureEnabled").val();var resourcePath=isFeatureEnabled?"https://ws.pagseguro.uol.com.br/v2":"https://pagseguro.uol.com.br/checkout/v2";ajax({url:resourcePath+"/installments.json",method:"GET",data:function(){var o={sessionId:_that.sessionId,amount:amount};if(data.brand){o.creditCardBrand=data.brand}if("undefined"!=typeof data.maxInstallmentNoInterest){o.maxInstallmentNoInterest=data.maxInstallmentNoInterest}return o}(),readyState:{4:{200:function(data){_that.getInstallmentsCallback(JSON.parse(data))},404:function(data){_that.getInstallmentsCallback(JSON.parse(data))}}}})},getInstallmentsCallback:function(data){var resultCommand={result:data,command:"getInstallments"};this.publish(resultCommand,"vendor")},getPaymentMethods:function(data){var _that=this;window.callbackPaymentMethods=function(data){_that.getPaymentMethodsCallback(data)};var url="https://ws.pagseguro.uol.com.br/payment-methods?callback=callbackPaymentMethods&sessionId="+_that.sessionId;if(data.status){url+="&status="+data.status}if(data.amount){var amount=Number(data.amount).toFixed(2);if("NaN"==amount){amount=data.amount}url+="&amount="+amount}url+="&Accept=application/vnd.pagseguro.com.br.v1%2Bjson;charset=ISO-8859-1";var script=document.createElement("script");script.setAttribute("type","text/javascript");script.setAttribute("src",url);document.getElementsByTagName("head")[0].appendChild(script)},getPaymentMethodsCallback:function(data){var resultCommand={result:data,command:"getPaymentMethods"};this.publish(resultCommand,"vendor")},additionalIframesbyVendor:function(){var url="https://pagseguro.uol.com.br/checkout/direct-payment/additional-iframes-by-vendor.jhtml";$.ajax({type:"GET",dataType:"json",cache:false,url:url,data:"sessionId="+this.sessionId+"&senderTrackingHash="+this.dnahash,success:function(data){var toAppend="";$(".iframesbyVendor").remove();if(data.length>0){for(var i=0;i'}$("body").append(toAppend)}}})},listenChannels:function(){var _that=this;this.subscribe("vendor",function(data){if(data.command){switch(data.command){case"createCardToken":_that.createCardToken(data.config);break;case"getBrand":_that.getBrand(data.config);break;case"getInstallments":_that.getInstallments(data.config);break;case"getPaymentMethods":_that.getPaymentMethods(data.config);break;case"setSessionId":_that.setSessionId(data.sessionId);break;case"registerVendor":_that.origin=("ps-direct-pay,"+data.url).match(/.{0,50}/).join();tokenMonitoration=data.tokenMonitoration;monitoration({"status":"onReady - back","services":{"sender_tracking_hash ":$("#senderTrackingHash").val(),"DataFortress_services":DataFortress.serviceOn},"url":data.tokenMonitoration});break}}})}};PagSeguro.APIMediator=function(core){var channels={vendor:{context:core.vendor,url:"",callbacks:[]}};this.postMessage=function(message,channel){if(channels[channel]){channels[channel].context.postMessage(JSON.stringify(message),channels[channel].url||"https://pagseguro.uol.com.br")}};this.acceptMessage=function(channel,callback){var _that=this,callbacks=channels[channel].callbacks,jsondata;callbacks[callbacks.length]=function(event){try{jsondata=JSON.parse(event.data)}catch(err){return false}if(jsondata.command){if("registerVendor"==jsondata.command){channels.vendor.url=jsondata.url;_that.postMessage({command:"getReady"},"vendor")}}if(!channels[channel]){return}if(event.origin==channels[channel].url){callback(jsondata)}};window.addListener(window.addEventListener?"message":"onmessage",callbacks[callbacks.length-1])};this.commandDispatch=function(command){var _that=this,commands=channels[channel].commands;commands[commands.length]=function(event){if(!channels[channel]){return}if(event.origin==channels[channel].url){callback(event.data)}};window.addListener(window.addEventListener?"message":"onmessage",callbacks[callbacks.length-1])};this.commandAccept=function(){};this.check=function(channel){if(""!==channels[channel].url){return true}return false};this.ignoreMessage=function(channel){var _that=this,i=channels[channel].callbacks.length;if(channels[channel]){while(i--){window.removeListener(window.removeEventListener?"message":"onmessage",channels[channel].callbacks[i])}}}};window.__DirectPaymentMediator=new PagSeguro.DirectPaymentMediator})();