Skip to content

Commit

Permalink
fix notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrique Goncalves Leite committed May 16, 2017
1 parent 45877d1 commit 1fc1796
Show file tree
Hide file tree
Showing 134 changed files with 9,712 additions and 2,468 deletions.
19 changes: 0 additions & 19 deletions v1.6.x/mercadopago/composer.json

This file was deleted.

17 changes: 9 additions & 8 deletions v1.6.x/mercadopago/config.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>mercadopago</name>
<displayName><![CDATA[Mercado Pago]]></displayName>
<version><![CDATA[1.0.4]]></version>
<description><![CDATA[Receive your payments using Mercado Pago, you can using or Checkout Standard.]]></description>
<author><![CDATA[Mercado Pago]]></author>
<tab><![CDATA[payments_gateways]]></tab>
<is_configurable>true</is_configurable>
<need_instance>1</need_instance>
<name>mercadopago</name>
<displayName><![CDATA[Mercado Pago]]></displayName>
<version><![CDATA[3.4.5]]></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>
<confirmUninstall><![CDATA[Are you sure you want to uninstall MercadoPago?]]></confirmUninstall>
<is_configurable>1</is_configurable>
<need_instance>0</need_instance>
<limited_countries></limited_countries>
</module>
18 changes: 9 additions & 9 deletions v1.6.x/mercadopago/config_br.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>mercadopago</name>
<displayName><![CDATA[Mercado Pago]]></displayName>
<version><![CDATA[1.0.3]]></version>
<description><![CDATA[Receive your payments using Mercado Pago, you can using the Checkout Standard.]]></description>
<author><![CDATA[Mercado Pago]]></author>
<tab><![CDATA[payments_gateways]]></tab>
<confirmUninstall><![CDATA[Are you sure you want to uninstall?]]></confirmUninstall>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
<name>mercadopago</name>
<displayName><![CDATA[Mercado Pago]]></displayName>
<version><![CDATA[3.4.5]]></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>
<confirmUninstall><![CDATA[Você tem certeza que deseja desinstalar o Mercado Pago?]]></confirmUninstall>
<is_configurable>1</is_configurable>
<need_instance>0</need_instance>
<limited_countries></limited_countries>
</module>
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.2]]></version>
<version><![CDATA[3.4.5]]></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
13 changes: 0 additions & 13 deletions v1.6.x/mercadopago/config_pt.xml

This file was deleted.

77 changes: 77 additions & 0 deletions v1.6.x/mercadopago/controllers/front/cancelorder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* 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 henriqueleite
* @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
*/

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

class MercadoPagoCancelOrderModuleFrontController extends ModuleFrontController
{
public function initContent()
{
parent::initContent();
$this->cancelOrder();
}

public function cancelOrder()
{
// card_token_id
$mercadopago = $this->module;
$mercadopago_sdk = $mercadopago->mercadopago;

$token = Tools::getAdminToken('AdminOrder'.Tools::getValue('id_order'));

$token_form = Tools::getValue('token_form');
//check token
if ($token == $token_form) {
$order = new Order(Tools::getValue("id_order"));
$order_payments = $order->getOrderPayments();
foreach ($order_payments as $order_payment) {
if ($order_payment->transaction_id > 0) {
$result = $mercadopago_sdk->getPayment($order_payment->transaction_id);
if ($result['status'] == 200) {
$responseCancel = $mercadopago_sdk->cancelPaymentsCustom(
$order_payment->transaction_id
);
} else {
$result = $mercadopago_sdk->getPaymentStandard($order_payment->transaction_id);
$responseCancel = $mercadopago_sdk->cancelPaymentsStandard(
$order_payment->transaction_id
);
}
}
break;
}

if ($responseCancel != null && $responseCancel['status'] == 200) {
$mercadopago->updateOrderHistory($order->id, Configuration::get('PS_OS_CANCELED'));
}

$getAdminLink = $this->context->link->getAdminLink('AdminOrders');
$getViewOrder = $getAdminLink.'&vieworder&id_order='.Tools::getValue('id_order');

Tools::redirectAdmin($getViewOrder);
}
}
}
178 changes: 178 additions & 0 deletions v1.6.x/mercadopago/controllers/front/custompayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?php
/**
* 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
*/

include_once dirname(__FILE__).'/../../mercadopago.php';
class MercadoPagoCustomPaymentModuleFrontController extends ModuleFrontController
{
public function initContent()
{
$this->display_column_left = false;
parent::initContent();
$this->placeOrder();
}

private function placeOrder()
{
// card_token_id
$mercadopago = $this->module;

$response = $mercadopago->execPayment($_POST);

$order_status = null;
if (array_key_exists('status', $response)) {
switch ($response['status']) {
case 'in_process':
$order_status = 'MERCADOPAGO_STATUS_0';
break;
case 'approved':
$order_status = 'MERCADOPAGO_STATUS_1';
break;
case 'pending':
$order_status = 'MERCADOPAGO_STATUS_7';
break;
}
}

if ($order_status != null) {
$cart = Context::getContext()->cart;

$total = (double) number_format($response['transaction_amount'], 2, '.', '');
$extra_vars = array(
'{bankwire_owner}' => $mercadopago->textshowemail,
'{bankwire_details}' => '',
'{bankwire_address}' => '',
);

$id_order = Order::getOrderByCartId($cart->id);

$order = new Order($id_order);
$existStates = $mercadopago->checkStateExist($id_order, Configuration::get($order_status));
if ($existStates) {
return;
}
$payment_type_id = $response['payment_type_id'];
$displayName = UtilMercadoPago::setNamePaymentType($payment_type_id);

$payment_mode = 'boleto';
$installments = 1;
if (Tools::getIsset('card_token_id')) {
$payment_mode = 'cartao';
$installments = (int)$response['installments'];
}

$percent = (float) Configuration::get('MERCADOPAGO_DISCOUNT_PERCENT');
$id_cart_rule = null;
if ($percent > 0) {
$id_cart_rule = $mercadopago->applyDiscount($cart, $payment_mode, $installments);
}

$mercadopago->validateOrder(
$cart->id,
Configuration::get($order_status),
$total,
$displayName,
null,
$extra_vars,
$cart->id_currency,
false,
$cart->secure_key
);

if ($id_cart_rule != null) {
$cartRule = new CartRule($id_cart_rule);
$cartRule->active = false;
$cartRule->save();
}

$order = new Order($mercadopago->currentOrder);
$order_payments = $order->getOrderPayments();
$order_payments[0]->transaction_id = $response['id'];

$uri = __PS_BASE_URI__.'order-confirmation.php?id_cart='.$cart->id.'&id_module='.$mercadopago->id.
'&id_order='.$mercadopago->currentOrder.'&key='.$order->secure_key.'&payment_id='.
$response['id'].'&payment_status='.$response['status'];

if (Tools::getIsset('card_token_id')) {
// get credit card last 4 digits
$four_digits = '**** **** **** '.$response['card']['last_four_digits'];

$cardholderName = $response['card']['cardholder']['name'];

$order_payments[0]->card_number = $four_digits;
$order_payments[0]->card_brand = Tools::ucfirst($response['payment_method_id']);
$order_payments[0]->card_holder = $cardholderName;

$uri .= '&card_token='.Tools::getValue('card_token_id').'&card_holder_name='.$cardholderName.
'&four_digits='.$four_digits.'&payment_method_id='.$response['payment_method_id'].
'&payment_type='.$response['payment_type_id'].'&installments='.$response['installments'].
'&statement_descriptor='.$response['statement_descriptor'].'&status_detail='.
$response['status_detail'].'&amount='.$response['transaction_details']['total_paid_amount'];
} else {
$uri .= '&payment_method_id='.$response['payment_method_id'].'&payment_type='.
$response['payment_type_id'].'&boleto_url='.
urlencode($response['transaction_details']['external_resource_url']);
}
$order_payments[0]->save();
Tools::redirectLink($uri);
} else {
$this->context->controller->addCss(
(Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').
htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.
'modules/mercadopago/views/css/mercadopago_core.css',
'all'
);

$data = array(
'version' => $mercadopago->getPrestashopVersion(),
'one_step' => Configuration::get('PS_ORDER_PROCESS_TYPE'),
);
$data['expiration_date'] = '';
if (array_key_exists('message', $response) && (strpos($response['message'], 'Invalid users involved') !==
false || (strpos($response['message'], 'users from different countries') !== false))) {
$data['valid_user'] = false;
} else {
$data['version'] = $mercadopago->getPrestashopVersion();

$data['status_detail'] = $response['status_detail'];
$data['card_holder_name'] = Tools::getValue('cardholderName');
$data['four_digits'] = Tools::getValue('lastFourDigits');
$data['payment_method_id'] = Tools::getValue('payment_method_id');
$data['installments'] = $response['installments'];
$data['amount'] = Tools::displayPrice(
$response['transaction_details']['total_paid_amount'],
new Currency(Context::getContext()->cart->id_currency),
false
);
$data['payment_id'] = $response['id'];
$data['one_step'] = Configuration::get('PS_ORDER_PROCESS_TYPE');
$data['valid_user'] = true;
$data['message'] = isset($response['message']) ? $response['message'] : '';
}
$this->context->smarty->assign($data);
$this->setTemplate('error.tpl');
}
}
}
Loading

0 comments on commit 1fc1796

Please sign in to comment.