Skip to content

Commit 7574915

Browse files
committed
Merge branch 'MAGETWO-39705' of github.corp.ebay.com:magento-troll/magento2ce into bugfixes
2 parents 65b5863 + b81e6ea commit 7574915

File tree

23 files changed

+1143
-306
lines changed

23 files changed

+1143
-306
lines changed

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

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Authorizenet\Model;
77

8+
use Magento\Payment\Model\Method\Logger;
9+
810
/**
911
* @SuppressWarnings(PHPMD.TooManyFields)
1012
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
@@ -54,6 +56,8 @@ abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc
5456

5557
const RESPONSE_REASON_CODE_PENDING_REVIEW_DECLINED = 254;
5658

59+
const PAYMENT_UPDATE_STATUS_CODE_SUCCESS = 'Ok';
60+
5761
/**
5862
* Transaction fraud state key
5963
*/
@@ -95,6 +99,11 @@ abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc
9599
*/
96100
protected $transactionDetails = [];
97101

102+
/**
103+
* {@inheritdoc}
104+
*/
105+
protected $_debugReplacePrivateDataKeys = ['merchantAuthentication', 'x_login'];
106+
98107
/**
99108
* @param \Magento\Framework\Model\Context $context
100109
* @param \Magento\Framework\Registry $registry
@@ -364,11 +373,11 @@ protected function buildRequest(\Magento\Framework\DataObject $payment)
364373
*/
365374
protected function postRequest(\Magento\Authorizenet\Model\Request $request)
366375
{
367-
$debugData = ['request' => $request->getData()];
368376
$result = $this->responseFactory->create();
369377
$client = new \Magento\Framework\HTTP\ZendClient();
370-
$uri = $this->getConfigData('cgi_url');
371-
$client->setUri($uri ? $uri : self::CGI_URL);
378+
$url = $this->getConfigData('cgi_url') ?: self::CGI_URL;
379+
$debugData = ['url' => $url, 'request' => $request->getData()];
380+
$client->setUri($url);
372381
$client->setConfig(['maxredirects' => 0, 'timeout' => 30]);
373382

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

382391
try {
383392
$response = $client->request();
393+
$responseBody = $response->getBody();
394+
$debugData['response'] = $responseBody;
384395
} catch (\Exception $e) {
385396
$result->setXResponseCode(-1)
386397
->setXResponseReasonCode($e->getCode())
387398
->setXResponseReasonText($e->getMessage());
388399

389-
$debugData['result'] = $result->getData();
390-
$this->_debug($debugData);
391400
throw new \Magento\Framework\Exception\LocalizedException(
392401
$this->dataHelper->wrapGatewayError($e->getMessage())
393402
);
403+
} finally {
404+
$this->_debug($debugData);
394405
}
395406

396-
$responseBody = $response->getBody();
397407
$r = explode(self::RESPONSE_DELIM_CHAR, $responseBody);
398-
399408
if ($r) {
400409
$result->setXResponseCode((int)str_replace('"', '', $r[0]))
401410
->setXResponseReasonCode((int)str_replace('"', '', $r[2]))
@@ -413,10 +422,6 @@ protected function postRequest(\Magento\Authorizenet\Model\Request $request)
413422
__('Something went wrong in the payment gateway.')
414423
);
415424
}
416-
417-
$debugData['result'] = $result->getData();
418-
$this->_debug($debugData);
419-
420425
return $result;
421426
}
422427

@@ -473,24 +478,35 @@ protected function loadTransactionDetails($transactionId)
473478
);
474479

475480
$client = new \Magento\Framework\HTTP\ZendClient();
476-
$uri = $this->getConfigData('cgi_url_td');
477-
$client->setUri($uri ? $uri : self::CGI_URL_TD);
481+
$url = $this->getConfigData('cgi_url_td') ?: self::CGI_URL_TD;
482+
$client->setUri($url);
478483
$client->setConfig(['timeout' => 45]);
479484
$client->setHeaders(['Content-Type: text/xml']);
480485
$client->setMethod(\Zend_Http_Client::POST);
481486
$client->setRawData($requestBody);
482487

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

485490
try {
486491
$responseBody = $client->request()->getBody();
487-
$debugData['result'] = $responseBody;
488-
$this->_debug($debugData);
492+
$debugData['response'] = $responseBody;
489493
libxml_use_internal_errors(true);
490494
$responseXmlDocument = new \Magento\Framework\Simplexml\Element($responseBody);
491495
libxml_use_internal_errors(false);
492496
} catch (\Exception $e) {
493-
throw new \Magento\Framework\Exception\LocalizedException(__('Payment updating error.'));
497+
throw new \Magento\Framework\Exception\LocalizedException(
498+
__('Unable to get transaction details. Try again later.')
499+
);
500+
} finally {
501+
$this->_debug($debugData);
502+
}
503+
504+
if (!isset($responseXmlDocument->messages->resultCode)
505+
|| $responseXmlDocument->messages->resultCode != static::PAYMENT_UPDATE_STATUS_CODE_SUCCESS
506+
) {
507+
throw new \Magento\Framework\Exception\LocalizedException(
508+
__('Unable to get transaction details. Try again later.')
509+
);
494510
}
495511

496512
$this->transactionDetails[$transactionId] = $responseXmlDocument;
@@ -509,4 +525,20 @@ protected function getTransactionDetails($transactionId)
509525
? $this->transactionDetails[$transactionId]
510526
: $this->loadTransactionDetails($transactionId);
511527
}
528+
529+
/**
530+
* Remove nodes with private data from XML string
531+
*
532+
* Uses values from $_debugReplacePrivateDataKeys property
533+
*
534+
* @param string $xml
535+
* @return string
536+
*/
537+
protected function removePrivateDataFromXml($xml)
538+
{
539+
foreach ($this->getDebugReplacePrivateDataKeys() as $key) {
540+
$xml = preg_replace(sprintf('~(?<=<%s>).*?(?=</%s>)~', $key, $key), Logger::DEBUG_KEYS_MASK, $xml);
541+
}
542+
return $xml;
543+
}
512544
}

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

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -726,17 +726,21 @@ protected function processOrder(\Magento\Sales\Model\Order $order)
726726
*/
727727
protected function processPaymentFraudStatus(\Magento\Sales\Model\Order\Payment $payment)
728728
{
729-
$fraudDetailsResponse = $payment->getMethodInstance()
730-
->fetchTransactionFraudDetails($this->getResponse()->getXTransId());
731-
$fraudData = $fraudDetailsResponse->getData();
729+
try {
730+
$fraudDetailsResponse = $payment->getMethodInstance()
731+
->fetchTransactionFraudDetails($this->getResponse()->getXTransId());
732+
$fraudData = $fraudDetailsResponse->getData();
732733

733-
if (empty($fraudData)) {
734-
$payment->setIsFraudDetected(false);
735-
return $this;
736-
}
734+
if (empty($fraudData)) {
735+
$payment->setIsFraudDetected(false);
736+
return $this;
737+
}
737738

738-
$payment->setIsFraudDetected(true);
739-
$payment->setAdditionalInformation('fraud_details', $fraudData);
739+
$payment->setIsFraudDetected(true);
740+
$payment->setAdditionalInformation('fraud_details', $fraudData);
741+
} catch (\Exception $e) {
742+
//this request is optional
743+
}
740744

741745
return $this;
742746
}
@@ -749,23 +753,27 @@ protected function processPaymentFraudStatus(\Magento\Sales\Model\Order\Payment
749753
*/
750754
protected function addStatusComment(\Magento\Sales\Model\Order\Payment $payment)
751755
{
752-
$transactionId = $this->getResponse()->getXTransId();
753-
$data = $payment->getMethodInstance()->getTransactionDetails($transactionId);
754-
$transactionStatus = (string)$data->transaction->transactionStatus;
755-
$fdsFilterAction = (string)$data->transaction->FDSFilterAction;
756-
757-
if ($payment->getIsTransactionPending()) {
758-
$message = 'Amount of %1 is pending approval on the gateway.<br/>'
759-
. 'Transaction "%2" status is "%3".<br/>'
760-
. 'Transaction FDS Filter Action is "%4"';
761-
$message = __(
762-
$message,
763-
$payment->getOrder()->getBaseCurrency()->formatTxt($this->getResponse()->getXAmount()),
764-
$transactionId,
765-
$this->dataHelper->getTransactionStatusLabel($transactionStatus),
766-
$this->dataHelper->getFdsFilterActionLabel($fdsFilterAction)
767-
);
768-
$payment->getOrder()->addStatusHistoryComment($message);
756+
try {
757+
$transactionId = $this->getResponse()->getXTransId();
758+
$data = $payment->getMethodInstance()->getTransactionDetails($transactionId);
759+
$transactionStatus = (string)$data->transaction->transactionStatus;
760+
$fdsFilterAction = (string)$data->transaction->FDSFilterAction;
761+
762+
if ($payment->getIsTransactionPending()) {
763+
$message = 'Amount of %1 is pending approval on the gateway.<br/>'
764+
. 'Transaction "%2" status is "%3".<br/>'
765+
. 'Transaction FDS Filter Action is "%4"';
766+
$message = __(
767+
$message,
768+
$payment->getOrder()->getBaseCurrency()->formatTxt($this->getResponse()->getXAmount()),
769+
$transactionId,
770+
$this->dataHelper->getTransactionStatusLabel($transactionStatus),
771+
$this->dataHelper->getFdsFilterActionLabel($fdsFilterAction)
772+
);
773+
$payment->getOrder()->addStatusHistoryComment($message);
774+
}
775+
} catch (\Exception $e) {
776+
//this request is optional
769777
}
770778
return $this;
771779
}

app/code/Magento/CatalogRule/Model/Rule.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,58 @@ protected function _getWebsitesMap()
347347
return $map;
348348
}
349349

350+
/**
351+
* {@inheritdoc}
352+
*/
353+
public function validateData(\Magento\Framework\DataObject $dataObject)
354+
{
355+
$result = parent::validateData($dataObject);
356+
if ($result === true) {
357+
$result = [];
358+
}
359+
360+
$action = $dataObject->getData('simple_action');
361+
$discount = $dataObject->getData('discount_amount');
362+
$result = array_merge($result, $this->validateDiscount($action, $discount));
363+
if ($dataObject->getData('sub_is_enable') == 1) {
364+
$action = $dataObject->getData('sub_simple_action');
365+
$discount = $dataObject->getData('sub_discount_amount');
366+
$result = array_merge($result, $this->validateDiscount($action, $discount));
367+
}
368+
369+
return !empty($result) ? $result : true;
370+
}
371+
372+
/**
373+
* Validate discount based on action
374+
*
375+
* @param string $action
376+
* @param string|int|float $discount
377+
*
378+
* @return array Validation errors
379+
*/
380+
protected function validateDiscount($action, $discount)
381+
{
382+
$result = [];
383+
switch ($action) {
384+
case 'by_percent':
385+
case 'to_percent':
386+
if ($discount < 0 || $discount > 100) {
387+
$result[] = __('Percentage discount should be between 0 and 100.');
388+
};
389+
break;
390+
case 'by_fixed':
391+
case 'to_fixed':
392+
if ($discount < 0) {
393+
$result[] = __('Discount value should be 0 or greater.');
394+
};
395+
break;
396+
default:
397+
$result[] = __('Unknown action.');
398+
}
399+
return $result;
400+
}
401+
350402
/**
351403
* Calculate price using catalog price rule of product
352404
*

0 commit comments

Comments
 (0)