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

Commit

Permalink
Merge pull request #75 from heidelpay/MAGE2-85/bugfix/order_mail_is_s…
Browse files Browse the repository at this point in the history
…ent_twice

MAGE2-85/bugfix/order_mail_is_sent_twice
sixer1182 authored Aug 9, 2018
2 parents 7fe07be + 4677431 commit 7130992
Showing 7 changed files with 106 additions and 114 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
28 changes: 15 additions & 13 deletions Controller/Index/Index.php
Original file line number Diff line number Diff line change
@@ -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;
@@ -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,
@@ -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,
@@ -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]);
@@ -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
60 changes: 20 additions & 40 deletions Controller/Index/Push.php
Original file line number Diff line number Diff line change
@@ -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;
@@ -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
@@ -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(
@@ -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(
@@ -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 */
@@ -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';
46 changes: 23 additions & 23 deletions Controller/Index/Redirect.php
Original file line number Diff line number Diff line change
@@ -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;
@@ -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.
@@ -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,
@@ -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,
@@ -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();
@@ -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 {
@@ -172,10 +173,9 @@ public function execute()
}
}


$session->clearHelperData();

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

60 changes: 28 additions & 32 deletions Controller/Index/Response.php
Original file line number Diff line number Diff line change
@@ -4,7 +4,13 @@

use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper;
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory;
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory;
use Heidelpay\Gateway\Model\TransactionFactory;
use Heidelpay\PhpPaymentApi\Exceptions\HashVerificationException;
use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\QuoteRepository;
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;
@@ -27,29 +33,21 @@
*
* @author Jens Richter
*
* @package heidelpay
* @subpackage magento2
* @category magento2
* @package heidelpay\magento2\controllers
*/
class Response extends \Heidelpay\Gateway\Controller\HgwAbstract
{
protected $resultPageFactory;
protected $logger;
/** @var QuoteRepository */
private $quoteRepository;

/** @var \Magento\Quote\Model\QuoteRepository */
protected $quoteRepository;
/** @var HeidelpayResponse The heidelpay response object */
private $heidelpayResponse;

/** @var \Magento\Framework\Controller\Result\RawFactory */
protected $resultFactory;
/** @var TransactionFactory */
private $transactionFactory;

/** @var \Heidelpay\PhpPaymentApi\Response The heidelpay response object */
protected $heidelpayResponse;

/** @var \Heidelpay\Gateway\Model\TransactionFactory */
protected $transactionFactory;

/** @var \Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory */
protected $paymentInformationCollectionFactory;
/** @var CollectionFactory */
private $paymentInformationCollectionFactory;

/**
* heidelpay Response constructor.
@@ -70,10 +68,9 @@ class Response extends \Heidelpay\Gateway\Controller\HgwAbstract
* @param \Magento\Framework\Encryption\Encryptor $encryptor
* @param \Magento\Customer\Model\Url $customerUrl
* @param \Magento\Framework\Controller\Result\RawFactory $rawResultFactory
* @param \Magento\Quote\Model\QuoteRepository $quoteRepository
* @param \Heidelpay\PhpPaymentApi\Response $heidelpayResponse
* @param QuoteRepository $quoteRepository
* @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory,
* @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory
* @param TransactionFactory $transactionFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
@@ -92,10 +89,9 @@ public function __construct(
\Magento\Framework\Encryption\Encryptor $encryptor,
\Magento\Customer\Model\Url $customerUrl,
\Magento\Framework\Controller\Result\RawFactory $rawResultFactory,
\Magento\Quote\Model\QuoteRepository $quoteRepository,
\Heidelpay\PhpPaymentApi\Response $heidelpayResponse,
QuoteRepository $quoteRepository,
PaymentInformationCollectionFactory $paymentInformationCollectionFactory,
\Heidelpay\Gateway\Model\TransactionFactory $transactionFactory
TransactionFactory $transactionFactory
) {
parent::__construct(
$context,
@@ -117,13 +113,13 @@ public function __construct(

$this->resultFactory = $rawResultFactory;
$this->quoteRepository = $quoteRepository;
$this->heidelpayResponse = $heidelpayResponse;
$this->paymentInformationCollectionFactory = $paymentInformationCollectionFactory;
$this->transactionFactory = $transactionFactory;
}

/**
* @inheritdoc
* @throws \Exception
*/
public function execute()
{
@@ -148,13 +144,13 @@ public function execute()
if (!$this->getRequest()->isPost()) {
$this->_logger->warning('Heidelpay - Response: Request is not POST.');

// return the result now, no further processing.
// no further processing.
return $result;
}

// initialize the Response object with data from the request.
try {
$this->heidelpayResponse->splitArray($this->getRequest()->getParams());
$this->heidelpayResponse = HeidelpayResponse::fromPost($this->getRequest()->getParams());
} catch (\Exception $e) {
$this->_logger->error(
'Heidelpay - Response: Cannot initialize response object from Post Request. ' . $e->getMessage()
@@ -174,11 +170,11 @@ public function execute()
try {
$this->heidelpayResponse->verifySecurityHash($secret, $identificationTransactionId);
} catch (HashVerificationException $e) {
$this->_logger->critical("Heidelpay Response - HashVerification Exception: " . $e->getMessage());
$this->_logger->critical('Heidelpay Response - HashVerification Exception: ' . $e->getMessage());
$this->_logger->critical(
"Heidelpay Response - Received request form server "
'Heidelpay Response - Received request form server '
. $this->getRequest()->getServer('REMOTE_ADDR')
. " with an invalid hash. This could be some kind of manipulation."
. ' with an invalid hash. This could be some kind of manipulation.'
);
$this->_logger->critical(
'Heidelpay Response - Reference secret hash: '
@@ -193,10 +189,10 @@ public function execute()
. print_r($this->heidelpayResponse, true)
);

/** @var \Magento\Sales\Model\Order $order */
/** @var Order $order */
$order = null;

/** @var \Magento\Quote\Model\Quote $quote */
/** @var Quote $quote */
$quote = null;

$data = $this->getRequest()->getParams();
@@ -247,7 +243,7 @@ public function execute()
if ($this->heidelpayResponse->isSuccess()) {
try {
// get the quote by transactionid from the heidelpay response
/** @var \Magento\Quote\Model\Quote $quote */
/** @var Quote $quote */
$quote = $this->quoteRepository->get($this->heidelpayResponse->getIdentification()->getTransactionId());
$quote->collectTotals();

19 changes: 14 additions & 5 deletions PaymentMethods/HeidelpayAbstractPaymentMethod.php
Original file line number Diff line number Diff line change
@@ -8,13 +8,15 @@
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory;
use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
use Heidelpay\PhpPaymentApi\ParameterGroups\BasketParameterGroup;
use Heidelpay\PhpPaymentApi\PaymentMethods\AbstractPaymentMethod;
use Heidelpay\PhpPaymentApi\Response;
use Magento\Sales\Api\Data\TransactionInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Invoice;
use Magento\Store\Model\ScopeInterface as StoreScopeInterface;
use Heidelpay\Gateway\Block\Payment\HgwAbstract;
use Heidelpay\PhpPaymentApi\PaymentMethods\PaymentMethodInterface;
use Magento\Store\Model\ScopeInterface;

/**
* Heidelpay abstract payment method
@@ -278,9 +280,16 @@ public function activeRedirect()
* @param integer $storeId
*
* @return string config value
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getConfigData($field, $storeId = null)
{
// in order to avoid the order mail to be sent twice,
// once by us and once by the SubmitObserver.
if ($field === 'order_place_redirect_url') {
return 'dummy_redirect_url';
}

$path = 'payment/' . $this->getCode() . '/' . $field;

return $this->_scopeConfig->getValue($path, StoreScopeInterface::SCOPE_STORE, $storeId);
@@ -401,7 +410,7 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
);
}

// set authentification data
// set authentication data
$this->performAuthentication();

// set basket data
@@ -562,7 +571,7 @@ public function saveHeidelpayTransaction(Response $response, $paymentMethod, $pa
/**
* Returns the heidelpay PhpPaymentApi Paymentmethod Instance.
*
* @return \Heidelpay\PhpPaymentApi\PaymentMethods\AbstractPaymentMethod
* @return AbstractPaymentMethod|PaymentMethodInterface
*/
public function getHeidelpayPaymentMethodInstance()
{
@@ -655,9 +664,9 @@ public function pendingTransactionProcessing($data, &$order, $message = null)
}

/**
*
* @param array $data
* @param array $data
* @param \Magento\Sales\Model\Order $order
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function processingTransactionProcessing($data, &$order)
{
@@ -717,7 +726,7 @@ public function getBookingMode($storeId = null)

return $this->_scopeConfig->getValue(
'payment/' . $this->getCode() . '/bookingmode',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_STORE,
$store
);
}
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Heidelpay_Gateway" schema_version="18.6.11" setup_version="18.6.11">
<module name="Heidelpay_Gateway" schema_version="18.8.9" setup_version="18.8.9">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />

0 comments on commit 7130992

Please sign in to comment.