From ebecd605370055c1d81b10aab62fd3c155e88031 Mon Sep 17 00:00:00 2001 From: torreytsui Date: Fri, 29 Jun 2018 13:25:00 +0100 Subject: [PATCH 1/6] Generalise request signature calculation --- Block/Redirect/Redirect.php | 14 +++----------- Controller/Process/Result.php | 12 +++--------- Gateway/Command/PayByMailCommand.php | 11 ++--------- 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/Block/Redirect/Redirect.php b/Block/Redirect/Redirect.php index 269c769ab..7477a9988 100755 --- a/Block/Redirect/Redirect.php +++ b/Block/Redirect/Redirect.php @@ -261,8 +261,6 @@ public function getFormFields() ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK); $formFields['resURL'] = $baseUrl . 'adyen/process/result'; - $hmacKey = $this->_adyenHelper->getHmac(); - if ($brandCode) { $formFields['brandCode'] = $brandCode; @@ -307,15 +305,9 @@ public function getFormFields() $formFields['dfValue'] = $this->_order->getPayment()->getAdditionalInformation("df_value"); } - // Sort the array by key using SORT_STRING order - ksort($formFields, SORT_STRING); - - // 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)); - + // Sign request using secret key + $hmacKey = $this->_adyenHelper->getHmac(); + $merchantSig = \Adyen\Util\Util::calculateSha256Signature($hmacKey, $formFields); $formFields['merchantSig'] = $merchantSig; $this->_adyenLogger->addAdyenDebug(print_r($formFields, true)); diff --git a/Controller/Process/Result.php b/Controller/Process/Result.php index 769c825d1..ba0ad48ce 100755 --- a/Controller/Process/Result.php +++ b/Controller/Process/Result.php @@ -279,7 +279,6 @@ protected function _validateUpdateOrder($order, $response) */ protected function _authenticate($response) { - $hmacKey = $this->_adyenHelper->getHmac(); $merchantSigNotification = $response['merchantSig']; // do it like this because $_GET is converting dot to underscore @@ -297,14 +296,9 @@ protected function _authenticate($response) { // do not include the merchantSig in the merchantSig calculation unset($result['merchantSig']); - // Sort the array by key using SORT_STRING order - ksort($result, SORT_STRING); - - // 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)); + // Sign request using secret key + $hmacKey = $this->_adyenHelper->getHmac(); + $merchantSig = \Adyen\Util\Util::calculateSha256Signature($hmacKey, $result); if (strcmp($merchantSig, $merchantSigNotification) === 0) { return true; diff --git a/Gateway/Command/PayByMailCommand.php b/Gateway/Command/PayByMailCommand.php index 4aaf72b3c..256a26878 100644 --- a/Gateway/Command/PayByMailCommand.php +++ b/Gateway/Command/PayByMailCommand.php @@ -199,15 +199,8 @@ protected function getFormFields($payment, $paymentAmount = false) $formFields['shopperReference'] = $customerId; } - // Sort the array by key using SORT_STRING order - ksort($formFields, SORT_STRING); - - // 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)); - + // Sign request using secret key + $merchantSig = \Adyen\Util\Util::calculateSha256Signature($hmacKey, $formFields); $formFields['merchantSig'] = $merchantSig; $this->_adyenLogger->addAdyenDebug(print_r($formFields, true)); From 9c8f56a17842a1dd6ce560b203af6587a9738017 Mon Sep 17 00:00:00 2001 From: Torrey Tsui Date: Sat, 30 Jun 2018 13:33:51 +0100 Subject: [PATCH 2/6] Fix unit test err due to missing dep on injection Adyen\Payment\Tests\Helper\DataTest::testFormatAmount ArgumentCountError: Too few arguments to function Adyen\Payment\Helper\Data::__construct(), 9 passed --- Test/Unit/Helper/DataTest.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Test/Unit/Helper/DataTest.php b/Test/Unit/Helper/DataTest.php index f5afc7e8a..eaece7d43 100755 --- a/Test/Unit/Helper/DataTest.php +++ b/Test/Unit/Helper/DataTest.php @@ -48,9 +48,22 @@ public function setUp() $assetRepo = $this->getSimpleMock(\Magento\Framework\View\Asset\Repository::class); $assetSource = $this->getSimpleMock(\Magento\Framework\View\Asset\Source::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, - $billingAgreementCollectionFactory, $assetRepo, $assetSource, $notificationFactory); + $this->dataHelper = new \Adyen\Payment\Helper\Data( + $context, + $encryptor, + $dataStorage, + $country, + $moduleList, + $billingAgreementCollectionFactory, + $assetRepo, + $assetSource, + $notificationFactory, + $taxConfig, + $taxCalculation + ); } public function testFormatAmount() From 73e31065db4f0e0c3d8111562e340683c804f541 Mon Sep 17 00:00:00 2001 From: Bas Maassen Date: Tue, 10 Jul 2018 10:27:07 +0200 Subject: [PATCH 3/6] Set state (#287) * Set state * Add in constructor comments --- Model/Cron.php | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Model/Cron.php b/Model/Cron.php index a2d238857..18dedfb4c 100755 --- a/Model/Cron.php +++ b/Model/Cron.php @@ -187,6 +187,11 @@ class Cron */ protected $_areaList; + /** + * @var \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory + */ + protected $_orderStatusCollection; + /** * Cron constructor. * @@ -203,7 +208,9 @@ class Cron * @param Api\PaymentRequest $paymentRequest * @param Order\PaymentFactory $adyenOrderPaymentFactory * @param ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory + * @param InvoiceFactory $adyenInvoiceFactory * @param AreaList $areaList + * @param \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory $orderStatusCollection */ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, @@ -220,8 +227,10 @@ public function __construct( \Adyen\Payment\Model\Order\PaymentFactory $adyenOrderPaymentFactory, \Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory, \Adyen\Payment\Model\InvoiceFactory $adyenInvoiceFactory, - AreaList $areaList - ) { + AreaList $areaList, + \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory $orderStatusCollection + ) + { $this->_scopeConfig = $scopeConfig; $this->_adyenLogger = $adyenLogger; $this->_notificationFactory = $notificationFactory; @@ -237,6 +246,7 @@ public function __construct( $this->_adyenOrderPaymentCollectionFactory = $adyenOrderPaymentCollectionFactory; $this->_adyenInvoiceFactory = $adyenInvoiceFactory; $this->_areaList = $areaList; + $this->_orderStatusCollection = $orderStatusCollection; } /** @@ -1137,6 +1147,8 @@ private function _setPrePaymentAuthorized() // only do this if status in configuration is set if (!empty($status)) { $this->_order->addStatusHistoryComment(__('Payment is authorised waiting for capture'), $status); + $this->_setState($status); + $this->_adyenLogger->addAdyenNotificationCronjob( 'Order status is changed to Pre-authorised status, status is ' . $status ); @@ -1594,14 +1606,30 @@ protected function _setPaymentAuthorized($manualReviewComment = true, $createInv $comment = "Adyen Payment is in Manual Review check the Adyen platform"; } } - $status = (!empty($status)) ? $status : $this->_order->getStatus(); $this->_order->addStatusHistoryComment(__($comment), $status); + $this->_setState($status); + $this->_adyenLogger->addAdyenNotificationCronjob( '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 From acbd2670f05eea59f4f7997fc1a84c3280d0f681 Mon Sep 17 00:00:00 2001 From: Alessio Zampatti Date: Thu, 12 Jul 2018 13:26:15 +0200 Subject: [PATCH 4/6] PW-515: added fix for Test Notifications (#289) * PW-515: added fix for Test Notifications * PW-515: removed old check * PW-515: added comment --- Controller/Process/Json.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Controller/Process/Json.php b/Controller/Process/Json.php index 687eeea14..1bb9bfff2 100755 --- a/Controller/Process/Json.php +++ b/Controller/Process/Json.php @@ -99,7 +99,7 @@ public function execute() $notificationMode = isset($notificationItems['live']) ? $notificationItems['live'] : ""; - if ($notificationMode != "" && $this->_validateNotificationMode($notificationMode)) { + if ($notificationMode !== "" && $this->_validateNotificationMode($notificationMode)) { foreach ($notificationItems['notificationItems'] as $notificationItem) { @@ -154,7 +154,8 @@ protected function _validateNotificationMode($notificationMode) { $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 false; From 97f7799d9d9e2ac9a67ff0a5295c5d875adddcfd Mon Sep 17 00:00:00 2001 From: Giorgos Adam Date: Fri, 10 Aug 2018 12:19:13 +0200 Subject: [PATCH 5/6] Adding cardBin and expiryDate additionalData --- Model/Cron.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Model/Cron.php b/Model/Cron.php index 18dedfb4c..b792373ea 100755 --- a/Model/Cron.php +++ b/Model/Cron.php @@ -655,6 +655,8 @@ protected function _updateOrderPaymentWithAdyenAttributes($additionalData) $acquirerReference = (isset($additionalData['acquirerReference'])) ? $additionalData['acquirerReference'] : ""; $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 @@ -695,6 +697,12 @@ protected function _updateOrderPaymentWithAdyenAttributes($additionalData) if (isset($authCode) && $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); + } } /** From dee1944e1b41ece3409ca83e34afd3bd735a3134 Mon Sep 17 00:00:00 2001 From: Giorgos Adam Date: Fri, 10 Aug 2018 15:22:36 +0200 Subject: [PATCH 6/6] Version bump 2.3.1 --- composer.json | 2 +- etc/module.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5b37a3f6b..8ceec6c91 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "adyen/module-payment", "description": "Official Magento2 Plugin to connect to Payment Service Provider Adyen.", "type": "magento2-module", - "version": "2.3.0", + "version": "2.3.1", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/etc/module.xml b/etc/module.xml index 8a64d1837..3c3014505 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -24,7 +24,7 @@ --> - +