Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

MAGE2-85/bugfix/order_mail_is_sent_twice #75

Merged
merged 3 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

This project does not follow a versioning standard. Versions are crafted after the dates; for example, the version 17.7.25 was released on July, 25th in 2017

## 18.8.9

### Fixed
- An issue which resulted in the order mail being sent twice.

## 18.6.11

### Fixed
Expand Down
28 changes: 15 additions & 13 deletions Controller/Index/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper;
use Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Escaper;
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender;
use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
Expand All @@ -16,21 +18,15 @@
* @link http://dev.heidelpay.com/magento2
* @author Jens Richter
*
* @package heidelpay
* @subpackage magento2
* @category magento2
* @package heidelpay\magento2\controllers
*/
class Index extends \Heidelpay\Gateway\Controller\HgwAbstract
{
protected $resultPageFactory;
protected $logger;

/** @var \Magento\Framework\Escaper */
protected $escaper;

/** @var Escaper */
private $escaper;

public function __construct(
\Magento\Framework\App\Action\Context $context,
Context $context,
\Magento\Customer\Model\Session $customerSession,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Sales\Model\OrderFactory $orderFactory,
Expand All @@ -45,7 +41,7 @@ public function __construct(
OrderCommentSender $orderCommentSender,
\Magento\Framework\Encryption\Encryptor $encryptor,
\Magento\Customer\Model\Url $customerUrl,
\Magento\Framework\Escaper $escaper
Escaper $escaper
) {
parent::__construct(
$context,
Expand All @@ -68,13 +64,19 @@ public function __construct(
$this->escaper = $escaper;
}

/**
* {@inheritDoc}
* @throws \Heidelpay\PhpBasketApi\Exception\InvalidBasketitemPositionException
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Exception
*/
public function execute()
{
$session = $this->getCheckout();
$quote = $session->getQuote();

if (!$quote->getId()) {
$message = __("An unexpected error occurred. Please contact us to get further information.");
$message = __('An unexpected error occurred. Please contact us to get further information.');
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($message));

return $this->_redirect('checkout/cart/', ['_secure' => true]);
Expand All @@ -87,7 +89,7 @@ public function execute()
/** @var \Heidelpay\PhpPaymentApi\Response $response */
$response = $payment->getHeidelpayUrl($quote);

$this->_logger->debug('Heidelpay init respose : ' . print_r($response, 1));
$this->_logger->debug('Heidelpay init response : ' . print_r($response, 1));

if ($response->isSuccess()) {
// redirect to payment url, if it uses redirecting
Expand Down
60 changes: 20 additions & 40 deletions Controller/Index/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Heidelpay\Gateway\Controller\Index;

use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender;
use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Magento\Sales\Model\Order\Payment\Transaction;
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Model\OrderRepository;
Expand All @@ -21,39 +23,20 @@
*
* @author Stephano Vogel
*
* @package heidelpay
* @subpackage magento2
* @category magento2
* @package heidelpay\magento2\controllers
*/
class Push extends \Heidelpay\Gateway\Controller\HgwAbstract
{
/**
* @var OrderRepository $orderRepository
*/
protected $orderRepository;
/** @var OrderRepository $orderRepository */
private $orderRepository;

/**
* @var \Magento\Sales\Api\Data\OrderInterface
*/
protected $order;

/**
* @var \Heidelpay\PhpPaymentApi\Push
*/
protected $heidelpayPush;
/** @var \Heidelpay\PhpPaymentApi\Push */
private $heidelpayPush;

/**
* @var HeidelpayTransactionCollectionFactory
*/
protected $transactionCollectionFactory;
/**
* @var SearchCriteriaBuilder
*/
/** @var SearchCriteriaBuilder */
private $searchCriteriaBuilder;

/**
* Push constructor.
*
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Checkout\Model\Session $checkoutSession
Expand All @@ -64,15 +47,13 @@ class Push extends \Heidelpay\Gateway\Controller\HgwAbstract
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteObject
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Heidelpay\Gateway\Helper\Payment $paymentHelper
* @param \Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender
* @param \Magento\Sales\Model\Order\Email\Sender\InvoiceSender $invoiceSender
* @param \Magento\Sales\Model\Order\Email\Sender\OrderCommentSender $orderCommentSender
* @param OrderSender $orderSender
* @param InvoiceSender $invoiceSender
* @param OrderCommentSender $orderCommentSender
* @param \Magento\Framework\Encryption\Encryptor $encryptor
* @param \Magento\Customer\Model\Url $customerUrl
* @param OrderRepository $orderRepository
* @param \Magento\Sales\Api\Data\OrderInterface $order
* @param \Heidelpay\PhpPaymentApi\Push $heidelpayPush
* @param HeidelpayTransactionCollectionFactory $collectionFactory
* @param SearchCriteriaBuilder $searchCriteriaBuilder
*/
public function __construct(
Expand All @@ -86,15 +67,13 @@ public function __construct(
\Magento\Quote\Api\CartRepositoryInterface $quoteObject,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Heidelpay\Gateway\Helper\Payment $paymentHelper,
\Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender,
\Magento\Sales\Model\Order\Email\Sender\InvoiceSender $invoiceSender,
\Magento\Sales\Model\Order\Email\Sender\OrderCommentSender $orderCommentSender,
OrderSender $orderSender,
InvoiceSender $invoiceSender,
OrderCommentSender $orderCommentSender,
\Magento\Framework\Encryption\Encryptor $encryptor,
\Magento\Customer\Model\Url $customerUrl,
OrderRepository $orderRepository,
\Magento\Sales\Api\Data\OrderInterface $order,
\Heidelpay\PhpPaymentApi\Push $heidelpayPush,
HeidelpayTransactionCollectionFactory $collectionFactory,
SearchCriteriaBuilder $searchCriteriaBuilder
) {
parent::__construct(
Expand All @@ -116,13 +95,14 @@ public function __construct(
);

$this->orderRepository = $orderRepository;
$this->order = $order;

$this->heidelpayPush = $heidelpayPush;
$this->transactionCollectionFactory = $collectionFactory;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
}

/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void
* @throws \Heidelpay\PhpPaymentApi\Exceptions\XmlResponseParserException
*/
public function execute()
{
/** @var \Magento\Framework\App\Request\Http $request */
Expand Down Expand Up @@ -176,7 +156,7 @@ public function execute()
$order = $orderList->getFirstItem();

$paidAmount = (float)$this->heidelpayPush->getResponse()->getPresentation()->getAmount();
$dueLeft = (float)($order->getTotalDue() - $paidAmount);
$dueLeft = $order->getTotalDue() - $paidAmount;

$state = Order::STATE_PROCESSING;
$comment = 'heidelpay - Purchase Complete';
Expand Down
46 changes: 23 additions & 23 deletions Controller/Index/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
namespace Heidelpay\Gateway\Controller\Index;

use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper;
use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory;
use Heidelpay\PhpPaymentApi\Response;
use Magento\Sales\Helper\Data;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender;
use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
Expand All @@ -20,23 +24,18 @@
* @link http://dev.heidelpay.com/magento2
* @author Jens Richter
*
* @package heidelpay
* @subpackage magento2
* @category magento2
* @package heidelpay\magento2\controllers
*/
class Redirect extends \Heidelpay\Gateway\Controller\HgwAbstract
{
protected $resultPageFactory;
protected $logger;
/** @var Response The heidelpay response class */
private $heidelpayResponse;

/** @var \Heidelpay\PhpPaymentApi\Response The heidelpay response class */
protected $heidelpayResponse;
/** @var CollectionFactory */
private $transactionCollectionFactory;

/** @var \Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory */
protected $transactionCollectionFactory;

/** @var \Magento\Sales\Helper\Data */
protected $salesHelper;
/** @var Data */
private $salesHelper;

/**
* heidelpay Redirect constructor.
Expand All @@ -51,14 +50,13 @@ class Redirect extends \Heidelpay\Gateway\Controller\HgwAbstract
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteObject
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param HeidelpayHelper $paymentHelper
* @param \Magento\Sales\Helper\Data $salesHelper
* @param Data $salesHelper
* @param OrderSender $orderSender
* @param InvoiceSender $invoiceSender
* @param OrderCommentSender $orderCommentSender
* @param \Magento\Framework\Encryption\Encryptor $encryptor
* @param \Magento\Customer\Model\Url $customerUrl
* @param \Heidelpay\PhpPaymentApi\Response $heidelpayResponse
* @param \Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory $transactionCollectionFactory
* @param CollectionFactory $transactionCollectionFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
Expand All @@ -71,14 +69,13 @@ public function __construct(
\Magento\Quote\Api\CartRepositoryInterface $quoteObject,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
HeidelpayHelper $paymentHelper,
\Magento\Sales\Helper\Data $salesHelper,
Data $salesHelper,
OrderSender $orderSender,
InvoiceSender $invoiceSender,
OrderCommentSender $orderCommentSender,
\Magento\Framework\Encryption\Encryptor $encryptor,
\Magento\Customer\Model\Url $customerUrl,
\Heidelpay\PhpPaymentApi\Response $heidelpayResponse,
\Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory $transactionCollectionFactory
CollectionFactory $transactionCollectionFactory
) {
parent::__construct(
$context,
Expand All @@ -98,11 +95,14 @@ public function __construct(
$customerUrl
);

$this->heidelpayResponse = $heidelpayResponse;
$this->transactionCollectionFactory = $transactionCollectionFactory;
$this->salesHelper = $salesHelper;
}

/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
* @throws \Heidelpay\MessageCodeMapper\Exceptions\MissingLocaleFileException
*/
public function execute()
{
$session = $this->getCheckout();
Expand Down Expand Up @@ -133,20 +133,21 @@ public function execute()

// display the customer-friendly message for the customer
$this->messageManager->addErrorMessage(
__("An unexpected error occurred. Please contact us to get further information.")
__('An unexpected error occurred. Please contact us to get further information.')
);

return $this->_redirect('checkout/cart/', ['_secure' => true]);
}

// initialize the Response object with data from the transaction.
$this->heidelpayResponse = $this->heidelpayResponse->splitArray($data);
$this->heidelpayResponse = Response::fromPost($data);

// set Parameters for success page
if ($this->heidelpayResponse->isSuccess()) {
// lock the quote
$session->getQuote()->setIsActive(false)->save();

/** @var Order $order */
$order = null;

try {
Expand All @@ -172,10 +173,9 @@ public function execute()
}
}


$session->clearHelperData();

// set QouteIds
// set QuoteIds
$session->setLastQuoteId($quoteId)
->setLastSuccessQuoteId($quoteId);

Expand Down
Loading