diff --git a/v2.3/custom/catalog/controller/extension/payment/mp_transparente.php b/v2.3/custom/catalog/controller/extension/payment/mp_transparente.php index 134c8d5..9fbb5ad 100755 --- a/v2.3/custom/catalog/controller/extension/payment/mp_transparente.php +++ b/v2.3/custom/catalog/controller/extension/payment/mp_transparente.php @@ -3,19 +3,21 @@ require_once "mercadopago.php"; class ControllerExtensionPaymentMPTransparente extends Controller { - private $version = "1.0"; + private $version = "1.0.1"; private $versionModule = "2.3"; private $error; private $order_info; private $message; private $special_checkouts = array('MLM', 'MLB', "MPE"); - private $sponsors = array('MLB' => 204931135, + private $sponsors = array( + 'MLB' => 204931135, 'MLM' => 204962951, 'MLA' => 204931029, 'MCO' => 204964815, 'MLV' => 204964612, 'MPE' => 217176790, - 'MLC' => 204927454); + 'MLC' => 204927454 + ); public function index() { @@ -24,6 +26,7 @@ public function index() { $data['button_back'] = $this->language->get('button_back'); $data['terms'] = ''; $data['public_key'] = $this->config->get('mp_transparente_public_key'); + $data['site_id'] = $this->config->get('mp_transparente_country'); $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); @@ -150,7 +153,7 @@ public function validCoupon($coupon_id) { } public function payment() { - + $params_mercadopago = $_REQUEST['mercadopago_custom']; $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); @@ -161,8 +164,13 @@ public function payment() { $params_mercadopago['paymentMethodId'] = $params_mercadopago['paymentMethodSelector']; } + $total_price = round($order_info['total'] * $order_info['currency_value'], 2); + if($this->config->get('mp_transparente_country') == 'MCO'){ + $total_price = $this->currency->format($order_info['total'], $order_info['currency_code'], false, false); + } + $payment = array(); - $payment['transaction_amount'] = round($params_mercadopago['amount'], 2); + $payment['transaction_amount'] = $total_price; $payment['token'] = $params_mercadopago['token']; $payment['installments'] = (int) $params_mercadopago['installments']; $payment['payment_method_id'] = $params_mercadopago['paymentMethodId']; @@ -316,7 +324,7 @@ public function getCustomerId() { if ($response_has_results_key && $response_has_at_least_one_item) { $customer_id = $response["response"]["results"][0]["id"]; - + } else { $new_customer = $this->createCustomer(); @@ -360,7 +368,7 @@ private function createCard($payment) { $issuerId = isset($payment['issuer_id']) ? intval($payment['issuer_id']) : ""; $paymentMethodId = isset($payment['payment_method_id']) ? $payment['payment_method_id'] : ""; - $card = $mp-> post("/v1/customers/" . $id . "/cards", + $card = $mp-> post("/v1/customers/" . $id . "/cards", array( "token" => $payment['metadata']['token'], "issuer_id" => $issuerId, @@ -447,5 +455,5 @@ function setPreModuleAnalytics() { //error_log("===setPreModuleAnalytics====" . json_encode($return)); return $return; - } + } } diff --git a/v2.3/standard/catalog/controller/extension/payment/mp_standard.php b/v2.3/standard/catalog/controller/extension/payment/mp_standard.php index eb2439c..c10cd33 100644 --- a/v2.3/standard/catalog/controller/extension/payment/mp_standard.php +++ b/v2.3/standard/catalog/controller/extension/payment/mp_standard.php @@ -8,8 +8,8 @@ class ControllerExtensionPaymentMPStandard extends Controller { public $sucess = true; private $order_info; private $message; - private $version = "1.0"; - private $versionModule = "2.3"; + private $version = "1.0.1"; + private $versionModule = "2.3"; private $sponsors = array('MLB' => 204931135, 'MLM' => 204962951, 'MLA' => 204931029, @@ -55,13 +55,18 @@ public function index() { $items = array(); foreach ($all_products as $product) { + $product_price = round($product['price'] * $order_info['currency_value'], 2); + if($this->config->get('mp_standard_country') == 'MCO'){ + $product_price = $this->currency->format($product['price'], $order_info['currency_code'], false, false); + } + $products .= $product['quantity'] . ' x ' . $product['name'] . ', '; $items[] = array( "id" => $product['product_id'], "title" => $product['name'], "description" => $product['quantity'] . ' x ' . $product['name'], // string "quantity" => intval($product['quantity']), - "unit_price" => $this->currency->format($product['price'], $order_info['currency_code'], false, false), //decimal + "unit_price" => $product_price, //"unit_price" => round(floatval($product['price']) * $order_info['currency_code'], 2), //decimal "currency_id" => $currency, "picture_url" => HTTP_SERVER . 'image/' . $product['image'], @@ -71,9 +76,6 @@ public function index() { $total = $this->currency->format($order_info['total'] - $this->cart->getSubTotal(), $order_info['currency_code'], false, false); - error_log("====total====".$total); - error_log("====text_total====".$this->language->get('text_total')); - if ($total > 0) { $items[] = array( "id" => 99, diff --git a/v2.3/ticket/catalog/controller/extension/payment/mp_ticket.php b/v2.3/ticket/catalog/controller/extension/payment/mp_ticket.php index ad49ffe..272ae2a 100644 --- a/v2.3/ticket/catalog/controller/extension/payment/mp_ticket.php +++ b/v2.3/ticket/catalog/controller/extension/payment/mp_ticket.php @@ -4,8 +4,8 @@ class ControllerExtensionPaymentMPTicket extends Controller { - private $version = "1.0"; - private $versionModule = "2.3"; + private $version = "1.0.1"; + private $versionModule = "2.3"; private $error; public $sucess = true; private $order_info; @@ -23,8 +23,8 @@ public function index() { $data['payment_button'] = $this->language->get('payment_button'); error_log("====tradução payment=====".$this->language->get('payment_button')); - - $data['analytics'] = $this->setPreModuleAnalytics(); + + $data['analytics'] = $this->setPreModuleAnalytics(); $data['payment_button'] = $this->language->get('payment_button'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/extension/payment/mp_ticket.tpl')) { @@ -42,6 +42,8 @@ public function payment() { $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); $all_products = $this->cart->getProducts(); $items = array(); + $site_id = $this->getCountry(); + foreach ($all_products as $product) { $items[] = array( "id" => $product['product_id'], @@ -68,14 +70,17 @@ public function payment() { "apartment" => "-", "street_number" => "-")); - $value = floatval(number_format(floatval($order_info['total']) * floatval($order_info['currency_value']), 2)); $access_token = $this->config->get('mp_ticket_access_token'); $mp = new MP($access_token); + $total_price = round($order_info['total'] * $order_info['currency_value'], 2); + if($site_id == 'MCO'){ + $total_price = $this->currency->format($order_info['total'], $order_info['currency_code'], false, false); + } $payment_data = array("payer" => $payer, "external_reference" => $order_info['order_id'], - "transaction_amount" => $value, + "transaction_amount" => $total_price, //"token" => $this->request->post['token'], "description" => 'Products', "payment_method_id" => $this->request->get['payment_method_id']); @@ -88,13 +93,10 @@ public function payment() { $payment_data['additional_info'] = array('shipments' => $shipments, 'items' => $items); $is_test_user = strpos($order_info['email'], '@testuser.com'); if (!$is_test_user) { - $payment_data["sponsor_id"] = $this->sponsors[$this->getCountry()]; + $payment_data["sponsor_id"] = $this->sponsors[$site_id]; } $payment_response = $mp->create_payment($payment_data); - error_log('payment response: ' . json_encode($payment_response)); - - error_log("=======payment_response========" . json_encode($payment_response)); $this->model_checkout_order->addOrderHistory($order_info['order_id'], $this->config->get('mp_ticket_order_status_id'), null, false); echo json_encode( @@ -262,5 +264,5 @@ function setPreModuleAnalytics() { error_log("===setPreModuleAnalytics====" . json_encode($return)); return $return; - } -} \ No newline at end of file + } +}