Created
July 15, 2020 21:28
-
-
Save brunitob/1318f271f905e95897dbf18e5f02cec0 to your computer and use it in GitHub Desktop.
backup mercadopago.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function(){!function(){if("undefined"!=typeof window.XMLHttpRequest.open){var e=new XMLHttpRequest;e.open("GET","https://api.mercadopago.com/preconnect",!0),e.send()}}(),window.mobilecheck=function(){var e=!1;return function(t){(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0,4)))&&(e=!0)}(navigator.userAgent||navigator.vendor||window.opera),e},String.prototype.trim||!function(){var e=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;String.prototype.trim=function(){return this.replace(e,"")}}();var JSON=JSON||{};JSON.parse||!function(){JSON.parse=function(obj){"use strict";return eval("("+obj+")")}}(),JSON.stringify||!function(){JSON.stringify=function(e){var t=typeof e;if("object"!=t||null===e)return"string"==t&&(e='"'+e+'"'),String(e);var n,r,i=[],o=e&&e.constructor==Array;for(n in e)r=e[n],t=typeof r,"string"==t?r='"'+r+'"':"object"==t&&null!==r&&(r=JSON.stringify(r)),"function"!==t&&i.push((o?"":'"'+n+'":')+String(r));return(o?"[":"{")+String(i)+(o?"]":"}")}}(),Array.prototype.filter||!function(){Array.prototype.filter=function(e){"use strict";if(void 0===this||null===this)throw new TypeError;var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=[],i=arguments.length>=2?arguments[1]:void 0,o=0;n>o;o++)if(o in t){var a=t[o];e.call(i,a,o,t)&&r.push(a)}return r}}(),Array.prototype.forEach||(Array.prototype.forEach=function(e,t){"use strict";var n,r;if(null==this)throw new TypeError("this is null or not defined");var i,o=Object(this),a=o.length>>>0;if("[object Function]"!=={}.toString.call(e))throw new TypeError(e+" is not a function");for(arguments.length>=2&&(n=t),r=0;a>r;)r in o&&(i=o[r],e.call(n,i,r,o)),r++}),document.querySelectorAll||!function(){document.querySelectorAll=function(e){var t,n=document.createElement("style"),r=[];for(document.documentElement.firstChild.appendChild(n),document._qsa=[],n.styleSheet.cssText=e+"{x-qsa:expression(document._qsa && document._qsa.push(this))}",window.scrollBy(0,0),n.parentNode.removeChild(n);document._qsa.length;)t=document._qsa.shift(),t.style.removeAttribute("x-qsa"),r.push(t);return document._qsa=null,r}}(),document.querySelector||!function(){document.querySelector=function(e){var t=document.querySelectorAll(e);return t.length?t[0]:null}}(),Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:function(e){"use strict";if(void 0===e||null===e)throw new TypeError("Cannot convert first argument to object");for(var t=Object(e),n=1;n<arguments.length;n++){var r=arguments[n];if(void 0!==r&&null!==r){r=Object(r);for(var i=Object.keys(Object(r)),o=0,a=i.length;a>o;o++){var c=i[o],u=Object.getOwnPropertyDescriptor(r,c);void 0!==u&&u.enumerable&&(t[c]=r[c])}}}return t}}),Promise||!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(this,function(){"use strict";function e(e){var t=this.constructor;return this.then(function(n){return t.resolve(e()).then(function(){return n})},function(n){return t.resolve(e()).then(function(){return t.reject(n)})})}function t(e){return Boolean(e&&"undefined"!=typeof e.length)}function n(){}function r(e,t){return function(){e.apply(t,arguments)}}function i(e){if(!(this instanceof i))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],s(e,this)}function o(e,t){for(;3===e._state;)e=e._value;return 0===e._state?void e._deferreds.push(t):(e._handled=!0,void i._immediateFn(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null===n)return void(1===e._state?a:c)(t.promise,e._value);var r;try{r=n(e._value)}catch(i){return void c(t.promise,i)}a(t.promise,r)}))}function a(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof i)return e._state=3,e._value=t,void u(e);if("function"==typeof n)return void s(r(n,t),e)}e._state=1,e._value=t,u(e)}catch(o){c(e,o)}}function c(e,t){e._state=2,e._value=t,u(e)}function u(e){2===e._state&&0===e._deferreds.length&&i._immediateFn(function(){e._handled||i._unhandledRejectionFn(e._value)});for(var t=0,n=e._deferreds.length;n>t;t++)o(e,e._deferreds[t]);e._deferreds=null}function d(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}function s(e,t){var n=!1;try{e(function(e){n||(n=!0,a(t,e))},function(e){n||(n=!0,c(t,e))})}catch(r){if(n)return;n=!0,c(t,r)}}var l=setTimeout;i.prototype["catch"]=function(e){return this.then(null,e)},i.prototype.then=function(e,t){var r=new this.constructor(n);return o(this,new d(e,t,r)),r},i.prototype["finally"]=e,i.all=function(e){return new i(function(n,r){function i(e,t){try{if(t&&("object"==typeof t||"function"==typeof t)){var c=t.then;if("function"==typeof c)return void c.call(t,function(t){i(e,t)},r)}o[e]=t,0===--a&&n(o)}catch(u){r(u)}}if(!t(e))return r(new TypeError("Promise.all accepts an array"));var o=Array.prototype.slice.call(e);if(0===o.length)return n([]);for(var a=o.length,c=0;c<o.length;c++)i(c,o[c])})},i.resolve=function(e){return e&&"object"==typeof e&&e.constructor===i?e:new i(function(t){t(e)})},i.reject=function(e){return new i(function(t,n){n(e)})},i.race=function(e){return new i(function(n,r){if(!t(e))return r(new TypeError("Promise.race accepts an array"));for(var o=0,a=e.length;a>o;o++)i.resolve(e[o]).then(n,r)})},i._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){l(e,0)},i._unhandledRejectionFn=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var f=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")}();"Promise"in f?f.Promise.prototype["finally"]||(f.Promise.prototype["finally"]=e):f.Promise=i})}(),function(){var e={version:"1.3.1",initialized:!1,initializedInsights:!1,key:null,deviceProfileId:null,tokenId:null,sessionId:null},t={utils:{},card:{},request:{},paymentMethods:{}},n=[];e.referer=function(){var e=window.location.protocol+"//"+window.location.hostname+(window.location.port?":"+window.location.port:"");return e}(),e.setPublishableKey=function(t){e.key=t,e.initMercadopago()},function(e){"use strict";var t={baseUrl:"https://api.mercadopago.com/v1"};t.clear=function(e){return(""+e).trim().replace(/\s+|-/g,"")},t.paramsForm=function(e){var t={},n=e.querySelectorAll("[data-checkout]");return Array.prototype.forEach.call(n,function(e){var n=e.getAttribute("data-checkout"),r=e.selectedIndex;t[n]="SELECT"===e.nodeName&&null!==r&&-1!==r?e.options[r].value:e.value}),t},t.isEmpty=function(e){var t=Object.prototype.hasOwnProperty;if(null==e)return!0;if(e.length>0)return!1;if(0===e.length)return!0;for(var n in e)if(t.call(e,n))return!1;return!0},e.utils=t}(t),function(e,t){function n(t){function n(){{var e,a=r?new XDomainRequest:new XMLHttpRequest;(new Date).getTime()}return a.open(t.method,t.url,!0),a.timeout=t.timeout||1e3,window.XDomainRequest?(a.onload=function(){e=JSON.parse(a.responseText),"function"==typeof t.success&&t.success("POST"===t.requestedMethod?201:200,e),"function"==typeof t.complete&&t.complete("POST"===t.requestedMethod?201:200,e)},a.onerror=a.ontimeout=function(){return i>0?(i--,o++,setTimeout(n,500)):("function"==typeof t.error&&t.error(400,{user_agent:window.navigator.userAgent,error:"bad_request",cause:[]}),void("function"==typeof t.complete&&t.complete(400,{user_agent:window.navigator.userAgent,error:"bad_request",cause:[]})))},a.onprogress=function(){}):(a.setRequestHeader("Accept","application/json"),-1!==t.url.indexOf("https://api.mercadopago.com/v1/card_tokens")&&(window.mobilecheck()?a.setRequestHeader("X-Product-Id","BCLQ07IBVKH001FP9VCG"):a.setRequestHeader("X-Product-Id","BCHJ1GABVKH001FP9V4G")),t.contentType?a.setRequestHeader("Content-Type",t.contentType):a.setRequestHeader("Content-Type","application/json"),a.onreadystatechange=function(){if(4===this.readyState){{0==o?t.id:t.id+"_retry"}if(this.status>=200&&this.status<400)e=JSON.parse(this.responseText),"function"==typeof t.success&&t.success(this.status,e),"function"==typeof t.complete&&t.complete(this.status,e);else if(this.status>=400&&this.status<500)e=JSON.parse(this.responseText),"function"==typeof t.error&&t.error(this.status,e),"function"==typeof t.complete&&t.complete(this.status,e);else if(this.status>=500){if(i>0)return i--,o++,setTimeout(n,500);e=JSON.parse(this.responseText),"function"==typeof t.error&&t.error(this.status,e),"function"==typeof t.complete&&t.complete(this.status,e)}else{if(i>0)return i--,o++,setTimeout(n,500);"function"==typeof t.error&&t.error(503,{}),"function"==typeof t.complete&&t.complete(503,{})}}}),0==i&&o>0?(a.abort(),!1):void("GET"===t.method||null==t.data||void 0==t.data?a.send():a.send(JSON.stringify(t.data)))}var r=!!window.XDomainRequest,i=parseInt(t.retries,10);i=isNaN(i)||1>i?2:i,i++;var o=0;t.url+=(t.url.indexOf("?")>=0?"&":"?")+"referer="+escape(e.referer),t.requestedMethod=t.method,r&&"PUT"==t.method&&(t.method="POST",t.url+="&_method=PUT"),t.id=t.id||"ajax",n()}t.request.AJAX=n,e.AJAX=n}(e,t),function(e,t){t.request,t.utils}(e,t),function(e,t){function r(t,n){var r=o.baseUrl+"/payment_methods/search?public_key="+e.key+"&marketplace=NONE&status=active&js_version="+e.version;t.bin?r+="&bins="+t.bin:t.payment_method_id&&(r+="&id="+t.payment_method_id),a.AJAX({id:"searchPaymentMethodsByBin",method:"GET",url:r,timeout:1e4,error:function(e,t){"function"==typeof n?n(e,t):null},success:function(e,t){"function"==typeof n?n(e,t):null}})}function i(e){for(var t=[],n=[],r=0;r<e.length;r++)for(var i=e[r],o=0;o<d.length;o++){var a=d[o];if(a.id===i.id&&a.payment_type_id===i.payment_type_id&&!n[i.id+i.payment_type_id]){var c=JSON.parse(JSON.stringify(a));c.settings=i.settings,t.push(c),n[i.id+i.payment_type_id]=!0;break}}return t}var o=t.utils,a=t.request,c={},u={},d=[],s={},l={};l.validateBinPattern=function(e,t){var n=e.slice(0,6);return!(!t||!t.bin||(n.match(t.bin.pattern)?0:1)||t.bin.exclusion_pattern&&n.match(t.bin.exclusion_pattern))},l.setPaymentMethods=function(e){d=e},l.getPaymentMethods=function(){return d},l.getPaymentMethod=function(t,a){if(!e.initialized)return n.push({method:"getPaymentMethod",args:arguments});t.bin&&(t.bin=o.clear(t.bin).replace(/[^0-9]/g,"").slice(0,6));var u=t.bin||t.payment_method_id;return u?c&&c[u]?"function"==typeof a?a(200,c[u]):null:r(t,function(e,t){var n=e,r=t;return 200===e&&t&&(t.results&&t.results.length>0?(r=i(t.results),c[u]=r):(n=400,r={message:"payment method not found",error:"bad_request",status:400,cause:[]})),"function"==typeof a?a(n,r):null}):"function"==typeof a?a(400,{status:400,error:"bad_request",cause:{code:"2000",description:"the payment_method_id or bin are required"}},t):null},l.getAllPaymentMethods=function(t){var n=o.baseUrl+"/payment_methods?public_key="+e.key+"&js_version="+e.version;document.querySelector("html").getAttribute("lang")&&(n+="&locale="+document.querySelector("html").getAttribute("lang")),a.AJAX({id:"getAllPaymentMethods",method:"GET",url:n,timeout:1e4,success:function(e,n){l.setPaymentMethods(n),"function"==typeof t?t(e,n):null},error:function(e,n){"function"==typeof t?t(e,n):null}})},l.getInstallments=function(t,r){if(!e.initialized)return n.push({method:"getInstallments",args:arguments});var i=o.baseUrl+"/payment_methods/installments?public_key="+e.key+"&js_version="+e.version,c=t.bin||t.payment_method_id,d="";return t.bin&&(d+="&bin="+t.bin),t.payment_method_id&&(d+="&payment_method_id="+t.payment_method_id),t.issuer_id&&(d+="&issuer.id="+t.issuer_id),t.payment_type_id&&(d+="&payment_type_id="+t.payment_type_id),t.amount&&(d+="&amount="+t.amount),t.differential_pricing_id&&(d+="&differential_pricing_id="+t.differential_pricing_id),document.querySelector("html").getAttribute("lang")&&(d+="&locale="+document.querySelector("html").getAttribute("lang")),i+=d,u&&u[d]?"function"==typeof r?r(200,u[d]):null:void a.AJAX({id:"getInstallments",method:"GET",url:i,timeout:1e4,error:function(e,n){"function"==typeof r?r(e,n,t):null},success:function(e,n){200===e&&n.length>0&&(c&&(u[c]=n),d&&(u[d]=n)),"function"==typeof r?r(e,n,t):null}})},l.getIssuers=function(t,n){var r=o.baseUrl+"/payment_methods/card_issuers?public_key="+e.key+"&js_version="+e.version;return(null!==t||void 0!==t)&&(r+="&payment_method_id="+t),s[t]?"function"==typeof n?n(200,s[t]):null:void a.AJAX({id:"cardIssuers",method:"GET",url:r,timeout:1e4,error:function(e,t){"function"==typeof n?n(e,t):null},success:function(e,r){200===e&&(s[t]=r),"function"==typeof n?n(e,r):null}})},t.paymentMethods=l;for(exports in l)e[exports]=l[exports]}(e,t),function(e,t){function r(t){function r(e,n){if("function"==typeof t)t(e,n);else if(200==e){var r=document.querySelector("select[data-checkout=docType]");if(r){r.options.length=0;for(var i=0;i<n.length;i++){var o=n[i],a=new Option(o.name,o.id);r.options.add(a)}}}}return e.initialized?void(y.identificationTypes.length>=1?r(200,y.identificationTypes):m.AJAX({id:"getIdentificationTypes",method:"GET",timeout:5e3,url:p.baseUrl+"/identification_types?public_key="+e.key,success:function(e,t){200==e&&(y.identificationTypes=t),r(e,t)},error:function(e,n){if(404==e){var r=[document.querySelector("select[data-checkout=docType]"),document.querySelector("input[data-checkout=docNumber]"),document.querySelector("label[for=docType]"),document.querySelector("label[for=docNumber]")];for(i in r)r[i]&&(r[i].style.display="none")}"function"==typeof t?t(e,n):null}})):n.push({method:"getIdentificationTypes",args:arguments})}function o(e){var t,n,r,i,o,a;for(r=!0,i=0,n=(e+"").split("").reverse(),o=0,a=n.length;a>o;o++)t=n[o],t=parseInt(t,10),(r=!r)&&(t*=2),t>9&&(t-=9),i+=t;return i%10===0}function a(e,t,n){e=p.clear(e),void 0==n&&"function"==typeof t&&(n=t);var r={bin:e,internal_validate:!0};"function"!=typeof t&&(r.payment_method_id=t),h.getPaymentMethod(r,function(t,r){var i=!1;if(200==t)for(var a=0;a<r.length&&!i;a++){config=r[a].settings;for(var c=0;config&&c<config.length&&!i;c++)i=e.length==config[c].card_number.length&&h.validateBinPattern(e,config[c])&&("none"==config[c].card_number.validation||o(e))}"function"==typeof n?n(t,i):null})}function c(e,t,n){return e=p.clear(e),e&&!/^\d+$/.test(e)?"function"==typeof n?n(200,!1):null:void h.getPaymentMethod({bin:t,internal_validate:!0},function(t,r){var i=!0;if(200==t)for(var o=r[0]?r[0].settings:[],a=0;o&&a<o.length&&i;a++)i=!o[a].security_code.length||e.length==o[a].security_code.length||"optional"==o[a].security_code.mode&&!e.length;return"function"==typeof n?n(t,i):null})}function u(e,t,n){var r=t.length;h.getPaymentMethod({bin:e.cardNumber,internal_validate:!0},function(i,o){if(200==i)for(var a=o[0]?o[0].additional_info_needed:[],c=0;c<a.length;c++)switch(a[c]){case"cardholder_name":e.cardholderName&&""!==e.cardholderName?d(e.cardholderName)||(t[r++]=y.invalidParamsCode.cardholderName):t[r++]=y.requiredParamsCodes.cardholderName;break;case"cardholder_identification_type":e.docType&&""!==e.docType?y.identificationTypes&&!y.identificationTypes.filter(function(t){return t.id==e.docType})&&(t[r++]=y.invalidParamsCode.docType):t[r++]=y.requiredParamsCodes.docType;break;case"cardholder_identification_number":e.docNumber&&""!==e.docNumber?s(e.docType,e.docNumber)||(t[r++]=y.invalidParamsCode.docNumber):t[r++]=y.requiredParamsCodes.docNumber}"function"==typeof n?n(i,t):null})}function d(e){var t="^[a-zA-ZãÃáÃà ÀâÂäÄẽẼéÉèÈêÊëËĩĨÃÃìÌîÎïÃõÕóÓòÒôÔöÖũŨúÚùÙûÛüÜçÇ’ñÑ .']*$";return e.match(t)?!0:!1}function s(e,t){if(0===y.identificationTypes.length)return!0;t=p.clear(t);var n=0===y.identificationTypes.length?null:y.identificationTypes.filter(function(t){return t.id==e})[0];return n=n||null,t=t||null,null!==n&&null!==t&&n.min_length<=t.length&&t.length<=n.max_length}function l(e,t){var n,r;if(e=(""+e).trim(),void 0==t){if(1==e.split("/").length)return!1;t=e.split("/")[1],e=e.split("/")[0]}return t=(""+t).trim(),2==t.length&&(t="20"+t),/^\d+$/.test(e)&&/^\d+$/.test(t)&&parseInt(e,10)<=12?(r=new Date(t,e),n=new Date,r.setMonth(r.getMonth()-1),r.setMonth(r.getMonth()+1,1),r>n):!1}function f(t,n){var r,i=0,o=[];if(t.cardId&&""!==t.cardId&&"-1"!==t.cardId)return void n(o);!t.cardExpiration||t.cardExpirationMonth&&t.cardExpirationYear?t.cardExpiration=t.cardExpirationMonth+"/"+t.cardExpirationYear:(t.cardExpirationMonth=t.cardExpiration.split("/")[0],t.cardExpirationYear=t.cardExpiration.split("/")[1]),t.cardExpirationYear&&2==t.cardExpirationYear.length&&(t.cardExpirationYear="20"+t.cardExpirationYear),t.docNumber=p.clear(t.docNumber);for(var d=0;d<y.whitelistedAttrs.length;d++)r=y.whitelistedAttrs[d],("cardNumber"==r||"securityCode"==r)&&(t[r]=p.clear(t[r])),t[r]&&""!==t[r]||"cardIssuerId"===r||"securityCode"===r||(o[i++]=y.requiredParamsCodes[r]);e.validateExpiryDate(t.cardExpirationMonth,t.cardExpirationYear)||(o[i++]=y.invalidParamsCode.cardExpirationMonth,o[i++]=y.invalidParamsCode.cardExpirationYear),a(t.cardNumber,function(e,r){r||(o[i++]=y.invalidParamsCode.cardNumber),c(t.securityCode,t.cardNumber,function(e,r){r||(o[i++]=y.invalidParamsCode.securityCode),u(t,o,function(e,t){n(t)})})})}var p=t.utils,m=t.request,h=t.paymentMethods,y={tokenName:"card",whitelistedAttrs:["cardNumber","securityCode","cardExpirationMonth","cardExpirationYear","cardExpiration","cardIssuerId"],identificationTypes:[],requiredParamsCodes:{cardholderName:{code:"221",description:"parameter cardholderName can not be null/empty"},docNumber:{code:"214",description:"parameter docNumber can not be null/empty"},docType:{code:"212",description:"parameter docType can not be null/empty"},cardNumber:{code:"205",description:"parameter cardNumber can not be null/empty"},securityCode:{code:"224",description:"parameter securityCode can not be null/empty"},cardExpirationMonth:{code:"208",description:"parameter cardExpirationMonth can not be null/empty"},cardExpirationYear:{code:"209",description:"parameter cardExpirationYear can not be null/empty"},cardIssuerId:{code:"220",description:"parameter cardIssuerId can not be null/empty"}},invalidParamsCode:{cardholderName:{code:"316",description:"invalid parameter cardholderName"},docNumber:{code:"324",description:"invalid parameter docNumber"},docType:{code:"322",description:"invalid parameter docType"},cardNumber:{code:"E301",description:"invalid parameter cardNumber"},securityCode:{code:"E302",description:"invalid parameter securityCode"},cardExpirationMonth:{code:"325",description:"invalid parameter cardExpirationMonth"},cardExpirationYear:{code:"326",description:"invalid parameter cardExpirationYear"}}};e.validateLuhn=o,e.validateCardNumber=a,e.validateSecurityCode=c,e.validateCardholderName=d,e.validateIdentification=s,e.validateExpiryDate=l,e.getIdentificationTypes=r,y.validate=f,t.card=y}(e,t),function(e,t){function n(t){var n={};return e.deviceProfileId&&(n.device={meli:{session_id:e.deviceProfileId}}),t.cardId&&""!==t.cardId&&"-1"!==t.cardId?(n.card_id=t.cardId,n.security_code=t.securityCode,n):(n.card_number=t.cardNumber,n.security_code=t.securityCode,n.expiration_month=parseInt(t.cardExpirationMonth,10),n.expiration_year=parseInt(t.cardExpirationYear,10),n.cardholder={name:t.cardholderName},n.cardholder.identification={type:""===t.docType||void 0===t.docType?null:t.docType,number:""===t.docNumber||void 0===t.docNumber?null:t.docNumber},n)}function r(n,r){e.tokenId?t.CardToken.update(n,r):t.CardToken.create(n,r)}function i(e,t,n){e&&e.jquery&&(e=e[0]),(e instanceof HTMLFormElement||void 0!==e.nodeType&&e.nodeType===document.ELEMENT_NODE)&&(e=c.paramsForm(e)),c.isEmpty(e)?n(e):u.validate(e,function(t){t.length&&(e=t),n(e)})}function o(t,n){function i(){for(var e=0,t=[],n=0;o&&n<o.length;n++){var r=o[n];null===r.name||void 0===r.name||""===r.name||"cardNumber"!=r.getAttribute("data-checkout")&&"securityCode"!=r.getAttribute("data-checkout")||(t[e++]=r.getAttribute("data-checkout"))}}if(!e.key||"string"!=typeof e.key)throw new Error("You did not set a valid publishable key. Call Mercadopago.setPublishableKey() with your public_key.");if(/\s/g.test(e.key))throw new Error("Your key is invalid, as it contains whitespaces.");var o=document.querySelectorAll("[data-checkout]");if("file:"!=window.location.protocol&&"https:"!=window.location.protocol&&o&&o.length>0&&!/^TEST/.test(e.key))throw new Error("Your payment cannot be processed because the website contains credit card data and is not using a secure connection.SSL certificate is required to operate.");i(),t.card.public_key=e.key,r(t,n)}function a(e,t){function n(e){return r[u.tokenName]=e,r[u.tokenName][0]?t(400,{error:"bad_request",message:"invalid parameters",cause:r[u.tokenName]}):o(r,t)}var r={};i(e,u.whitelistedAttrs,n)}var c=t.utils,u=t.card,d=t.request,s={};s.request=function(t,r,i){var o=c.baseUrl+"/card_tokens",a=r.card?n(r.card):{};if(i="function"==typeof i?i:function(){},"POST"!=t&&"PUT"!=t)throw new Error("Method not allowed.");"PUT"==t&&(o+="/"+e.tokenId),o+="?public_key="+e.key+"&js_version="+e.version,d.AJAX({id:"cardForm",method:t,url:o,data:a,timeout:35e3,retries:3,success:function(t,n){e.tokenId=n.id},complete:i})},s["new"]=function(t){s.request("POST",{},function(){return function(n,r){201==n?e.createDeviceProfile(t):t(n,r)}}())},s.update=function(t,n){e.tokenId?s.request("PUT",t,n):s.create(t,n)},s.create=function(e,t){s["new"](function(){return function(){s.update(e,t)}}())},t.CardToken=s,e.createToken=a}(e,t),function(e,t){function n(n){if(e.deviceProfileId||1==t.creatingDevice)return void("function"==typeof n?n():null);t.creatingDevice=!0;var i="https://api.mercadopago.com/v1/devices/widgets";r.AJAX({id:"createDeviceProfile",method:"POST",url:i,data:{section:"open_platform",view:"checkout"},timeout:2e3,error:function(){t.creatingDevice=!1,"function"==typeof n?n():null},success:function(r,i){e.deviceProfileId=i.session_id;var o=document.createElement("script");o.appendChild(document.createTextNode(i.widget.replace(/<script\b[^<]*">/gi,"").replace(/<\/script>[\s\S]*/gi,""))),document.querySelector("head").appendChild(o),t.creatingDevice=!1,"function"==typeof n?n():null}})}var r=t.request;t.creatingDevice=!1,e.createDeviceProfile=n}(e,t),function(e){e.createDeviceProfile(null)}(e),function(e,t){function r(){var e=window.crypto||window.msCrypto;if("undefined"==typeof e||"undefined"==typeof window.Uint32Array)return null;var t=new Uint32Array(8);e.getRandomValues(t);for(var n="",r=0;r<t.length;r++)n+=(2>r||r>5?"":"-")+t[r].toString(16).slice(-4);return n}function i(){e.initialized=!0,t.CardToken["new"](),0===e.getPaymentMethods().length&&e.getAllPaymentMethods()}function o(){if(e.initialized!==!0&&(setTimeout(function(){if(e.initialized===!1&&i(),n.length>0)for(var t=0;t<n.length;t++)e[n[t].method].apply(null,n[t].args);e.initialized=!0},1e3),window.eventMetricSessionId=r(),e.initializedInsights===!1)){var t=document.createElement("script");t.src="https://http2.mlstatic.com/storage/event-metrics-sdk/js",t.type="text/javascript",t.async=!1,t.setAttribute("data-client-info-name","MercadoPago-SDK-Javascript"),t.setAttribute("data-client-info-version",e.version),window.mobilecheck()?(t.setAttribute("data-business-flow-name","sdk-js-checkout-mobile"),t.setAttribute("data-business-flow-uid","BCLQ07IBVKH001FP9VCG")):(t.setAttribute("data-business-flow-name","sdk-js-checkout-web"),t.setAttribute("data-business-flow-uid","BCHJ1GABVKH001FP9V4G")),t.setAttribute("data-event-info-name","checkout"),t.setAttribute("data-event-info-source",window.eventMetricSessionId),t.onload=function(){i()},t.onerror=function(){i()},document.head.appendChild(t),e.initializedInsights=!0}}function a(){e.tokenId=null}e.clearSession=a,e.initMercadopago=o}(e,t),this.Mercadopago=e}.call(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case I need it in the future 🤷♂️