Skip to content

Commit

Permalink
Merge pull request #793 from mollie/release/2.40.0
Browse files Browse the repository at this point in the history
Release/2.40.0
  • Loading branch information
Marvin-Magmodules authored Jul 12, 2024
2 parents ca64e77 + f41dda4 commit ba68f4b
Show file tree
Hide file tree
Showing 70 changed files with 827 additions and 301 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/templates/magento/configure-mollie.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ bin/magento config:set payment/mollie_methods_bancontact/active 1 &
bin/magento config:set payment/mollie_methods_bancomatpay/active 1 &
bin/magento config:set payment/mollie_methods_belfius/active 1 &
bin/magento config:set payment/mollie_methods_eps/active 1 &
bin/magento config:set payment/mollie_methods_giropay/active 1 &
bin/magento config:set payment/mollie_methods_klarnapaylater/active 1 &
bin/magento config:set payment/mollie_methods_paymentlink/active 1 &
bin/magento config:set payment/mollie_methods_paysafecard/active 1 &
bin/magento config:set payment/mollie_methods_pointofsale/active 1 &
bin/magento config:set payment/mollie_methods_riverty/active 1 &
bin/magento config:set payment/mollie_methods_sofort/active 1 &
bin/magento config:set payment/mollie_methods_trustly/active 1 &
bin/magento config:set payment/mollie_methods_twint/active 1 &

# Enable Components
Expand All @@ -45,6 +46,7 @@ bin/magento config:set payment/mollie_methods_creditcard/use_components 1 &
# Enable QR
bin/magento config:set payment/mollie_methods_ideal/add_qr 1 &

# Disable webhooks
bin/magento config:set payment/mollie_general/use_webhooks disabled &

# Configure currency for the swiss store view
Expand All @@ -58,6 +60,13 @@ bin/magento config:set payment/mollie_general/currency 0 --scope=ch &
bin/magento config:set currency/options/default PLN --scope=pl &
bin/magento config:set payment/mollie_general/currency 0 --scope=pl &

# Disable the use of the base currency
bin/magento config:set payment/mollie_general/currency 0 &

# Insert rates, otherwise the currency switcher won't show
magerun2 db:query 'INSERT INTO `directory_currency_rate` (`currency_from`, `currency_to`, `rate`) VALUES ("EUR", "PLN", 1.0);' &
magerun2 db:query 'INSERT INTO `directory_currency_rate` (`currency_from`, `currency_to`, `rate`) VALUES ("EUR", "CHF", 1.0);' &

wait

if grep -q Magento_TwoFactorAuth "app/etc/config.php"; then
Expand Down
52 changes: 5 additions & 47 deletions Block/Adminhtml/System/Config/Button/Selftest.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,29 @@
<?php
/**
* Copyright © Magmodules.eu. All rights reserved.
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Mollie\Payment\Block\Adminhtml\System\Config\Button;

use Exception;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Button;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Data\Form\Element\AbstractElement;

/**
* Selftest button class
*/
class Selftest extends Field
{

/**
* @var string
*/
protected $_template = 'Mollie_Payment::system/config/button/selftest.phtml';

/**
* @var RequestInterface
*/
private $request;

/**
* Credentials constructor.
*
* @param Context $context
* @param array $data
*/
public function __construct(
Context $context,
array $data = []
) {
$this->request = $context->getRequest();
parent::__construct($context, $data);
}

/**
* @param AbstractElement $element
*
* @return string
*/
public function render(AbstractElement $element)
public function render(AbstractElement $element): string
{
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
Expand All @@ -60,32 +34,16 @@ public function render(AbstractElement $element)
*
* @return string
*/
public function _getElementHtml(AbstractElement $element)
public function _getElementHtml(AbstractElement $element): string
{
return $this->_toHtml();
}

/**
* @return string
*/
public function getSelftestUrl()
public function getSelftestUrl(): string
{
return $this->getUrl('mollie/action/selfTest/');
}

/**
* @return mixed
*/
public function getButtonHtml()
{
$buttonData = ['id' => 'button_test', 'label' => __('Run Self-test')];
try {
$button = $this->getLayout()->createBlock(
Button::class
)->setData($buttonData);
return $button->toHtml();
} catch (Exception $e) {
return false;
}
}
}
16 changes: 13 additions & 3 deletions Block/Info/Base.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

Expand All @@ -15,10 +15,12 @@
use Mollie\Payment\Config;
use Mollie\Payment\Helper\General as MollieHelper;
use Mollie\Payment\Model\Methods\Billie;
use Mollie\Payment\Model\Methods\In3;
use Mollie\Payment\Model\Methods\Klarna;
use Mollie\Payment\Model\Methods\Klarnapaylater;
use Mollie\Payment\Model\Methods\Klarnapaynow;
use Mollie\Payment\Model\Methods\Klarnasliceit;
use Mollie\Payment\Model\Methods\Riverty;
use Mollie\Payment\Service\Magento\PaymentLinkUrl;

class Base extends Info
Expand Down Expand Up @@ -166,7 +168,15 @@ public function isBuyNowPayLaterMethod(): bool
{
try {
$code = $this->getInfo()->getMethod();
$methods = [Billie::CODE, Klarna::CODE, Klarnapaylater::CODE, Klarnasliceit::CODE, Klarnapaynow::CODE];
$methods = [
Billie::CODE,
In3::CODE,
Klarna::CODE,
Klarnapaylater::CODE,
Klarnasliceit::CODE,
Klarnapaynow::CODE,
Riverty::CODE,
];

if (in_array($code, $methods)) {
return true;
Expand Down
19 changes: 4 additions & 15 deletions Controller/Adminhtml/Action/SelfTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

Expand All @@ -20,18 +20,10 @@
*/
class SelfTest extends Action
{
/**
* @var \Magento\Framework\App\RequestInterface
*/
private $request;
/**
* @var JsonFactory
*/
private $resultJsonFactory;
/**
* @var TestsHelper
*/
private $testsHelper;
/**
* @var MollieHelper
*/
Expand All @@ -44,15 +36,13 @@ class SelfTest extends Action
public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
TestsHelper $testsHelper,
MollieHelper $mollieHelper,
array $tests
) {
$this->request = $context->getRequest();
parent::__construct($context);

$this->resultJsonFactory = $resultJsonFactory;
$this->testsHelper = $testsHelper;
$this->mollieHelper = $mollieHelper;
parent::__construct($context);
$this->tests = $tests;
}

Expand All @@ -67,7 +57,6 @@ public function __construct(
public function execute()
{
$result = $this->resultJsonFactory->create();

if (!class_exists('Mollie\Api\CompatibilityChecker')) {
return $this->getPhpApiErrorMessage($result);
}
Expand Down
2 changes: 1 addition & 1 deletion Controller/Checkout/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected function checkIfLastRealOrder(array $orderIds)
}

try {
$order = $this->orderRepository->get(end($orderIds));
$order = $this->orderRepository->get(array_key_last($orderIds));
$this->checkoutSession->setLastRealOrderId($order->getIncrementId());
} catch (NoSuchEntityException $exception) {
//
Expand Down
63 changes: 15 additions & 48 deletions Controller/Checkout/Redirect.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

Expand All @@ -11,7 +11,6 @@
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\Result\PageFactory;
use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Payment\Model\MethodInterface;
use Magento\Sales\Api\Data\OrderInterface;
Expand All @@ -20,8 +19,6 @@
use Magento\Sales\Model\Order;
use Mollie\Payment\Api\PaymentTokenRepositoryInterface;
use Mollie\Payment\Config;
use Mollie\Payment\Helper\General as MollieHelper;
use Mollie\Payment\Model\Methods\ApplePay;
use Mollie\Payment\Model\Methods\CreditcardVault;
use Mollie\Payment\Model\Mollie;
use Mollie\Payment\Service\Mollie\FormatExceptionMessages;
Expand All @@ -38,18 +35,10 @@ class Redirect extends Action
* @var Session
*/
protected $checkoutSession;
/**
* @var PageFactory
*/
protected $resultPageFactory;
/**
* @var PaymentHelper
*/
protected $paymentHelper;
/**
* @var MollieHelper
*/
protected $mollieHelper;
/**
* @var OrderManagementInterface
*/
Expand Down Expand Up @@ -81,9 +70,7 @@ class Redirect extends Action
*
* @param Context $context
* @param Session $checkoutSession
* @param PageFactory $resultPageFactory
* @param PaymentHelper $paymentHelper
* @param MollieHelper $mollieHelper
* @param OrderManagementInterface $orderManagement
* @param Config $config
* @param PaymentTokenRepositoryInterface $paymentTokenRepository ,
Expand All @@ -94,9 +81,7 @@ class Redirect extends Action
public function __construct(
Context $context,
Session $checkoutSession,
PageFactory $resultPageFactory,
PaymentHelper $paymentHelper,
MollieHelper $mollieHelper,
OrderManagementInterface $orderManagement,
Config $config,
PaymentTokenRepositoryInterface $paymentTokenRepository,
Expand All @@ -105,9 +90,7 @@ public function __construct(
FormatExceptionMessages $formatExceptionMessages
) {
$this->checkoutSession = $checkoutSession;
$this->resultPageFactory = $resultPageFactory;
$this->paymentHelper = $paymentHelper;
$this->mollieHelper = $mollieHelper;
$this->orderManagement = $orderManagement;
$this->config = $config;
$this->paymentTokenRepository = $paymentTokenRepository;
Expand All @@ -125,50 +108,39 @@ public function execute()
try {
$order = $this->getOrder();
} catch (LocalizedException $exception) {
$this->mollieHelper->addTolog('error', $exception->getMessage());
$this->config->addTolog('error', $exception->getMessage());
return $this->_redirect('checkout/cart');
}

try {
$payment = $order->getPayment();
if (!isset($payment)) {
if ($order->getPayment() === null) {
return $this->_redirect('checkout/cart');
}

$method = $order->getPayment()->getMethod();
$methodInstance = $this->getMethodInstance($method);
if ($methodInstance instanceof Mollie) {
$storeId = $order->getStoreId();
$redirectUrl = $this->redirectUrl->execute($methodInstance, $order);
// This is deprecated since 2.18.0 and will be removed in a future version.
if (!($methodInstance instanceof ApplePay) &&
$this->mollieHelper->useLoadingScreen($storeId)
) {
$resultPage = $this->resultPageFactory->create();
$resultPage->getLayout()->initMessages();
$resultPage->getLayout()->getBlock('mollie_loading')->setMollieRedirect($redirectUrl);
return $resultPage;
} else {
return $this->getResponse()->setRedirect($redirectUrl);
}
} else {
if (!$methodInstance instanceof Mollie) {
$msg = __('Payment Method not found');
$this->messageManager->addErrorMessage($msg);
$this->mollieHelper->addTolog('error', $msg);
$this->config->addTolog('error', $msg);
$this->checkoutSession->restoreQuote();
return $this->_redirect('checkout/cart');
}

return $this->getResponse()->setRedirect(
$this->redirectUrl->execute($methodInstance, $order)
);
} catch (Exception $exception) {
$errorMessage = $this->formatExceptionMessages->execute($exception, $methodInstance ?? null);
$this->messageManager->addErrorMessage($errorMessage);
$this->mollieHelper->addTolog('error', $exception->getMessage());
$this->config->addTolog('error', $exception->getMessage());
$this->checkoutSession->restoreQuote();
$this->cancelUnprocessedOrder($order, $exception->getMessage());
return $this->_redirect('checkout/cart');
}
}

private function cancelUnprocessedOrder(OrderInterface $order, $message)
private function cancelUnprocessedOrder(OrderInterface $order, string $message): void
{
if (!$this->config->cancelFailedOrders()) {
return;
Expand All @@ -184,21 +156,16 @@ private function cancelUnprocessedOrder(OrderInterface $order, $message)
$this->orderManagement->cancel($order->getEntityId());
$order->addCommentToStatusHistory($order->getEntityId(), $historyMessage);

$this->mollieHelper->addToLog('info', sprintf('Canceled order %s', $order->getIncrementId()));
$this->config->addToLog('info', sprintf('Canceled order %s', $order->getIncrementId()));
} catch (Exception $e) {
$message = sprintf('Cannot cancel order %s: %s', $order->getIncrementId(), $e->getMessage());
$this->mollieHelper->addToLog('error', $message);
$this->config->addToLog('error', $message);
}
}

/**
* @return OrderInterface
* @throws LocalizedException
*/
private function getOrder()
private function getOrder(): OrderInterface
{
$token = $this->getRequest()->getParam('paymentToken');

if (!$token) {
throw new LocalizedException(__('The required payment token is not available'));
}
Expand Down
Loading

0 comments on commit ba68f4b

Please sign in to comment.