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 #196 from PluginAndPartners/main
Browse files Browse the repository at this point in the history
Release v3.18.0
  • Loading branch information
katelucena-meli authored Nov 16, 2022
2 parents 40cde6a + 7651ed9 commit 474f739
Show file tree
Hide file tree
Showing 24 changed files with 302 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:

- name: Detect Coding Standard Violations
id: phpcs
run: magento2/vendor/bin/phpcs -q --report=full --standard=Magento2 magento2/app/code/MercadoPago/
run: magento2/vendor/bin/phpcs -qn --report=full --standard=Magento2 magento2/app/code/MercadoPago/

- name: PHPStan version
id: phpstan-version
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.18.0] - 2022-11-16

### Added
- Feature for recording payment records in the Transaction table

## [3.17.1] - 2022-08-16

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</a>
</p>

# Magento 2 - Mercado Pago Module (v3.17.1)
# Magento 2 - Mercado Pago Module (v3.18.0)

The Mercado Pago plugin for Magento 2 allows you to expand the functionalities of your online store and offer a unique payment experience for your customers.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"type": "magento2-module",
"version": "3.17.1",
"version": "3.18.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
1 change: 1 addition & 0 deletions src/MercadoPago/Core/Helper/ConfigData.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class ConfigData
const PATH_ADVANCED_SUCCESS_PAGE = 'payment/mercadopago/use_successpage_mp';
const PATH_ADVANCED_CONSIDER_DISCOUNT = 'payment/mercadopago/consider_discount';
const PATH_ADVANCED_INTEGRATOR = 'payment/mercadopago/integrator_id';
const PATH_ADVANCED_SAVE_TRANSACTION = 'payment/mercadopago/save_transaction';
const PATH_ADVANCED_EMAIL_CREATE = 'payment/mercadopago/email_order_create';
const PATH_ADVANCED_EMAIL_UPDATE = 'payment/mercadopago/email_order_update';
}
13 changes: 13 additions & 0 deletions src/MercadoPago/Core/Model/Basic/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use MercadoPago\Core\Helper\ConfigData;
use MercadoPago\Core\Helper\Data as dataHelper;
use MercadoPago\Core\Model\Preference\Basic;
use MercadoPago\Core\Model\Transaction;

/**
* Class Payment
Expand Down Expand Up @@ -82,6 +83,7 @@ class Payment extends AbstractMethod

protected $_isInitializeNeeded = true;

private $_transaction;

/**
* Payment constructor.
Expand All @@ -100,6 +102,7 @@ class Payment extends AbstractMethod
* @param ScopeConfigInterface $scopeConfig
* @param Logger $logger
* @param Basic $basic
* @param Transaction $transaction
* @param array $data
*/
public function __construct(
Expand All @@ -117,6 +120,7 @@ public function __construct(
ScopeConfigInterface $scopeConfig,
Logger $logger,
Basic $basic,
Transaction $transaction,
array $data=[]
) {
parent::__construct(
Expand All @@ -140,6 +144,7 @@ public function __construct(
$this->_urlBuilder = $urlBuilder;
$this->_scopeConfig = $scopeConfig;
$this->_basic = $basic;
$this->_transaction = $transaction;

}//end __construct()

Expand All @@ -163,6 +168,14 @@ public function postPago()
'status' => 201,
];
$this->_helperData->log('Array preference ok', 'mercadopago-basic.log');

$order = $this->_orderFactory->create()->loadByIncrementId($response['response']['external_reference']);
$payment = $order->getPayment();

if ($this->_scopeConfig->isSetFlag(ConfigData::PATH_ADVANCED_SAVE_TRANSACTION, ScopeInterface::SCOPE_STORE)) {
$createTransaction = $this->_transaction->create($payment, $order, $response['response']['id']);
$this->_transaction->save($createTransaction);
}
} else {
$message = 'Processing error in the payment gateway. Please contact the administrator.';
if ($response['status'] == 500) {
Expand Down
18 changes: 17 additions & 1 deletion src/MercadoPago/Core/Model/Custom/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use MercadoPago\Core\Model\Core;
use MercadoPago\Core\Block\Adminhtml\System\Config\Version;
use MercadoPago\Core\Model\Notifications\Topics\Payment as PaymentNotification;
use MercadoPago\Core\Model\Transaction;

/**
* Class Payment
Expand Down Expand Up @@ -266,6 +267,11 @@ class Payment extends Cc implements GatewayInterface
*/
protected $_statusDetailMessage;

/**
* @var Transaction
*/
private $_transaction;

/**
* @param MercadopagoData $helperData
* @param CheckoutSession $checkoutSession
Expand Down Expand Up @@ -317,7 +323,8 @@ public function __construct(
Image $helperImage,
OrderInterface $order,
PaymentNotification $paymentNotification,
StatusDetailMessage $statusDetailMessage
StatusDetailMessage $statusDetailMessage,
Transaction $transaction
) {
parent::__construct(
$context,
Expand Down Expand Up @@ -347,6 +354,7 @@ public function __construct(
$this->_order = $order;
$this->_paymentNotification = $paymentNotification;
$this->_statusDetailMessage = $statusDetailMessage;
$this->_transaction = $transaction;
}//end __construct()

/**
Expand Down Expand Up @@ -493,6 +501,14 @@ public function createCustomPayment($preference, $gateway, $logName)
throw new LocalizedException($this->getRejectedStatusDetailMessage($statusDetail));
}

/** @var \Magento\Sales\Model\Order\Payment $payment */
$order = $this->getInfoInstance()->getOrder();
$payment = $order->getPayment();

if ($this->_scopeConfig->isSetFlag(ConfigData::PATH_ADVANCED_SAVE_TRANSACTION, ScopeInterface::SCOPE_STORE)) {
$this->_transaction->create($payment, $order, $response['response']['id']);
}

$this->getInfoInstance()->setAdditionalInformation('paymentResponse', $response['response']);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use MercadoPago\Core\Helper\Response;
use MercadoPago\Core\Model\Core;
use MercadoPago\Core\Model\Notifications\Notifications;
use MercadoPago\Core\Model\Transaction;

class MerchantOrder extends TopicsAbstract
{
Expand Down Expand Up @@ -64,6 +65,7 @@ class MerchantOrder extends TopicsAbstract
* @param TransactionFactory $transactionFactory
* @param InvoiceSender $invoiceSender
* @param InvoiceService $invoiceService
* @param Transaction $transaction
*/
public function __construct(
mpHelper $mpHelper,
Expand All @@ -77,13 +79,14 @@ public function __construct(
OrderCommentSender $orderCommentSender,
TransactionFactory $transactionFactory,
InvoiceSender $invoiceSender,
InvoiceService $invoiceService
InvoiceService $invoiceService,
Transaction $transaction
) {
$this->_mpHelper = $mpHelper;
$this->_scopeConfig = $scopeConfig;
$this->_coreModel = $coreModel;

parent::__construct($scopeConfig, $mpHelper, $orderFactory, $creditmemoFactory, $messageInterface, $statusFactory, $orderSender, $orderCommentSender, $transactionFactory, $invoiceSender, $invoiceService);
parent::__construct($scopeConfig, $mpHelper, $orderFactory, $creditmemoFactory, $messageInterface, $statusFactory, $orderSender, $orderCommentSender, $transactionFactory, $invoiceSender, $invoiceService, $transaction);
}

/**
Expand Down
18 changes: 16 additions & 2 deletions src/MercadoPago/Core/Model/Notifications/Topics/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use MercadoPago\Core\Helper\Round;
use MercadoPago\Core\Lib\RestClient;
use MercadoPago\Core\Model\Core;
use MercadoPago\Core\Model\Transaction;

class Payment extends TopicsAbstract
{
Expand All @@ -45,6 +46,11 @@ class Payment extends TopicsAbstract
*/
protected $_coreModel;

/**
* @var Transaction
*/
protected $_transaction;

/**
* Payment constructor.
*
Expand All @@ -60,6 +66,7 @@ class Payment extends TopicsAbstract
* @param TransactionFactory $transactionFactory
* @param InvoiceSender $invoiceSender
* @param InvoiceService $invoiceService
* @param Transaction $transaction
*/
public function __construct(
mpHelper $mpHelper,
Expand All @@ -73,14 +80,16 @@ public function __construct(
OrderCommentSender $orderCommentSender,
TransactionFactory $transactionFactory,
InvoiceSender $invoiceSender,
InvoiceService $invoiceService
InvoiceService $invoiceService,
Transaction $transaction
)
{
$this->_mpHelper = $mpHelper;
$this->_scopeConfig = $scopeConfig;
$this->_coreModel = $coreModel;
$this->_transaction = $transaction;

parent::__construct($scopeConfig, $mpHelper, $orderFactory, $creditmemoFactory, $messageInterface, $statusFactory, $orderSender, $orderCommentSender, $transactionFactory, $invoiceSender, $invoiceService);
parent::__construct($scopeConfig, $mpHelper, $orderFactory, $creditmemoFactory, $messageInterface, $statusFactory, $orderSender, $orderCommentSender, $transactionFactory, $invoiceSender, $invoiceService, $transaction);
} //end __construct()

/**
Expand Down Expand Up @@ -138,6 +147,11 @@ public function updateStatusOrderByPayment($payment)
];
}

if ($this->_scopeConfig->isSetFlag(ConfigData::PATH_ADVANCED_SAVE_TRANSACTION, ScopeInterface::SCOPE_STORE)) {
$paymentOrder = $order->getPayment();
$this->_transaction->update($paymentOrder, $order, $payment['status']);
}

$order = self::setStatusAndComment($order, $newOrderStatus, $message);

$this->updateAdditionalInformation($order, $payment);
Expand Down
18 changes: 16 additions & 2 deletions src/MercadoPago/Core/Model/Notifications/Topics/TopicsAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use MercadoPago\Core\Helper\Message\MessageInterface;
use MercadoPago\Core\Helper\Response;
use MercadoPago\Core\Helper\Round;
use MercadoPago\Core\Model\Transaction;

abstract class TopicsAbstract
{
Expand Down Expand Up @@ -80,6 +81,11 @@ abstract class TopicsAbstract
*/
protected $_invoiceService;

/**
* @var Transaction
*/
private $_transaction;

/**
* TopicsAbstract constructor.
* @param ScopeConfigInterface $scopeConfig
Expand All @@ -93,6 +99,7 @@ abstract class TopicsAbstract
* @param TransactionFactory $transactionFactory
* @param InvoiceSender $invoiceSender
* @param InvoiceService $invoiceService
* @param Transaction $transaction
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
Expand All @@ -105,7 +112,8 @@ public function __construct(
OrderCommentSender $orderCommentSender,
TransactionFactory $transactionFactory,
InvoiceSender $invoiceSender,
InvoiceService $invoiceService
InvoiceService $invoiceService,
Transaction $transaction
) {
$this->_dataHelper = $dataHelper;
$this->_scopeConfig = $scopeConfig;
Expand All @@ -118,6 +126,7 @@ public function __construct(
$this->_transactionFactory = $transactionFactory;
$this->_invoiceSender = $invoiceSender;
$this->_invoiceService = $invoiceService;
$this->_transaction = $transaction;
}

/**
Expand Down Expand Up @@ -431,7 +440,7 @@ public function updateStatus($order, $payment, $message)
$couponMP = $payment['coupon_amount'];
$paidTotal = $payment['transaction_details']['total_paid_amount'];

if($couponMP > 0){
if ($couponMP > 0) {
$paidTotal += $couponMP;
}

Expand All @@ -453,6 +462,11 @@ public function updateStatus($order, $payment, $message)
$order->setState($this->_getAssignedState($statusOrder));
}

if ($this->_scopeConfig->isSetFlag(ConfigData::PATH_ADVANCED_SAVE_TRANSACTION, ScopeInterface::SCOPE_STORE)) {
$paymentOrder = $order->getPayment();
$this->_transaction->update($paymentOrder, $order, $payment['status']);
}

$order->addStatusToHistory($statusOrder, $message, true);
if ($emailOrderCreate) {
if (!$order->getEmailSent()) {
Expand Down
Loading

0 comments on commit 474f739

Please sign in to comment.