Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Adyen Magento2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shared Libs
Adyen Magento2
Commits
b6cda614
Commit
b6cda614
authored
Jul 03, 2018
by
Rik ter Beek
Committed by
GitHub
Jul 03, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #285 from torreytsui/feature/generalise-signature-calculation
Generalise request signature calculation
parents
4495500d
9c8f56a1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
31 deletions
+23
-31
Block/Redirect/Redirect.php
Block/Redirect/Redirect.php
+3
-11
Controller/Process/Result.php
Controller/Process/Result.php
+3
-9
Gateway/Command/PayByMailCommand.php
Gateway/Command/PayByMailCommand.php
+2
-9
Test/Unit/Helper/DataTest.php
Test/Unit/Helper/DataTest.php
+15
-2
No files found.
Block/Redirect/Redirect.php
View file @
b6cda614
...
...
@@ -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
));
...
...
Controller/Process/Result.php
View file @
b6cda614
...
...
@@ -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
;
...
...
Gateway/Command/PayByMailCommand.php
View file @
b6cda614
...
...
@@ -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
));
...
...
Test/Unit/Helper/DataTest.php
View file @
b6cda614
...
...
@@ -48,9 +48,22 @@ class DataTest extends \PHPUnit\Framework\TestCase
$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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment