-
Notifications
You must be signed in to change notification settings - Fork 54
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 #194 from mollie/1.7.1
1.7.1
- Loading branch information
Showing
34 changed files
with
646 additions
and
91 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
/** | ||
* Copyright © 2019 Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Mollie\Payment\Service\Mollie\Order\Transaction; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Stdlib\DateTime\TimezoneInterface; | ||
|
||
class Expires | ||
{ | ||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @var TimezoneInterface | ||
*/ | ||
private $timezone; | ||
|
||
/** | ||
* @var RequestInterface | ||
*/ | ||
private $request; | ||
|
||
public function __construct( | ||
ScopeConfigInterface $config, | ||
TimezoneInterface $timezone, | ||
RequestInterface $request | ||
) { | ||
$this->config = $config; | ||
$this->timezone = $timezone; | ||
$this->request = $request; | ||
} | ||
|
||
public function availableForMethod(string $method = null, $storeId = null) | ||
{ | ||
$value = $this->getExpiresAtForMethod($method, $storeId); | ||
return (bool)$value; | ||
} | ||
|
||
public function atDateForMethod(string $method = null, $storeId = null) | ||
{ | ||
$days = $this->getExpiresAtForMethod($method, $storeId); | ||
|
||
if (strtotime($days)) { | ||
return $days; | ||
} | ||
|
||
$date = $this->timezone->scopeDate($storeId); | ||
$date->add(new \DateInterval('P' . $days . 'D')); | ||
|
||
return $date->format('Y-m-d'); | ||
} | ||
|
||
/** | ||
* @param string $method | ||
* @param $storeId | ||
* @return mixed | ||
*/ | ||
public function getExpiresAtForMethod(string $method = null, $storeId = null) | ||
{ | ||
if (!$method && $value = $this->getValueFromRequest()) { | ||
return $value; | ||
} | ||
|
||
$path = sprintf('payment/mollie_methods_%s/days_before_expire', $method); | ||
|
||
return $this->config->getValue($path, 'store', $storeId); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
private function getValueFromRequest() | ||
{ | ||
$payment = $this->request->getParam('payment'); | ||
|
||
if (!$payment || !isset($payment['days_before_expire'])) { | ||
return false; | ||
} | ||
|
||
return $payment['days_before_expire']; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
/** | ||
* Copyright © 2019 Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Mollie\Payment\Test\Integration\Block\Form; | ||
|
||
use Mollie\Payment\Block\Form\Paymentlink; | ||
use Mollie\Payment\Test\Integration\IntegrationTestCase; | ||
|
||
class PaymentlinkTest extends IntegrationTestCase | ||
{ | ||
/** | ||
* @magentoConfigFixture current_store payment/mollie_methods_paymentlink/days_before_expire 10 | ||
*/ | ||
public function testReturnsTheCorrectDate() | ||
{ | ||
/** @var Paymentlink $instance */ | ||
$instance = $this->objectManager->create(Paymentlink::class); | ||
|
||
$now = new \DateTimeImmutable('now'); | ||
$expected = $now->add(new \DateInterval('P10D')); | ||
|
||
$this->assertEquals($expected->format('Y-m-d'), $instance->getExpiresAt()); | ||
} | ||
|
||
/** | ||
* @magentoConfigFixture current_store payment/mollie_methods_paymentlink/days_before_expire | ||
*/ | ||
public function testAnEmptyStringWhenNoConfigAvailable() | ||
{ | ||
/** @var Paymentlink $instance */ | ||
$instance = $this->objectManager->create(Paymentlink::class); | ||
|
||
$this->assertEmpty($instance->getExpiresAt()); | ||
} | ||
} |
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.