Skip to content

Commit

Permalink
Merge pull request #203 from michielgerritsen/1.8.0-merged
Browse files Browse the repository at this point in the history
1.8.0 merged
  • Loading branch information
Marvin-Magmodules authored Nov 7, 2019
2 parents e00bcf3 + f047b67 commit b4b7c3d
Show file tree
Hide file tree
Showing 64 changed files with 2,245 additions and 64 deletions.
33 changes: 33 additions & 0 deletions Block/PaymentFee/Sales/Creditmemo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Block\PaymentFee\Sales;

use Magento\Framework\DataObject;
use Magento\Framework\View\Element\Template;
use Magento\Sales\Block\Adminhtml\Order\Creditmemo\Totals;

class Creditmemo extends Template
{
public function initTotals()
{
/** @var Totals $parentBlock */
$parentBlock = $this->getParentBlock();
$creditmemo = $parentBlock->getCreditmemo();

if (!(int)$creditmemo->getBaseMolliePaymentFee()) {
return;
}

$total = new DataObject([
'code' => 'mollie_payment_fee',
'value' => $creditmemo->getMolliePaymentFee() + $creditmemo->getMolliePaymentFeeTax(),
'label' => __('Payment Fee'),
]);

$parentBlock->addTotalBefore($total, 'tax');
}
}
54 changes: 54 additions & 0 deletions Block/PaymentFee/Sales/CreditmemoNew.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Block\PaymentFee\Sales;

use Magento\Framework\DataObject;
use Magento\Framework\View\Element\Template;
use Magento\Sales\Block\Adminhtml\Order\Creditmemo\Totals;
use Mollie\Payment\Service\Order\Creditmemo as CreditmemoService;

class CreditmemoNew extends Template
{
/**
* @var CreditmemoService
*/
private $creditmemoService;

public function __construct(
Template\Context $context,
CreditmemoService $creditmemoService,
array $data = []
) {
parent::__construct($context, $data);

$this->creditmemoService = $creditmemoService;
}

public function initTotals()
{
/** @var Totals $parentBlock */
$parentBlock = $this->getParentBlock();
$order = $parentBlock->getOrder();
$creditmemo = $parentBlock->getCreditmemo();

if (!($order->getMolliePaymentFee() + $order->getMolliePaymentFeeTax())) {
return;
}

if (!$this->creditmemoService->isFullOrLastPartialCreditmemo($creditmemo)) {
return;
}

$total = new DataObject([
'code' => 'mollie_payment_fee',
'value' => $order->getMolliePaymentFee() + $order->getMolliePaymentFeeTax(),
'label' => __('Payment Fee'),
]);

$parentBlock->addTotalBefore($total, 'tax');
}
}
33 changes: 33 additions & 0 deletions Block/PaymentFee/Sales/Order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Block\PaymentFee\Sales;

use Magento\Framework\DataObject;
use Magento\Framework\View\Element\Template;
use Magento\Sales\Block\Adminhtml\Order\Totals;

class Order extends Template
{
public function initTotals()
{
/** @var Totals $parentBlock */
$parentBlock = $this->getParentBlock();
$order = $parentBlock->getOrder();

if (!($order->getMolliePaymentFee() + $order->getMolliePaymentFeeTax())) {
return;
}

$total = new DataObject([
'code' => 'mollie_payment_fee',
'value' => $order->getMolliePaymentFee() + $order->getMolliePaymentFeeTax(),
'label' => __('Payment Fee'),
]);

$parentBlock->addTotalBefore($total, 'tax');
}
}
95 changes: 95 additions & 0 deletions Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

class Config
{
const XML_PATH_STATUS_PENDING_BANKTRANSFER = 'payment/mollie_methods_banktransfer/order_status_pending';
const XML_PATH_STATUS_NEW_PAYMENT_LINK = 'payment/mollie_methods_paymentlink/order_status_new';
const PAYMENT_KLARNAPAYLATER_PAYMENT_SURCHARGE = 'payment/mollie_methods_klarnapaylater/payment_surcharge';
const PAYMENT_KLARNAPAYLATER_PAYMENT_SURCHARGE_TAX_CLASS = 'payment/mollie_methods_klarnapaylater/payment_surcharge_tax_class';
const PAYMENT_KLARNASLICEIT_PAYMENT_SURCHARGE = 'payment/mollie_methods_klarnasliceit/payment_surcharge';
const PAYMENT_KLARNASLICEIT_PAYMENT_SURCHARGE_TAX_CLASS = 'payment/mollie_methods_klarnasliceit/payment_surcharge_tax_class';

/**
* @var ScopeConfigInterface
*/
private $config;

public function __construct(
ScopeConfigInterface $config
) {
$this->config = $config;
}

/**
* @param $path
* @param $storeId
* @return string
*/
private function getPath($path, $storeId)
{
return $this->config->getValue($path, ScopeInterface::SCOPE_STORE, $storeId);
}

public function statusPendingBanktransfer($storeId = null)
{
return $this->config->getValue(
static::XML_PATH_STATUS_PENDING_BANKTRANSFER,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

public function statusNewPaymentLink($storeId = null)
{
return $this->config->getValue(
static::XML_PATH_STATUS_NEW_PAYMENT_LINK,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* @param int|null $storeId
* @return string
*/
public function klarnaPaylaterPaymentSurcharge($storeId = null)
{
return $this->getPath(static::PAYMENT_KLARNAPAYLATER_PAYMENT_SURCHARGE, $storeId);
}

/**
* @param int|null $storeId
* @return string
*/
public function klarnaPaylaterPaymentSurchargeTaxClass($storeId = null)
{
return $this->getPath(static::PAYMENT_KLARNAPAYLATER_PAYMENT_SURCHARGE_TAX_CLASS, $storeId);
}

/**
* @param int|null $storeId
* @return string
*/
public function klarnaSliceitPaymentSurcharge($storeId = null)
{
return $this->getPath(static::PAYMENT_KLARNASLICEIT_PAYMENT_SURCHARGE, $storeId);
}

/**
* @param int|null $storeId
* @return string
*/
public function klarnaSliceitPaymentSurchargeTaxClass($storeId = null)
{
return $this->getPath(static::PAYMENT_KLARNASLICEIT_PAYMENT_SURCHARGE_TAX_CLASS, $storeId);
}
}
30 changes: 26 additions & 4 deletions Controller/Checkout/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Exception;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Payment\Model\MethodInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Store\Model\ScopeInterface;
Expand Down Expand Up @@ -121,11 +122,11 @@ public function execute()
$this->checkoutSession->restoreQuote();
$this->_redirect('checkout/cart');
}
} catch (Exception $e) {
$this->messageManager->addExceptionMessage($e, __($e->getMessage()));
$this->mollieHelper->addTolog('error', $e->getMessage());
} catch (Exception $exception) {
$this->formatExceptionMessage($exception, $methodInstance);
$this->mollieHelper->addTolog('error', $exception->getMessage());
$this->checkoutSession->restoreQuote();
$this->cancelUnprocessedOrder($order, $e->getMessage());
$this->cancelUnprocessedOrder($order, $exception->getMessage());
$this->_redirect('checkout/cart');
}
}
Expand Down Expand Up @@ -158,4 +159,25 @@ private function cancelUnprocessedOrder(OrderInterface $order, $message)
$this->mollieHelper->addToLog('error', $message);
}
}

/**
* @param Exception $exception
* @param MethodInterface $methodInstance
*/
private function formatExceptionMessage(Exception $exception, MethodInterface $methodInstance)
{
if (stripos($exception->getMessage(), 'cURL error 28') !== false) {
$this->messageManager->addErrorMessage(
__(
'A Timeout while connecting to %1 occurred, this could be the result of an outage. ' .
'Please try again or select another payment method.',
$methodInstance->getTitle()
)
);

return;
}

$this->messageManager->addExceptionMessage($exception, __($exception->getMessage()));
}
}
25 changes: 18 additions & 7 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
use Magento\Sales\Model\OrderRepository;
use Magento\Store\Model\Information;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Config\Model\ResourceModel\Config;
use Magento\Config\Model\ResourceModel\Config as ResourceConfig;
use Magento\Payment\Helper\Data as PaymentHelper;
use Mollie\Api\Resources\Order as MollieOrder;
use Mollie\Payment\Config;
use Mollie\Payment\Logger\MollieLogger;
use Magento\SalesRule\Model\Coupon;
use Magento\SalesRule\Model\ResourceModel\Coupon\Usage as CouponUsage;
Expand All @@ -30,6 +31,7 @@
* Class General
*
* @package Mollie\Payment\Helper
* @deprecated These helper classes will be removed in a future release.
*/
class General extends AbstractHelper
{
Expand Down Expand Up @@ -96,7 +98,7 @@ class General extends AbstractHelper
*/
private $storeManager;
/**
* @var Config
* @var ResourceConfig
*/
private $resourceConfig;
/**
Expand Down Expand Up @@ -143,6 +145,10 @@ class General extends AbstractHelper
* @var OrderManagementInterface
*/
private $orderManagement;
/**
* @var Config
*/
private $config;

/**
* General constructor.
Expand All @@ -151,7 +157,7 @@ class General extends AbstractHelper
* @param PaymentHelper $paymentHelper
* @param OrderRepository $orderRepository
* @param StoreManagerInterface $storeManager
* @param Config $resourceConfig
* @param ResourceConfig $resourceConfig
* @param ModuleListInterface $moduleList
* @param ProductMetadataInterface $metadata
* @param Resolver $resolver
Expand All @@ -161,13 +167,14 @@ class General extends AbstractHelper
* @param CouponUsage $couponUsage
* @param OrderCommentHistory $orderCommentHistory
* @param OrderManagementInterface $orderManagement
* @param Config $config
*/
public function __construct(
Context $context,
PaymentHelper $paymentHelper,
OrderRepository $orderRepository,
StoreManagerInterface $storeManager,
Config $resourceConfig,
ResourceConfig $resourceConfig,
ModuleListInterface $moduleList,
ProductMetadataInterface $metadata,
Resolver $resolver,
Expand All @@ -176,7 +183,8 @@ public function __construct(
Coupon $coupon,
CouponUsage $couponUsage,
OrderCommentHistory $orderCommentHistory,
OrderManagementInterface $orderManagement
OrderManagementInterface $orderManagement,
Config $config
) {
$this->paymentHelper = $paymentHelper;
$this->storeManager = $storeManager;
Expand All @@ -191,8 +199,9 @@ public function __construct(
$this->coupon = $coupon;
$this->couponUsage = $couponUsage;
$this->orderCommentHistory = $orderCommentHistory;
parent::__construct($context);
$this->orderManagement = $orderManagement;
$this->config = $config;
parent::__construct($context);
}

/**
Expand Down Expand Up @@ -455,12 +464,14 @@ public function getStatusProcessing($storeId = 0)
* Selected pending (payment) status for banktransfer
*
* @param int $storeId
* @deprecated
* @see Config::statusPendingBanktransfer()
*
* @return mixed
*/
public function getStatusPendingBanktransfer($storeId = 0)
{
return $this->getStoreConfig(self::XML_PATH_STATUS_PENDING_BANKTRANSFER, $storeId);
return $this->config->statusPendingBanktransfer($storeId);
}

/**
Expand Down
Loading

0 comments on commit b4b7c3d

Please sign in to comment.