Skip to content

Commit e49166d

Browse files
author
Korshenko, Olexii(okorshenko)
committed
Merge pull request #712 from magento-mpi/MPI-BUGFIXES
[MPI] Bugfixes
2 parents 882be01 + d844ada commit e49166d

File tree

106 files changed

+3137
-1104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+3137
-1104
lines changed

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

Lines changed: 10 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Authorizenet\Model;
77

8-
use Magento\Payment\Model\Method\Logger;
8+
use Magento\Authorizenet\Model\TransactionService;
99

1010
/**
1111
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -19,11 +19,6 @@ abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc
1919
*/
2020
const CGI_URL = 'https://secure.authorize.net/gateway/transact.dll';
2121

22-
/**
23-
* Transaction Details gateway url
24-
*/
25-
const CGI_URL_TD = 'https://apitest.authorize.net/xml/v1/request.api';
26-
2722
const REQUEST_METHOD_CC = 'CC';
2823

2924
const REQUEST_TYPE_AUTH_CAPTURE = 'AUTH_CAPTURE';
@@ -56,8 +51,6 @@ abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc
5651

5752
const RESPONSE_REASON_CODE_PENDING_REVIEW_DECLINED = 254;
5853

59-
const PAYMENT_UPDATE_STATUS_CODE_SUCCESS = 'Ok';
60-
6154
/**
6255
* Transaction fraud state key
6356
*/
@@ -93,22 +86,17 @@ abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc
9386
protected $responseFactory;
9487

9588
/**
96-
* Stored information about transaction
97-
*
98-
* @var array
89+
* @var \Magento\Authorizenet\Model\TransactionService;
9990
*/
100-
protected $transactionDetails = [];
91+
protected $transactionService;
10192

10293
/**
103-
* {@inheritdoc}
94+
* Fields that should be replaced in debug with '***'
95+
*
96+
* @var array
10497
*/
10598
protected $_debugReplacePrivateDataKeys = ['merchantAuthentication', 'x_login'];
10699

107-
/**
108-
* @var \Magento\Framework\Xml\Security
109-
*/
110-
protected $xmlSecurityHelper;
111-
112100
/**
113101
* @param \Magento\Framework\Model\Context $context
114102
* @param \Magento\Framework\Registry $registry
@@ -122,7 +110,7 @@ abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc
122110
* @param \Magento\Authorizenet\Helper\Data $dataHelper
123111
* @param \Magento\Authorizenet\Model\Request\Factory $requestFactory
124112
* @param \Magento\Authorizenet\Model\Response\Factory $responseFactory
125-
* @param \Magento\Framework\Xml\Security $xmlSecurityHelper
113+
* @param \Magento\Authorizenet\Model\TransactionService $transactionService
126114
* @param \Magento\Framework\Model\ModelResource\AbstractResource $resource
127115
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
128116
* @param array $data
@@ -141,15 +129,15 @@ public function __construct(
141129
\Magento\Authorizenet\Helper\Data $dataHelper,
142130
\Magento\Authorizenet\Model\Request\Factory $requestFactory,
143131
\Magento\Authorizenet\Model\Response\Factory $responseFactory,
144-
\Magento\Framework\Xml\Security $xmlSecurityHelper,
132+
TransactionService $transactionService,
145133
\Magento\Framework\Model\ModelResource\AbstractResource $resource = null,
146134
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
147135
array $data = []
148136
) {
149137
$this->dataHelper = $dataHelper;
150138
$this->requestFactory = $requestFactory;
151139
$this->responseFactory = $responseFactory;
152-
$this->xmlSecurityHelper = $xmlSecurityHelper;
140+
$this->transactionService = $transactionService;
153141

154142
parent::__construct(
155143
$context,
@@ -216,7 +204,7 @@ public function cancel(\Magento\Payment\Model\InfoInterface $payment)
216204
*/
217205
public function fetchTransactionFraudDetails($transactionId)
218206
{
219-
$responseXmlDocument = $this->getTransactionDetails($transactionId);
207+
$responseXmlDocument = $this->transactionService->getTransactionDetails($this, $transactionId);
220208
$response = new \Magento\Framework\DataObject();
221209

222210
if (empty($responseXmlDocument->transaction->FDSFilters->FDSFilter)) {
@@ -443,114 +431,4 @@ protected function isGatewayActionsLocked($payment)
443431
{
444432
return $payment->getAdditionalInformation(self::GATEWAY_ACTIONS_LOCKED_STATE_KEY);
445433
}
446-
447-
/**
448-
* This function returns full transaction details for a specified transaction ID.
449-
*
450-
* @param string $transactionId
451-
* @return \Magento\Framework\DataObject
452-
* @throws \Magento\Framework\Exception\LocalizedException
453-
* @link http://www.authorize.net/support/ReportingGuide_XML.pdf
454-
* @link http://developer.authorize.net/api/transaction_details/
455-
*/
456-
protected function getTransactionResponse($transactionId)
457-
{
458-
$responseXmlDocument = $this->getTransactionDetails($transactionId);
459-
460-
$response = new \Magento\Framework\DataObject();
461-
$response->setXResponseCode((string)$responseXmlDocument->transaction->responseCode)
462-
->setXResponseReasonCode((string)$responseXmlDocument->transaction->responseReasonCode)
463-
->setTransactionStatus((string)$responseXmlDocument->transaction->transactionStatus);
464-
465-
return $response;
466-
}
467-
468-
/**
469-
* Load transaction details
470-
*
471-
* @param string $transactionId
472-
* @return \Magento\Framework\Simplexml\Element
473-
* @throws \Magento\Framework\Exception\LocalizedException
474-
*/
475-
protected function loadTransactionDetails($transactionId)
476-
{
477-
$requestBody = sprintf(
478-
'<?xml version="1.0" encoding="utf-8"?>' .
479-
'<getTransactionDetailsRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">' .
480-
'<merchantAuthentication><name>%s</name><transactionKey>%s</transactionKey></merchantAuthentication>' .
481-
'<transId>%s</transId>' .
482-
'</getTransactionDetailsRequest>',
483-
$this->getConfigData('login'),
484-
$this->getConfigData('trans_key'),
485-
$transactionId
486-
);
487-
488-
$client = new \Magento\Framework\HTTP\ZendClient();
489-
$url = $this->getConfigData('cgi_url_td') ?: self::CGI_URL_TD;
490-
$client->setUri($url);
491-
$client->setConfig(['timeout' => 45]);
492-
$client->setHeaders(['Content-Type: text/xml']);
493-
$client->setMethod(\Zend_Http_Client::POST);
494-
$client->setRawData($requestBody);
495-
496-
$debugData = ['url' => $url, 'request' => $this->removePrivateDataFromXml($requestBody)];
497-
498-
try {
499-
$responseBody = $client->request()->getBody();
500-
if (!$this->xmlSecurityHelper->scan($responseBody)) {
501-
$this->_logger->critical('Attempt loading of external XML entities in response from Authorizenet.');
502-
throw new \Exception();
503-
}
504-
$debugData['response'] = $responseBody;
505-
libxml_use_internal_errors(true);
506-
$responseXmlDocument = new \Magento\Framework\Simplexml\Element($responseBody);
507-
libxml_use_internal_errors(false);
508-
} catch (\Exception $e) {
509-
throw new \Magento\Framework\Exception\LocalizedException(
510-
__('Unable to get transaction details. Try again later.')
511-
);
512-
} finally {
513-
$this->_debug($debugData);
514-
}
515-
516-
if (!isset($responseXmlDocument->messages->resultCode)
517-
|| $responseXmlDocument->messages->resultCode != static::PAYMENT_UPDATE_STATUS_CODE_SUCCESS
518-
) {
519-
throw new \Magento\Framework\Exception\LocalizedException(
520-
__('Unable to get transaction details. Try again later.')
521-
);
522-
}
523-
524-
$this->transactionDetails[$transactionId] = $responseXmlDocument;
525-
return $responseXmlDocument;
526-
}
527-
528-
/**
529-
* Get transaction information
530-
*
531-
* @param string $transactionId
532-
* @return \Magento\Framework\Simplexml\Element
533-
*/
534-
protected function getTransactionDetails($transactionId)
535-
{
536-
return isset($this->transactionDetails[$transactionId])
537-
? $this->transactionDetails[$transactionId]
538-
: $this->loadTransactionDetails($transactionId);
539-
}
540-
541-
/**
542-
* Remove nodes with private data from XML string
543-
*
544-
* Uses values from $_debugReplacePrivateDataKeys property
545-
*
546-
* @param string $xml
547-
* @return string
548-
*/
549-
protected function removePrivateDataFromXml($xml)
550-
{
551-
foreach ($this->getDebugReplacePrivateDataKeys() as $key) {
552-
$xml = preg_replace(sprintf('~(?<=<%s>).*?(?=</%s>)~', $key, $key), Logger::DEBUG_KEYS_MASK, $xml);
553-
}
554-
return $xml;
555-
}
556434
}

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

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

8+
use Magento\Authorizenet\Model\TransactionService;
89
use Magento\Payment\Model\Method\ConfigInterface;
910
use Magento\Payment\Model\Method\TransparentInterface;
1011
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
@@ -128,13 +129,13 @@ class Directpost extends \Magento\Authorizenet\Model\Authorizenet implements Tra
128129
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
129130
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
130131
* @param \Magento\Authorizenet\Helper\Data $dataHelper
131-
* @param \Magento\Authorizenet\Model\Directpost\Request\Factory $requestFactory
132-
* @param \Magento\Authorizenet\Model\Directpost\Response\Factory $responseFactory
133-
* @param \Magento\Framework\Xml\Security $xmlSecurityHelper
132+
* @param Directpost\Request\Factory $requestFactory
133+
* @param Directpost\Response\Factory $responseFactory
134+
* @param \Magento\Authorizenet\Model\TransactionService $transactionService
134135
* @param \Magento\Sales\Model\OrderFactory $orderFactory
135136
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
136137
* @param \Magento\Quote\Model\QuoteRepository $quoteRepository
137-
* @param \Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender
138+
* @param OrderSender $orderSender
138139
* @param \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository
139140
* @param \Magento\Framework\Model\ModelResource\AbstractResource $resource
140141
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
@@ -154,7 +155,7 @@ public function __construct(
154155
\Magento\Authorizenet\Helper\Data $dataHelper,
155156
\Magento\Authorizenet\Model\Directpost\Request\Factory $requestFactory,
156157
\Magento\Authorizenet\Model\Directpost\Response\Factory $responseFactory,
157-
\Magento\Framework\Xml\Security $xmlSecurityHelper,
158+
TransactionService $transactionService,
158159
\Magento\Sales\Model\OrderFactory $orderFactory,
159160
\Magento\Store\Model\StoreManagerInterface $storeManager,
160161
\Magento\Quote\Model\QuoteRepository $quoteRepository,
@@ -185,7 +186,7 @@ public function __construct(
185186
$dataHelper,
186187
$requestFactory,
187188
$responseFactory,
188-
$xmlSecurityHelper,
189+
$transactionService,
189190
$resource,
190191
$resourceCollection,
191192
$data
@@ -884,6 +885,8 @@ public function fetchTransactionInfo(\Magento\Payment\Model\InfoInterface $payme
884885
if ($response->getXResponseCode() == self::RESPONSE_CODE_APPROVED) {
885886
if ($response->getTransactionStatus() == 'voided') {
886887
$payment->setIsTransactionDenied(true);
888+
$payment->setIsTransactionClosed(true);
889+
$transaction->close();
887890
} else {
888891
$transaction->setAdditionalInformation(self::TRANSACTION_FRAUD_STATE_KEY, false);
889892
$payment->setIsTransactionApproved(true);
@@ -892,7 +895,7 @@ public function fetchTransactionInfo(\Magento\Payment\Model\InfoInterface $payme
892895
$payment->setIsTransactionDenied(true);
893896
}
894897
$this->addStatusCommentOnUpdate($payment, $response, $transactionId);
895-
return parent::fetchTransactionInfo($payment, $transactionId);
898+
return [];
896899
}
897900

898901
/**
@@ -947,4 +950,25 @@ public function setMethodCode($methodCode)
947950
public function setPathPattern($pathPattern)
948951
{
949952
}
953+
954+
/**
955+
* This function returns full transaction details for a specified transaction ID.
956+
*
957+
* @param string $transactionId
958+
* @return \Magento\Framework\DataObject
959+
* @throws \Magento\Framework\Exception\LocalizedException
960+
* @link http://www.authorize.net/support/ReportingGuide_XML.pdf
961+
* @link http://developer.authorize.net/api/transaction_details/
962+
*/
963+
protected function getTransactionResponse($transactionId)
964+
{
965+
$responseXmlDocument = $this->transactionService->getTransactionDetails($this, $transactionId);
966+
967+
$response = new \Magento\Framework\DataObject();
968+
$response->setXResponseCode((string)$responseXmlDocument->transaction->responseCode)
969+
->setXResponseReasonCode((string)$responseXmlDocument->transaction->responseReasonCode)
970+
->setTransactionStatus((string)$responseXmlDocument->transaction->transactionStatus);
971+
972+
return $response;
973+
}
950974
}

0 commit comments

Comments
 (0)