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
->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 @@ class Redirect extends \Magento\Payment\Block\Form
$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));
......
......@@ -279,7 +279,6 @@ class Result extends \Magento\Framework\App\Action\Action
*/
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 @@ class Result extends \Magento\Framework\App\Action\Action
// 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;
......
......@@ -199,15 +199,8 @@ class PayByMailCommand implements CommandInterface
$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));
......
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