Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #70 from gmatsuoka/master
Browse files Browse the repository at this point in the history
Version 2.0.1
  • Loading branch information
gmatsuoka authored Apr 27, 2018
2 parents 3ad5d83 + 3b0ddeb commit 1be185b
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 1,353 deletions.
6 changes: 6 additions & 0 deletions src/MercadoPago/Core/Block/AbstractSuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/Controller/Checkout/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ public function execute()

$order = $this->_getOrder();
$infoPayment = $this->_core->getInfoPaymentByOrder($order->getIncrementId());

$status = null;

//checkout Custom Credit Card
if (!empty($infoPayment['status']['value'])) {
$status = $infoPayment['status']['value'];
//$detail = $infoPayment['status_detail']['value'];
}

//checkout redirect
if ($status == 'approved' || $status == 'pending'){
$this->_redirect('checkout/onepage/success');
Expand Down
8 changes: 7 additions & 1 deletion src/MercadoPago/Core/Cron/OrderUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
27 changes: 18 additions & 9 deletions src/MercadoPago/Core/Helper/StatusUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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'];
Expand All @@ -473,6 +476,7 @@ 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];
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 2 additions & 12 deletions src/MercadoPago/Core/Model/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,10 @@ public function getAmount($quote = null)
if (!$quote) {
$quote = $this->_getQuote();
}

$total = $quote->getBaseSubtotalWithDiscount() + $quote->getShippingAddress()->getShippingAmount() + $quote->getShippingAddress()->getBaseTaxAmount();

return (float)$total;
return (float) $total;

}

Expand All @@ -711,20 +712,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;
Expand Down
9 changes: 9 additions & 0 deletions src/MercadoPago/Core/Model/Custom/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/MercadoPago/Core/Model/CustomTicket/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/MercadoPago/Core/Model/Standard/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
35 changes: 18 additions & 17 deletions src/MercadoPago/Core/Plugin/OrderCancelPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function aroundCancel(\Magento\Sales\Model\Order $order, \Closure $procee
*/
protected function salesOrderBeforeCancel()
{

if ($this->order->getExternalRequest()) {
return;
}
Expand Down Expand Up @@ -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();
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MercadoPago_Core" setup_version="2.0.0">
<module name="MercadoPago_Core" setup_version="2.0.1">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Core/view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 10 additions & 4 deletions src/MercadoPago/Core/view/frontend/templates/custom/success.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

$payment_method = $this->getPaymentMethod();
$info_payment = $this->getInfoPayment();

?>

<div id="box-mercadopago">
Expand All @@ -32,8 +33,10 @@
<h2 class="mercadopago-title"><?php echo $block->escapeHtml($message_status['title']); ?></h2>

<p><?php echo $block->escapeHtml($message_status['message']); ?></p>

<p><?php /* @escapeNotVerified */ echo __($successMsg, $link_to_order); ?></p>

<?php if($info_payment['status']['value'] != 'rejected'): ?>
<p><?php /* @escapeNotVerified */ echo __($successMsg, $link_to_order); ?></p>
<?php endif; ?>

<h3 class="mercadopago-title-info-payment"><?php /* @escapeNotVerified */ echo __('Payment information'); ?></h3>

Expand All @@ -50,6 +53,9 @@


<div class="primary button-success">
<a class="action primary continue" href="<?php echo $block->escapeUrl($block->getUrl()) ?>"><span><?php /* @escapeNotVerified */ echo __('Continue Shopping') ?></span></a>
<?php if($info_payment['status']['value'] == 'rejected'): ?>
<a class="action primary continue" href="<?php echo $block->escapeUrl($block->getReOrderUrl()) ?>"><span><?php /* @escapeNotVerified */ echo __('Retry order') ?></span></a>
<?php else: ?>
<a class="action primary continue" href="<?php echo $block->escapeUrl($block->getUrl()) ?>"><span><?php /* @escapeNotVerified */ echo __('Continue Shopping') ?></span></a>
<?php endif; ?>
</div>

10 changes: 5 additions & 5 deletions src/MercadoPago/Core/view/frontend/web/css/style-success.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -60,7 +60,7 @@
}

#logo-mercadopago{
margin: 20px auto;
margin: 20px 0;
width: 100px;
/*float: left;*/
}
Expand All @@ -71,7 +71,7 @@
}

.button-success{
text-align: center;
margin: 40px 0 20px 0;
text-align: left;
margin: 20px 0 20px 0;
}

Loading

0 comments on commit 1be185b

Please sign in to comment.