Skip to content

Commit 1e58f70

Browse files
authored
Merge pull request #4395 from magento-mpi/MPI_PR_2019_06_21
[MPI] Bugfixes
2 parents 9c7a51d + a7a0e54 commit 1e58f70

File tree

24 files changed

+883
-116
lines changed

24 files changed

+883
-116
lines changed

app/code/Magento/Braintree/Gateway/Validator/ErrorCodeProvider.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public function getErrorCodes($response): array
3838
$result[] = $error->code;
3939
}
4040

41+
if (isset($response->transaction) && $response->transaction->status === 'gateway_rejected') {
42+
$result[] = $response->transaction->gatewayRejectionReason;
43+
}
44+
45+
if (isset($response->transaction) && $response->transaction->status === 'processor_declined') {
46+
$result[] = $response->transaction->processorResponseCode;
47+
}
48+
4149
return $result;
4250
}
4351
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Braintree\Test\Unit\Gateway\Validator;
9+
10+
use Braintree\Result\Error;
11+
use Magento\Braintree\Gateway\Validator\ErrorCodeProvider;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Class ErrorCodeProviderTest
16+
*/
17+
class ErrorCodeProviderTest extends TestCase
18+
{
19+
/**
20+
* @var ErrorCodeProvider
21+
*/
22+
private $model;
23+
24+
/**
25+
* Checks a extracting error codes from response.
26+
*
27+
* @param array $errors
28+
* @param array $transaction
29+
* @param array $expectedResult
30+
* @return void
31+
* @dataProvider getErrorCodeDataProvider
32+
*/
33+
public function testGetErrorCodes(array $errors, array $transaction, array $expectedResult): void
34+
{
35+
$response = new Error(
36+
[
37+
'errors' => ['errors' => $errors],
38+
'transaction' => $transaction,
39+
]
40+
);
41+
$this->model = new ErrorCodeProvider();
42+
$actual = $this->model->getErrorCodes($response);
43+
44+
$this->assertSame($expectedResult, $actual);
45+
}
46+
47+
/**
48+
* Gets list of errors variations.
49+
*
50+
* @return array
51+
*/
52+
public function getErrorCodeDataProvider(): array
53+
{
54+
return [
55+
[
56+
'errors' => [
57+
['code' => 91734],
58+
['code' => 91504]
59+
],
60+
'transaction' => [
61+
'status' => 'success',
62+
],
63+
'expectedResult' => ['91734', '91504']
64+
],
65+
[
66+
'errors' => [],
67+
'transaction' => [
68+
'status' => 'processor_declined',
69+
'processorResponseCode' => '1000'
70+
],
71+
'expectedResult' => ['1000']
72+
],
73+
[
74+
'errors' => [],
75+
'transaction' => [
76+
'status' => 'processor_declined',
77+
'processorResponseCode' => '1000'
78+
],
79+
'expectedResult' => ['1000']
80+
],
81+
[
82+
'errors' => [
83+
['code' => 91734],
84+
['code' => 91504]
85+
],
86+
'transaction' => [
87+
'status' => 'processor_declined',
88+
'processorResponseCode' => '1000'
89+
],
90+
'expectedResult' => ['91734', '91504', '1000']
91+
],
92+
];
93+
}
94+
}

app/code/Magento/Braintree/Test/Unit/Gateway/Validator/GeneralResponseValidatorTest.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
1515
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1616

17+
/**
18+
* Class GeneralResponseValidatorTest
19+
*/
1720
class GeneralResponseValidatorTest extends \PHPUnit\Framework\TestCase
1821
{
1922
/**
@@ -61,11 +64,13 @@ public function testValidate(array $validationSubject, bool $isValid, $messages,
6164
$result = new Result($isValid, $messages);
6265

6366
$this->resultInterfaceFactory->method('create')
64-
->with([
65-
'isValid' => $isValid,
66-
'failsDescription' => $messages,
67-
'errorCodes' => $errorCodes
68-
])
67+
->with(
68+
[
69+
'isValid' => $isValid,
70+
'failsDescription' => $messages,
71+
'errorCodes' => $errorCodes
72+
]
73+
)
6974
->willReturn($result);
7075

7176
$actual = $this->responseValidator->validate($validationSubject);
@@ -82,9 +87,11 @@ public function dataProviderTestValidate()
8287
{
8388
$successTransaction = new \stdClass();
8489
$successTransaction->success = true;
90+
$successTransaction->status = 'authorized';
8591

8692
$failureTransaction = new \stdClass();
8793
$failureTransaction->success = false;
94+
$failureTransaction->status = 'declined';
8895
$failureTransaction->message = 'Transaction was failed.';
8996

9097
$errors = [
@@ -93,10 +100,10 @@ public function dataProviderTestValidate()
93100
'code' => 81804,
94101
'attribute' => 'base',
95102
'message' => 'Cannot process transaction.'
96-
]
103+
],
97104
]
98105
];
99-
$errorTransaction = new Error(['errors' => $errors]);
106+
$errorTransaction = new Error(['errors' => $errors, 'transaction' => ['status' => 'declined']]);
100107

101108
return [
102109
[

app/code/Magento/Braintree/etc/braintree_error_mapping.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<message code="81716" translate="true">Credit card number must be 12-19 digits.</message>
2121
<message code="81723" translate="true">Cardholder name is too long.</message>
2222
<message code="81736" translate="true">CVV verification failed.</message>
23+
<message code="cvv" translate="true">CVV verification failed.</message>
2324
<message code="81737" translate="true">Postal code verification failed.</message>
2425
<message code="81750" translate="true">Credit card number is prohibited.</message>
2526
<message code="81801" translate="true">Addresses must have at least one field filled in.</message>

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/multishipping/cc-form.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ define([
1212
'Magento_Ui/js/model/messageList',
1313
'mage/translate',
1414
'Magento_Checkout/js/model/full-screen-loader',
15-
'Magento_Checkout/js/action/set-payment-information',
15+
'Magento_Checkout/js/action/set-payment-information-extended',
1616
'Magento_Checkout/js/model/payment/additional-validators',
1717
'Magento_Braintree/js/view/payment/validator-handler'
1818
], function (
@@ -22,7 +22,7 @@ define([
2222
messageList,
2323
$t,
2424
fullScreenLoader,
25-
setPaymentInformationAction,
25+
setPaymentInformationExtended,
2626
additionalValidators,
2727
validatorManager
2828
) {
@@ -51,9 +51,10 @@ define([
5151
if (additionalValidators.validate()) {
5252
fullScreenLoader.startLoader();
5353
$.when(
54-
setPaymentInformationAction(
54+
setPaymentInformationExtended(
5555
this.messageContainer,
56-
this.getData()
56+
this.getData(),
57+
true
5758
)
5859
).done(this.done.bind(this))
5960
.fail(this.fail.bind(this));

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/multishipping/paypal.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ define([
88
'jquery',
99
'underscore',
1010
'Magento_Braintree/js/view/payment/method-renderer/paypal',
11-
'Magento_Checkout/js/action/set-payment-information',
11+
'Magento_Checkout/js/action/set-payment-information-extended',
1212
'Magento_Checkout/js/model/payment/additional-validators',
1313
'Magento_Checkout/js/model/full-screen-loader'
1414
], function (
1515
$,
1616
_,
1717
Component,
18-
setPaymentInformationAction,
18+
setPaymentInformationExtended,
1919
additionalValidators,
2020
fullScreenLoader
2121
) {
@@ -131,9 +131,10 @@ define([
131131
placeOrder: function () {
132132
fullScreenLoader.startLoader();
133133
$.when(
134-
setPaymentInformationAction(
134+
setPaymentInformationExtended(
135135
this.messageContainer,
136-
this.getData()
136+
this.getData(),
137+
true
137138
)
138139
).done(this.done.bind(this))
139140
.fail(this.fail.bind(this));
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogInventory\Observer;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface as Product;
11+
12+
/**
13+
* Interface for processing parent items of complex product types
14+
*/
15+
interface ParentItemProcessorInterface
16+
{
17+
/**
18+
* Process stock for parent items
19+
*
20+
* @param Product $product
21+
* @return void
22+
*/
23+
public function process(Product $product);
24+
}

app/code/Magento/CatalogInventory/Observer/SaveInventoryDataObserver.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\CatalogInventory\Api\StockRegistryInterface;
1414
use Magento\CatalogInventory\Model\StockItemValidator;
1515
use Magento\Framework\Event\Observer as EventObserver;
16+
use Magento\Framework\Exception\LocalizedException;
17+
use Magento\Framework\Exception\NoSuchEntityException;
1618

1719
/**
1820
* Saves stock data from a product to the Stock Item
@@ -39,6 +41,11 @@ class SaveInventoryDataObserver implements ObserverInterface
3941
*/
4042
private $stockItemValidator;
4143

44+
/**
45+
* @var ParentItemProcessorInterface[]
46+
*/
47+
private $parentItemProcessorPool;
48+
4249
/**
4350
* @var array
4451
*/
@@ -77,15 +84,18 @@ class SaveInventoryDataObserver implements ObserverInterface
7784
* @param StockConfigurationInterface $stockConfiguration
7885
* @param StockRegistryInterface $stockRegistry
7986
* @param StockItemValidator $stockItemValidator
87+
* @param ParentItemProcessorInterface[] $parentItemProcessorPool
8088
*/
8189
public function __construct(
8290
StockConfigurationInterface $stockConfiguration,
8391
StockRegistryInterface $stockRegistry,
84-
StockItemValidator $stockItemValidator = null
92+
StockItemValidator $stockItemValidator = null,
93+
array $parentItemProcessorPool = []
8594
) {
8695
$this->stockConfiguration = $stockConfiguration;
8796
$this->stockRegistry = $stockRegistry;
8897
$this->stockItemValidator = $stockItemValidator ?: ObjectManager::getInstance()->get(StockItemValidator::class);
98+
$this->parentItemProcessorPool = $parentItemProcessorPool;
8999
}
90100

91101
/**
@@ -96,10 +106,15 @@ public function __construct(
96106
*
97107
* @param EventObserver $observer
98108
* @return void
109+
* @throws LocalizedException
110+
* @throws NoSuchEntityException
99111
*/
100112
public function execute(EventObserver $observer)
101113
{
114+
/** @var Product $product */
102115
$product = $observer->getEvent()->getProduct();
116+
117+
/** @var Item $stockItem */
103118
$stockItem = $this->getStockItemToBeUpdated($product);
104119

105120
if ($product->getStockData() !== null) {
@@ -108,6 +123,7 @@ public function execute(EventObserver $observer)
108123
}
109124
$this->stockItemValidator->validate($product, $stockItem);
110125
$this->stockRegistry->updateStockItemBySku($product->getSku(), $stockItem);
126+
$this->processParents($product);
111127
}
112128

113129
/**
@@ -156,4 +172,17 @@ private function getStockData(Product $product)
156172
}
157173
return $stockData;
158174
}
175+
176+
/**
177+
* Process stock data for parent products
178+
*
179+
* @param Product $product
180+
* @return void
181+
*/
182+
private function processParents(Product $product)
183+
{
184+
foreach ($this->parentItemProcessorPool as $processor) {
185+
$processor->process($product);
186+
}
187+
}
159188
}

0 commit comments

Comments
 (0)