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 #142 from heidelpay/develop
Browse files Browse the repository at this point in the history
Release 20.5.13
  • Loading branch information
Simon Gabriel authored May 12, 2020
2 parents b9d234c + e0a0715 commit a16fc0d
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 58 deletions.
9 changes: 8 additions & 1 deletion Block/Info/AbstractBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ public function printAdditionalInformationHtml()
}

if (! empty($this->transactionInfo->getJsonResponse())) {
return $this->getMethod()->additionalPaymentInformation($this->transactionInfo->getJsonResponse());
$methodInstance = $this->getMethod();
if (\is_callable([$methodInstance, 'additionalPaymentInformation'])) {
return $methodInstance->additionalPaymentInformation(
$this->transactionInfo->getJsonResponse()
);
}

$this->_logger->debug('heidelpay: Could not retrieve additionalPaymentInformation for class: \"' . \get_class($methodInstance) . '\".');
}

return '';
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

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

## 20.5.13
### Fixed
- An issue during checkout if phone number is optional and not set by customer. That leads to a failing address comparison
for secured payment methods and PayPal.
- Disable caching for dynamic blocks.
- An issue creating orders from Reservations.
- Problem when switching from an unknown payment method to a heidelpay gateway method.
- Invoice Payment methods : An issue not always setting the expected state after shipment.

## 20.2.24
### Added
- Refund to iDeal payment method.
Expand Down
16 changes: 7 additions & 9 deletions Controller/Adminhtml/Order/Shipment/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public function beforeExecute()

// if the response isn't successful, redirect back to the order view.
if (!$heidelpayMethod->getResponse()->isSuccess()) {
$this->messageManager->addErrorMessage(
__('Heidelpay Error at sending Finalize Request. The Shipment was not created.')
$this->messageManager->addWarningMessage(
__('Heidelpay Error at sending Finalize Request. The Shipment was created.')
. ' Error Message: ' . $heidelpayMethod->getResponse()->getError()['message']
);

Expand All @@ -142,16 +142,14 @@ public function beforeExecute()
);

$this->_redirect('*/*/new', ['order_id' => $this->getRequest()->getParam('order_id')]);
} else {
$order->addStatusHistoryComment('heidelpay - Finalizing Order');
$this->messageManager->addSuccessMessage(__('Shipping Notification has been sent to Heidelpay.'));
}

// set order state to "pending payment"
$state = Order::STATE_PENDING_PAYMENT;
$order->setState($state)->addStatusHistoryComment('heidelpay - Finalizing Order', true);

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

$this->messageManager->addSuccessMessage(__('Shipping Notification has been sent to Heidelpay.'));
}
$method->setShippedOrderState($order);
$this->orderResository->save($order);
}
}
}
6 changes: 3 additions & 3 deletions Controller/Index/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,21 @@ public function execute()
if (
$pushResponse->isSuccess() &&
!$pushResponse->isPending() &&
$this->_paymentHelper->isNewOrderType($paymentType)
$this->_paymentHelper->isNewOrderType($paymentMethod, $paymentType)
) {
$transactionId = $pushResponse->getIdentification()->getTransactionId();
$order = $this->orderHelper->fetchOrder($transactionId);
$quote = $this->quoteRepository->get($transactionId);

// create order if it doesn't exists already.
$order = $this->orderHelper->fetchOrderByQuoteId($transactionId);
if ($order === null || $order->isEmpty()) {
$transactionData = $this->_paymentHelper->getDataFromResponse($pushResponse);
$this->_paymentHelper->saveHeidelpayTransaction($pushResponse, $transactionData, 'PUSH');
$this->_logger->debug('heidelpay Push - Order does not exist for transaction. heidelpay transaction id: '
. $transactionId);

try {
$order = $this->_paymentHelper->createOrderFromQuote($quote);
$order = $this->_paymentHelper->handleOrderCreation($quote, 'PUSH');
if ($order === null || $order->isEmpty())
{
$this->_logger->error('Heidelpay - Response: Cannot submit the Quote. ' . $e->getMessage());
Expand Down
28 changes: 20 additions & 8 deletions Controller/Index/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Heidelpay\Gateway\Controller\HgwAbstract;
use Heidelpay\Gateway\Helper\Order as OrderHelper;
use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper;
use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory;
use Heidelpay\Gateway\Model\Transaction as HeidelpayTransaction;
Expand Down Expand Up @@ -50,6 +51,9 @@ class Redirect extends HgwAbstract
/** @var CollectionFactory */
private $transactionCollectionFactory;

/** @var OrderHelper */
private $orderHelper;

/**
* heidelpay Redirect constructor.
*
Expand All @@ -69,6 +73,7 @@ class Redirect extends HgwAbstract
* @param Encryptor $encryptor
* @param Url $customerUrl
* @param CollectionFactory $transactionCollectionFactory
* @param OrderHelper $orderHelper
*/
public function __construct(
Context $context,
Expand All @@ -86,7 +91,8 @@ public function __construct(
OrderCommentSender $orderCommentSender,
Encryptor $encryptor,
Url $customerUrl,
CollectionFactory $transactionCollectionFactory
CollectionFactory $transactionCollectionFactory,
OrderHelper $orderHelper
) {
parent::__construct(
$context,
Expand All @@ -107,6 +113,7 @@ public function __construct(
);

$this->transactionCollectionFactory = $transactionCollectionFactory;
$this->orderHelper = $orderHelper;
}

/**
Expand Down Expand Up @@ -156,15 +163,17 @@ public function execute()
/** @var Order $order */
$order = null;
try {
$order = $this->_orderFactory->create()->loadByAttribute('quote_id', $quoteId);
$this->_logger->debug('Load order by QuoteId: ' . $quoteId);
$order = $this->orderHelper->fetchOrderByQuoteId($quoteId);
} catch (Exception $e) {
$this->_logger->error(
'Heidelpay - Redirect: Cannot receive order.' . $e->getMessage()
);
}

// Check whether order was loaded correctly
if($order === null || $order->isEmpty()) {
$hasHeidelpayPayment = $this->orderHelper->hasHeidelpayPayment($order);
if($order === null || $order->isEmpty() || $order->isCanceled() || !$hasHeidelpayPayment) {
$this->_logger->error(
'Heidelpay - Redirect: Cannot receive order. Order creation might have failed.'
);
Expand Down Expand Up @@ -206,17 +215,20 @@ protected function updateSessionData($quoteId, Order $order, array $data)
$checkoutSession->clearHelperData();

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

// set OrderIds
$checkoutSession->setLastOrderId($order->getId())
->setLastRealOrderId($order->getIncrementId())
->setLastOrderStatus($order->getStatus());

$additionalPaymentInformation = $order->getPayment()
->getMethodInstance()
->additionalPaymentInformation($data);
$methodInstance = $order->getPayment()->getMethodInstance();
$additionalPaymentInformation = '';
if (\is_callable([$methodInstance, 'additionalPaymentInformation'])) {
$additionalPaymentInformation = $methodInstance->additionalPaymentInformation($data);
} else {
$this->_logger->error('heidelpay - The payment method seems to be from a different plugin.');
}

$checkoutSession->setHeidelpayInfo($additionalPaymentInformation);
}
Expand Down
2 changes: 1 addition & 1 deletion Controller/Index/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public function execute()
$quote = $this->quoteRepository->get($identificationTransactionId);

/** @var Order $order */
$order = $this->_paymentHelper->createOrderFromQuote($quote);
$order = $this->_paymentHelper->handleOrderCreation($quote, 'RESPONSE');
} catch (Exception $e) {
$this->_logger->error('Heidelpay - Response: Cannot submit the Quote. ' . $e->getMessage());
return $result;
Expand Down
50 changes: 43 additions & 7 deletions Helper/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Heidelpay\Gateway\Helper;


use Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Data\Collection;
use Magento\Framework\DataObject;
use Magento\Sales\Helper\Data as SalesHelper;
use Magento\Sales\Model\Order as MagentoOrder;
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender;
Expand Down Expand Up @@ -117,16 +119,50 @@ public function handleOrderMail($order)
}

/**
* @param $transactionId
* @return MagentoOrder
* Returns the last Order to the quote with the given quoteId or an empty order object.
*
* @param $quoteId
* @return MagentoOrder|DataObject
*/
public function fetchOrderByQuoteId($quoteId)
{
$orderList = $this->fetchOrdersByQuoteId($quoteId);

return $orderList->getLastItem();
}

/**
* @param $quoteId
* @return Collection
*/
public function fetchOrder($transactionId)
protected function fetchOrdersByQuoteId($quoteId): Collection
{
$criteria = $this->searchCriteriaBuilder->addFilter('quote_id', $transactionId)->create();
$criteria = $this->searchCriteriaBuilder->addFilter('quote_id', $quoteId)->create();

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

/**
* Returns true if the payment of the order is part of this payment module.
*
* @param MagentoOrder $order
* @return bool
*/
public function hasHeidelpayPayment(MagentoOrder $order): bool
{
$payment = $order->getPayment();
$returnVal = true;

if ($payment === null) {
$this->_logger->error('heidelpay - Empty payment.');
$returnVal = false;
} elseif (!$payment->getMethodInstance() instanceof HeidelpayAbstractPaymentMethod) {
$this->_logger->error('heidelpay - Not heidelpay payment.');
$returnVal = false;
}

return $orderList->getFirstItem();
return $returnVal;
}
}
}
Loading

0 comments on commit a16fc0d

Please sign in to comment.