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 #43 from heidelpay/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
stevenobird authored Jan 24, 2018
2 parents 5687967 + 906031e commit c36bc38
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.project
/composer.phar
/composer.lock
/auth.json
42 changes: 28 additions & 14 deletions Controller/Index/Push.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace Heidelpay\Gateway\Controller\Index;

use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Sales\Model\Order\Payment\Transaction;
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Model\OrderRepository;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\Collection;

/**
* heidelpay Push Controller
Expand All @@ -25,9 +28,9 @@
class Push extends \Heidelpay\Gateway\Controller\HgwAbstract
{
/**
* @var \Magento\Quote\Model\QuoteRepository
* @var OrderRepository $orderRepository
*/
protected $quoteRepository;
protected $orderRepository;

/**
* @var \Magento\Sales\Api\Data\OrderInterface
Expand All @@ -43,6 +46,10 @@ class Push extends \Heidelpay\Gateway\Controller\HgwAbstract
* @var HeidelpayTransactionCollectionFactory
*/
protected $transactionCollectionFactory;
/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;

/**
* Push constructor.
Expand All @@ -62,10 +69,11 @@ class Push extends \Heidelpay\Gateway\Controller\HgwAbstract
* @param \Magento\Sales\Model\Order\Email\Sender\OrderCommentSender $orderCommentSender
* @param \Magento\Framework\Encryption\Encryptor $encryptor
* @param \Magento\Customer\Model\Url $customerUrl
* @param \Magento\Quote\Model\QuoteRepository $quoteRepository
* @param OrderRepository $orderRepository
* @param \Magento\Sales\Api\Data\OrderInterface $order
* @param \Heidelpay\PhpApi\Push $heidelpayPush
* @param HeidelpayTransactionCollectionFactory $collectionFactory
* @param SearchCriteriaBuilder $searchCriteriaBuilder
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
Expand All @@ -83,10 +91,11 @@ public function __construct(
\Magento\Sales\Model\Order\Email\Sender\OrderCommentSender $orderCommentSender,
\Magento\Framework\Encryption\Encryptor $encryptor,
\Magento\Customer\Model\Url $customerUrl,
\Magento\Quote\Model\QuoteRepository $quoteRepository,
OrderRepository $orderRepository,
\Magento\Sales\Api\Data\OrderInterface $order,
\Heidelpay\PhpApi\Push $heidelpayPush,
HeidelpayTransactionCollectionFactory $collectionFactory
HeidelpayTransactionCollectionFactory $collectionFactory,
SearchCriteriaBuilder $searchCriteriaBuilder
) {
parent::__construct(
$context,
Expand All @@ -106,11 +115,12 @@ public function __construct(
$customerUrl
);

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

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

public function execute()
Expand Down Expand Up @@ -152,14 +162,18 @@ public function execute()
if ($this->_paymentHelper->isReceiptAble($paymentMethod, $paymentType)) {
// only when the Response is ACK.
if ($this->heidelpayPush->getResponse()->isSuccess()) {
// load the reference quote to receive the quote information.
$quote = $this->quoteRepository->get(
$this->heidelpayPush->getResponse()->getIdentification()->getTransactionId()
);

// load the order by quote.
/** @var \Magento\Sales\Model\Order $order */
$order = $this->order->loadByIncrementIdAndStoreId($quote->getReservedOrderId(), $quote->getStoreId());
// load the referenced order to receive the order information.
$criteria = $this->searchCriteriaBuilder
->addFilter(
'quote_id',
$this->heidelpayPush->getResponse()->getIdentification()->getTransactionId()
)->create();

/** @var Collection $orderList */
$orderList = $this->orderRepository->getList($criteria);

/** @var Order $order */
$order = $orderList->getFirstItem();

$paidAmount = (float)$this->heidelpayPush->getResponse()->getPresentation()->getAmount();
$dueLeft = (float)($order->getTotalDue() - $paidAmount);
Expand Down
6 changes: 3 additions & 3 deletions Helper/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Heidelpay\Gateway\Helper;

use Heidelpay\CustomerMessages\CustomerMessage;
use Heidelpay\MessageCodeMapper\MessageCodeMapper;
use Magento\Framework\HTTP\ZendClientFactory;
use Magento\Payment\Model\Method\Logger;
use Magento\Sales\Model\Order;
Expand Down Expand Up @@ -118,8 +118,8 @@ public function format($number)
*/
public function handleError($errorCode = null)
{
$customerMessage = new CustomerMessage($this->localeResolver->getLocale());
return $customerMessage->getMessage($errorCode);
$messageCodeMapper = new MessageCodeMapper($this->localeResolver->getLocale());
return $messageCodeMapper->getMessage($errorCode);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"magento/module-backend": "^100.0.0 | ^101.0.0",
"magento/framework": "^100.0.0 | ^101.0.0",
"heidelpay/php-api": "~17.7.14",
"heidelpay/php-customer-messages": "~17.10.11"
"heidelpay/php-message-code-mapper": "~1.0.0"
},
"require-dev": {
"magento/marketplace-eqp": "~1.0.5",
Expand Down

0 comments on commit c36bc38

Please sign in to comment.