-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #414 from mollie/1.28.0
1.28.0
- Loading branch information
Showing
13 changed files
with
250 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Model/Adminhtml/Source/RedirectUserWhenTransactionFails.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)'), | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.