From 1bfde24ac2f76cb761de7c64e28b60e9fefa755c Mon Sep 17 00:00:00 2001 From: Gabriel Matsuoka Date: Fri, 27 Apr 2018 18:13:52 -0300 Subject: [PATCH 1/3] fix bugs: success_page & stock | update version | add reorder in custom checkout --- .../Core/Block/AbstractSuccess.php | 6 + .../Core/Controller/Checkout/Page.php | 2 +- src/MercadoPago/Core/Cron/OrderUpdate.php | 8 +- src/MercadoPago/Core/Helper/StatusUpdate.php | 33 +- src/MercadoPago/Core/Model/Core.php | 22 +- src/MercadoPago/Core/Model/Custom/Payment.php | 9 + .../Core/Model/CustomTicket/Payment.php | 5 + .../Core/Model/Standard/Payment.php | 1 + .../Core/Plugin/OrderCancelPlugin.php | 35 +- src/MercadoPago/Core/composer.json | 2 +- src/MercadoPago/Core/etc/module.xml | 2 +- .../Core/view/frontend/requirejs-config.js | 1 - .../frontend/templates/custom/success.phtml | 14 +- .../view/frontend/web/css/style-success.css | 10 +- .../view/frontend/web/js/mercadopago.debug.js | 1299 ----------------- src/MercadoPago/MercadoEnvios/composer.json | 2 +- src/MercadoPago/MercadoEnvios/etc/module.xml | 2 +- 17 files changed, 96 insertions(+), 1357 deletions(-) delete mode 100755 src/MercadoPago/Core/view/frontend/web/js/mercadopago.debug.js diff --git a/src/MercadoPago/Core/Block/AbstractSuccess.php b/src/MercadoPago/Core/Block/AbstractSuccess.php index c60176ff..de3fb953 100755 --- a/src/MercadoPago/Core/Block/AbstractSuccess.php +++ b/src/MercadoPago/Core/Block/AbstractSuccess.php @@ -147,4 +147,10 @@ public function getOrderUrl() return $url; } + + public function getReOrderUrl(){ + $params = ['order_id' => $this->_checkoutSession->getLastRealOrder()->getId()]; + $url = $this->_urlBuilder->getUrl('sales/order/reorder', $params); + return $url; + } } \ No newline at end of file diff --git a/src/MercadoPago/Core/Controller/Checkout/Page.php b/src/MercadoPago/Core/Controller/Checkout/Page.php index cf2445c3..6fe75116 100755 --- a/src/MercadoPago/Core/Controller/Checkout/Page.php +++ b/src/MercadoPago/Core/Controller/Checkout/Page.php @@ -112,7 +112,6 @@ public function execute() $order = $this->_getOrder(); $infoPayment = $this->_core->getInfoPaymentByOrder($order->getIncrementId()); - $status = null; //checkout Custom Credit Card @@ -120,6 +119,7 @@ public function execute() $status = $infoPayment['status']['value']; //$detail = $infoPayment['status_detail']['value']; } + //checkout redirect if ($status == 'approved' || $status == 'pending'){ $this->_redirect('checkout/onepage/success'); diff --git a/src/MercadoPago/Core/Cron/OrderUpdate.php b/src/MercadoPago/Core/Cron/OrderUpdate.php index 2dd640aa..72f768ab 100755 --- a/src/MercadoPago/Core/Cron/OrderUpdate.php +++ b/src/MercadoPago/Core/Cron/OrderUpdate.php @@ -129,7 +129,13 @@ public function execute(){ * @param $paymentOrder */ protected function _updateOrder($order, $statusOrder, $paymentOrder){ - $order->setState($this->_statusHelper->_getAssignedState($statusOrder)); + + if($statusOrder == 'canceled'){ + $order->cancel(); + }else{ + $order->setState($this->_statusHelper->_getAssignedState($statusOrder)); + } + $order->addStatusToHistory($statusOrder, $this->_statusHelper->getMessage($statusOrder, $statusOrder), true); $order->sendOrderUpdateEmail(true, $this->_statusHelper->getMessage($statusOrder, $paymentOrder)); $order->save(); diff --git a/src/MercadoPago/Core/Helper/StatusUpdate.php b/src/MercadoPago/Core/Helper/StatusUpdate.php index a1d6a190..c906dcac 100755 --- a/src/MercadoPago/Core/Helper/StatusUpdate.php +++ b/src/MercadoPago/Core/Helper/StatusUpdate.php @@ -111,16 +111,22 @@ public function setStatusUpdated($notificationData, $order) { $status = $notificationData['status']; $statusDetail = $notificationData['status_detail']; - $currentStatus = $order->getPayment()->getAdditionalInformation('status'); - $currentStatusDetail = $order->getPayment()->getAdditionalInformation('status_detail'); if (!is_null($order->getPayment()) && $order->getPayment()->getAdditionalInformation('second_card_token')) { $this->_statusUpdatedFlag = false; - return; } - if ($status == $currentStatus && $statusDetail == $currentStatusDetail) { - $this->_statusUpdatedFlag = true; + + //get the posible status update order + $statusToUpdate = $this->getStatusOrder($status, $statusDetail, false); + $order = $this->_coreHelper->_getOrder($notificationData["external_reference"]); + $commentsObject = $order->getStatusHistoryCollection(true); + + //check if the status has been updated in some time + foreach ($commentsObject as $commentObj) { + if($commentObj->getStatus() == $statusToUpdate){ + $this->_statusUpdatedFlag = true; + } } } @@ -462,9 +468,6 @@ protected function _updateAtributesData($data, $payment) */ public function setStatusOrder($payment) { - - $this->_dataHelper->log("teste ======>", 'mercadopago.log', $payment); - $order = $this->_coreHelper->_getOrder($payment["external_reference"]); $statusDetail = $payment['status_detail']; @@ -473,10 +476,11 @@ public function setStatusOrder($payment) if (isset($payment['status_final'])) { $status = $payment['status_final']; } + $message = $this->getMessage($status, $payment); - if ($this->isStatusUpdated()) { - return ['text' => $message, 'code' => \MercadoPago\Core\Helper\Response::HTTP_OK]; - } + // if ($this->isStatusUpdated()) { + // return ['text' => $message, 'code' => \MercadoPago\Core\Helper\Response::HTTP_OK]; + // } //if state is not complete updates according to setting $this->_updateStatus($order, $status, $message, $statusDetail); @@ -547,7 +551,12 @@ protected function _updateStatus($order, $status, $message, $statusDetail) if ($order->getState() !== \Magento\Sales\Model\Order::STATE_COMPLETE) { $statusOrder = $this->getStatusOrder($status, $statusDetail, $order->canCreditmemo()); - $order->setState($this->_getAssignedState($statusOrder)); + if($statusOrder == 'canceled'){ + $order->cancel(); + }else{ + $order->setState($this->_getAssignedState($statusOrder)); + } + $order->addStatusToHistory($statusOrder, $message, true); if (!$order->getEmailSent()){ $this->_orderSender->send($order, true, $message); diff --git a/src/MercadoPago/Core/Model/Core.php b/src/MercadoPago/Core/Model/Core.php index 16133203..9f696d72 100755 --- a/src/MercadoPago/Core/Model/Core.php +++ b/src/MercadoPago/Core/Model/Core.php @@ -687,9 +687,16 @@ public function getAmount($quote = null) if (!$quote) { $quote = $this->_getQuote(); } - $total = $quote->getBaseSubtotalWithDiscount() + $quote->getShippingAddress()->getShippingAmount() + $quote->getShippingAddress()->getBaseTaxAmount(); - return (float)$total; + //get grant total + $total = $quote->getGrandTotal(); + + //if not exist calculate + if(! $total ){ + $total = $quote->getBaseSubtotalWithDiscount() + $quote->getShippingAddress()->getShippingAmount() + $quote->getShippingAddress()->getBaseTaxAmount(); + } + + return (float) $total; } @@ -711,20 +718,9 @@ public function validCoupon($id) $payer_email = $this->getEmailCustomer(); $coupon_code = $id; - $this->_coreHelper->log("Discount: " . $transaction_amount . " teste: " . $payer_email . " teste: " . $coupon_code, 'mercadopago-custom.log'); - $mp = $this->_coreHelper->getApiInstance($this->_accessToken); $details_discount = $mp->check_discount_campaigns($transaction_amount, $payer_email, $coupon_code); - // $params = array( - // "transaction_amount" => $this->getAmount(), - // "payer_email" => $this->getEmailCustomer(), - // "coupon_code" => $id - // ); - - // $details_discount = $mp->get("/discount_campaigns", $params); - - // $this->_coreHelper->log("Discount: " . $transaction_amount . " teste: " . $payer_email . " teste: " . $coupon_code, 'mercadopago-custom.log'); //add value on return api discount $details_discount['response']['transaction_amount'] = $transaction_amount; diff --git a/src/MercadoPago/Core/Model/Custom/Payment.php b/src/MercadoPago/Core/Model/Custom/Payment.php index d9ea3c48..b1fe6560 100755 --- a/src/MercadoPago/Core/Model/Custom/Payment.php +++ b/src/MercadoPago/Core/Model/Custom/Payment.php @@ -281,6 +281,15 @@ public function initialize($paymentAction, $stateObject) $infoInstance->setAdditionalInformation('payment_id_detail', $payment['id']); $infoInstance->setAdditionalInformation('payer_identification_type', $payment['payer']['identification']['type']); $infoInstance->setAdditionalInformation('payer_identification_number', $payment['payer']['identification']['number']); + + if(isset($response['response']['status'])){ + $this->getInfoInstance()->setAdditionalInformation('status', $response['response']['status']); + } + + if(isset($response['response']['status_detail'])){ + $this->getInfoInstance()->setAdditionalInformation('status_detail', $response['response']['status_detail']); + } + return true; } diff --git a/src/MercadoPago/Core/Model/CustomTicket/Payment.php b/src/MercadoPago/Core/Model/CustomTicket/Payment.php index eec427f6..9ec37d53 100755 --- a/src/MercadoPago/Core/Model/CustomTicket/Payment.php +++ b/src/MercadoPago/Core/Model/CustomTicket/Payment.php @@ -35,6 +35,11 @@ public function initialize($paymentAction, $stateObject) if ($response !== false) { $this->getInfoInstance()->setAdditionalInformation('activation_uri', $response['response']['transaction_details']['external_resource_url']); + + if(isset($response['response']['status'])){ + $this->getInfoInstance()->setAdditionalInformation('status', $response['response']['status']); + } + $this->setOrderSubtotals($response['response']); return true; } diff --git a/src/MercadoPago/Core/Model/Standard/Payment.php b/src/MercadoPago/Core/Model/Standard/Payment.php index d02fb3ce..fd5d2d0b 100755 --- a/src/MercadoPago/Core/Model/Standard/Payment.php +++ b/src/MercadoPago/Core/Model/Standard/Payment.php @@ -257,6 +257,7 @@ public function makePreference() $total_item = $this->getTotalItems($arr['items']); $total_item += (float)$order->getBaseShippingAmount(); $order_amount = (float)$order->getBaseGrandTotal(); + if (!$order_amount) { $order_amount = (float)$order->getBasePrice() + $order->getBaseShippingAmount(); } diff --git a/src/MercadoPago/Core/Plugin/OrderCancelPlugin.php b/src/MercadoPago/Core/Plugin/OrderCancelPlugin.php index 23b8c10c..16796414 100755 --- a/src/MercadoPago/Core/Plugin/OrderCancelPlugin.php +++ b/src/MercadoPago/Core/Plugin/OrderCancelPlugin.php @@ -53,7 +53,6 @@ public function aroundCancel(\Magento\Sales\Model\Order $order, \Closure $procee */ protected function salesOrderBeforeCancel() { - if ($this->order->getExternalRequest()) { return; } @@ -83,28 +82,30 @@ protected function salesOrderBeforeCancel() if ($isValidaData){ $clientId = $this->dataHelper->getClientId(); $clientSecret = $this->dataHelper->getClientSecret(); - - $response = null; - $accessToken = $this->_scopeConfig->getValue(\MercadoPago\Core\Model\Core::XML_PATH_ACCESS_TOKEN, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); + $response = null; + $mp = $this->dataHelper->getApiInstance($accessToken); if ($paymentMethod == 'mercadopago_standard') { $mp = $this->dataHelper->getApiInstance($clientId, $clientSecret); - $response = $mp->cancel_payment($paymentID); - } else { - $mp = $this->dataHelper->getApiInstance($accessToken); - $data = [ - "status" => 'cancelled' - ]; - $response = $mp->put("/v1/payments/$paymentID?access_token=$accessToken", $data); } + + $mp = $this->dataHelper->getApiInstance($accessToken); + $response = $mp->get("/v1/payments/$paymentID?access_token=$accessToken"); + + if ($response['status'] == 200 && ($response['response']['status'] == 'pending' || $response['response']['status'] == 'in_process')) { + + $data = ["status" => 'cancelled']; + + $response = $mp->put("/v1/payments/$paymentID?access_token=$accessToken", $data); - if ($response['status'] == 200) { - $this->messageManager->addSuccessMessage(__('Cancellation made by Mercado Pago')); - } else { - $this->messageManager->addErrorMessage(__('Failed to make the cancellation by Mercado Pago')); - $this->messageManager->addErrorMessage($response['status'] . ' ' . $response['response']['message']); - $this->throwCancelationException(); + if ($response['status'] == 200) { + $this->messageManager->addSuccessMessage(__('Cancellation made by Mercado Pago')); + } else { + $this->messageManager->addErrorMessage(__('Failed to make the cancellation by Mercado Pago')); + $this->messageManager->addErrorMessage($response['status'] . ' ' . $response['response']['message']); + $this->throwCancelationException(); + } } } } diff --git a/src/MercadoPago/Core/composer.json b/src/MercadoPago/Core/composer.json index c6add9fa..56dff75d 100755 --- a/src/MercadoPago/Core/composer.json +++ b/src/MercadoPago/Core/composer.json @@ -2,7 +2,7 @@ "name": "mercadopago/module-core", "description": "Mercado Pago payment method module", "type": "magento2-module", - "version": "2.0.0", + "version": "2.0.1", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/src/MercadoPago/Core/etc/module.xml b/src/MercadoPago/Core/etc/module.xml index 572c794a..fa1485b5 100755 --- a/src/MercadoPago/Core/etc/module.xml +++ b/src/MercadoPago/Core/etc/module.xml @@ -1,6 +1,6 @@ - + diff --git a/src/MercadoPago/Core/view/frontend/requirejs-config.js b/src/MercadoPago/Core/view/frontend/requirejs-config.js index ad945566..5d6b1e30 100755 --- a/src/MercadoPago/Core/view/frontend/requirejs-config.js +++ b/src/MercadoPago/Core/view/frontend/requirejs-config.js @@ -8,7 +8,6 @@ var config = { '*': { MPcheckout: 'https://www.mercadopago.com/org-img/jsapi/mptools/buttons/render.js', MPcustom: 'https://secure.mlstatic.com/sdk/javascript/v1/mercadopago.js', - // MPcustom: 'MercadoPago_Core/js/mercadopago.debug', MPanalytics: 'https://secure.mlstatic.com/modules/javascript/analytics.js', meli: 'MercadoPago_Core/js/mercadopago', tinyj: 'MercadoPago_Core/js/tinyJ', diff --git a/src/MercadoPago/Core/view/frontend/templates/custom/success.phtml b/src/MercadoPago/Core/view/frontend/templates/custom/success.phtml index 7f6aa445..0d6946c9 100755 --- a/src/MercadoPago/Core/view/frontend/templates/custom/success.phtml +++ b/src/MercadoPago/Core/view/frontend/templates/custom/success.phtml @@ -12,6 +12,7 @@ $payment_method = $this->getPaymentMethod(); $info_payment = $this->getInfoPayment(); + ?>
@@ -32,8 +33,10 @@

escapeHtml($message_status['title']); ?>

escapeHtml($message_status['message']); ?>

- -

+ + +

+

@@ -50,6 +53,9 @@
- + + + + +
- diff --git a/src/MercadoPago/Core/view/frontend/web/css/style-success.css b/src/MercadoPago/Core/view/frontend/web/css/style-success.css index d87a8088..d78f3ddb 100755 --- a/src/MercadoPago/Core/view/frontend/web/css/style-success.css +++ b/src/MercadoPago/Core/view/frontend/web/css/style-success.css @@ -2,11 +2,11 @@ #box-mercadopago, #logo-mercadopago{ padding: 0; - text-align: center; + text-align: left; } #box-mercadopago > p{ - text-transform: capitalize; + text-transform: unset; line-height: 22px; } @@ -60,7 +60,7 @@ } #logo-mercadopago{ - margin: 20px auto; + margin: 20px 0; width: 100px; /*float: left;*/ } @@ -71,7 +71,7 @@ } .button-success{ - text-align: center; - margin: 40px 0 20px 0; + text-align: left; + margin: 20px 0 20px 0; } diff --git a/src/MercadoPago/Core/view/frontend/web/js/mercadopago.debug.js b/src/MercadoPago/Core/view/frontend/web/js/mercadopago.debug.js deleted file mode 100755 index 27a9cc4e..00000000 --- a/src/MercadoPago/Core/view/frontend/web/js/mercadopago.debug.js +++ /dev/null @@ -1,1299 +0,0 @@ -/** - * Polyfills - * @public - */ -(function (){ - - // IE8, IE9 - if (!String.prototype.trim) { - (function() { - // Make sure we trim BOM and NBSP - var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g; - String.prototype.trim = function() { - return this.replace(rtrim, ''); - }; - })(); - } - - var JSON = JSON || {}; - - if (!JSON.parse) { - (function() { - JSON.parse = function (obj) { - 'use strict'; - return eval("(" + obj + ")"); - }; - })(); - } - - if (!JSON.stringify) { - (function() { - JSON.stringify = function (obj) { - var t = typeof (obj); - if (t != "object" || obj === null) { - // simple data type - if (t == "string"){ - obj = '"'+obj+'"'; - } - return String(obj); - } else { - // recurse array or object - var n, v, json = [], arr = (obj && obj.constructor == Array); - for (n in obj) { - v = obj[n]; t = typeof(v); - if (t == "string"){ - v = '"'+v+'"'; - }else if (t == "object" && v !== null){ - v = JSON.stringify(v); - } - if(t !== "function"){ - json.push((arr ? "" : '"' + n + '":') + String(v)); - } - } - return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}"); - } - }; - })(); - } - - if (!Array.prototype.filter) { - (function(){ - Array.prototype.filter = function (fun) { - 'use strict'; - if (this === void 0 || this === null) { - throw new TypeError(); - } - var t = Object(this); - var len = t.length >>> 0; - if (typeof fun !== 'function') { - throw new TypeError(); - } - - var res = []; - var thisArg = arguments.length >= 2 ? arguments[1] : void 0; - for (var i = 0; i < len; i++) { - if (i in t) { - var val = t[i]; - if (fun.call(thisArg, val, i, t)) { - res.push(val); - } - } - } - return res; - }; - })(); - } - - // Production steps of ECMA-262, Edition 5, 15.4.4.18 - if (!Array.prototype.forEach) { - - Array.prototype.forEach = function forEach(callback, thisArg) { - 'use strict'; - var T, k; - - if (this == null) { - throw new TypeError("this is null or not defined"); - } - - var kValue, - // 1. Let O be the result of calling ToObject passing the |this| value as the argument. - O = Object(this), - - // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length". - // 3. Let len be ToUint32(lenValue). - len = O.length >>> 0; // Hack to convert O.length to a UInt32 - - // 4. If IsCallable(callback) is false, throw a TypeError exception. - // See: http://es5.github.com/#x9.11 - if ({}.toString.call(callback) !== "[object Function]") { - throw new TypeError(callback + " is not a function"); - } - - // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. - if (arguments.length >= 2) { - T = thisArg; - } - - // 6. Let k be 0 - k = 0; - - // 7. Repeat, while k < len - while (k < len) { - - // a. Let Pk be ToString(k). - // This is implicit for LHS operands of the in operator - // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk. - // This step can be combined with c - // c. If kPresent is true, then - if (k in O) { - - // i. Let kValue be the result of calling the Get internal method of O with argument Pk. - kValue = O[k]; - - // ii. Call the Call internal method of callback with T as the this value and - // argument list containing kValue, k, and O. - callback.call(T, kValue, k, O); - } - // d. Increase k by 1. - k++; - } - // 8. return undefined - }; - } - - if (!document.querySelectorAll) { - (function(){ - document.querySelectorAll = function (selectors) { - var style = document.createElement('style'), elements = [], element; - document.documentElement.firstChild.appendChild(style); - document._qsa = []; - - style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}'; - window.scrollBy(0, 0); - style.parentNode.removeChild(style); - - while (document._qsa.length) { - element = document._qsa.shift(); - element.style.removeAttribute('x-qsa'); - elements.push(element); - } - document._qsa = null; - return elements; - }; - })(); - } - - if (!document.querySelector) { - (function(){ - document.querySelector = function (selectors) { - var elements = document.querySelectorAll(selectors); - return (elements.length) ? elements[0] : null; - }; - })(); - } - -})(); - - -(function (){ - var Mercadopago = { - 'version' : '1.5.4', - 'initialized' : false, - 'key' : null, - 'deviceProfileId' : null, - 'tokenId' : null - }, - _exports = { - 'utils' : {}, - 'card' : {}, - 'request' : {}, - 'trackErrors' : {}, - 'paymentMethods' : {} - } - ; - - Mercadopago.referer = (function () { - var referer = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: ''); - - return referer; - })(); - - Mercadopago.setPublishableKey = function(publicKey){ - Mercadopago.key = publicKey; - Mercadopago.initMercadopago(); - }; - - /** - * Utils - * @private - */ - (function (exports) { - 'use strict'; - - var Utils = { - 'baseUrl' : 'https://api.mercadopago.com/v1' - }; - - /** - * @private - */ - Utils.clear = function (value){ - return ("" + value).trim().replace(/\s+|-/g, ""); - }; - - Utils.paramsForm = function (form){ - var values = {}, - data = form.querySelectorAll('[data-checkout]'); - - Array.prototype.forEach.call(data, function(el){ - var attr = el.getAttribute('data-checkout'), - index = el.selectedIndex; - - if (el.nodeName === 'SELECT' && index !== null && index !== -1) { - values[attr] = el.options[index].value; - } else { - values[attr] = el.value; - } - - }); - return values; - }; - - Utils.isEmpty = function (obj) { - - var hasOwnProperty = Object.prototype.hasOwnProperty; - - // null and undefined are "empty" - if (obj == null){ - return true; - } - - // Assume if it has a length property with a non-zero value - // that that property is correct. - if (obj.length > 0){ - return false; - } - if (obj.length === 0){ - return true; - } - - // Otherwise, does it have any properties of its own? - // Note that this doesn't handle - // toString and valueOf enumeration bugs in IE < 9 - for (var key in obj) { - if (hasOwnProperty.call(obj, key)){ - return false; - } - } - - return true; - }; - - exports.utils = Utils; - - }(_exports)); - - - (function (exports){ - - /** - * AJAX native - * @private - */ - - function AJAX(options){ - var useXDomain = !!window.XDomainRequest; - - var req = useXDomain ? new XDomainRequest() : new XMLHttpRequest() - var data; - - options.url += (options.url.indexOf("?") >= 0 ? "&" : "?") + "referer="+escape(Mercadopago.referer); - - options.requestedMethod = options.method; - - if (useXDomain && options.method == "PUT") { - options.method = "POST"; - options.url += "&_method=PUT"; - } - - req.open(options.method, options.url, true); - - req.timeout = options.timeout || 1000; - - if (window.XDomainRequest) { - req.onload = function(){ - data = JSON.parse(req.responseText); - if (typeof options.success === "function") { - options.success(options.requestedMethod === 'POST' ? 201 : 200, data); - } - if (typeof options.complete === "function") { - options.complete(options.requestedMethod === 'POST' ? 201 : 200, data); - } - }; - req.onerror = req.ontimeout = function(){ - if(typeof options.error === "function"){ - options.error(400,{user_agent:window.navigator.userAgent, error : "bad_request", cause:[]}); - } - if(typeof options.complete === "function"){ - options.complete(400,{user_agent:window.navigator.userAgent, error : "bad_request", cause:[]}); - } - }; - req.onprogress = function() {}; - } else { - req.setRequestHeader('Accept','application/json'); - - if(options.contentType){ - req.setRequestHeader('Content-Type', options.contentType); - }else{ - req.setRequestHeader('Content-Type', 'application/json'); - } - - req.onreadystatechange = function() { - if (this.readyState === 4){ - if (this.status >= 200 && this.status < 400){ - // Success! - data = JSON.parse(this.responseText); - if (typeof options.success === "function") { - options.success(this.status, data); - } - if (typeof options.complete === "function") { - options.complete(this.status, data); - } - } else if(this.status >= 400){ - data = JSON.parse(this.responseText); - if (typeof options.error === "function") { - options.error(this.status, data); - } - if (typeof options.complete === "function") { - options.complete(this.status, data); - } - } else { - if (typeof options.error === "function") { - options.error(503, {}); - } - if (typeof options.complete === "function") { - options.complete(503, {}); - } - } - } - }; - } - - if(options.method === 'GET' || options.data == null || options.data == undefined){ - req.send(); - }else{ - req.send(JSON.stringify(options.data)); - } - } - - exports['request'].AJAX = AJAX; - - }(_exports)); - - - /** - * Track errors - * @private - */ - (function(Mercadopago,_exports){ - - var request = _exports['request'], - Utils = _exports['utils']; - - function trackErrors(data){ - - var url = Utils.baseUrl + "/payment_methods/track_error?public_key=" + Mercadopago.key + "&js_version=" + Mercadopago.version; - - request.AJAX({ - url: url, - method : "POST", - data:data, - timeout : 5000 - }); - } - - _exports['trackErrors'] = trackErrors; - - }(Mercadopago, _exports)); - - /** - * Payment methods functions - * - */ - (function(Mercadopago, _exports){ - - var Utils = _exports['utils'], - trackErrors = _exports['trackErrors'], - request = _exports['request'], - guessedPaymentMethods = {}, - guessedInstallments = {}, - acceptedPaymentMethods = [], - acceptedCardIssuers = {}, - paymentMethods = {}; - - - paymentMethods.validateBinPattern = function validateBinPattern(cn,config){ - var bin = cn.slice(0, 6); - return config && config.bin && (bin.match(config.bin.pattern)?true:false) && ( !config.bin.exclusion_pattern || !bin.match(config.bin.exclusion_pattern)); - }; - - paymentMethods.setPaymentMethods = function setPaymentMethods(pm){ - acceptedPaymentMethods = pm; - }; - - paymentMethods.getPaymentMethods = function getPaymentMethods(){ - return acceptedPaymentMethods; - }; - - function searchPaymentMethods(object,callback){ - var acceptedPM = paymentMethods.getPaymentMethods(), - paymentMethod, - i = 0, - id = object.bin || object.payment_method_id, - _status = 200, - _response; - - - function searchPm(allPmt){ - - if (object.bin) { - paymentMethod = []; - for(pm in allPmt){ - if(!object.payment_type_id || (object.payment_type_id && object.payment_type_id == allPmt[pm].payment_type_id)){ - for (c in allPmt[pm].settings){ - - if(paymentMethods.validateBinPattern(object.bin,allPmt[pm].settings[c])){ - paymentMethod[i++] = allPmt[pm]; - } - } - } - } - }else if(object.payment_method_id) { - paymentMethod = allPmt.filter(function(pm){ - return pm.id==object.payment_method_id; - }); - } - - if(paymentMethod && paymentMethod.length>0){ - guessedPaymentMethods[id] = paymentMethod; - } - - if(paymentMethod && paymentMethod.length==0){ - _status = 400; - _response = { - "message": "payment method not found", - "error": "bad_request", - "status": 400, - "cause": [] - }; - }else{ - _response = paymentMethod; - } - typeof callback === 'function' ? callback(_status,_response) : null; - - } - - if (acceptedPM.length>0) { - searchPm(acceptedPM); - } - else{ - paymentMethods.getAllPaymentMethods(function(status,response){ - if(status === 200){ - searchPm(response); - }else{ - typeof callback === 'function' ? callback(status,response) : null; - } - }); - } - - } - - paymentMethods.getPaymentMethod = function getPaymentMethod(object,callback){ - - var id = object.bin || object.payment_method_id; - - if(!id){ - return typeof callback == "function" ? callback(400, {status:400, error : "bad_request", cause:{"code": "2000","description": "the payment_method_id or bin are required"}}, object) : null; - } - - if(object.bin){ - object.bin = Utils.clear(object.bin).replace(/[^0-9]/g, "").slice(0,6); - } - if(guessedPaymentMethods && guessedPaymentMethods[id]){ - return (typeof callback == "function" ? callback(200 , guessedPaymentMethods[id]) : null); - } - return searchPaymentMethods(object,callback); - }; - - paymentMethods.getAllPaymentMethods = function getAllPaymentMethods(callback){ - - var url = Utils.baseUrl + '/payment_methods?public_key=' + Mercadopago.key + '&js_version=' + Mercadopago.version; - - if (document.querySelector('html').getAttribute('lang')) { - url += '&locale=' + document.querySelector('html').getAttribute('lang'); - } - - request.AJAX({ - method : 'GET', - url : url, - timeout: 10000, - success : function successAllPMT(status,response){ - paymentMethods.setPaymentMethods(response); - typeof callback == "function" ? callback(status, response) : null; - }, - error : function(status,response){ - trackErrors({status:status, type:'getAllPaymentMethods', data:response}); - typeof callback == "function" ? callback(status, response) : null; - } - }); - }; - - paymentMethods.getInstallments = function getInstallments(object,callback){ - var url = Utils.baseUrl + "/payment_methods/installments?public_key=" + Mercadopago.key + "&js_version="+ Mercadopago.version, - id = object.bin || object.payment_method_id, - query = ""; - - if(object.bin){ - query += "&bin=" + object.bin; - } - if(object.payment_method_id){ - query += "&payment_method_id=" + object.payment_method_id; - } - if(object.issuer_id){ - query += "&issuer.id=" + object.issuer_id; - } - if(object.payment_type_id){ - query += "&payment_type_id=" + object.payment_type_id; - } - if(object.amount){ - query += "&amount=" + object.amount; - } - if(object.differential_pricing_id){ - query += "&differential_pricing_id=" + object.differential_pricing_id; - } - if (document.querySelector('html').getAttribute('lang')) { - query += "&locale=" + document.querySelector('html').getAttribute('lang'); - } - url += query; - - if(guessedInstallments && guessedInstallments[query]){ - return (typeof callback === 'function' ? callback(200 , guessedInstallments[query]) : null); - } - - request.AJAX({ - method : "GET", - url : url, - timeout : 10000, - error : function(status, response) { - trackErrors({status:status, type:"getInstallments", data:response}); - typeof callback == "function" ? callback(status, response, object) : null; - }, - success: function successGetInstallments(status, response) { - - if(status === 200 && response.length>0){ - if(id){ - guessedInstallments[id] = response; - } - if(query){ - guessedInstallments[query] = response; - } - } - - typeof callback == "function" ? callback(status, response, object) : null; - } - }); - }; - - paymentMethods.getIssuers = function(id,callback){ - - var url = Utils.baseUrl + "/payment_methods/card_issuers?public_key=" + Mercadopago.key + "&js_version=" + Mercadopago.version; - - if(id !== null || id !== undefined){ - url += "&payment_method_id=" + id; - } - - if(acceptedCardIssuers[id]){ - return typeof callback === 'function' ? callback(200, acceptedCardIssuers[id]) : null; - } - - request.AJAX({ - method : "GET", - url : url, - timeout : 10000, - error : function(status, response) { - trackErrors({status:status, type:"cardIssuers", data:response}); - typeof callback === 'function' ? callback(status, response) : null; - }, - success: function successIssuers(status, response) { - if(status === 200){ - acceptedCardIssuers[id] = response; - } - typeof callback === 'function' ? callback(status, response) : null; - } - }); - - }; - - _exports['paymentMethods'] = paymentMethods; - - for(exports in paymentMethods){ - Mercadopago[exports] = paymentMethods[exports]; - } - - }(Mercadopago,_exports)); - - - (function(Mercadopago, _exports){ - - var Utils = _exports['utils'], - trackErrors = _exports['trackErrors'], - request = _exports['request'], - paymentMethods = _exports['paymentMethods'], - _Card = { - '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"} - } - }; - - function getIdentificationTypes(callback){ - - function successIdentificationTypes(status,response){ - - if(typeof callback === 'function'){ - callback(status,response); - }else if(status==200){ - var selectorTypes = document.querySelector('select[data-checkout=docType]'), - addEvent = false; - - if(selectorTypes){ - - selectorTypes.options.length = 0; - - for (var i=0; i < response.length; i++) { - - var el = response[i], - option = new Option(el.name,el.id); - - selectorTypes.options.add(option); - } - } - } - } - - if (_Card.identificationTypes.length>=1) { - successIdentificationTypes(200,_Card.identificationTypes); - } - else{ - request.AJAX({ - method : 'GET', - timeout: 5000, - url : Utils.baseUrl + '/identification_types?public_key=' + Mercadopago.key, - success : function(status,response){ - if(status==200){ - _Card.identificationTypes = response; - } - successIdentificationTypes(status,response); - }, - error : function(status,response){ - if (status!==404) { - trackErrors({status:status, type:'getIdentificationTypes', data:response}); - }else{ - var list = [ 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 list) { - if (list[i]) { - list[i].style.display = "none"; - } - } - } - typeof callback === 'function' ? callback(status,response) : null; - } - }); - } - } - - function validateLuhn(num){ - var digit, digits, odd, sum, _i, _len; - odd = true; - sum = 0; - digits = (num + '').split('').reverse(); - for (_i = 0, _len = digits.length; _i < _len; _i++) { - digit = digits[_i]; - digit = parseInt(digit, 10); - if ((odd = !odd)) { - digit *= 2; - } - if (digit > 9) { - digit -= 9; - } - sum += digit; - } - return sum % 10 === 0; - } - - function validateCardNumber(cardNumber, pm, callback) { - cardNumber = Utils.clear(cardNumber); - - if(callback == undefined && (typeof pm === 'function')){ - callback = pm; - } - - var pmtData = { - 'bin':cardNumber, - 'internal_validate':true - }; - - if(typeof pm !== 'function'){ - pmtData['payment_method_id'] = pm; - } - - paymentMethods.getPaymentMethod(pmtData, - function(status,data){ - var result = false; - if(status == 200){ - for(var j=0; j < data.length && !result; j++){ - config = data[j].settings; - for (var i=0; config && i < config.length && !result; i++){ - result = cardNumber.length == config[i].card_number.length && paymentMethods.validateBinPattern(cardNumber,config[i]) && ( config[i].card_number.validation == "none" || validateLuhn(cardNumber)); - } - } - } - typeof callback == "function" ? callback(status,result) : null; - } - ); - } - - function validateSecurityCode(securityCode, pm, callback) { - securityCode = Utils.clear(securityCode); - - if (securityCode && !(/^\d+$/.test(securityCode))){ - return typeof callback === 'function' ? callback(200,false) : null; - } - paymentMethods.getPaymentMethod({"bin": pm, "internal_validate":true}, - function(status,data){ - var result = true; - if(status == 200){ - var config = data[0] ? data[0].settings : []; - for (var i=0; config && i < config.length && result ; i++){ - result = !config[i].security_code.length || securityCode.length == config[i].security_code.length || (config[i].security_code.mode == 'optional' && !securityCode.length); - } - } - return typeof callback == "function" ? callback(status,result) : null; - }); - } - - function validateAdditionalInfoNeeded(params, errors, callback){ - var index = errors.length; - - paymentMethods.getPaymentMethod({'bin':params['cardNumber'],'internal_validate':true}, - function(status,data){ - - if(status == 200){ - var additionalInfoNeeded = data[0] ? data[0].additional_info_needed : []; - - for (var j=0; j currentTime; - } - - function validate(params, callback){ - var attr, - index = 0, - errors = [], - callApi = false; - - if (params['cardId'] && params['cardId'] !== '' && params["cardId"] !== '-1') { - callback(errors); - return; - } - - if (params['cardExpiration'] && (!params['cardExpirationMonth'] || !params['cardExpirationYear'])) { - params['cardExpirationMonth'] = params['cardExpiration'].split('/')[0]; - params['cardExpirationYear'] = params['cardExpiration'].split('/')[1]; - }else{ - params['cardExpiration'] = params['cardExpirationMonth'] + '/' + params['cardExpirationYear']; - } - - if (params['cardExpirationYear'] && params['cardExpirationYear'].length==2) { - params['cardExpirationYear'] = ('20' + params['cardExpirationYear']); - } - - params['docNumber'] = Utils.clear(params['docNumber']); - - for(var i = 0; i < _Card.whitelistedAttrs.length; i++) { - attr = _Card.whitelistedAttrs[i]; - if(attr == 'cardNumber' || attr == 'securityCode'){ - params[attr] = Utils.clear(params[attr]); - } - if((!params[attr] || params[attr]==='') && attr!=='cardIssuerId' && attr!=='securityCode'){ - errors[index++] = _Card.requiredParamsCodes[attr]; - } - } - - if(!Mercadopago.validateExpiryDate(params['cardExpirationMonth'],params['cardExpirationYear'])){ - errors[index++] = _Card.invalidParamsCode['cardExpirationMonth']; - errors[index++] = _Card.invalidParamsCode['cardExpirationYear']; - } - - - validateCardNumber(params['cardNumber'], - function(status,result){ - if(!result){ - errors[index++] = _Card.invalidParamsCode['cardNumber']; - } - validateSecurityCode(params['securityCode'],params['cardNumber'], - function(status,result){ - if(!result){ - errors[index++] = _Card.invalidParamsCode['securityCode']; - } - - validateAdditionalInfoNeeded(params, errors, - function(status, errors){ - callback(errors); - }); - }); - }); - } - - Mercadopago.validateLuhn = validateLuhn; - - Mercadopago.validateCardNumber = validateCardNumber; - - Mercadopago.validateSecurityCode = validateSecurityCode; - - Mercadopago.validateCardholderName = validateCardholderName; - - Mercadopago.validateIdentification = validateIdentification; - - Mercadopago.validateExpiryDate = validateExpiryDate; - - Mercadopago.getIdentificationTypes = getIdentificationTypes; - - _Card.validate = validate; - - _exports['card'] = _Card; - - }(Mercadopago, _exports)); - - - (function (Mercadopago, _exports) { - - var Utils = _exports['utils'], - Card = _exports['card'], - trackErrors = _exports['trackErrors'], - request = _exports['request']; - - /** - * mappingCard - * @private - */ - function mappingCard(data){ - var tokenData = {}; - - if(Mercadopago.deviceProfileId){ - tokenData["device"] = { "meli" : { "session_id" : Mercadopago.deviceProfileId } }; - } - - if(data.cardId && data.cardId !== "" && data.cardId !== "-1") { - tokenData["card_id"] = data.cardId; - tokenData["security_code"] = data.securityCode; - return tokenData; - } - - tokenData["card_number"] = data.cardNumber; - tokenData["security_code"] = data.securityCode; - tokenData["expiration_month"] = parseInt(data.cardExpirationMonth,10); - tokenData["expiration_year"] = parseInt(data.cardExpirationYear,10); - tokenData["cardholder"] = {"name" : data.cardholderName}; - tokenData["cardholder"]["identification"] = { "type": (data.docType===""||data.docType===undefined)?null:data.docType, - "number": (data.docNumber===""||data.docNumber===undefined)?null:data.docNumber - }; - return tokenData; - } - - /** - * CardToken - * @private - */ - var CardToken = {}; - - CardToken.request = function CardTokenRequest(_method, data, callback) { - var url = Utils.baseUrl + "/card_tokens"; - var _body = data.card ? mappingCard(data.card) : {}; - - callback = typeof callback == "function" ? callback : function(){}; - - if (_method != "POST" && _method != "PUT") { - throw new Error("Method not allowed."); - } - - if (_method == "PUT") { - url += '/' + Mercadopago.tokenId; - } - - url += '?public_key=' + Mercadopago.key + '&js_version=' + Mercadopago.version; - - request.AJAX({ - method: _method, - url : url, - data: _body, - timeout : 10000, - error: function(status, response) { - trackErrors({status:status, type:"cardForm", data:response}); - }, - success: function(status,response){ - Mercadopago.tokenId = response.id; - }, - complete: callback - }); - }; - - CardToken.new = function CardTokenNew(callback) { - CardToken.request("POST", {}, (function(){ - return function() { - Mercadopago.createDeviceProfile(callback) - }; - }())); - }; - - CardToken.update = function CardTokenUpdate(data, callback) { - CardToken.request("PUT", data, callback); - } - - CardToken.create = function CardTokenCreate(data, callback) { - CardToken.new((function() { - return function() { - CardToken.update(data, callback); - }; - }())); - } - - _exports.CardToken = CardToken; - - /** - * post - * @private - */ - function post(dataObj, callback) { - if (Mercadopago.tokenId) { - _exports.CardToken.update(dataObj, callback); - } else { - _exports.CardToken.create(dataObj, callback); - } - } - - /** - * post - * @public - */ - function formatData(data, whitelistedAttrs, callback) { - - if(data && data.jquery){ - data = data[0]; - } - - if(data instanceof HTMLFormElement || data.nodeType !== undefined && data.nodeType === document.ELEMENT_NODE){ - data = Utils.paramsForm(data); - } - - if(Utils.isEmpty(data)){ - callback(data); - }else{ - Card.validate(data, function(validateResult){ - - if (validateResult.length) { - data = validateResult; - - trackErrors({ - 'status': 400, - 'type': 'validateForm', - 'data': data - }); - } - callback(data); - }); - } - } - - /** - * create - * @public - */ - function create(params, callback) { - - /** validate key*/ - if (!Mercadopago.key || typeof Mercadopago.key != "string") { - throw new Error("You did not set a valid publishable key. Call Mercadopago.setPublishableKey() with your public_key."); - } - if (/\s/g.test(Mercadopago.key)) { - throw new Error("Your key is invalid, as it contains whitespaces."); - } - - var data = document.querySelectorAll('[data-checkout]'); - - /* SSL */ - /* "file:" protocol support - Remove it when Hybrid Mobile apps problem is solved */ - // if(window.location.protocol != 'file:' && window.location.protocol != 'https:' && data && data.length > 0 && !(/^TEST/.test(Mercadopago.key))){ - // trackErrors({status:200, type:"validateReferer", data: { referer: window.location.host, user_agent: window.navigator.userAgent, public_key: Mercadopago.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."); - // } - - /* validate PCI DSS */ - function validateDSS(){ - var j = 0, - invalidNames = []; - - for(var i=0; data && i < data.length; i++){ - var el = data[i]; - if(el.name !==null && el.name !== undefined && el.name !== "" && (el.getAttribute('data-checkout') == "cardNumber" || el.getAttribute('data-checkout') == "securityCode")){ - invalidNames[j++] = el.getAttribute('data-checkout'); - } - } - if(invalidNames.length > 0){ - trackErrors({status:200, type:"DSS-" + window.location.host , data: { inputNames: invalidNames, user_agent: window.navigator.userAgent, public_key: Mercadopago.key}}); - } - } - - validateDSS(); - - params.card.public_key = Mercadopago.key; - - post(params, callback); - } - - function createToken(data, callback) { - var params = {}; - - function complete(response){ - params[Card.tokenName] = response; - if(!params[Card.tokenName][0]){ - return create(params, callback); - }else{ - return callback(400,{error : "bad_request", message: "invalid parameters", cause: params[Card.tokenName]}); - } - } - formatData(data, Card.whitelistedAttrs, complete); - } - - Mercadopago.createToken = createToken; - - }(Mercadopago, _exports)); - - (function(Mercadopago, _exports){ - - /** Device Profile - */ - var deviceProfileCallback = null; - var deviceProfileCallbackTimer = null; - _exports.creatingDevice = false; - function sessionIdListener (event) { - if (event.origin != "https://mldp.mercadopago.com") { - return; - } - clearTimeout(deviceProfileCallbackTimer); - - var data = null; - try { - data = JSON.parse(event.data); - } catch (e) {} - - if (data.session_id == Mercadopago.deviceProfileId) { - return; - } - - Mercadopago.deviceProfileId = data.session_id; - _exports.creatingDevice = false; - - if (deviceProfileCallback) { - deviceProfileCallback(); - } - - getTHM(data.session_id); - }; - - function createDeviceProfile(callback){ - - if (!Mercadopago.tokenId) { - return; - } - - _exports.creatingDevice = true; - - var existent = document.querySelector("iframe#device_profile"); - if (existent) { - var removed = existent.parentElement.removeChild(existent); - try { - delete removed; - } catch (e) {/* don't worry if cannot delete, is still removed */} - } else { - if (window.addEventListener) { - window.addEventListener ("message", sessionIdListener, false); - } else if (window.attachEvent) { - window.attachEvent ("onmessage", sessionIdListener); - } - } - - var iframe = document.createElement('iframe'); - iframe.id = "device_profile"; - - deviceProfileCallback = (typeof callback == "function") ? callback : null; - if (deviceProfileCallback) { - deviceProfileCallbackTimer = setTimeout(function() { - _exports.creatingDevice = false; - deviceProfileCallback(); - }, 3000); - } - - iframe.style.display = "none"; - iframe.src = "https://mldp.mercadopago.com/device_profile/widget?public_key=" + Mercadopago.key + "&session_id=" + Mercadopago.tokenId; - document.body.appendChild(iframe); - } - - /** THM pixel - */ - function getTHM(sessionId){ - /* Initialize pixel iframe */ - var existent = document.querySelector("iframe#thm_mp_cntnr"); - if (existent) { - var removed = existent.parentElement.removeChild(existent); - try { - delete removed; - } catch (e) {/* don't worry if cannot delete, is still removed */} - } - - var cntnr = document.createElement("iframe"); - cntnr.id = "thm_mp_cntnr"; - cntnr.setAttribute("width", "0"); - cntnr.setAttribute("height", "0"); - cntnr.setAttribute("frameborder", "0"); - cntnr.style.visibility = "hidden"; - - document.querySelector("body").appendChild(cntnr); - - cntnr.contentDocument.open(); - cntnr.contentDocument.write(""); - cntnr.contentDocument.close(); - /* END - Initialize pixel iframe */ - - var script = document.createElement("script"); - script.id = "thm_loader"; - script.setAttribute("type", "text/javascript"); - script.setAttribute("src", "https://content.mercadopago.com/fp/check.js?org_id=jk96mpy0&session_id=" + sessionId); - - cntnr.contentDocument.body.appendChild(script); - } - - Mercadopago.createDeviceProfile = createDeviceProfile; - - }(Mercadopago, _exports)); - - (function(Mercadopago, _exports){ - - function initMercadopago(){ - - if(Mercadopago.initialized === true){ - return; - } - - _exports.CardToken.new(); - - if(Mercadopago.getPaymentMethods().length===0) { - Mercadopago.getAllPaymentMethods(); - } - - Mercadopago.initialized = true; - } - - function clearSession(){ - Mercadopago.tokenId = null; - Mercadopago.deviceProfileId = null; - } - - Mercadopago.clearSession = clearSession; - - Mercadopago.initMercadopago = initMercadopago; - - }(Mercadopago, _exports)); - - this.Mercadopago = Mercadopago; - - -}).call(); \ No newline at end of file diff --git a/src/MercadoPago/MercadoEnvios/composer.json b/src/MercadoPago/MercadoEnvios/composer.json index 926f3414..20bc8656 100755 --- a/src/MercadoPago/MercadoEnvios/composer.json +++ b/src/MercadoPago/MercadoEnvios/composer.json @@ -5,7 +5,7 @@ "php": "~5.5.0|~5.6.0|~7.0.0" }, "type": "magento2-module", - "version": "2.0.0", + "version": "2.0.1", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/src/MercadoPago/MercadoEnvios/etc/module.xml b/src/MercadoPago/MercadoEnvios/etc/module.xml index 5c18f3c6..324278f4 100755 --- a/src/MercadoPago/MercadoEnvios/etc/module.xml +++ b/src/MercadoPago/MercadoEnvios/etc/module.xml @@ -1,6 +1,6 @@ - + From ba32933cb1693d5d89251d6abc30aa9a89e303b1 Mon Sep 17 00:00:00 2001 From: Gabriel Matsuoka Date: Fri, 27 Apr 2018 18:15:12 -0300 Subject: [PATCH 2/3] return validation isUpdate --- src/MercadoPago/Core/Helper/StatusUpdate.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MercadoPago/Core/Helper/StatusUpdate.php b/src/MercadoPago/Core/Helper/StatusUpdate.php index c906dcac..1605925f 100755 --- a/src/MercadoPago/Core/Helper/StatusUpdate.php +++ b/src/MercadoPago/Core/Helper/StatusUpdate.php @@ -478,9 +478,9 @@ public function setStatusOrder($payment) } $message = $this->getMessage($status, $payment); - // if ($this->isStatusUpdated()) { - // return ['text' => $message, 'code' => \MercadoPago\Core\Helper\Response::HTTP_OK]; - // } + if ($this->isStatusUpdated()) { + return ['text' => $message, 'code' => \MercadoPago\Core\Helper\Response::HTTP_OK]; + } //if state is not complete updates according to setting $this->_updateStatus($order, $status, $message, $statusDetail); From 3b0ddeb91090c786eb30a45b3a57a132a88f8131 Mon Sep 17 00:00:00 2001 From: Gabriel Matsuoka Date: Fri, 27 Apr 2018 18:17:27 -0300 Subject: [PATCH 3/3] restore getAmount --- src/MercadoPago/Core/Model/Core.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/MercadoPago/Core/Model/Core.php b/src/MercadoPago/Core/Model/Core.php index 9f696d72..bde585c4 100755 --- a/src/MercadoPago/Core/Model/Core.php +++ b/src/MercadoPago/Core/Model/Core.php @@ -688,13 +688,7 @@ public function getAmount($quote = null) $quote = $this->_getQuote(); } - //get grant total - $total = $quote->getGrandTotal(); - - //if not exist calculate - if(! $total ){ - $total = $quote->getBaseSubtotalWithDiscount() + $quote->getShippingAddress()->getShippingAmount() + $quote->getShippingAddress()->getBaseTaxAmount(); - } + $total = $quote->getBaseSubtotalWithDiscount() + $quote->getShippingAddress()->getShippingAmount() + $quote->getShippingAddress()->getBaseTaxAmount(); return (float) $total;