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 ebecd605 authored by torreytsui's avatar torreytsui

Generalise request signature calculation

parent 4495500d
...@@ -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));
......
...@@ -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));
......
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