Skip to content

Commit

Permalink
Merge pull request #516 from magento-mpi/MPI-BUGFIXES
Browse files Browse the repository at this point in the history
[MPI] Bugfixes
  • Loading branch information
Akimov, Alexander(aakimov) committed Apr 6, 2016
2 parents 7200766 + 4d18d80 commit f732a63
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 74 deletions.
24 changes: 22 additions & 2 deletions app/code/Magento/Authorizenet/Model/Directpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ class Directpost extends \Magento\Authorizenet\Model\Authorizenet implements Tra
*/
protected $transactionRepository;

/**
* @var \Psr\Log\LoggerInterface
*/
private $psrLogger;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand Down Expand Up @@ -761,7 +766,7 @@ protected function addStatusComment(\Magento\Sales\Model\Order\Payment $payment)
{
try {
$transactionId = $this->getResponse()->getXTransId();
$data = $payment->getMethodInstance()->getTransactionDetails($transactionId);
$data = $this->transactionService->getTransactionDetails($this, $transactionId);
$transactionStatus = (string)$data->transaction->transactionStatus;
$fdsFilterAction = (string)$data->transaction->FDSFilterAction;

Expand All @@ -779,6 +784,7 @@ protected function addStatusComment(\Magento\Sales\Model\Order\Payment $payment)
$payment->getOrder()->addStatusHistoryComment($message);
}
} catch (\Exception $e) {
$this->getPsrLogger()->critical($e);
//this request is optional
}
return $this;
Expand All @@ -805,7 +811,7 @@ protected function declineOrder(\Magento\Sales\Model\Order $order, $message = ''
$order->registerCancellation($message)->save();
} catch (\Exception $e) {
//quiet decline
$this->logger->critical($e);
$this->getPsrLogger()->critical($e);
}
}

Expand Down Expand Up @@ -973,4 +979,18 @@ protected function getTransactionResponse($transactionId)

return $response;
}

/**
* @return \Psr\Log\LoggerInterface
*
* @deprecated
*/
private function getPsrLogger()
{
if (null === $this->psrLogger) {
$this->psrLogger = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Psr\Log\LoggerInterface::class);
}
return $this->psrLogger;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,31 @@ define(
[
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/url-builder',
'mage/storage',
'Magento_Checkout/js/model/error-processor',
'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/full-screen-loader'
'Magento_Checkout/js/model/place-order'
],
function (quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader) {
function (quote, urlBuilder, customer, placeOrderService) {
'use strict';

return function (paymentData, messageContainer) {
var serviceUrl,
payload;
var serviceUrl, payload;

/** Checkout for guest and registered customer. */
if (!customer.isLoggedIn()) {
payload = {
cartId: quote.getQuoteId(),
billingAddress: quote.billingAddress(),
paymentMethod: paymentData
};

if (customer.isLoggedIn()) {
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
} else {
serviceUrl = urlBuilder.createUrl('/guest-carts/:quoteId/payment-information', {
quoteId: quote.getQuoteId()
});
payload = {
cartId: quote.getQuoteId(),
email: quote.guestEmail,
paymentMethod: paymentData,
billingAddress: quote.billingAddress()
};
} else {
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
payload = {
cartId: quote.getQuoteId(),
paymentMethod: paymentData,
billingAddress: quote.billingAddress()
};
payload.email = quote.guestEmail;
}

fullScreenLoader.startLoader();

return storage.post(
serviceUrl, JSON.stringify(payload)
).fail(
function (response) {
errorProcessor.process(response, messageContainer);
fullScreenLoader.stopLoader();
}
);
return placeOrderService(serviceUrl, payload, messageContainer);
};
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
define(
[
'mage/storage',
'Magento_Checkout/js/model/error-processor',
'Magento_Checkout/js/model/full-screen-loader'
],
function (storage, errorProcessor, fullScreenLoader) {
'use strict';

return function (serviceUrl, payload, messageContainer) {
fullScreenLoader.startLoader();

return storage.post(
serviceUrl, JSON.stringify(payload)
).fail(
function (response) {
errorProcessor.process(response, messageContainer);
fullScreenLoader.stopLoader();
}
);
};
}
);
3 changes: 1 addition & 2 deletions app/code/Magento/Dhl/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -1123,9 +1123,8 @@ protected function _parseResponse($response)
throw new \Magento\Framework\Exception\LocalizedException($responseError);
}
$this->debugErrors($this->_errors);

return false;
}
$result->append($this->getErrorMessage());
}

return $result;
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Fedex/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,10 @@ protected function _getQuotes()
// make general request for all methods
$response = $this->_doRatesRequest(self::RATE_REQUEST_GENERAL);
$preparedGeneral = $this->_prepareRateResponse($response);
if (!$preparedGeneral->getError() || $this->_result->getError() && $preparedGeneral->getError()) {
if (!$preparedGeneral->getError()
|| $this->_result->getError() && $preparedGeneral->getError()
|| empty($this->_result->getAllRates())
) {
$this->_result->append($preparedGeneral);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,21 @@ public function __construct(
*/
public function execute()
{
try {
if ($this->isValidationRequired() &&
!$this->agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', [])))
) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Please agree to all the terms and conditions before placing the order.')
);
}
if ($this->isValidationRequired() &&
!$this->agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', [])))
) {
$e = new \Magento\Framework\Exception\LocalizedException(
__('Please agree to all the terms and conditions before placing the order.')
);
$this->messageManager->addExceptionMessage(
$e,
$e->getMessage()
);
$this->_redirect('*/*/review');
return;
}

try {
$this->_initCheckout();
$this->_checkout->place($this->_initToken());

Expand Down Expand Up @@ -108,12 +114,6 @@ public function execute()
return;
} catch (ApiProcessableException $e) {
$this->_processPaypalApiError($e);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addExceptionMessage(
$e,
$e->getMessage()
);
$this->_redirect('*/*/review');
} catch (\Exception $e) {
$this->messageManager->addExceptionMessage(
$e,
Expand Down Expand Up @@ -141,6 +141,9 @@ protected function _processPaypalApiError($exception)
case ApiProcessableException::API_DO_EXPRESS_CHECKOUT_FAIL:
$this->_redirectSameToken();
break;
case ApiProcessableException::API_ADDRESS_MATCH_FAIL:
$this->redirectToOrderReviewPageAndShowError($exception->getUserMessage());
break;
case ApiProcessableException::API_UNABLE_TRANSACTION_COMPLETE:
if ($this->_config->getPaymentAction() == \Magento\Payment\Model\Method\AbstractMethod::ACTION_ORDER) {
$paypalTransactionData = $this->_getCheckoutSession()->getPaypalTransactionData();
Expand Down Expand Up @@ -182,6 +185,18 @@ protected function _redirectToCartAndShowError($errorMessage)
$this->_redirect('checkout/cart');
}

/**
* Redirect customer to the paypal order review page and show error message
*
* @param string $errorMessage
* @return void
*/
private function redirectToOrderReviewPageAndShowError($errorMessage)
{
$this->messageManager->addErrorMessage($errorMessage);
$this->_redirect('*/*/review');
}

/**
* Return true if agreements validation required
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Start extends GetToken
public function execute()
{
try {

$token = $this->getToken();
if ($token === null) {

Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Paypal/Controller/Express/GetToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ public function execute()
if ($token === null) {
$token = false;
}
$url = $this->_checkout->getRedirectUrl();
$this->_initToken($token);
$controllerResult->setData(['token' => $token]);
$controllerResult->setData(['url' => $url]);
} catch (LocalizedException $exception) {
$this->messageManager->addExceptionMessage(
$exception,
Expand Down
5 changes: 3 additions & 2 deletions app/code/Magento/Paypal/Model/Api/Nvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -1288,9 +1288,10 @@ protected function _handleCallErrors($response)
$exceptionPhrase = __('PayPal gateway has rejected request. %1', $errorMessages);

/** @var \Magento\Framework\Exception\LocalizedException $exception */
$exception = count($errors) == 1 && $this->_isProcessableError($errors[0]['code'])
$firstError = $errors[0]['code'];
$exception = $this->_isProcessableError($firstError)
? $this->_processableExceptionFactory->create(
['phrase' => $exceptionPhrase, 'code' => $errors[0]['code']]
['phrase' => $exceptionPhrase, 'code' => $firstError]
)
: $this->_frameworkExceptionFactory->create(
['phrase' => $exceptionPhrase]
Expand Down
8 changes: 7 additions & 1 deletion app/code/Magento/Paypal/Model/Api/ProcessableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ProcessableException extends LocalizedException
const API_COUNTRY_FILTER_DECLINE = 10537;
const API_MAXIMUM_AMOUNT_FILTER_DECLINE = 10538;
const API_OTHER_FILTER_DECLINE = 10539;
const API_ADDRESS_MATCH_FAIL = 10736;
/**#@-*/

/**
Expand Down Expand Up @@ -61,8 +62,13 @@ public function getUserMessage()
'I\'m sorry - but we are not able to complete your transaction. Please contact us so we can assist you.'
);
break;
case self::API_ADDRESS_MATCH_FAIL:
$message = __(
'A match of the Shipping Address City, State, and Postal Code failed.'
);
break;
default:
$message = __($this->getMessage());
$message = __('We can\'t place the order.');
break;
}
return $message;
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Paypal/Model/Express.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ protected function _setApiProcessableErrors()
ApiProcessableException::API_COUNTRY_FILTER_DECLINE,
ApiProcessableException::API_MAXIMUM_AMOUNT_FILTER_DECLINE,
ApiProcessableException::API_OTHER_FILTER_DECLINE,
ApiProcessableException::API_ADDRESS_MATCH_FAIL,
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
*/
namespace Magento\Paypal\Test\Unit\Model\Api;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Paypal\Model\Api\ProcessableException;

class ProcessableExceptionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
*/
protected $objectManager;
const UNKNOWN_CODE = 10411;

/**
* @var \Magento\Paypal\Model\Api\ProcessableException
* @var ProcessableException
*/
protected $model;
private $model;

/**
* @param int $code
Expand All @@ -27,8 +24,7 @@ class ProcessableExceptionTest extends \PHPUnit_Framework_TestCase
*/
public function testGetUserMessage($code, $msg)
{
$this->objectManager = new ObjectManager($this);
$this->model = new \Magento\Paypal\Model\Api\ProcessableException(__($msg), null, $code);
$this->model = new ProcessableException(__($msg), null, $code);
$this->assertEquals($msg, $this->model->getUserMessage());
}

Expand All @@ -39,28 +35,35 @@ public function getUserMessageDataProvider()
{
return [
[
10001,
ProcessableException::API_INTERNAL_ERROR,
"I'm sorry - but we were not able to process your payment. "
. "Please try another payment method or contact us so we can assist you.",
],
[
10417,
ProcessableException::API_UNABLE_PROCESS_PAYMENT_ERROR_CODE,
"I'm sorry - but we were not able to process your payment. "
. "Please try another payment method or contact us so we can assist you."
],
[
10537,
ProcessableException::API_COUNTRY_FILTER_DECLINE,
"I'm sorry - but we are not able to complete your transaction. Please contact us so we can assist you."
],
[
10538,
ProcessableException::API_MAXIMUM_AMOUNT_FILTER_DECLINE,
"I'm sorry - but we are not able to complete your transaction. Please contact us so we can assist you."
],
[
10539,
ProcessableException::API_OTHER_FILTER_DECLINE,
"I'm sorry - but we are not able to complete your transaction. Please contact us so we can assist you."
],
[10411, "something went wrong"]
[
ProcessableException::API_ADDRESS_MATCH_FAIL,
'A match of the Shipping Address City, State, and Postal Code failed.'
],
[
self::UNKNOWN_CODE,
"We can't place the order."
]
];
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Paypal/Test/Unit/Model/ExpressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ExpressTest extends \PHPUnit_Framework_TestCase
ApiProcessableException::API_COUNTRY_FILTER_DECLINE,
ApiProcessableException::API_MAXIMUM_AMOUNT_FILTER_DECLINE,
ApiProcessableException::API_OTHER_FILTER_DECLINE,
ApiProcessableException::API_ADDRESS_MATCH_FAIL
];

/**
Expand Down
Loading

0 comments on commit f732a63

Please sign in to comment.