Skip to content

Commit

Permalink
fix uruguay and cancel button order
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrique Goncalves Leite committed May 24, 2017
1 parent 1fc1796 commit ca1046a
Show file tree
Hide file tree
Showing 16 changed files with 272 additions and 102 deletions.
1 change: 0 additions & 1 deletion *.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion v1.6.x/mercadopago/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>mercadopago</name>
<displayName><![CDATA[Mercado Pago]]></displayName>
<version><![CDATA[3.4.5]]></version>
<version><![CDATA[3.4.6]]></version>
<description><![CDATA[Receive your payments using Mercado Pago, you can using the Custom Checkout or Checkout Standard.]]></description>
<author><![CDATA[MERCADOPAGO.COM Representações LTDA.]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
2 changes: 1 addition & 1 deletion v1.6.x/mercadopago/config_br.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>mercadopago</name>
<displayName><![CDATA[Mercado Pago]]></displayName>
<version><![CDATA[3.4.5]]></version>
<version><![CDATA[3.4.6]]></version>
<description><![CDATA[Receba seus pagamentos utilizando o Mercado Pago e receba em cart&atilde;o de cr&eacute;dito e boletos atrav&eacute;s no nosso checkout Transparente ou Padr&atilde;o.]]></description>
<author><![CDATA[MERCADOPAGO.COM Representa&ccedil;&otilde;es LTDA.]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
2 changes: 1 addition & 1 deletion v1.6.x/mercadopago/config_es.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>mercadopago</name>
<displayName><![CDATA[Mercado Pago]]></displayName>
<version><![CDATA[3.4.5]]></version>
<version><![CDATA[3.4.6]]></version>
<description><![CDATA[Receba seus pagamentos utilizando o Mercado Pago e receba em cart&atilde;o de cr&eacute;dito e boletos atrav&eacute;s no nosso checkout Transparente ou Padr&atilde;o.]]></description>
<author><![CDATA[MERCADOPAGO.COM Representa&ccedil;&otilde;es LTDA.]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
33 changes: 26 additions & 7 deletions v1.6.x/mercadopago/controllers/front/cancelorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/

include_once dirname(__FILE__) . '/../../includes/MPApi.php';

class MercadoPagoCancelOrderModuleFrontController extends ModuleFrontController
{
public function initContent()
Expand All @@ -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"));
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion v1.6.x/mercadopago/controllers/front/custompayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
51 changes: 39 additions & 12 deletions v1.6.x/mercadopago/controllers/front/standardreturn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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}' => '',
Expand All @@ -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'];
Expand All @@ -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),
Expand All @@ -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];
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion v1.6.x/mercadopago/includes/MPApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

class MPApi
{
const VERSION = '3.4.5';
const VERSION = '3.4.6';

/* Info */
const INFO = 1;
Expand Down
1 change: 0 additions & 1 deletion v1.6.x/mercadopago/includes/MPRestCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
37 changes: 18 additions & 19 deletions v1.6.x/mercadopago/includes/UtilMercadoPago.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '>=')) {
Expand Down Expand Up @@ -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,"."));
}
}
Loading

0 comments on commit ca1046a

Please sign in to comment.