We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit f7f6fbde authored by Rik ter Beek's avatar Rik ter Beek

Merge remote-tracking branch 'origin/develop' into pw-364

parents c6fa0745 66988071
......@@ -5,6 +5,6 @@
**Tested scenarios**
<!-- Description of tested scenarios -->
<!-- Please verify that the unit tests are passing by running "vendor/bin/phpunit -c ." -->
<!-- Please verify that the unit tests are passing by running "vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist vendor/adyen/module-payment/Test/" -->
**Fixed issue**: <!-- #-prefixed issue number -->
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2018 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\AdminMessage;
class VersionMessage implements \Magento\Framework\Notification\MessageInterface
{
protected $_authSession;
protected $_adyenHelper;
protected $_inboxFactory;
public function __construct(
\Magento\Backend\Model\Auth\Session $authSession,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\AdminNotification\Model\InboxFactory $inboxFactory
) {
$this->_authSession = $authSession;
$this->_adyenHelper = $adyenHelper;
$this->_inboxFactory = $inboxFactory;
}
/**
* Message identity
*/
const MESSAGE_IDENTITY = 'Adyen Version Control message';
/**
* Retrieve unique system message identity
*
* @return string
*/
public function getIdentity()
{
return self::MESSAGE_IDENTITY;
}
/**
* Check whether the system message should be shown
*
* @return bool
*/
public function isDisplayed()
{
// Only execute the query the first time you access the Admin page
if ($this->_authSession->isFirstPageAfterLogin()) {
try {
$githubContent = $this->getDecodedContentFromGithub();
$this->setSessionData("AdyenGithubVersion", $githubContent);
$title = "Adyen extension version " . $githubContent['tag_name'] . " available!";
$versionData[] = array(
'severity' => self::SEVERITY_NOTICE,
'date_added' => $githubContent['published_at'],
'title' => $title,
'description' => $githubContent['body'],
'url' => $githubContent['html_url'],
);
/*
* The parse function checks if the $versionData message exists in the inbox,
* otherwise it will create it and add it to the inbox.
*/
$this->_inboxFactory->create()->parse(array_reverse($versionData));
/*
* This will compare the currently installed version with the latest available one.
* A message will appear after the login if the two are not matching.
*/
if ($this->_adyenHelper->getModuleVersion() != $githubContent['tag_name']) {
return true;
}
} catch (\Exception $e) {
return false;
}
}
return false;
}
/**
* Retrieve system message text
*
* @return \Magento\Framework\Phrase
*/
public function getText()
{
$githubContent = $this->getSessionData("AdyenGithubVersion");
$message = __("A new Adyen extension version is now available: ");
$message .= __("<a href= \"" . $githubContent['html_url'] . "\" target='_blank'> " . $githubContent['tag_name'] . "!</a>");
$message .= __(" You are running the " . $this->_adyenHelper->getModuleVersion() . " version. We advise to update your extension.");
return __($message);
}
/**
* Retrieve system message severity
*
* @return int
*/
public function getSeverity()
{
return self::SEVERITY_MAJOR;
}
public function getDecodedContentFromGithub()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.github.com/repos/adyen/adyen-magento2/releases/latest');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'magento');
$content = curl_exec($ch);
curl_close($ch);
$json = json_decode($content, true);
return $json;
}
/**
* Set the current value for the backend session
*/
public function setSessionData($key, $value)
{
return $this->_authSession->setData($key, $value);
}
/**
* Retrieve the session value
*/
public function getSessionData($key, $remove = false)
{
return $this->_authSession->getData($key, $remove);
}
}
......@@ -852,15 +852,15 @@ class Data extends AbstractHelper
*/
public function isPaymentMethodOpenInvoiceMethod($paymentMethod)
{
if (strlen($paymentMethod) >= 9 && substr($paymentMethod, 0, 9) == 'afterpay_') {
if (strpos($paymentMethod, 'afterpay') !== false) {
return true;
} else {
if ($paymentMethod == 'klarna' || $paymentMethod == 'ratepay') {
} elseif (strpos($paymentMethod, 'klarna') !== false) {
return true;
} elseif (strpos($paymentMethod, 'ratepay') !== false) {
return true;
} else {
return false;
}
}
return false;
}
public function getRatePayId()
......
......@@ -210,7 +210,8 @@ class Cron
\Adyen\Payment\Model\Order\PaymentFactory $adyenOrderPaymentFactory,
\Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory,
AreaList $areaList
) {
)
{
$this->_scopeConfig = $scopeConfig;
$this->_adyenLogger = $adyenLogger;
$this->_notificationFactory = $notificationFactory;
......@@ -235,7 +236,7 @@ class Cron
{
try {
$this->execute();
} catch(\Exception $e) {
} catch (\Exception $e) {
$this->_adyenLogger->addAdyenNotificationCronjob($e->getMessage() . "\n" . $e->getTraceAsString());
throw $e;
}
......@@ -536,11 +537,7 @@ class Cron
}
// if payment method is klarna, ratepay or openinvoice/afterpay show the reservartion number
if (($this->_paymentMethod == "klarna" || $this->_paymentMethod == "afterpay_default" ||
$this->_paymentMethod == "openinvoice" || $this->_paymentMethod == "ratepay"
) && ($this->_klarnaReservationNumber != null &&
$this->_klarnaReservationNumber != "")
) {
if ($this->_adyenHelper->isPaymentMethodOpenInvoiceMethod($this->_paymentMethod) && !empty($this->_klarnaReservationNumber)) {
$klarnaReservationNumberText = "<br /> reservationNumber: " . $this->_klarnaReservationNumber;
} else {
$klarnaReservationNumberText = "";
......@@ -1298,6 +1295,11 @@ class Cron
$manualCaptureAllowed = null;
$paymentMethod = $this->_paymentMethod;
// For all openinvoice methods manual capture is the default
if ($this->_adyenHelper->isPaymentMethodOpenInvoiceMethod($paymentMethod)) {
return true;
}
switch ($paymentMethod) {
case 'cup':
case 'cartebancaire':
......@@ -1314,17 +1316,10 @@ class Cron
case 'jcb':
case 'laser':
case 'paypal':
case 'klarna':
case 'afterpay_default':
case 'ratepay':
case 'sepadirectdebit':
$manualCaptureAllowed = true;
break;
default:
// To be sure check if it payment method starts with afterpay_ then manualCapture is allowed
if (strlen($this->_paymentMethod) >= 9 && substr($this->_paymentMethod, 0, 9) == "afterpay_") {
$manualCaptureAllowed = true;
}
$manualCaptureAllowed = false;
}
......
......@@ -24,9 +24,8 @@
namespace Adyen\Payment\Tests\Helper;
use Adyen\Payment\Helper\Data;
use PHPUnit\Framework\TestCase;
class DataTest extends TestCase
class DataTest extends \PHPUnit_Framework_TestCase
{
private $dataHelper;
......@@ -59,4 +58,16 @@ class DataTest extends TestCase
$this->assertEquals("1200", $this->dataHelper->formatAmount("12.00", "USD"));
$this->assertEquals("12", $this->dataHelper->formatAmount("12.00", "JPY"));
}
public function testisPaymentMethodOpenInvoiceMethod()
{
$this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod("klarna"));
$this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod("klarna_account"));
$this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod("afterpay"));
$this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod("afterpay_default"));
$this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod("ratepay"));
$this->assertEquals(false, $this->dataHelper->isPaymentMethodOpenInvoiceMethod("ideal"));
$this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod("test_klarna"));
}
}
......@@ -17,9 +17,6 @@
"adyen/php-api-library": "*",
"magento/framework": ">=100.1.0"
},
"require-dev": {
"phpunit/phpunit": "~5"
},
"autoload": {
"files": [
"registration.php"
......
......@@ -3,7 +3,8 @@
<type name="Magento\Framework\Notification\MessageList">
<arguments>
<argument name="messages" xsi:type="array">
<item name="cronMessage" xsi:type="string">Adyen\Payment\AdminMessage\CronMessage</item>
<item name="AdyenCronMessage" xsi:type="string">Adyen\Payment\AdminMessage\CronMessage</item>
<item name="AdyenVersionMessage" xsi:type="string">Adyen\Payment\AdminMessage\VersionMessage</item>
</argument>
</arguments>
</type>
......
<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Adyen payment module tests">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment