From ca1046a2106da305ee50721156840d647742fd74 Mon Sep 17 00:00:00 2001 From: Henrique Goncalves Leite Date: Wed, 24 May 2017 17:15:30 -0300 Subject: [PATCH] fix uruguay and cancel button order --- *.gitignore | 1 - v1.6.x/mercadopago/config.xml | 2 +- v1.6.x/mercadopago/config_br.xml | 2 +- v1.6.x/mercadopago/config_es.xml | 2 +- .../controllers/front/cancelorder.php | 33 +++-- .../controllers/front/custompayment.php | 2 +- .../controllers/front/standardreturn.php | 51 ++++++-- v1.6.x/mercadopago/includes/MPApi.php | 2 +- v1.6.x/mercadopago/includes/MPRestCli.php | 1 - .../mercadopago/includes/UtilMercadoPago.php | 37 +++--- v1.6.x/mercadopago/mercadopago.php | 114 ++++++++++++++---- .../mercadopago/views/css/mercadopago_v6.css | 2 +- .../views/templates/hook/checkout.tpl | 29 ++--- .../views/templates/hook/checkoutStandard.tpl | 45 +++++++ .../hook/creditcard_payment_return.tpl | 23 ++-- .../templates/hook/display_admin_order.tpl | 28 ++++- 16 files changed, 272 insertions(+), 102 deletions(-) delete mode 100644 *.gitignore create mode 100644 v1.6.x/mercadopago/views/templates/hook/checkoutStandard.tpl diff --git a/*.gitignore b/*.gitignore deleted file mode 100644 index e43b0f9..0000000 --- a/*.gitignore +++ /dev/null @@ -1 +0,0 @@ -.DS_Store diff --git a/v1.6.x/mercadopago/config.xml b/v1.6.x/mercadopago/config.xml index ae88a86..d47080d 100644 --- a/v1.6.x/mercadopago/config.xml +++ b/v1.6.x/mercadopago/config.xml @@ -2,7 +2,7 @@ mercadopago - + diff --git a/v1.6.x/mercadopago/config_br.xml b/v1.6.x/mercadopago/config_br.xml index 155ab5d..f129332 100644 --- a/v1.6.x/mercadopago/config_br.xml +++ b/v1.6.x/mercadopago/config_br.xml @@ -2,7 +2,7 @@ mercadopago - + diff --git a/v1.6.x/mercadopago/config_es.xml b/v1.6.x/mercadopago/config_es.xml index 38afe35..873c53e 100644 --- a/v1.6.x/mercadopago/config_es.xml +++ b/v1.6.x/mercadopago/config_es.xml @@ -2,7 +2,7 @@ mercadopago - + diff --git a/v1.6.x/mercadopago/controllers/front/cancelorder.php b/v1.6.x/mercadopago/controllers/front/cancelorder.php index 4c12039..19916a9 100644 --- a/v1.6.x/mercadopago/controllers/front/cancelorder.php +++ b/v1.6.x/mercadopago/controllers/front/cancelorder.php @@ -25,7 +25,6 @@ */ include_once dirname(__FILE__) . '/../../includes/MPApi.php'; - class MercadoPagoCancelOrderModuleFrontController extends ModuleFrontController { public function initContent() @@ -39,10 +38,14 @@ public function cancelOrder() // card_token_id $mercadopago = $this->module; $mercadopago_sdk = $mercadopago->mercadopago; - + $responseCancel = null; $token = Tools::getAdminToken('AdminOrder'.Tools::getValue('id_order')); $token_form = Tools::getValue('token_form'); + + error_log("id order =-==" . Tools::getValue('id_order')); + error_log("token_form =-==" . Tools::getValue('token_form')); + //check token if ($token == $token_form) { $order = new Order(Tools::getValue("id_order")); @@ -63,15 +66,31 @@ public function cancelOrder() } break; } - + error_log("====retorno=====" . Tools::jsonEncode($responseCancel)); if ($responseCancel != null && $responseCancel['status'] == 200) { - $mercadopago->updateOrderHistory($order->id, Configuration::get('PS_OS_CANCELED')); + $return = $mercadopago->updateOrderHistory($order->id, Configuration::get('PS_OS_CANCELED')); + error_log("====retorno=====" . Tools::jsonEncode($return)); + $response = array( + 'status' => '200', + 'message' => $this->module->l('The payment was cancelled.') + ); + } else { + $response = array( + 'status' => '404', + 'message' => $this->module->l('Cannnot cancel the payment, please see the PrestaShop Log.') + ); + UtilMercadoPago::logMensagem( + 'Cannnot cancel the payment = ' . Tools::jsonEncode($responseCancel), MPApi::WARNING + ); } - $getAdminLink = $this->context->link->getAdminLink('AdminOrders'); - $getViewOrder = $getAdminLink.'&vieworder&id_order='.Tools::getValue('id_order'); - Tools::redirectAdmin($getViewOrder); + error_log("retorno web === = = ". Tools::jsonEncode($response)); + } + + header('Content-Type: application/json'); + echo Tools::jsonEncode($response); + exit; } } diff --git a/v1.6.x/mercadopago/controllers/front/custompayment.php b/v1.6.x/mercadopago/controllers/front/custompayment.php index 830ecf8..0cc5daa 100644 --- a/v1.6.x/mercadopago/controllers/front/custompayment.php +++ b/v1.6.x/mercadopago/controllers/front/custompayment.php @@ -74,7 +74,7 @@ private function placeOrder() return; } $payment_type_id = $response['payment_type_id']; - $displayName = UtilMercadoPago::setNamePaymentType($payment_type_id); + $displayName = $mercadopago->setNamePaymentType($payment_type_id); $payment_mode = 'boleto'; $installments = 1; diff --git a/v1.6.x/mercadopago/controllers/front/standardreturn.php b/v1.6.x/mercadopago/controllers/front/standardreturn.php index bb3bd68..dcda365 100644 --- a/v1.6.x/mercadopago/controllers/front/standardreturn.php +++ b/v1.6.x/mercadopago/controllers/front/standardreturn.php @@ -31,6 +31,7 @@ class MercadoPagoStandardReturnModuleFrontController extends ModuleFrontControll public function initContent() { parent::initContent(); + error_log("entrou aqui return standard"); if (Tools::getIsset('collection_id') && Tools::getValue('collection_id') != 'null') { // payment variables $payment_statuses = array(); @@ -65,26 +66,43 @@ public function initContent() $transaction_amounts += $payment_info['transaction_amount']; - if (isset($payment_info['payment_type']) && $payment_info['payment_type'] == 'credit_card') { + if (isset($payment_info['payment_type']) && + $payment_info['payment_type'] == 'credit_card' || + $payment_info['payment_type'] == 'account_money' + ) { $card_holder_names[] = isset($payment_info['card']['cardholder']['name']) ? $payment_info['card']['cardholder']['name'] : ''; if (isset($payment_info['card']['last_four_digits'])) { $four_digits_arr[] = '**** **** **** '.$payment_info['card']['last_four_digits']; } - $statement_descriptors[] = $payment_info['statement_descriptor']; + $statement_descriptors[] = isset($payment_info['statement_descriptor']) ? + $payment_info['statement_descriptor'] : '' ; $status_details[] = $payment_info['status_detail']; } } + + error_log("".Tools::ps_round(floatval(36.226256), 2) + Tools::ps_round(floatval(36.226256), 2) + Tools::ps_round(floatval(300.502569), 2) + Tools::ps_round(floatval(44.632), 2) + Tools::ps_round(floatval(63.742691), 2)); + + error_log("".Tools::ps_round(floatval(300.502569), 2)); + error_log("".Tools::ps_round(floatval(44.632), 2)); + error_log("".Tools::ps_round(floatval(63.742691), 2)); + + + error_log("".number_format(Tools::convertPrice(36.226256, $cart->id_currency), 2, '.', '')); + error_log("".number_format(Tools::convertPrice(36.226256, $cart->id_currency), 2, '.', '')); + error_log("".number_format(Tools::convertPrice(300.502569, $cart->id_currency), 2, '.', '')); + error_log("".number_format(Tools::convertPrice(44.632, $cart->id_currency), 2, '.', '')); + error_log("".number_format(Tools::convertPrice(63.742691, $cart->id_currency), 2, '.', '')); + if (Validate::isLoadedObject($cart)) { - if (Configuration::get('MERCADOPAGO_COUNTRY') == 'MCO') { - $total = (double) ceil($transaction_amounts); - $total_ordem = ceil($cart->getOrderTotal(true, Cart::BOTH)); + if (Configuration::get('MERCADOPAGO_COUNTRY') == 'MCO' || Configuration::get('MERCADOPAGO_COUNTRY') == 'MLC') { + $total = (double) round($transaction_amounts); + $total_ordem = UtilMercadoPago::getOrderTotalMLC_MCO($cart->getOrderTotal(true, Cart::BOTH)); } else { $total = (double) number_format($transaction_amounts, 2, '.', ''); $total_ordem = $cart->getOrderTotal(true, Cart::BOTH); } - $extra_vars = array( '{bankwire_owner}' => $mercadopago->textshowemail, '{bankwire_details}' => '', @@ -103,9 +121,7 @@ public function initContent() $order_status = 'MERCADOPAGO_STATUS_7'; break; } - $order_id = $mercadopago->getOrderByCartId($cart->id); - if ($order_status != null) { $result_merchant = $mercadopago_sdk->getMerchantOrder($merchant_order_id); $merchant_order_info = $result_merchant['response']; @@ -117,17 +133,24 @@ public function initContent() $total += $cost_mercadoEnvios; } + error_log("Total===".$total); + error_log("Total_ordem===". $total_ordem); + error_log("id_currency getTotalCart ====".Cart::getTotalCart($cart->id)); + if ($total != $total_ordem) { PrestaShopLogger::addLog('Não atualizou o pedido, valores diferentes'. ' merchant_order_id = '.$merchant_order_id, MPApi::INFO, 0); + error_log("Não atualizou o pedido, valores diferentes'. + ' merchant_order_id = ".$merchant_order_id); return; } - if (Configuration::get('MERCADOPAGO_COUNTRY') == 'MCO') { + + if (Configuration::get('MERCADOPAGO_COUNTRY') == 'MCO' || Configuration::get('MERCADOPAGO_COUNTRY') == 'MLC') { $total = $cart->getOrderTotal(true, Cart::BOTH); } if (!$order_id) { - $displayName = UtilMercadoPago::setNamePaymentType($payment_types[0]); + $displayName = $mercadopago->setNamePaymentType($payment_types[0]); $mercadopago->validateOrder( $cart->id, Configuration::get($order_status), @@ -150,16 +173,17 @@ public function initContent() $order_payments = $order->getOrderPayments(); if ($order_payments == null || $order_payments[0] == null) { + error_log("ENTROU AQUI 12==="); $order_payments[0] = new stdClass(); } - + error_log("ENTROU AQUI 1234==="); $order_payments[0]->transaction_id = Tools::getValue('collection_id'); $uri .= '&payment_status='.$payment_statuses[0]; $uri .= '&payment_id='.implode(' / ', $payment_ids); $uri .= '&payment_type='.implode(' / ', $payment_types); $uri .= '&payment_method_id='.implode(' / ', $payment_method_ids); $uri .= '&amount='.$total; - if ($payment_info['payment_type'] == 'credit_card') { + if ($payment_info['payment_type'] == 'credit_card' || $payment_info['payment_type'] == 'account_money') { $uri .= '&card_holder_name='.implode(' / ', $card_holder_names); $uri .= '&four_digits='.implode(' / ', $four_digits_arr); $uri .= '&statement_descriptor='.$statement_descriptors[0]; @@ -170,8 +194,11 @@ public function initContent() implode(' / ', $payment_method_ids); $order_payments[0]->card_holder = implode(' / ', $card_holder_names); } + error_log("ENTROU AQUI save==="); $order_payments[0]->save(); + $order_payments = $order->getOrderPayments(); + error_log("ENTROU AQUI URI===".$uri); Tools::redirectLink($uri); } } diff --git a/v1.6.x/mercadopago/includes/MPApi.php b/v1.6.x/mercadopago/includes/MPApi.php index f00fef4..8e180ee 100644 --- a/v1.6.x/mercadopago/includes/MPApi.php +++ b/v1.6.x/mercadopago/includes/MPApi.php @@ -31,7 +31,7 @@ class MPApi { - const VERSION = '3.4.5'; + const VERSION = '3.4.6'; /* Info */ const INFO = 1; diff --git a/v1.6.x/mercadopago/includes/MPRestCli.php b/v1.6.x/mercadopago/includes/MPRestCli.php index 4998947..e795094 100644 --- a/v1.6.x/mercadopago/includes/MPRestCli.php +++ b/v1.6.x/mercadopago/includes/MPRestCli.php @@ -135,7 +135,6 @@ private static function exec($method, $uri, $data, $content_type, $uri_base) } $api_result = curl_exec($connect); - error_log("===saida exec====". Tools::jsonEncode($api_result)); $api_http_code = curl_getinfo($connect, CURLINFO_HTTP_CODE); $response = array( 'status' => $api_http_code, diff --git a/v1.6.x/mercadopago/includes/UtilMercadoPago.php b/v1.6.x/mercadopago/includes/UtilMercadoPago.php index b3c89af..3a9aee8 100644 --- a/v1.6.x/mercadopago/includes/UtilMercadoPago.php +++ b/v1.6.x/mercadopago/includes/UtilMercadoPago.php @@ -35,31 +35,13 @@ public static function logMensagem($mensagem, $nivel) $data_hora."===".$mensagem, $nivel, 0, - null, + 'MercadoPago', null, true ); } } - public static function setNamePaymentType($payment_type_id) - { - if ($payment_type_id == "ticket") { - $displayName = "Mercado Pago - ticket"; - } elseif ($payment_type_id == "atm") { - $displayName = "Mercado Pago - ATM"; - } elseif ($payment_type_id == "credit_card") { - $displayName = "Mercado Pago - Credit card"; - } elseif ($payment_type_id == "debit_card") { - $displayName = "Mercado Pago - Debit card"; - } elseif ($payment_type_id == "prepaid_card") { - $displayName = "Mercado Pago - Prepaid card"; - } else { - $displayName = "Mercado Pago"; - } - return $displayName; - } - public static function getPrestashopVersion() { if (version_compare(_PS_VERSION_, '1.7.0.0', '>=')) { @@ -125,4 +107,21 @@ public static function checkValueNull($value) } return $value; } + + public static function getString($value) + { + if (is_null($value) || empty($value)) { + return ""; + } + return $value; + } + + public static function getOrderTotalMLC_MCO($value) + { + error_log("entrou no util"); + if (is_null($value) || empty($value)) { + return 0; + } + return (double)substr($value, 0, strpos($value,".")); + } } diff --git a/v1.6.x/mercadopago/mercadopago.php b/v1.6.x/mercadopago/mercadopago.php index d5cbbbb..44ec2fb 100644 --- a/v1.6.x/mercadopago/mercadopago.php +++ b/v1.6.x/mercadopago/mercadopago.php @@ -88,7 +88,7 @@ public function __construct() { $this->name = 'mercadopago'; $this->tab = 'payments_gateways'; - $this->version = '3.4.5'; + $this->version = '3.4.6'; $this->currencies = true; //$this->currencies_mode = 'radio'; $this->need_instance = 0; @@ -350,12 +350,16 @@ private function isMercadoEnvios($id_carrier) */ public static function getOrderStatePending($id_order) { - return (int) Db::getInstance()->getValue( - ' - SELECT MAX(id_order_state) - FROM '._DB_PREFIX_.'order_history - WHERE id_order = '.(int) $id_order - ); + $select = 'SELECT id_order_state FROM ps_order_history WHERE id_order = '. + (int) $id_order. + ' order by date_add desc limit 1;'; + $result = (Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($select)); + + if ($result) { + return $result[0]['id_order_state']; + } else { + return 0; + } } public function hookDisplayAdminOrder($params) @@ -398,12 +402,9 @@ public function hookDisplayAdminOrder($params) ); $this->context->smarty->assign('pos_active', Configuration::get('MERCADOPAGO_POINT')); - error_log("====MERCADOPAGO_POINT====" . Configuration::get('MERCADOPAGO_POINT')); if (Configuration::get('MERCADOPAGO_POINT') == "true") { - error_log("====entrou aqui===="); $this->context->smarty->assign('pos_options', $this->loadPoints()); } else { - error_log("====entrou aqui no else===="); $this->context->smarty->assign('pos_options', array()); } @@ -411,9 +412,7 @@ public function hookDisplayAdminOrder($params) $order_carrier = new OrderCarrier($id_order_carrier); $id_mercadoenvios_service_code = $this->isMercadoEnvios($order_carrier->id_carrier); - error_log("====entrou aqui mercadoenvios====".$id_mercadoenvios_service_code); if ($id_mercadoenvios_service_code > 0) { - error_log("====entrou aqui mercadoenvios 1===="); $order_payments = $order->getOrderPayments(); foreach ($order_payments as $order_payment) { $result = $this->mercadopago->getPaymentStandard($order_payment->transaction_id); @@ -780,7 +779,7 @@ public function getContent() Configuration::updateValue( 'MERCADOPAGO_CUSTOM_TEXT', - (int) Tools::getValue('MERCADOPAGO_CUSTOM_TEXT') + Tools::getValue('MERCADOPAGO_CUSTOM_TEXT') ); $this->smarty->assign(array( @@ -1061,7 +1060,7 @@ public function getContent() 'test_user' => $test_user, 'requirements' => $requirements, 'requirements' => $requirements, - 'custom_text' => htmlentities(Configuration::get('MERCADOPAGO_CUSTOM_TEXT'), ENT_COMPAT, 'UTF-8'), + 'custom_text' => htmlentities(UtilMercadoPago::getString(Configuration::get('MERCADOPAGO_CUSTOM_TEXT')), ENT_COMPAT, 'UTF-8'), 'two_cards' => htmlentities(Configuration::get('MERCADOPAGO_TWO_CARDS'), ENT_COMPAT, 'UTF-8'), 'public_key' => htmlentities(Configuration::get('MERCADOPAGO_PUBLIC_KEY'), ENT_COMPAT, 'UTF-8'), 'access_token' => htmlentities(Configuration::get('MERCADOPAGO_ACCESS_TOKEN'), ENT_COMPAT, 'UTF-8'), @@ -1135,6 +1134,7 @@ private function setDefaultValues($client_id, $client_secret) Configuration::updateValue('MERCADOPAGO_IFRAME_HEIGHT', '570'); Configuration::updateValue('MERCADOPAGO_INSTALLMENTS', '12'); Configuration::updateValue('MERCADOPAGO_AUTO_RETURN', 'approved'); + Configuration::updateValue('MERCADOPAGO_CUSTOM_TEXT', 'Pay via MercadoPago and split into up to 24 times'); $this->setCustomSettings($client_id, $client_secret, $country); } @@ -1259,8 +1259,14 @@ public function hookDisplayFooter() return $this->display(__file__, '/views/templates/hook/display.tpl'); } + public function hookPaymentStandard($params) + { + return $this->display(__file__, '/views/templates/hook/checkoutStandard.tpl'); + } public function hookPayment($params) { + //henrique + PrestaShopLogger::addLog("entrou aqui no hookPayment",MPApi::ERROR,0); if (!$this->active) { return; } @@ -1270,6 +1276,8 @@ public function hookPayment($params) //calculo desconto parcela a vista $cart = $params['cart']; + + $active_credit_card = (int) Configuration::get('MERCADOPAGO_ACTIVE_CREDITCARD'); $shipping_cost = (double) $cart->getOrderTotal(true, Cart::ONLY_SHIPPING); $product_cost = (double) $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS); @@ -1364,8 +1372,13 @@ public function hookPayment($params) } // send standard configurations only activated if (Configuration::get('MERCADOPAGO_STANDARD_ACTIVE') == 'true') { - $result = $this->createStandardCheckoutPreference(); + $data['custom_text'] = Configuration::get('MERCADOPAGO_CUSTOM_TEXT'); + + $result = $this->createStandardCheckoutPreference(); + $messageLog = "====result standard====".Tools::jsonEncode($result); + error_log($messageLog); + PrestaShopLogger::addLog($messageLog, MPApi::ERROR, 0); if (Configuration::get('MERCADOPAGO_LOG') == 'true') { $messageLog = "====result====".Tools::jsonEncode($result); PrestaShopLogger::addLog( @@ -1470,6 +1483,9 @@ public function hookPaymentReturn($params) return; } + error_log("====payment_method_id====".Tools::getValue('payment_method_id')); + error_log("====payment_type====".Tools::getValue('payment_type')); + if (Tools::getValue('payment_method_id') == 'bolbradesco' || Tools::getValue('payment_type') == 'bank_transfer' || Tools::getValue('payment_type') == 'atm' || Tools::getValue('payment_type') == 'ticket') { @@ -1492,13 +1508,14 @@ public function hookPaymentReturn($params) return $this->display(__file__, '/views/templates/hook/boleto_payment_return.tpl'); } else { $this->context->controller->addCss($this->_path.'views/css/mercadopago_core.css', 'all'); + error_log("===status_detail===".Tools::getValue('status_detail')); $this->context->smarty->assign( array( 'payment_status' => Tools::getValue('payment_status'), 'status_detail' => Tools::getValue('status_detail'), 'card_holder_name' => Tools::getValue('card_holder_name'), 'four_digits' => Tools::getValue('four_digits'), - 'payment_method_id' => Tools::getValue('payment_method_id'), + 'payment_method_id' => $this->setNamePaymentType(Tools::getValue('payment_type')), 'installments' => Tools::getValue('installments'), 'transaction_amount' => Tools::displayPrice( Tools::getValue('amount'), @@ -1880,9 +1897,13 @@ private function getPreferencesCustom($post) private function getPrestashopPreferencesStandard() { + //henrique $customer_fields = Context::getContext()->customer->getFields(); $cart = Context::getContext()->cart; + error_log("ID DO CARRINHO === ". $cart->id); + + // Get costumer data $address_invoice = new Address((integer) $cart->id_address_invoice); $phone = $address_invoice->phone; @@ -1915,7 +1936,7 @@ private function getPrestashopPreferencesStandard() $summary = ''; $round = false; - if (Configuration::get('MERCADOPAGO_COUNTRY') == 'MCO') { + if (Configuration::get('MERCADOPAGO_COUNTRY') == 'MCO' || Configuration::get('MERCADOPAGO_COUNTRY') == 'MLC') { $round = true; } @@ -1934,7 +1955,7 @@ private function getPrestashopPreferencesStandard() 'title' => $product['name'], 'description' => $product['description_short'], 'quantity' => $product['quantity'], - 'unit_price' => $round ? floor($product['price_wt']) : $product['price_wt'], + 'unit_price' => $round ? round($product['price_wt']) : Tools::ps_round(floatval($product['price_wt']), 2), 'picture_url' => (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').$imagePath, 'category_id' => Configuration::get('MERCADOPAGO_CATEGORY'), ); @@ -1948,12 +1969,13 @@ private function getPrestashopPreferencesStandard() // include wrapping cost $wrapping_cost = (double) $cart->getOrderTotal(true, Cart::ONLY_WRAPPING); + error_log("".$wrapping_cost); if ($wrapping_cost > 0) { $item = array( 'title' => 'Wrapping', 'description' => 'Wrapping service used by store', 'quantity' => 1, - 'unit_price' => $round ? floor($wrapping_cost) : $wrapping_cost, + 'unit_price' => $round ? round($wrapping_cost) : $wrapping_cost, 'category_id' => Configuration::get('MERCADOPAGO_CATEGORY'), 'currency_id' => $cart->id_currency, ); @@ -1961,6 +1983,7 @@ private function getPrestashopPreferencesStandard() } // include discounts $discounts = (double) $cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS); + error_log("".- $discounts); if ($discounts > 0) { $item = array( 'title' => 'Discount', @@ -2002,17 +2025,21 @@ private function getPrestashopPreferencesStandard() $shipments = array(); // include shipping cost $shipping_cost = (double) $cart->getOrderTotal(true, Cart::ONLY_SHIPPING); + error_log("".- $shipping_cost); if ($shipping_cost > 0) { $item = array( 'title' => 'Shipping', 'description' => 'Shipping service used by store', 'quantity' => 1, - 'unit_price' => $round ? floor($shipping_cost) : $shipping_cost, + 'unit_price' => $round ? round($shipping_cost) : $shipping_cost, 'category_id' => Configuration::get('MERCADOPAGO_CATEGORY'), ); $items[] = $item; } } + + error_log("==== standard cart id ===".$cart->id); + $data = array( 'external_reference' => $cart->id, 'customer' => $customer_data, @@ -2168,7 +2195,7 @@ public function createStandardCheckoutPreference() { $preferences = $this->getPrestashopPreferencesStandard(null); if (Configuration::get('MERCADOPAGO_LOG') == 'true') { - PrestaShopLogger::addLog("=====preferences=====".Tools::jsonEncode($preferences), MPApi::INFO, 0); + PrestaShopLogger::addLog("=====preferences 1 =====".Tools::jsonEncode($preferences), MPApi::INFO, 0); } return $this->mercadopago->createPreference($preferences); } @@ -2226,7 +2253,6 @@ public function listenIPN($checkout, $topic, $id) $cost_mercadoEnvios = 0; $isMercadoEnvios = 0; - if (Configuration::get('MERCADOPAGO_LOG') == 'true') { PrestaShopLogger::addLog('MercadoPago :: listenIPN - topic = '.$topic, MPApi::INFO, 0); PrestaShopLogger::addLog('MercadoPago :: listenIPN - id = '.$id, MPApi::INFO, 0); @@ -2242,8 +2268,11 @@ public function listenIPN($checkout, $topic, $id) // check value $cart = new Cart($merchant_order_info['external_reference']); - if (Configuration::get('MERCADOPAGO_COUNTRY') == 'MCO') { - $total = floor($cart->getOrderTotal(true, Cart::BOTH)); + $currency = new Currency((int) $cart->id_currency); + + if (Configuration::get('MERCADOPAGO_COUNTRY') == 'MCO' || Configuration::get('MERCADOPAGO_COUNTRY') == 'MLC') { + error_log("====getOrderTotalMLC_MCO=======".UtilMercadoPago::getOrderTotalMLC_MCO($cart->getOrderTotal(true, Cart::BOTH))); + $total = UtilMercadoPago::getOrderTotalMLC_MCO($cart->getOrderTotal(true, Cart::BOTH)); } else { $total = (float)$cart->getOrderTotal(true, Cart::BOTH); } @@ -2253,6 +2282,15 @@ public function listenIPN($checkout, $topic, $id) $order = new Order($id_order); $total_amount = $merchant_order_info['total_amount']; + + $currency = new Currency((int) $cart->id_currency); + error_log("valor formatado ====". Tools::displayPrice($cart->getOrderTotal(true), $currency)); + + error_log('MercadoPago :: listenIPN - external_reference - '.$merchant_order_info['external_reference']); + error_log('MercadoPago :: listenIPN - total_amount - '.$total_amount); + error_log('MercadoPago :: listenIPN - total - '.$total); + error_log('MercadoPago :: listenIPN - getTotalCart - '.Cart::getTotalCart($cart->id)); + if ($total_amount != $total) { PrestaShopLogger::addLog('MercadoPago :: listenIPN - Não atualizou o pedido, valores diferentes'. ' id = '.$id, MPApi::INFO, 0); @@ -2314,7 +2352,7 @@ public function listenIPN($checkout, $topic, $id) } if ($merchant_order_info['total_amount'] == $transaction_amounts) { - if (Configuration::get('MERCADOPAGO_COUNTRY') == 'MCO') { + if (Configuration::get('MERCADOPAGO_COUNTRY') == 'MCO' || Configuration::get('MERCADOPAGO_COUNTRY') == 'MLC') { $transaction_amounts = $cart->getOrderTotal(true, Cart::BOTH); } if ($isMercadoEnvios) { @@ -2492,7 +2530,7 @@ private function updateOrder( return; } - $displayName = UtilMercadoPago::setNamePaymentType($payment_type); + $displayName = $this->setNamePaymentType($payment_type); $this->validateOrder( $id_cart, @@ -2553,6 +2591,8 @@ private function updateOrder( $order_payment->save(); } } + + } } } @@ -3262,6 +3302,28 @@ public function setSettings() } } + public function setNamePaymentType($payment_type_id) + { + + error_log("===$payment_type_id=====".$payment_type_id); + if ($payment_type_id == "ticket") { + $displayName = $this->l('Mercado Pago - Ticket'); + } elseif ($payment_type_id == "atm") { + $displayName = $this->l('Mercado Pago - ATM'); + } elseif ($payment_type_id == "credit_card") { + $displayName = $this->l('Mercado Pago - Credit Card'); + } elseif ($payment_type_id == "debit_card") { + $displayName = $this->l('Mercado Pago - Debit Card'); + } elseif ($payment_type_id == "prepaid_card") { + $displayName = $this->l('Mercado Pago - Prepaid Card'); + } elseif ($payment_type_id == "account_money") { + $displayName = $this->l('Mercado Pago - Account Money'); + } else { + $displayName = $this->l('Mercado Pago'); + } + return $displayName; + } + public function getPrestashopVersion() { if (version_compare(_PS_VERSION_, '1.7.0.0', '>=')) { diff --git a/v1.6.x/mercadopago/views/css/mercadopago_v6.css b/v1.6.x/mercadopago/views/css/mercadopago_v6.css index ca67790..583feb0 100644 --- a/v1.6.x/mercadopago/views/css/mercadopago_v6.css +++ b/v1.6.x/mercadopago/views/css/mercadopago_v6.css @@ -212,7 +212,7 @@ } .mp-module .standard { - font: 600 13px/15px "Open Sans", sans-serif; + font: 600 13px/16px "Open Sans", sans-serif; margin-left: 174px; display: block; } diff --git a/v1.6.x/mercadopago/views/templates/hook/checkout.tpl b/v1.6.x/mercadopago/views/templates/hook/checkout.tpl index fce533e..52a7371 100644 --- a/v1.6.x/mercadopago/views/templates/hook/checkout.tpl +++ b/v1.6.x/mercadopago/views/templates/hook/checkout.tpl @@ -437,13 +437,19 @@ http://opensource.org/licenses/osl-3.0.php Open Software License (OSL
+ {if $country eq 'MLU'} + {$custom_text|escape:'htmlall':'UTF-8'} + {else} {l s='Pay via MercadoPago - and split into up to 24 times' mod='mercadopago'} + class="payment-label standard">{$custom_text|escape:'htmlall':'UTF-8'} + {/if}
@@ -462,27 +468,12 @@ http://opensource.org/licenses/osl-3.0.php Open Software License (OSL - - - - {/if} + + diff --git a/v1.6.x/mercadopago/views/templates/hook/checkoutStandard.tpl b/v1.6.x/mercadopago/views/templates/hook/checkoutStandard.tpl new file mode 100644 index 0000000..355c186 --- /dev/null +++ b/v1.6.x/mercadopago/views/templates/hook/checkoutStandard.tpl @@ -0,0 +1,45 @@ +{** * 2007-2015 PrestaShop * * NOTICE OF LICENSE * * This source file is +subject to the Open Software License (OSL 3.0) * that is bundled with +this package in the file LICENSE.txt. * It is also available through the +world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php +* If you did not receive a copy of the license and are unable to * +obtain it through the world-wide-web, please send an email * to +license@prestashop.com so we can send you a copy immediately. * * +DISCLAIMER * * Do not edit or add to this file if you wish to upgrade +PrestaShop to newer * versions in the future. If you wish to customize +PrestaShop for your * needs please refer to http://www.prestashop.com +for more information. * * @author MercadoPago * @copyright Copyright +(c) MercadoPago [http://www.mercadopago.com] * @license +http://opensource.org/licenses/osl-3.0.php Open Software License (OSL +3.0) * International Registered Trademark & Property of MercadoPago *} + +
+ +
diff --git a/v1.6.x/mercadopago/views/templates/hook/creditcard_payment_return.tpl b/v1.6.x/mercadopago/views/templates/hook/creditcard_payment_return.tpl index f1ccd4b..6740caa 100644 --- a/v1.6.x/mercadopago/views/templates/hook/creditcard_payment_return.tpl +++ b/v1.6.x/mercadopago/views/templates/hook/creditcard_payment_return.tpl @@ -24,7 +24,7 @@ *}
-

+

{if $status_detail eq 'accredited'} {l s='Thank for your purchase!' mod='mercadopago'}
@@ -32,13 +32,13 @@


-

+

{if $card_holder_name != null} {l s='Card holder name: ' mod='mercadopago'} {$card_holder_name|escape:'htmlall':'UTF-8'}
{/if} - + {if $four_digits != null} {l s='Credit card: ' mod='mercadopago'} {$four_digits|escape:'htmlall':'UTF-8'}
@@ -55,11 +55,14 @@ {l s='Installments: ' mod='mercadopago'} {$installments|escape:'htmlall':'UTF-8'}
{/if} - {l s='Statement descriptor: ' mod='mercadopago'} - {$statement_descriptor|escape:'htmlall':'UTF-8'}
+ + {if $statement_descriptor != null && ! $statement_descriptor eq ''} + {l s='Statement descriptor: ' mod='mercadopago'} + {$statement_descriptor|escape:'htmlall':'UTF-8'}
+ {/if} {l s='Payment id (MercadoPago): ' mod='mercadopago'} - {$payment_id|escape:'htmlall':'UTF-8'}
-

+ {$payment_id|escape:'htmlall':'UTF-8'}
+ {elseif $status_detail eq 'pending_review_manual' || $status_detail eq 'pending_review'} {l s='We are processing the payment. In less than 2 business days we will tell you by e-mail if it is accredited or if we need more information.' mod='mercadopago'} {elseif $status_detail eq 'pending_contingency'} @@ -67,16 +70,16 @@ {elseif status_detail eq 'expired'} {l s='Payment expired.' mod='mercadopago'} {/if} - +
- --> \ No newline at end of file diff --git a/v1.6.x/mercadopago/views/templates/hook/display_admin_order.tpl b/v1.6.x/mercadopago/views/templates/hook/display_admin_order.tpl index c2961b0..53bcd08 100644 --- a/v1.6.x/mercadopago/views/templates/hook/display_admin_order.tpl +++ b/v1.6.x/mercadopago/views/templates/hook/display_admin_order.tpl @@ -25,7 +25,6 @@
-
@@ -44,11 +43,12 @@
{if $statusOrder == "Pendente"}
+
@@ -151,6 +151,30 @@ }); -->