Skip to content

Commit

Permalink
Merge pull request magento#607 from magento-tango/S60PR
Browse files Browse the repository at this point in the history
[Tango] S60 - Support Tool, Bug Fixes
  • Loading branch information
Korshenko, Olexii(okorshenko) committed Sep 21, 2015
2 parents 444e252 + e468b8e commit 2cb2fa5
Show file tree
Hide file tree
Showing 12 changed files with 908 additions and 292 deletions.
66 changes: 49 additions & 17 deletions app/code/Magento/Authorizenet/Model/Authorizenet.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Authorizenet\Model;

use Magento\Payment\Model\Method\Logger;

/**
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
Expand Down Expand Up @@ -54,6 +56,8 @@ abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc

const RESPONSE_REASON_CODE_PENDING_REVIEW_DECLINED = 254;

const PAYMENT_UPDATE_STATUS_CODE_SUCCESS = 'Ok';

/**
* Transaction fraud state key
*/
Expand Down Expand Up @@ -95,6 +99,11 @@ abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc
*/
protected $transactionDetails = [];

/**
* {@inheritdoc}
*/
protected $_debugReplacePrivateDataKeys = ['merchantAuthentication', 'x_login'];

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand Down Expand Up @@ -364,11 +373,11 @@ protected function buildRequest(\Magento\Framework\DataObject $payment)
*/
protected function postRequest(\Magento\Authorizenet\Model\Request $request)
{
$debugData = ['request' => $request->getData()];
$result = $this->responseFactory->create();
$client = new \Magento\Framework\HTTP\ZendClient();
$uri = $this->getConfigData('cgi_url');
$client->setUri($uri ? $uri : self::CGI_URL);
$url = $this->getConfigData('cgi_url') ?: self::CGI_URL;
$debugData = ['url' => $url, 'request' => $request->getData()];
$client->setUri($url);
$client->setConfig(['maxredirects' => 0, 'timeout' => 30]);

foreach ($request->getData() as $key => $value) {
Expand All @@ -381,21 +390,21 @@ protected function postRequest(\Magento\Authorizenet\Model\Request $request)

try {
$response = $client->request();
$responseBody = $response->getBody();
$debugData['response'] = $responseBody;
} catch (\Exception $e) {
$result->setXResponseCode(-1)
->setXResponseReasonCode($e->getCode())
->setXResponseReasonText($e->getMessage());

$debugData['result'] = $result->getData();
$this->_debug($debugData);
throw new \Magento\Framework\Exception\LocalizedException(
$this->dataHelper->wrapGatewayError($e->getMessage())
);
} finally {
$this->_debug($debugData);
}

$responseBody = $response->getBody();
$r = explode(self::RESPONSE_DELIM_CHAR, $responseBody);

if ($r) {
$result->setXResponseCode((int)str_replace('"', '', $r[0]))
->setXResponseReasonCode((int)str_replace('"', '', $r[2]))
Expand All @@ -413,10 +422,6 @@ protected function postRequest(\Magento\Authorizenet\Model\Request $request)
__('Something went wrong in the payment gateway.')
);
}

$debugData['result'] = $result->getData();
$this->_debug($debugData);

return $result;
}

Expand Down Expand Up @@ -473,24 +478,35 @@ protected function loadTransactionDetails($transactionId)
);

$client = new \Magento\Framework\HTTP\ZendClient();
$uri = $this->getConfigData('cgi_url_td');
$client->setUri($uri ? $uri : self::CGI_URL_TD);
$url = $this->getConfigData('cgi_url_td') ?: self::CGI_URL_TD;
$client->setUri($url);
$client->setConfig(['timeout' => 45]);
$client->setHeaders(['Content-Type: text/xml']);
$client->setMethod(\Zend_Http_Client::POST);
$client->setRawData($requestBody);

$debugData = ['request' => $requestBody];
$debugData = ['url' => $url, 'request' => $this->removePrivateDataFromXml($requestBody)];

try {
$responseBody = $client->request()->getBody();
$debugData['result'] = $responseBody;
$this->_debug($debugData);
$debugData['response'] = $responseBody;
libxml_use_internal_errors(true);
$responseXmlDocument = new \Magento\Framework\Simplexml\Element($responseBody);
libxml_use_internal_errors(false);
} catch (\Exception $e) {
throw new \Magento\Framework\Exception\LocalizedException(__('Payment updating error.'));
throw new \Magento\Framework\Exception\LocalizedException(
__('Unable to get transaction details. Try again later.')
);
} finally {
$this->_debug($debugData);
}

if (!isset($responseXmlDocument->messages->resultCode)
|| $responseXmlDocument->messages->resultCode != static::PAYMENT_UPDATE_STATUS_CODE_SUCCESS
) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Unable to get transaction details. Try again later.')
);
}

$this->transactionDetails[$transactionId] = $responseXmlDocument;
Expand All @@ -509,4 +525,20 @@ protected function getTransactionDetails($transactionId)
? $this->transactionDetails[$transactionId]
: $this->loadTransactionDetails($transactionId);
}

/**
* Remove nodes with private data from XML string
*
* Uses values from $_debugReplacePrivateDataKeys property
*
* @param string $xml
* @return string
*/
protected function removePrivateDataFromXml($xml)
{
foreach ($this->getDebugReplacePrivateDataKeys() as $key) {
$xml = preg_replace(sprintf('~(?<=<%s>).*?(?=</%s>)~', $key, $key), Logger::DEBUG_KEYS_MASK, $xml);
}
return $xml;
}
}
60 changes: 34 additions & 26 deletions app/code/Magento/Authorizenet/Model/Directpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,17 +726,21 @@ protected function processOrder(\Magento\Sales\Model\Order $order)
*/
protected function processPaymentFraudStatus(\Magento\Sales\Model\Order\Payment $payment)
{
$fraudDetailsResponse = $payment->getMethodInstance()
->fetchTransactionFraudDetails($this->getResponse()->getXTransId());
$fraudData = $fraudDetailsResponse->getData();
try {
$fraudDetailsResponse = $payment->getMethodInstance()
->fetchTransactionFraudDetails($this->getResponse()->getXTransId());
$fraudData = $fraudDetailsResponse->getData();

if (empty($fraudData)) {
$payment->setIsFraudDetected(false);
return $this;
}
if (empty($fraudData)) {
$payment->setIsFraudDetected(false);
return $this;
}

$payment->setIsFraudDetected(true);
$payment->setAdditionalInformation('fraud_details', $fraudData);
$payment->setIsFraudDetected(true);
$payment->setAdditionalInformation('fraud_details', $fraudData);
} catch (\Exception $e) {
//this request is optional
}

return $this;
}
Expand All @@ -749,23 +753,27 @@ protected function processPaymentFraudStatus(\Magento\Sales\Model\Order\Payment
*/
protected function addStatusComment(\Magento\Sales\Model\Order\Payment $payment)
{
$transactionId = $this->getResponse()->getXTransId();
$data = $payment->getMethodInstance()->getTransactionDetails($transactionId);
$transactionStatus = (string)$data->transaction->transactionStatus;
$fdsFilterAction = (string)$data->transaction->FDSFilterAction;

if ($payment->getIsTransactionPending()) {
$message = 'Amount of %1 is pending approval on the gateway.<br/>'
. 'Transaction "%2" status is "%3".<br/>'
. 'Transaction FDS Filter Action is "%4"';
$message = __(
$message,
$payment->getOrder()->getBaseCurrency()->formatTxt($this->getResponse()->getXAmount()),
$transactionId,
$this->dataHelper->getTransactionStatusLabel($transactionStatus),
$this->dataHelper->getFdsFilterActionLabel($fdsFilterAction)
);
$payment->getOrder()->addStatusHistoryComment($message);
try {
$transactionId = $this->getResponse()->getXTransId();
$data = $payment->getMethodInstance()->getTransactionDetails($transactionId);
$transactionStatus = (string)$data->transaction->transactionStatus;
$fdsFilterAction = (string)$data->transaction->FDSFilterAction;

if ($payment->getIsTransactionPending()) {
$message = 'Amount of %1 is pending approval on the gateway.<br/>'
. 'Transaction "%2" status is "%3".<br/>'
. 'Transaction FDS Filter Action is "%4"';
$message = __(
$message,
$payment->getOrder()->getBaseCurrency()->formatTxt($this->getResponse()->getXAmount()),
$transactionId,
$this->dataHelper->getTransactionStatusLabel($transactionStatus),
$this->dataHelper->getFdsFilterActionLabel($fdsFilterAction)
);
$payment->getOrder()->addStatusHistoryComment($message);
}
} catch (\Exception $e) {
//this request is optional
}
return $this;
}
Expand Down
31 changes: 28 additions & 3 deletions app/code/Magento/Config/Model/Config/Backend/Admin/Custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,37 @@ class Custom extends \Magento\Framework\App\Config\Value
const CONFIG_SCOPE_ID = 0;

const XML_PATH_UNSECURE_BASE_URL = 'web/unsecure/base_url';

const XML_PATH_SECURE_BASE_URL = 'web/secure/base_url';

const XML_PATH_UNSECURE_BASE_LINK_URL = 'web/unsecure/base_link_url';

const XML_PATH_SECURE_BASE_LINK_URL = 'web/secure/base_link_url';
const XML_PATH_CURRENCY_OPTIONS_BASE = 'currency/options/base';
const XML_PATH_ADMIN_SECURITY_USEFORMKEY = 'admin/security/use_form_key';
const XML_PATH_MAINTENANCE_MODE = 'maintenance_mode';
const XML_PATH_WEB_COOKIE_COOKIE_LIFETIME = 'web/cookie/cookie_lifetime';
const XML_PATH_WEB_COOKIE_COOKE_PATH = 'web/cookie/cookie_path';
const XML_PATH_WEB_COOKIE_COOKIE_DOMAIN = 'web/cookie/cookie_domain';
const XML_PATH_WEB_COOKIE_HTTPONLY = 'web/cookie/cookie_httponly';
const XML_PATH_WEB_COOKIE_RESTRICTION = 'web/cookie/cookie_restriction';
const XML_PATH_GENERAL_LOCALE_TIMEZONE = 'general/locale/timezone';
const XML_PATH_GENERAL_LOCALE_CODE = 'general/locale/code';
const XML_PATH_GENERAL_COUNTRY_DEFAULT = 'general/country/default';
const XML_PATH_SYSTEM_BACKUP_ENABLED = 'system/backup/enabled';
const XML_PATH_DEV_JS_MERGE_FILES = 'dev/js/merge_files';
const XML_PATH_DEV_JS_MINIFY_FILES = 'dev/js/minify_files';
const XML_PATH_DEV_CSS_MERGE_CSS_FILES = 'dev/css/merge_css_files';
const XML_PATH_DEV_CSS_MINIFY_FILES = 'dev/css/minify_files';
const XML_PATH_DEV_IMAGE_DEFAULT_ADAPTER = 'dev/image/default_adapter';
const XML_PATH_WEB_SESSION_USE_FRONTEND_SID = 'web/session/use_frontend_sid';
const XML_PATH_WEB_SESSION_USE_HTTP_X_FORWARDED_FOR = 'web/session/use_http_x_forwarded_for';
const XML_PATH_WEB_SESSION_USE_HTTP_VIA = 'web/session/use_http_via';
const XML_PATH_WEB_SESSION_USE_REMOTE_ADDR = 'web/session/use_remote_addr';
const XML_PATH_WEB_SESSION_USE_HTTP_USER_AGENT = 'web/session/use_http_user_agent';
const XML_PATH_CATALOG_FRONTEND_FLAT_CATALOG_CATEGORY = 'catalog/frontend/flat_catalog_category';
const XML_PATH_CATALOG_FRONTEND_FLAT_CATALOG_PRODUCT = 'catalog/frontend/flat_catalog_product';
const XML_PATH_TAX_WEEE_ENABLE = 'tax/weee/enable';
const XML_PATH_CATALOG_SEARCH_ENGINE = 'catalog/search/engine';
const XML_PATH_CARRIERS = 'carriers';
const XML_PATH_PAYMENT = 'payment';

/* @var \Magento\Framework\App\Config\Storage\WriterInterface */
protected $_configWriter;
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Payment/Model/Method/AbstractMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl

const CHECK_ZERO_TOTAL = 'zero_total';

const GROUP_OFFLINE = 'offline';

/**
* @var string
*/
Expand Down
57 changes: 57 additions & 0 deletions app/code/Magento/Store/App/Response/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
namespace Magento\Store\App\Response;

use Magento\Store\Api\StoreResolverInterface;

class Redirect implements \Magento\Framework\App\Response\RedirectInterface
{
/**
Expand Down Expand Up @@ -94,6 +96,8 @@ protected function _getUrl()

if (!$this->_isUrlInternal($refererUrl)) {
$refererUrl = $this->_storeManager->getStore()->getBaseUrl();
} else {
$refererUrl = $this->normalizeRefererUrl($refererUrl);
}
return $refererUrl;
}
Expand Down Expand Up @@ -210,4 +214,57 @@ protected function _isUrlInternal($url)
}
return false;
}

/**
* Normalize path to avoid wrong store change
*
* @param string $refererUrl
* @return string
*/
protected function normalizeRefererUrl($refererUrl)
{
if (!$refererUrl || !filter_var($refererUrl, FILTER_VALIDATE_URL)) {
return $refererUrl;
}

$redirectParsedUrl = parse_url($refererUrl);
$refererQuery = [];

if (!isset($redirectParsedUrl['query'])) {
return $refererUrl;
}

parse_str($redirectParsedUrl['query'], $refererQuery);

$refererQuery = $this->normalizeRefererQueryParts($refererQuery);
$normalizedUrl = $redirectParsedUrl['scheme']
. '://'
. $redirectParsedUrl['host']
. (isset($redirectParsedUrl['port']) ? ':' . $redirectParsedUrl['port'] : '')
. $redirectParsedUrl['path']
. ($refererQuery ? '?' . http_build_query($refererQuery) : '');

return $normalizedUrl;
}

/**
* Normalize special parts of referer query
*
* @param array $refererQuery
* @return array
*/
protected function normalizeRefererQueryParts($refererQuery)
{
$store = $this->_storeManager->getStore();

if (
$store
&& !empty($refererQuery[StoreResolverInterface::PARAM_NAME])
&& ($refererQuery[StoreResolverInterface::PARAM_NAME] !== $store->getCode())
) {
$refererQuery[StoreResolverInterface::PARAM_NAME] = $store->getCode();
}

return $refererQuery;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_layout.xsd">
<container name="root" htmlTag="section" htmlClass="page-wrapper">
<container name="after.body.start" as="after.body.start" label="Page Top" before="-"/>
<container name="login.header" htmlTag="header" htmlClass="login-header"/>
<container name="login.content" htmlTag="div" htmlClass="login-content"/>
<container name="login.footer" htmlTag="footer" htmlClass="login-footer"/>
Expand Down
Loading

0 comments on commit 2cb2fa5

Please sign in to comment.