We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit d1635b1e authored by Giorgos Adam's avatar Giorgos Adam Committed by GitHub

Merge pull request #300 from Adyen/develop

Release 2.3.1
parents 527ab731 dee1944e
...@@ -261,8 +261,6 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -261,8 +261,6 @@ class Redirect extends \Magento\Payment\Block\Form
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK); ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);
$formFields['resURL'] = $baseUrl . 'adyen/process/result'; $formFields['resURL'] = $baseUrl . 'adyen/process/result';
$hmacKey = $this->_adyenHelper->getHmac();
if ($brandCode) { if ($brandCode) {
$formFields['brandCode'] = $brandCode; $formFields['brandCode'] = $brandCode;
...@@ -307,15 +305,9 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -307,15 +305,9 @@ class Redirect extends \Magento\Payment\Block\Form
$formFields['dfValue'] = $this->_order->getPayment()->getAdditionalInformation("df_value"); $formFields['dfValue'] = $this->_order->getPayment()->getAdditionalInformation("df_value");
} }
// Sort the array by key using SORT_STRING order // Sign request using secret key
ksort($formFields, SORT_STRING); $hmacKey = $this->_adyenHelper->getHmac();
$merchantSig = \Adyen\Util\Util::calculateSha256Signature($hmacKey, $formFields);
// Generate the signing data string
$signData = implode(":", array_map([$this, 'escapeString'],
array_merge(array_keys($formFields), array_values($formFields))));
$merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true));
$formFields['merchantSig'] = $merchantSig; $formFields['merchantSig'] = $merchantSig;
$this->_adyenLogger->addAdyenDebug(print_r($formFields, true)); $this->_adyenLogger->addAdyenDebug(print_r($formFields, true));
......
...@@ -99,7 +99,7 @@ class Json extends \Magento\Framework\App\Action\Action ...@@ -99,7 +99,7 @@ class Json extends \Magento\Framework\App\Action\Action
$notificationMode = isset($notificationItems['live']) ? $notificationItems['live'] : ""; $notificationMode = isset($notificationItems['live']) ? $notificationItems['live'] : "";
if ($notificationMode != "" && $this->_validateNotificationMode($notificationMode)) { if ($notificationMode !== "" && $this->_validateNotificationMode($notificationMode)) {
foreach ($notificationItems['notificationItems'] as $notificationItem) { foreach ($notificationItems['notificationItems'] as $notificationItem) {
...@@ -154,7 +154,8 @@ class Json extends \Magento\Framework\App\Action\Action ...@@ -154,7 +154,8 @@ class Json extends \Magento\Framework\App\Action\Action
{ {
$mode = $this->_adyenHelper->getAdyenAbstractConfigData('demo_mode'); $mode = $this->_adyenHelper->getAdyenAbstractConfigData('demo_mode');
if (($mode == '1' && $notificationMode == "false") || ($mode == '0' && $notificationMode == 'true')) { // Notification mode can be a string or a boolean
if (($mode == '1' && ($notificationMode == "false" || $notificationMode == false)) || ($mode == '0' && ($notificationMode == 'true' || $notificationMode == true))) {
return true; return true;
} }
return false; return false;
......
...@@ -279,7 +279,6 @@ class Result extends \Magento\Framework\App\Action\Action ...@@ -279,7 +279,6 @@ class Result extends \Magento\Framework\App\Action\Action
*/ */
protected function _authenticate($response) { protected function _authenticate($response) {
$hmacKey = $this->_adyenHelper->getHmac();
$merchantSigNotification = $response['merchantSig']; $merchantSigNotification = $response['merchantSig'];
// do it like this because $_GET is converting dot to underscore // do it like this because $_GET is converting dot to underscore
...@@ -297,14 +296,9 @@ class Result extends \Magento\Framework\App\Action\Action ...@@ -297,14 +296,9 @@ class Result extends \Magento\Framework\App\Action\Action
// do not include the merchantSig in the merchantSig calculation // do not include the merchantSig in the merchantSig calculation
unset($result['merchantSig']); unset($result['merchantSig']);
// Sort the array by key using SORT_STRING order // Sign request using secret key
ksort($result, SORT_STRING); $hmacKey = $this->_adyenHelper->getHmac();
$merchantSig = \Adyen\Util\Util::calculateSha256Signature($hmacKey, $result);
// Generate the signing data string
$signData = implode(":", array_map([$this, 'escapeString'],
array_merge(array_keys($result), array_values($result))));
$merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true));
if (strcmp($merchantSig, $merchantSigNotification) === 0) { if (strcmp($merchantSig, $merchantSigNotification) === 0) {
return true; return true;
......
...@@ -199,15 +199,8 @@ class PayByMailCommand implements CommandInterface ...@@ -199,15 +199,8 @@ class PayByMailCommand implements CommandInterface
$formFields['shopperReference'] = $customerId; $formFields['shopperReference'] = $customerId;
} }
// Sort the array by key using SORT_STRING order // Sign request using secret key
ksort($formFields, SORT_STRING); $merchantSig = \Adyen\Util\Util::calculateSha256Signature($hmacKey, $formFields);
// Generate the signing data string
$signData = implode(":", array_map([$this, 'escapeString'],
array_merge(array_keys($formFields), array_values($formFields))));
$merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true));
$formFields['merchantSig'] = $merchantSig; $formFields['merchantSig'] = $merchantSig;
$this->_adyenLogger->addAdyenDebug(print_r($formFields, true)); $this->_adyenLogger->addAdyenDebug(print_r($formFields, true));
......
...@@ -187,6 +187,11 @@ class Cron ...@@ -187,6 +187,11 @@ class Cron
*/ */
protected $_areaList; protected $_areaList;
/**
* @var \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory
*/
protected $_orderStatusCollection;
/** /**
* Cron constructor. * Cron constructor.
* *
...@@ -203,7 +208,9 @@ class Cron ...@@ -203,7 +208,9 @@ class Cron
* @param Api\PaymentRequest $paymentRequest * @param Api\PaymentRequest $paymentRequest
* @param Order\PaymentFactory $adyenOrderPaymentFactory * @param Order\PaymentFactory $adyenOrderPaymentFactory
* @param ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory * @param ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory
* @param InvoiceFactory $adyenInvoiceFactory
* @param AreaList $areaList * @param AreaList $areaList
* @param \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory $orderStatusCollection
*/ */
public function __construct( public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
...@@ -220,8 +227,10 @@ class Cron ...@@ -220,8 +227,10 @@ class Cron
\Adyen\Payment\Model\Order\PaymentFactory $adyenOrderPaymentFactory, \Adyen\Payment\Model\Order\PaymentFactory $adyenOrderPaymentFactory,
\Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory, \Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory,
\Adyen\Payment\Model\InvoiceFactory $adyenInvoiceFactory, \Adyen\Payment\Model\InvoiceFactory $adyenInvoiceFactory,
AreaList $areaList AreaList $areaList,
) { \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory $orderStatusCollection
)
{
$this->_scopeConfig = $scopeConfig; $this->_scopeConfig = $scopeConfig;
$this->_adyenLogger = $adyenLogger; $this->_adyenLogger = $adyenLogger;
$this->_notificationFactory = $notificationFactory; $this->_notificationFactory = $notificationFactory;
...@@ -237,6 +246,7 @@ class Cron ...@@ -237,6 +246,7 @@ class Cron
$this->_adyenOrderPaymentCollectionFactory = $adyenOrderPaymentCollectionFactory; $this->_adyenOrderPaymentCollectionFactory = $adyenOrderPaymentCollectionFactory;
$this->_adyenInvoiceFactory = $adyenInvoiceFactory; $this->_adyenInvoiceFactory = $adyenInvoiceFactory;
$this->_areaList = $areaList; $this->_areaList = $areaList;
$this->_orderStatusCollection = $orderStatusCollection;
} }
/** /**
...@@ -645,6 +655,8 @@ class Cron ...@@ -645,6 +655,8 @@ class Cron
$acquirerReference = (isset($additionalData['acquirerReference'])) ? $acquirerReference = (isset($additionalData['acquirerReference'])) ?
$additionalData['acquirerReference'] : ""; $additionalData['acquirerReference'] : "";
$authCode = (isset($additionalData['authCode'])) ? $additionalData['authCode'] : ""; $authCode = (isset($additionalData['authCode'])) ? $additionalData['authCode'] : "";
$cardBin = (isset($additionalData['cardBin'])) ? $additionalData['cardBin'] : "";
$expiryDate = (isset($additionalData['expiryDate'])) ? $additionalData['expiryDate'] : "";
} }
// if there is no server communication setup try to get last4 digits from reason field // if there is no server communication setup try to get last4 digits from reason field
...@@ -685,6 +697,12 @@ class Cron ...@@ -685,6 +697,12 @@ class Cron
if (isset($authCode) && $authCode != "") { if (isset($authCode) && $authCode != "") {
$this->_order->getPayment()->setAdditionalInformation('adyen_auth_code', $authCode); $this->_order->getPayment()->setAdditionalInformation('adyen_auth_code', $authCode);
} }
if (!empty($cardBin)) {
$this->_order->getPayment()->setAdditionalInformation('adyen_card_bin', $cardBin);
}
if (!empty($expiryDate)) {
$this->_order->getPayment()->setAdditionalInformation('adyen_expiry_date', $expiryDate);
}
} }
/** /**
...@@ -1137,6 +1155,8 @@ class Cron ...@@ -1137,6 +1155,8 @@ class Cron
// only do this if status in configuration is set // only do this if status in configuration is set
if (!empty($status)) { if (!empty($status)) {
$this->_order->addStatusHistoryComment(__('Payment is authorised waiting for capture'), $status); $this->_order->addStatusHistoryComment(__('Payment is authorised waiting for capture'), $status);
$this->_setState($status);
$this->_adyenLogger->addAdyenNotificationCronjob( $this->_adyenLogger->addAdyenNotificationCronjob(
'Order status is changed to Pre-authorised status, status is ' . $status 'Order status is changed to Pre-authorised status, status is ' . $status
); );
...@@ -1594,14 +1614,30 @@ class Cron ...@@ -1594,14 +1614,30 @@ class Cron
$comment = "Adyen Payment is in Manual Review check the Adyen platform"; $comment = "Adyen Payment is in Manual Review check the Adyen platform";
} }
} }
$status = (!empty($status)) ? $status : $this->_order->getStatus(); $status = (!empty($status)) ? $status : $this->_order->getStatus();
$this->_order->addStatusHistoryComment(__($comment), $status); $this->_order->addStatusHistoryComment(__($comment), $status);
$this->_setState($status);
$this->_adyenLogger->addAdyenNotificationCronjob( $this->_adyenLogger->addAdyenNotificationCronjob(
'Order status is changed to authorised status, status is ' . $status 'Order status is changed to authorised status, status is ' . $status
); );
} }
/**
* Set State from Status
*/
protected function _setState($status)
{
$statusObject = $this->_orderStatusCollection->create()
->addFieldToFilter('main_table.status', $status)
->addFieldToFilter('state_table.is_default', true)
->joinStates()
->getFirstItem();
$this->_order->setState($statusObject->getState());
$this->_adyenLogger->addAdyenNotificationCronjob('State is changed to ' . $statusObject->getState());
}
/** /**
* Create shipment * Create shipment
......
...@@ -48,9 +48,22 @@ class DataTest extends \PHPUnit\Framework\TestCase ...@@ -48,9 +48,22 @@ class DataTest extends \PHPUnit\Framework\TestCase
$assetRepo = $this->getSimpleMock(\Magento\Framework\View\Asset\Repository::class); $assetRepo = $this->getSimpleMock(\Magento\Framework\View\Asset\Repository::class);
$assetSource = $this->getSimpleMock(\Magento\Framework\View\Asset\Source::class); $assetSource = $this->getSimpleMock(\Magento\Framework\View\Asset\Source::class);
$notificationFactory = $this->getSimpleMock(\Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory::class); $notificationFactory = $this->getSimpleMock(\Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory::class);
$taxConfig = $this->getSimpleMock(\Magento\Tax\Model\Config::class);
$taxCalculation = $this->getSimpleMock(\Magento\Tax\Model\Calculation::class);
$this->dataHelper = new \Adyen\Payment\Helper\Data($context, $encryptor, $dataStorage, $country, $moduleList, $this->dataHelper = new \Adyen\Payment\Helper\Data(
$billingAgreementCollectionFactory, $assetRepo, $assetSource, $notificationFactory); $context,
$encryptor,
$dataStorage,
$country,
$moduleList,
$billingAgreementCollectionFactory,
$assetRepo,
$assetSource,
$notificationFactory,
$taxConfig,
$taxCalculation
);
} }
public function testFormatAmount() public function testFormatAmount()
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"name": "adyen/module-payment", "name": "adyen/module-payment",
"description": "Official Magento2 Plugin to connect to Payment Service Provider Adyen.", "description": "Official Magento2 Plugin to connect to Payment Service Provider Adyen.",
"type": "magento2-module", "type": "magento2-module",
"version": "2.3.0", "version": "2.3.1",
"license": [ "license": [
"OSL-3.0", "OSL-3.0",
"AFL-3.0" "AFL-3.0"
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
--> -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Adyen_Payment" setup_version="2.3.0"> <module name="Adyen_Payment" setup_version="2.3.1">
<sequence> <sequence>
<module name="Magento_Sales"/> <module name="Magento_Sales"/>
<module name="Magento_Quote"/> <module name="Magento_Quote"/>
......
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