Skip to content

Commit f732a63

Browse files
author
Akimov, Alexander(aakimov)
committed
Merge pull request #516 from magento-mpi/MPI-BUGFIXES
[MPI] Bugfixes
2 parents 7200766 + 4d18d80 commit f732a63

File tree

16 files changed

+143
-74
lines changed

16 files changed

+143
-74
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ class Directpost extends \Magento\Authorizenet\Model\Authorizenet implements Tra
119119
*/
120120
protected $transactionRepository;
121121

122+
/**
123+
* @var \Psr\Log\LoggerInterface
124+
*/
125+
private $psrLogger;
126+
122127
/**
123128
* @param \Magento\Framework\Model\Context $context
124129
* @param \Magento\Framework\Registry $registry
@@ -761,7 +766,7 @@ protected function addStatusComment(\Magento\Sales\Model\Order\Payment $payment)
761766
{
762767
try {
763768
$transactionId = $this->getResponse()->getXTransId();
764-
$data = $payment->getMethodInstance()->getTransactionDetails($transactionId);
769+
$data = $this->transactionService->getTransactionDetails($this, $transactionId);
765770
$transactionStatus = (string)$data->transaction->transactionStatus;
766771
$fdsFilterAction = (string)$data->transaction->FDSFilterAction;
767772

@@ -779,6 +784,7 @@ protected function addStatusComment(\Magento\Sales\Model\Order\Payment $payment)
779784
$payment->getOrder()->addStatusHistoryComment($message);
780785
}
781786
} catch (\Exception $e) {
787+
$this->getPsrLogger()->critical($e);
782788
//this request is optional
783789
}
784790
return $this;
@@ -805,7 +811,7 @@ protected function declineOrder(\Magento\Sales\Model\Order $order, $message = ''
805811
$order->registerCancellation($message)->save();
806812
} catch (\Exception $e) {
807813
//quiet decline
808-
$this->logger->critical($e);
814+
$this->getPsrLogger()->critical($e);
809815
}
810816
}
811817

@@ -973,4 +979,18 @@ protected function getTransactionResponse($transactionId)
973979

974980
return $response;
975981
}
982+
983+
/**
984+
* @return \Psr\Log\LoggerInterface
985+
*
986+
* @deprecated
987+
*/
988+
private function getPsrLogger()
989+
{
990+
if (null === $this->psrLogger) {
991+
$this->psrLogger = \Magento\Framework\App\ObjectManager::getInstance()
992+
->get(\Psr\Log\LoggerInterface::class);
993+
}
994+
return $this->psrLogger;
995+
}
976996
}

app/code/Magento/Checkout/view/frontend/web/js/action/place-order.js

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,31 @@ define(
66
[
77
'Magento_Checkout/js/model/quote',
88
'Magento_Checkout/js/model/url-builder',
9-
'mage/storage',
10-
'Magento_Checkout/js/model/error-processor',
119
'Magento_Customer/js/model/customer',
12-
'Magento_Checkout/js/model/full-screen-loader'
10+
'Magento_Checkout/js/model/place-order'
1311
],
14-
function (quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader) {
12+
function (quote, urlBuilder, customer, placeOrderService) {
1513
'use strict';
1614

1715
return function (paymentData, messageContainer) {
18-
var serviceUrl,
19-
payload;
16+
var serviceUrl, payload;
2017

21-
/** Checkout for guest and registered customer. */
22-
if (!customer.isLoggedIn()) {
18+
payload = {
19+
cartId: quote.getQuoteId(),
20+
billingAddress: quote.billingAddress(),
21+
paymentMethod: paymentData
22+
};
23+
24+
if (customer.isLoggedIn()) {
25+
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
26+
} else {
2327
serviceUrl = urlBuilder.createUrl('/guest-carts/:quoteId/payment-information', {
2428
quoteId: quote.getQuoteId()
2529
});
26-
payload = {
27-
cartId: quote.getQuoteId(),
28-
email: quote.guestEmail,
29-
paymentMethod: paymentData,
30-
billingAddress: quote.billingAddress()
31-
};
32-
} else {
33-
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
34-
payload = {
35-
cartId: quote.getQuoteId(),
36-
paymentMethod: paymentData,
37-
billingAddress: quote.billingAddress()
38-
};
30+
payload.email = quote.guestEmail;
3931
}
4032

41-
fullScreenLoader.startLoader();
42-
43-
return storage.post(
44-
serviceUrl, JSON.stringify(payload)
45-
).fail(
46-
function (response) {
47-
errorProcessor.process(response, messageContainer);
48-
fullScreenLoader.stopLoader();
49-
}
50-
);
33+
return placeOrderService(serviceUrl, payload, messageContainer);
5134
};
5235
}
5336
);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright © 2016 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define(
6+
[
7+
'mage/storage',
8+
'Magento_Checkout/js/model/error-processor',
9+
'Magento_Checkout/js/model/full-screen-loader'
10+
],
11+
function (storage, errorProcessor, fullScreenLoader) {
12+
'use strict';
13+
14+
return function (serviceUrl, payload, messageContainer) {
15+
fullScreenLoader.startLoader();
16+
17+
return storage.post(
18+
serviceUrl, JSON.stringify(payload)
19+
).fail(
20+
function (response) {
21+
errorProcessor.process(response, messageContainer);
22+
fullScreenLoader.stopLoader();
23+
}
24+
);
25+
};
26+
}
27+
);

app/code/Magento/Dhl/Model/Carrier.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,8 @@ protected function _parseResponse($response)
11231123
throw new \Magento\Framework\Exception\LocalizedException($responseError);
11241124
}
11251125
$this->debugErrors($this->_errors);
1126-
1127-
return false;
11281126
}
1127+
$result->append($this->getErrorMessage());
11291128
}
11301129

11311130
return $result;

app/code/Magento/Fedex/Model/Carrier.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,10 @@ protected function _getQuotes()
501501
// make general request for all methods
502502
$response = $this->_doRatesRequest(self::RATE_REQUEST_GENERAL);
503503
$preparedGeneral = $this->_prepareRateResponse($response);
504-
if (!$preparedGeneral->getError() || $this->_result->getError() && $preparedGeneral->getError()) {
504+
if (!$preparedGeneral->getError()
505+
|| $this->_result->getError() && $preparedGeneral->getError()
506+
|| empty($this->_result->getAllRates())
507+
) {
505508
$this->_result->append($preparedGeneral);
506509
}
507510

app/code/Magento/Paypal/Controller/Express/AbstractExpress/PlaceOrder.php

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,21 @@ public function __construct(
6262
*/
6363
public function execute()
6464
{
65-
try {
66-
if ($this->isValidationRequired() &&
67-
!$this->agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', [])))
68-
) {
69-
throw new \Magento\Framework\Exception\LocalizedException(
70-
__('Please agree to all the terms and conditions before placing the order.')
71-
);
72-
}
65+
if ($this->isValidationRequired() &&
66+
!$this->agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', [])))
67+
) {
68+
$e = new \Magento\Framework\Exception\LocalizedException(
69+
__('Please agree to all the terms and conditions before placing the order.')
70+
);
71+
$this->messageManager->addExceptionMessage(
72+
$e,
73+
$e->getMessage()
74+
);
75+
$this->_redirect('*/*/review');
76+
return;
77+
}
7378

79+
try {
7480
$this->_initCheckout();
7581
$this->_checkout->place($this->_initToken());
7682

@@ -108,12 +114,6 @@ public function execute()
108114
return;
109115
} catch (ApiProcessableException $e) {
110116
$this->_processPaypalApiError($e);
111-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
112-
$this->messageManager->addExceptionMessage(
113-
$e,
114-
$e->getMessage()
115-
);
116-
$this->_redirect('*/*/review');
117117
} catch (\Exception $e) {
118118
$this->messageManager->addExceptionMessage(
119119
$e,
@@ -141,6 +141,9 @@ protected function _processPaypalApiError($exception)
141141
case ApiProcessableException::API_DO_EXPRESS_CHECKOUT_FAIL:
142142
$this->_redirectSameToken();
143143
break;
144+
case ApiProcessableException::API_ADDRESS_MATCH_FAIL:
145+
$this->redirectToOrderReviewPageAndShowError($exception->getUserMessage());
146+
break;
144147
case ApiProcessableException::API_UNABLE_TRANSACTION_COMPLETE:
145148
if ($this->_config->getPaymentAction() == \Magento\Payment\Model\Method\AbstractMethod::ACTION_ORDER) {
146149
$paypalTransactionData = $this->_getCheckoutSession()->getPaypalTransactionData();
@@ -182,6 +185,18 @@ protected function _redirectToCartAndShowError($errorMessage)
182185
$this->_redirect('checkout/cart');
183186
}
184187

188+
/**
189+
* Redirect customer to the paypal order review page and show error message
190+
*
191+
* @param string $errorMessage
192+
* @return void
193+
*/
194+
private function redirectToOrderReviewPageAndShowError($errorMessage)
195+
{
196+
$this->messageManager->addErrorMessage($errorMessage);
197+
$this->_redirect('*/*/review');
198+
}
199+
185200
/**
186201
* Return true if agreements validation required
187202
*

app/code/Magento/Paypal/Controller/Express/AbstractExpress/Start.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class Start extends GetToken
2121
public function execute()
2222
{
2323
try {
24-
2524
$token = $this->getToken();
2625
if ($token === null) {
2726

app/code/Magento/Paypal/Controller/Express/GetToken.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ public function execute()
5353
if ($token === null) {
5454
$token = false;
5555
}
56+
$url = $this->_checkout->getRedirectUrl();
5657
$this->_initToken($token);
57-
$controllerResult->setData(['token' => $token]);
58+
$controllerResult->setData(['url' => $url]);
5859
} catch (LocalizedException $exception) {
5960
$this->messageManager->addExceptionMessage(
6061
$exception,

app/code/Magento/Paypal/Model/Api/Nvp.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,9 +1288,10 @@ protected function _handleCallErrors($response)
12881288
$exceptionPhrase = __('PayPal gateway has rejected request. %1', $errorMessages);
12891289

12901290
/** @var \Magento\Framework\Exception\LocalizedException $exception */
1291-
$exception = count($errors) == 1 && $this->_isProcessableError($errors[0]['code'])
1291+
$firstError = $errors[0]['code'];
1292+
$exception = $this->_isProcessableError($firstError)
12921293
? $this->_processableExceptionFactory->create(
1293-
['phrase' => $exceptionPhrase, 'code' => $errors[0]['code']]
1294+
['phrase' => $exceptionPhrase, 'code' => $firstError]
12941295
)
12951296
: $this->_frameworkExceptionFactory->create(
12961297
['phrase' => $exceptionPhrase]

app/code/Magento/Paypal/Model/Api/ProcessableException.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ProcessableException extends LocalizedException
2525
const API_COUNTRY_FILTER_DECLINE = 10537;
2626
const API_MAXIMUM_AMOUNT_FILTER_DECLINE = 10538;
2727
const API_OTHER_FILTER_DECLINE = 10539;
28+
const API_ADDRESS_MATCH_FAIL = 10736;
2829
/**#@-*/
2930

3031
/**
@@ -61,8 +62,13 @@ public function getUserMessage()
6162
'I\'m sorry - but we are not able to complete your transaction. Please contact us so we can assist you.'
6263
);
6364
break;
65+
case self::API_ADDRESS_MATCH_FAIL:
66+
$message = __(
67+
'A match of the Shipping Address City, State, and Postal Code failed.'
68+
);
69+
break;
6470
default:
65-
$message = __($this->getMessage());
71+
$message = __('We can\'t place the order.');
6672
break;
6773
}
6874
return $message;

app/code/Magento/Paypal/Model/Express.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ protected function _setApiProcessableErrors()
266266
ApiProcessableException::API_COUNTRY_FILTER_DECLINE,
267267
ApiProcessableException::API_MAXIMUM_AMOUNT_FILTER_DECLINE,
268268
ApiProcessableException::API_OTHER_FILTER_DECLINE,
269+
ApiProcessableException::API_ADDRESS_MATCH_FAIL,
269270
]
270271
);
271272
}

app/code/Magento/Paypal/Test/Unit/Model/Api/ProcessableExceptionTest.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@
55
*/
66
namespace Magento\Paypal\Test\Unit\Model\Api;
77

8-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
8+
use Magento\Paypal\Model\Api\ProcessableException;
99

1010
class ProcessableExceptionTest extends \PHPUnit_Framework_TestCase
1111
{
12-
/**
13-
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
14-
*/
15-
protected $objectManager;
12+
const UNKNOWN_CODE = 10411;
1613

1714
/**
18-
* @var \Magento\Paypal\Model\Api\ProcessableException
15+
* @var ProcessableException
1916
*/
20-
protected $model;
17+
private $model;
2118

2219
/**
2320
* @param int $code
@@ -27,8 +24,7 @@ class ProcessableExceptionTest extends \PHPUnit_Framework_TestCase
2724
*/
2825
public function testGetUserMessage($code, $msg)
2926
{
30-
$this->objectManager = new ObjectManager($this);
31-
$this->model = new \Magento\Paypal\Model\Api\ProcessableException(__($msg), null, $code);
27+
$this->model = new ProcessableException(__($msg), null, $code);
3228
$this->assertEquals($msg, $this->model->getUserMessage());
3329
}
3430

@@ -39,28 +35,35 @@ public function getUserMessageDataProvider()
3935
{
4036
return [
4137
[
42-
10001,
38+
ProcessableException::API_INTERNAL_ERROR,
4339
"I'm sorry - but we were not able to process your payment. "
4440
. "Please try another payment method or contact us so we can assist you.",
4541
],
4642
[
47-
10417,
43+
ProcessableException::API_UNABLE_PROCESS_PAYMENT_ERROR_CODE,
4844
"I'm sorry - but we were not able to process your payment. "
4945
. "Please try another payment method or contact us so we can assist you."
5046
],
5147
[
52-
10537,
48+
ProcessableException::API_COUNTRY_FILTER_DECLINE,
5349
"I'm sorry - but we are not able to complete your transaction. Please contact us so we can assist you."
5450
],
5551
[
56-
10538,
52+
ProcessableException::API_MAXIMUM_AMOUNT_FILTER_DECLINE,
5753
"I'm sorry - but we are not able to complete your transaction. Please contact us so we can assist you."
5854
],
5955
[
60-
10539,
56+
ProcessableException::API_OTHER_FILTER_DECLINE,
6157
"I'm sorry - but we are not able to complete your transaction. Please contact us so we can assist you."
6258
],
63-
[10411, "something went wrong"]
59+
[
60+
ProcessableException::API_ADDRESS_MATCH_FAIL,
61+
'A match of the Shipping Address City, State, and Postal Code failed.'
62+
],
63+
[
64+
self::UNKNOWN_CODE,
65+
"We can't place the order."
66+
]
6467
];
6568
}
6669
}

app/code/Magento/Paypal/Test/Unit/Model/ExpressTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ExpressTest extends \PHPUnit_Framework_TestCase
2222
ApiProcessableException::API_COUNTRY_FILTER_DECLINE,
2323
ApiProcessableException::API_MAXIMUM_AMOUNT_FILTER_DECLINE,
2424
ApiProcessableException::API_OTHER_FILTER_DECLINE,
25+
ApiProcessableException::API_ADDRESS_MATCH_FAIL
2526
];
2627

2728
/**

0 commit comments

Comments
 (0)