Skip to content

Commit

Permalink
Merge pull request #15 from mercadopago/release/1.8.0
Browse files Browse the repository at this point in the history
v1.8.0
  • Loading branch information
luiztucillo authored Apr 9, 2024
2 parents 171828e + 2aa31c3 commit cf185e6
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 114 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/ESLint.yml

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ 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).

## [1.8.0] - 2024-04-09
### Fixed
- Adjust 3ds modal sizing to be compliant with documentation
- Fix area code not set on setup:upgrade
- Fix/quote mp payment int in 3DS flow
- Fix sending payer.id in any payment flow

## [1.7.0] - 2024-03-27
### Added
- Added trackings in selected paths for melidata
Expand Down
21 changes: 19 additions & 2 deletions Controller/Notification/CheckoutPro.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Framework\App\Request\InvalidRequestException;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\Order\Payment\Transaction;
use MercadoPago\AdbPayment\Controller\MpIndex;
use MercadoPago\AdbPayment\Model\Notification\Refund\CheckoutPro as CheckoutProRefund;
Expand Down Expand Up @@ -317,12 +318,12 @@ public function processNotification(
}
}

$this->createChild($mpTransactionId, $childTransactionId, $order);

$notificationId = $mercadopagoData['notification_id'];

$order = $this->fetchStatus->fetch($order->getEntityId(), $notificationId);

$this->updateInvoice($order, $mpTransactionId, $childTransactionId);

$result = [
'code' => 200,
'msg' => [
Expand All @@ -334,4 +335,20 @@ public function processNotification(

return $result;
}

private function updateInvoice(OrderInterface $order, $mpTransactionId, $transactionId): void
{
$payment = $order->getPayment();

if ($payment->getIsTransactionApproved()) {
$payment->setShouldCloseParentTransaction(true);
$payment->setParentTransactionId($mpTransactionId);
$payment->setTransactionId($transactionId);
$payment->setIsTransactionClosed(true);
$payment->addTransaction(Transaction::TYPE_CAPTURE);

$order->getPayment()->update(true);
$this->orderRepository->save($order);
}
}
}
12 changes: 7 additions & 5 deletions Gateway/Request/PayerDataRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ public function build(array $buildSubject)
['order' => $payment->getOrder()]
);

$mpUserId = $payment->getAdditionalInformation('mp_user_id');
$type = isset($mpUserId) ? 'customer' : null;

$payerEntityType = $payment->getAdditionalInformation('payer_entity_type');

$billingAddress = $orderAdapter->getBillingAddress();
Expand All @@ -128,8 +125,6 @@ public function build(array $buildSubject)
$phoneNumber = substr($phone, 2);

$result[self::PAYER] = [
self::TYPE => $type,
self::ID => $mpUserId,
self::EMAIL => $billingAddress->getEmail(),
self::FIRST_NAME => $billingAddress->getFirstname(),
self::LAST_NAME => $billingAddress->getLastname(),
Expand All @@ -143,6 +138,13 @@ public function build(array $buildSubject)
$result[self::PAYER][self::ENTITY_TYPE] = $payerEntityType;
}

$result = $this->_prepareData($buildSubject, $result);

return $result;
}

protected function _prepareData(array $buildSubject, array $result): array
{
return $result;
}
}
32 changes: 32 additions & 0 deletions Gateway/Request/PayerDataRequestVault.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Copyright © MercadoPago. All rights reserved.
*
* @author Mercado Pago
* @license See LICENSE for license details.
*/

namespace MercadoPago\AdbPayment\Gateway\Request;

use Magento\Payment\Gateway\Request\BuilderInterface;

/**
* Gateway requests for Payer data.
*/
class PayerDataRequestVault extends PayerDataRequest implements BuilderInterface
{
protected function _prepareData(array $buildSubject, array $result): array
{
$paymentDO = $this->subjectReader->readPayment($buildSubject);
$payment = $paymentDO->getPayment();

$mpUserId = $payment->getAdditionalInformation('mp_user_id');
$type = isset($mpUserId) ? 'customer' : null;

$result[self::PAYER][self::TYPE] = $type;
$result[self::PAYER][self::ID] = $mpUserId;

return $result;
}
}
5 changes: 0 additions & 5 deletions Model/Console/Command/Adminstrative/FetchMerchant.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ public function __construct(
$this->storeManager = $storeManager;
$this->json = $json;
$this->messageManager = $messageManager;
try {
$this->state->getAreaCode();
} catch (Exception $e) {
$this->state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,15 @@

namespace MercadoPago\AdbPayment\Model\Console\Command\Notification;

use Exception;
use Magento\Sales\Model\Order;
use MercadoPago\AdbPayment\Model\Console\Command\Notification\CheckoutProAddChildPayment as CheckoutProAddChildPayment;

/**
* Model for Command lines to add child transaction in Checkout Credits.
*/
class CheckoutCreditsAddChildPayment extends CheckoutProAddChildPayment
{
/**
* Command Add.
*
* @param int $orderId
* @param string $childTransaction
*
* @return void
*/
public function add($orderId, $childTransaction)
protected function _getInitMessage(): string
{
$this->writeln('Init Fetch Checkout Credits Payments');

/** @var Order $order */
$order = $this->order->load($orderId);

$payment = $order->getPayment();

$preferenceId = $order->getExtOrderId();

try {
$payment->setTransactionId($childTransaction);
$payment->setParentTransactionId($preferenceId);
$payment->setIsTransactionClosed(false);
$payment->setShouldCloseParentTransaction(true);
$payment->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_AUTH);
$order->save();
$payment->update(true);
} catch (Exception $exc) {
$this->writeln('<error>' . $exc->getMessage() . '</error>');
}

if ($order->getState() === Order::STATE_PAYMENT_REVIEW) {
if (
$order->getStatus() === Order::STATE_CLOSED
|| $order->getStatus() === Order::STATE_PROCESSING
|| $order->getStatus() === Order::STATE_COMPLETE
) {
$order = $payment->getOrder();
$order->setState($order->getStatus());
} else {
$order = $payment->getOrder();
$order->setState(Order::STATE_NEW);
$order->setStatus('pending');
}
}

$this->writeln(
'<info>' .
__(
'Order %1 - Increment Id %2 - state %3',
$orderId,
$order->getIncrementId(),
$order->getState(),
)
. '</info>'
);

$order->save();

$this->writeln(__('Finished'));
return 'Init Fetch Checkout Credits Payments';
}
}
23 changes: 14 additions & 9 deletions Model/Console/Command/Notification/CheckoutProAddChildPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Exception;
use Magento\Payment\Model\Method\Logger;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Payment\Transaction;
use Magento\Sales\Api\OrderRepositoryInterface;
use MercadoPago\AdbPayment\Model\Console\Command\AbstractModel;

/**
Expand All @@ -25,22 +25,27 @@ class CheckoutProAddChildPayment extends AbstractModel
protected $logger;

/**
* @var Order
* @var OrderRepository
*/
protected $order;
protected $orderRepository;

/**
* @param Logger $logger
* @param Order $order
*/
public function __construct(
Logger $logger,
Order $order
OrderRepositoryInterface $orderRepository
) {
parent::__construct(
$logger
);
$this->order = $order;
$this->orderRepository = $orderRepository;
}

protected function _getInitMessage(): string
{
return 'Init Fetch Checkout Pro Payments';
}

/**
Expand All @@ -53,10 +58,10 @@ public function __construct(
*/
public function add($orderId, $childTransaction)
{
$this->writeln('Init Fetch Checkout Pro Payments');
$this->writeln($this->_getInitMessage());

/** @var Order $order */
$order = $this->order->load($orderId);
$order = $this->orderRepository->get($orderId);

$payment = $order->getPayment();

Expand All @@ -68,7 +73,7 @@ public function add($orderId, $childTransaction)
$payment->setIsTransactionClosed(false);
$payment->setShouldCloseParentTransaction(true);
$payment->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_AUTH);
$order->save();
$this->orderRepository->save($order);
$payment->update(true);
} catch (Exception $exc) {
$this->writeln('<error>'.$exc->getMessage().'</error>');
Expand Down Expand Up @@ -100,7 +105,7 @@ public function add($orderId, $childTransaction)
.'</info>'
);

$order->save();
$this->orderRepository->save($order);

$this->writeln(__('Finished'));
}
Expand Down
13 changes: 7 additions & 6 deletions Model/Console/Command/Notification/FetchStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Exception;
use Magento\Payment\Model\Method\Logger;
use Magento\Sales\Model\Order;
use Magento\Sales\Api\OrderRepositoryInterface;
use MercadoPago\AdbPayment\Model\Console\Command\AbstractModel;

/**
Expand All @@ -24,22 +25,22 @@ class FetchStatus extends AbstractModel
protected $logger;

/**
* @var Order
* @var OrderRepository
*/
protected $order;
protected $orderRepository;

/**
* @param Logger $logger
* @param Order $order
*/
public function __construct(
Logger $logger,
Order $order
OrderRepositoryInterface $orderRepository
) {
parent::__construct(
$logger
);
$this->order = $order;
$this->orderRepository = $orderRepository;
}

/**
Expand All @@ -54,7 +55,7 @@ public function fetch($orderId, $notificationId = null)
{
$this->writeln('Init Fetch Status');
/** @var Order $order */
$order = $this->order->load($orderId);
$order = $this->orderRepository->get($orderId);

$payment = $order->getPayment();

Expand Down Expand Up @@ -96,7 +97,7 @@ public function fetch($orderId, $notificationId = null)
.'</info>'
);

$order->save();
$this->orderRepository->save($order);

$this->writeln(__('Finished'));

Expand Down
Loading

0 comments on commit cf185e6

Please sign in to comment.