Skip to content

Commit

Permalink
Merge pull request #414 from mollie/1.28.0
Browse files Browse the repository at this point in the history
1.28.0
  • Loading branch information
Marvin-Magmodules committed Jul 9, 2021
2 parents 533c2b6 + 0e1ad1b commit 67b1dc7
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 70 deletions.
6 changes: 6 additions & 0 deletions Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Config
const GENERAL_LOCALE = 'payment/mollie_general/locale';
const GENERAL_ORDER_STATUS_PENDING = 'payment/mollie_general/order_status_pending';
const GENERAL_PROFILEID = 'payment/mollie_general/profileid';
const GENERAL_REDIRECT_WHEN_TRANSACTION_FAILS_TO = 'payment/mollie_general/redirect_when_transaction_fails_to';
const GENERAL_SECOND_CHANCE_EMAIL_TEMPLATE = 'payment/mollie_general/second_chance_email_template';
const GENERAL_SECOND_CHANCE_DELAY = 'payment/mollie_general/second_chance_email_delay';
const GENERAL_TYPE = 'payment/mollie_general/type';
Expand Down Expand Up @@ -550,6 +551,11 @@ public function customRedirectUrl($storeId = null, $scope = ScopeInterface::SCOP
return $this->getPath(static::GENERAL_CUSTOM_REDIRECT_URL, $storeId, $scope);
}

public function redirectWhenTransactionFailsTo($storeId = null, $scope = ScopeInterface::SCOPE_STORE): ?string
{
return $this->getPath(static::GENERAL_REDIRECT_WHEN_TRANSACTION_FAILS_TO, $storeId, $scope);
}

/**
* @see \Mollie\Payment\Model\Adminhtml\Source\Locale for possible values
* @param null|int|string $storeId
Expand Down
23 changes: 11 additions & 12 deletions Controller/Checkout/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Checkout\Model\Session;
use Mollie\Payment\Service\Order\RedirectOnError;

/**
* Class Process
Expand Down Expand Up @@ -52,30 +53,28 @@ class Process extends Action
private $eventManager;

/**
* Process constructor.
*
* @param Context $context
* @param Session $checkoutSession
* @param PaymentHelper $paymentHelper
* @param MollieModel $mollieModel
* @param MollieHelper $mollieHelper
* @param OrderRepositoryInterface $orderRepository
* @var RedirectOnError
*/
private $redirectOnError;

public function __construct(
Context $context,
Session $checkoutSession,
PaymentHelper $paymentHelper,
MollieModel $mollieModel,
MollieHelper $mollieHelper,
OrderRepositoryInterface $orderRepository,
RedirectOnError $redirectOnError,
ManagerInterface $eventManager
) {
$this->checkoutSession = $checkoutSession;
$this->paymentHelper = $paymentHelper;
$this->mollieModel = $mollieModel;
$this->mollieHelper = $mollieHelper;
$this->orderRepository = $orderRepository;
$this->redirectOnError = $redirectOnError;
$this->eventManager = $eventManager;

parent::__construct($context);
}

Expand All @@ -88,7 +87,7 @@ public function execute()
if (!$orderIds) {
$this->mollieHelper->addTolog('error', __('Invalid return, missing order id.'));
$this->messageManager->addNoticeMessage(__('Invalid return from Mollie.'));
$this->_redirect('checkout/cart');
$this->_redirect($this->redirectOnError->getUrl());
return;
}

Expand All @@ -101,7 +100,7 @@ public function execute()
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
$this->messageManager->addExceptionMessage($e, __('There was an error checking the transaction status.'));
$this->_redirect('checkout/cart');
$this->_redirect($this->redirectOnError->getUrl());
return;
}

Expand All @@ -119,7 +118,7 @@ public function execute()
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', $e->getMessage());
$this->messageManager->addErrorMessage(__('Something went wrong.'));
$this->_redirect('checkout/cart');
$this->_redirect($this->redirectOnError->getUrl());
}

return;
Expand All @@ -146,7 +145,7 @@ protected function handleNonSuccessResult(array $result, array $orderIds)
$this->checkoutSession->restoreQuote();
$this->addResultMessage($result);

$this->_redirect('checkout/cart');
$this->_redirect($this->redirectOnError->getUrl());
}

/**
Expand Down
34 changes: 34 additions & 0 deletions Model/Adminhtml/Source/RedirectUserWhenTransactionFails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Model\Adminhtml\Source;

use Magento\Framework\Data\OptionSourceInterface;

class RedirectUserWhenTransactionFails implements OptionSourceInterface
{
const REDIRECT_TO_CART = 'redirect_to_cart';
const REDIRECT_TO_CHECKOUT_SHIPPING = 'redirect_to_checkout_shipping';
const REDIRECT_TO_CHECKOUT_PAYMENT = 'redirect_to_checkout_payment';

public function toOptionArray()
{
return [
[
'value' => static::REDIRECT_TO_CART,
'label' => __('Redirect to cart'),
],
[
'value' => static::REDIRECT_TO_CHECKOUT_SHIPPING,
'label' => __('Redirect to checkout (shipping)'),
],
[
'value' => static::REDIRECT_TO_CHECKOUT_PAYMENT,
'label' => __('Redirect to checkout (payment)'),
],
];
}
}
2 changes: 1 addition & 1 deletion Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function loadMollieApi($apiKey)
$mollieApiClient = new MollieApiClient();
$mollieApiClient->setApiKey($apiKey);
$mollieApiClient->addVersionString('Magento/' . $this->mollieHelper->getMagentoVersion());
$mollieApiClient->addVersionString('MollieMagento2/' . $this->mollieHelper->getExtensionVersion());
$mollieApiClient->addVersionString('MollieMagento2/' . $this->config->getVersion());
return $mollieApiClient;
} else {
throw new LocalizedException(__('Class Mollie\Api\MollieApiClient does not exist'));
Expand Down
48 changes: 48 additions & 0 deletions Service/Order/RedirectOnError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Service\Order;


use Magento\Framework\UrlInterface;
use Mollie\Payment\Config;
use Mollie\Payment\Model\Adminhtml\Source\RedirectUserWhenTransactionFails;

class RedirectOnError
{
/**
* @var Config
*/
private $config;

/**
* @var UrlInterface
*/
private $urlBuilder;

public function __construct(
Config $config,
UrlInterface $urlBuilder
) {
$this->config = $config;
$this->urlBuilder = $urlBuilder;
}

public function getUrl(): string
{
$redirectTo = $this->config->redirectWhenTransactionFailsTo();
if ($redirectTo == RedirectUserWhenTransactionFails::REDIRECT_TO_CHECKOUT_SHIPPING) {
return $this->urlBuilder->getUrl('checkout');
}

if ($redirectTo == RedirectUserWhenTransactionFails::REDIRECT_TO_CHECKOUT_PAYMENT) {
return $this->urlBuilder->getUrl('checkout') . '#payment';
}

// Always redirect to the cart, independent of the value.
return $this->urlBuilder->getUrl('checkout/cart');
}
}
57 changes: 57 additions & 0 deletions Test/Integration/Service/Order/RedirectOnErrorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Test\Integration\Service\Order;

use Mollie\Payment\Service\Order\RedirectOnError;
use Mollie\Payment\Test\Integration\IntegrationTestCase;

class RedirectOnErrorTest extends IntegrationTestCase
{
/**
* @magentoConfigFixture default_store payment/mollie_general/redirect_when_transaction_fails_to redirect_to_checkout_shipping
*/
public function testGeneratesTheCorrectUrlWhenRedirectedToShipping()
{
/** @var RedirectOnError $instance */
$instance = $this->objectManager->create(RedirectOnError::class);

$this->assertStringEndsWith('checkout/', $instance->getUrl());
}

/**
* @magentoConfigFixture default_store payment/mollie_general/redirect_when_transaction_fails_to redirect_to_checkout_payment
*/
public function testGeneratesTheCorrectUrlWhenRedirectedToPayment()
{
/** @var RedirectOnError $instance */
$instance = $this->objectManager->create(RedirectOnError::class);

$this->assertStringEndsWith('checkout/#payment', $instance->getUrl());
}

/**
* @magentoConfigFixture default_store payment/mollie_general/redirect_when_transaction_fails_to redirect_to_cart
*/
public function testGeneratesTheCorrectUrlWhenRedirectedToCart()
{
/** @var RedirectOnError $instance */
$instance = $this->objectManager->create(RedirectOnError::class);

$this->assertStringEndsWith('checkout/cart/', $instance->getUrl());
}

/**
* @magentoConfigFixture default_store payment/mollie_general/redirect_when_transaction_fails_to invalid_value
*/
public function testWhenTheSettingIsInvalidItRedirectsToCart()
{
/** @var RedirectOnError $instance */
$instance = $this->objectManager->create(RedirectOnError::class);

$this->assertStringEndsWith('checkout/cart/', $instance->getUrl());
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mollie/magento2",
"description": "Mollie Payment Module for Magento 2",
"version": "1.27.1",
"version": "1.28.0",
"keywords": [
"mollie",
"payment",
Expand Down
21 changes: 14 additions & 7 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@
<config_path>payment/mollie_general/cancel_failed_orders</config_path>
<comment><![CDATA[When the order can't be created due to various reasons (connection failure or data verification errors), the just created order will be canceled.]]></comment>
</field>
<field id="include_shipping_in_surcharge" translate="label" type="select" sortOrder="40" showInDefault="1"
<field id="redirect_when_transaction_fails_to" translate="label" type="select" sortOrder="40" showInDefault="1"
showInWebsite="0" showInStore="1">
<label>Redirect user when redirect fails</label>
<source_model>Mollie\Payment\Model\Adminhtml\Source\RedirectUserWhenTransactionFails</source_model>
<config_path>payment/mollie_general/redirect_when_transaction_fails_to</config_path>
<comment><![CDATA[When the transaction fails due to various reasons (i.e., Cancelled, insufficient funds, etc.), where do we need to redirect the user? Please be cautious: Depending on the used checkout, error messages may not be displayed.]]></comment>
</field>
<field id="include_shipping_in_surcharge" translate="label" type="select" sortOrder="50" showInDefault="1"
showInWebsite="0" showInStore="1">
<label>Include shipping in Surcharge calculation</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand All @@ -196,34 +203,34 @@
<strong>Yes</strong>: The surcharge is calculated on the total of subtotal + shipping.
]]></comment>
</field>
<field id="currency" translate="label" type="select" sortOrder="50" showInDefault="1"
<field id="currency" translate="label" type="select" sortOrder="60" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Use Base Currency</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/mollie_general/currency</config_path>
<comment>Force use of base currency for the payment request. Is set to no the selected currency of the storeview will be used for request.</comment>
</field>
<field id="locale" translate="label comment" type="select" sortOrder="60" showInDefault="1"
<field id="locale" translate="label comment" type="select" sortOrder="70" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Language Payment Page</label>
<source_model>Mollie\Payment\Model\Adminhtml\Source\Locale</source_model>
<config_path>payment/mollie_general/locale</config_path>
<comment><![CDATA[Let Mollie automatically detect the language or force the language from the store view.]]></comment>
</field>
<field id="transaction_details" translate="label" type="select" sortOrder="70" showInDefault="1"
<field id="transaction_details" translate="label" type="select" sortOrder="80" showInDefault="1"
showInWebsite="0" showInStore="0">
<label>Show Transaction Details</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>Display Transaction Details like e.g. IBAN, BIC, Paypal Reference, Card Holder etc.</comment>
</field>
<field id="loading_screen" translate="label" type="select" sortOrder="80" showInDefault="1"
<field id="loading_screen" translate="label" type="select" sortOrder="90" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Use Loading Screen</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/mollie_general/loading_screen</config_path>
<comment><![CDATA[Use loading screen before redirect. This will enable mobile users to use the back button.]]></comment>
</field>
<field id="use_webhooks" translate="label" type="select" sortOrder="220" showInDefault="1"
<field id="use_webhooks" translate="label" type="select" sortOrder="100" showInDefault="1"
showInWebsite="0" showInStore="1">
<label>Use webhooks</label>
<source_model>Mollie\Payment\Model\Adminhtml\Source\WebhookUrlOptions</source_model>
Expand All @@ -232,7 +239,7 @@
<strong>Note:</strong> This setting has only effect when the store deploy mode is in <u>development</u>. When the store deploy mode is in production, this setting is ignored and the webhooks are always <u>enabled</u>.
]]></comment>
</field>
<field id="custom_webhook_url" translate="label" type="text" sortOrder="230" showInDefault="1"
<field id="custom_webhook_url" translate="label" type="text" sortOrder="110" showInDefault="1"
showInWebsite="0" showInStore="1">
<label>Custom webhook url</label>
<config_path>payment/mollie_general/custom_webhook_url</config_path>
Expand Down
3 changes: 2 additions & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<default>
<payment>
<mollie_general>
<version>v1.27.1</version>
<version>v1.28.0</version>
<active>0</active>
<enabled>0</enabled>
<type>test</type>
Expand All @@ -24,6 +24,7 @@
<use_webhooks>enabled</use_webhooks>
<automatically_send_second_chance_emails>0</automatically_send_second_chance_emails>
<second_chance_email_delay>1</second_chance_email_delay>
<redirect_when_transaction_fails_to>redirect_to_cart</redirect_when_transaction_fails_to>
</mollie_general>
<mollie_methods_applepay>
<active>0</active>
Expand Down
Loading

0 comments on commit 67b1dc7

Please sign in to comment.