Skip to content

Commit 1a5e412

Browse files
Merge branch 2.3-develop into ENGCOM-4502-magento-magento2-21774
2 parents 663a696 + 3666e03 commit 1a5e412

File tree

53 files changed

+1328
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1328
-228
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ Tests:
626626
* Fixed an issue where filters were not shown on product reviews report grid
627627
* Fixed an issue where second customer address was not deleted from customer account
628628
* Fixed an issue where custom options pop-up was still displayed after submit
629-
* Fixed an issue where Second Product was not added to Shopping Cart from Wishlist at first atempt
629+
* Fixed an issue where Second Product was not added to Shopping Cart from Wishlist at first attempt
630630
* Fixed an issue where customer invalid email message was not displayed
631631
* Fixed an issue where All Access Tokens for Customer without Tokens could not be revoked
632632
* Fixed an issue where it was impossible to add Product to Shopping Cart from shared Wishlist

app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
185185
* @param AdvancedPricing\Validator\Website $websiteValidator
186186
* @param AdvancedPricing\Validator\TierPrice $tierPriceValidator
187187
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
188+
* @throws \Exception
188189
*/
189190
public function __construct(
190191
\Magento\Framework\Json\Helper\Data $jsonHelper,
@@ -255,6 +256,7 @@ public function getEntityTypeCode()
255256
* @param array $rowData
256257
* @param int $rowNum
257258
* @return bool
259+
* @throws \Zend_Validate_Exception
258260
*/
259261
public function validateRow(array $rowData, $rowNum)
260262
{
@@ -308,6 +310,7 @@ protected function _importData()
308310
* Save advanced pricing
309311
*
310312
* @return $this
313+
* @throws \Exception
311314
*/
312315
public function saveAdvancedPricing()
313316
{
@@ -319,6 +322,7 @@ public function saveAdvancedPricing()
319322
* Deletes Advanced price data from raw data.
320323
*
321324
* @return $this
325+
* @throws \Exception
322326
*/
323327
public function deleteAdvancedPricing()
324328
{
@@ -347,6 +351,7 @@ public function deleteAdvancedPricing()
347351
* Replace advanced pricing
348352
*
349353
* @return $this
354+
* @throws \Exception
350355
*/
351356
public function replaceAdvancedPricing()
352357
{
@@ -360,6 +365,7 @@ public function replaceAdvancedPricing()
360365
* @return $this
361366
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
362367
* @SuppressWarnings(PHPMD.NPathComplexity)
368+
* @throws \Exception
363369
*/
364370
protected function saveAndReplaceAdvancedPrices()
365371
{
@@ -368,8 +374,8 @@ protected function saveAndReplaceAdvancedPrices()
368374
$this->_cachedSkuToDelete = null;
369375
}
370376
$listSku = [];
377+
$tierPrices = [];
371378
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
372-
$tierPrices = [];
373379
foreach ($bunch as $rowNum => $rowData) {
374380
if (!$this->validateRow($rowData, $rowNum)) {
375381
$this->addRowError(ValidatorInterface::ERROR_SKU_IS_EMPTY, $rowNum);
@@ -397,15 +403,8 @@ protected function saveAndReplaceAdvancedPrices()
397403
];
398404
}
399405
}
400-
if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
401-
if ($listSku) {
402-
$this->processCountNewPrices($tierPrices);
403-
if ($this->deleteProductTierPrices(array_unique($listSku), self::TABLE_TIER_PRICE)) {
404-
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE);
405-
$this->setUpdatedAt($listSku);
406-
}
407-
}
408-
} elseif (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $behavior) {
406+
407+
if (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $behavior) {
409408
$this->processCountExistingPrices($tierPrices, self::TABLE_TIER_PRICE)
410409
->processCountNewPrices($tierPrices);
411410

@@ -415,6 +414,17 @@ protected function saveAndReplaceAdvancedPrices()
415414
}
416415
}
417416
}
417+
418+
if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
419+
if ($listSku) {
420+
$this->processCountNewPrices($tierPrices);
421+
if ($this->deleteProductTierPrices(array_unique($listSku), self::TABLE_TIER_PRICE)) {
422+
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE);
423+
$this->setUpdatedAt($listSku);
424+
}
425+
}
426+
}
427+
418428
return $this;
419429
}
420430

@@ -424,6 +434,7 @@ protected function saveAndReplaceAdvancedPrices()
424434
* @param array $priceData
425435
* @param string $table
426436
* @return $this
437+
* @throws \Exception
427438
*/
428439
protected function saveProductPrices(array $priceData, $table)
429440
{
@@ -455,6 +466,7 @@ protected function saveProductPrices(array $priceData, $table)
455466
* @param array $listSku
456467
* @param string $table
457468
* @return boolean
469+
* @throws \Exception
458470
*/
459471
protected function deleteProductTierPrices(array $listSku, $table)
460472
{
@@ -532,6 +544,7 @@ protected function getCustomerGroupId($customerGroup)
532544
* Retrieve product skus
533545
*
534546
* @return array
547+
* @throws \Exception
535548
*/
536549
protected function retrieveOldSkus()
537550
{
@@ -552,6 +565,7 @@ protected function retrieveOldSkus()
552565
* @param array $prices
553566
* @param string $table
554567
* @return $this
568+
* @throws \Exception
555569
*/
556570
protected function processCountExistingPrices($prices, $table)
557571
{

app/code/Magento/Authorizenet/Model/Directpost.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,15 +546,16 @@ public function setResponseData(array $postData)
546546
public function validateResponse()
547547
{
548548
$response = $this->getResponse();
549-
//md5 check
550-
if (!$this->getConfigData('trans_md5')
551-
|| !$this->getConfigData('login')
552-
|| !$response->isValidHash($this->getConfigData('trans_md5'), $this->getConfigData('login'))
549+
$hashConfigKey = !empty($response->getData('x_SHA2_Hash')) ? 'signature_key' : 'trans_md5';
550+
551+
//hash check
552+
if (!$response->isValidHash($this->getConfigData($hashConfigKey), $this->getConfigData('login'))
553553
) {
554554
throw new \Magento\Framework\Exception\LocalizedException(
555555
__('The transaction was declined because the response hash validation failed.')
556556
);
557557
}
558+
558559
return true;
559560
}
560561

app/code/Magento/Authorizenet/Model/Directpost/Request.php

Lines changed: 105 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
namespace Magento\Authorizenet\Model\Directpost;
99

1010
use Magento\Authorizenet\Model\Request as AuthorizenetRequest;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Intl\DateTimeFactory;
1113

1214
/**
1315
* Authorize.net request model for DirectPost model
@@ -20,10 +22,35 @@ class Request extends AuthorizenetRequest
2022
*/
2123
protected $_transKey = null;
2224

25+
/**
26+
* Hexadecimal signature key.
27+
*
28+
* @var string
29+
*/
30+
private $signatureKey = '';
31+
32+
/**
33+
* @var DateTimeFactory
34+
*/
35+
private $dateTimeFactory;
36+
37+
/**
38+
* @param array $data
39+
* @param DateTimeFactory $dateTimeFactory
40+
*/
41+
public function __construct(
42+
array $data = [],
43+
DateTimeFactory $dateTimeFactory = null
44+
) {
45+
$this->dateTimeFactory = $dateTimeFactory ?? ObjectManager::getInstance()
46+
->get(DateTimeFactory::class);
47+
parent::__construct($data);
48+
}
49+
2350
/**
2451
* Return merchant transaction key.
2552
*
26-
* Needed to generate sign.
53+
* Needed to generate MD5 sign.
2754
*
2855
* @return string
2956
*/
@@ -35,7 +62,7 @@ protected function _getTransactionKey()
3562
/**
3663
* Set merchant transaction key.
3764
*
38-
* Needed to generate sign.
65+
* Needed to generate MD5 sign.
3966
*
4067
* @param string $transKey
4168
* @return $this
@@ -47,7 +74,7 @@ protected function _setTransactionKey($transKey)
4774
}
4875

4976
/**
50-
* Generates the fingerprint for request.
77+
* Generates the MD5 fingerprint for request.
5178
*
5279
* @param string $merchantApiLoginId
5380
* @param string $merchantTransactionKey
@@ -67,7 +94,7 @@ public function generateRequestSign(
6794
) {
6895
return hash_hmac(
6996
"md5",
70-
$merchantApiLoginId . "^" . $fpSequence . "^" . $fpTimestamp . "^" . $amount . "^" . $currencyCode,
97+
$merchantApiLoginId . '^' . $fpSequence . '^' . $fpTimestamp . '^' . $amount . '^' . $currencyCode,
7198
$merchantTransactionKey
7299
);
73100
}
@@ -82,7 +109,7 @@ public function setConstantData(\Magento\Authorizenet\Model\Directpost $paymentM
82109
{
83110
$this->setXVersion('3.1')->setXDelimData('FALSE')->setXRelayResponse('TRUE');
84111

85-
$this->setXTestRequest($paymentMethod->getConfigData('test') ? 'TRUE' : 'FALSE');
112+
$this->setSignatureKey($paymentMethod->getConfigData('signature_key'));
86113

87114
$this->setXLogin($paymentMethod->getConfigData('login'))
88115
->setXMethod(\Magento\Authorizenet\Model\Authorizenet::REQUEST_METHOD_CC)
@@ -173,17 +200,81 @@ public function setDataFromOrder(
173200
*/
174201
public function signRequestData()
175202
{
176-
$fpTimestamp = time();
177-
$hash = $this->generateRequestSign(
178-
$this->getXLogin(),
179-
$this->_getTransactionKey(),
180-
$this->getXAmount(),
181-
$this->getXCurrencyCode(),
182-
$this->getXFpSequence(),
183-
$fpTimestamp
184-
);
203+
$fpDate = $this->dateTimeFactory->create('now', new \DateTimeZone('UTC'));
204+
$fpTimestamp = $fpDate->getTimestamp();
205+
206+
if (!empty($this->getSignatureKey())) {
207+
$hash = $this->generateSha2RequestSign(
208+
(string)$this->getXLogin(),
209+
(string)$this->getSignatureKey(),
210+
(string)$this->getXAmount(),
211+
(string)$this->getXCurrencyCode(),
212+
(string)$this->getXFpSequence(),
213+
$fpTimestamp
214+
);
215+
} else {
216+
$hash = $this->generateRequestSign(
217+
$this->getXLogin(),
218+
$this->_getTransactionKey(),
219+
$this->getXAmount(),
220+
$this->getXCurrencyCode(),
221+
$this->getXFpSequence(),
222+
$fpTimestamp
223+
);
224+
}
225+
185226
$this->setXFpTimestamp($fpTimestamp);
186227
$this->setXFpHash($hash);
228+
187229
return $this;
188230
}
231+
232+
/**
233+
* Generates the SHA2 fingerprint for request.
234+
*
235+
* @param string $merchantApiLoginId
236+
* @param string $merchantSignatureKey
237+
* @param string $amount
238+
* @param string $currencyCode
239+
* @param string $fpSequence An invoice number or random number.
240+
* @param int $fpTimestamp
241+
* @return string The fingerprint.
242+
*/
243+
private function generateSha2RequestSign(
244+
string $merchantApiLoginId,
245+
string $merchantSignatureKey,
246+
string $amount,
247+
string $currencyCode,
248+
string $fpSequence,
249+
int $fpTimestamp
250+
): string {
251+
$message = $merchantApiLoginId . '^' . $fpSequence . '^' . $fpTimestamp . '^' . $amount . '^' . $currencyCode;
252+
253+
return strtoupper(hash_hmac('sha512', $message, pack('H*', $merchantSignatureKey)));
254+
}
255+
256+
/**
257+
* Return merchant hexadecimal signature key.
258+
*
259+
* Needed to generate SHA2 sign.
260+
*
261+
* @return string
262+
*/
263+
private function getSignatureKey(): string
264+
{
265+
return $this->signatureKey;
266+
}
267+
268+
/**
269+
* Set merchant hexadecimal signature key.
270+
*
271+
* Needed to generate SHA2 sign.
272+
*
273+
* @param string $signatureKey
274+
* @return void
275+
*/
276+
private function setSignatureKey(string $signatureKey)
277+
{
278+
$this->signatureKey = $signatureKey;
279+
}
189280
}

0 commit comments

Comments
 (0)