5
5
*/
6
6
namespace Magento \Authorizenet \Model ;
7
7
8
- use Magento \Payment \Model \Method \ Logger ;
8
+ use Magento \Authorizenet \Model \TransactionService ;
9
9
10
10
/**
11
11
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -19,11 +19,6 @@ abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc
19
19
*/
20
20
const CGI_URL = 'https://secure.authorize.net/gateway/transact.dll ' ;
21
21
22
- /**
23
- * Transaction Details gateway url
24
- */
25
- const CGI_URL_TD = 'https://apitest.authorize.net/xml/v1/request.api ' ;
26
-
27
22
const REQUEST_METHOD_CC = 'CC ' ;
28
23
29
24
const REQUEST_TYPE_AUTH_CAPTURE = 'AUTH_CAPTURE ' ;
@@ -56,8 +51,6 @@ abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc
56
51
57
52
const RESPONSE_REASON_CODE_PENDING_REVIEW_DECLINED = 254 ;
58
53
59
- const PAYMENT_UPDATE_STATUS_CODE_SUCCESS = 'Ok ' ;
60
-
61
54
/**
62
55
* Transaction fraud state key
63
56
*/
@@ -93,22 +86,17 @@ abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc
93
86
protected $ responseFactory ;
94
87
95
88
/**
96
- * Stored information about transaction
97
- *
98
- * @var array
89
+ * @var \Magento\Authorizenet\Model\TransactionService;
99
90
*/
100
- protected $ transactionDetails = [] ;
91
+ protected $ transactionService ;
101
92
102
93
/**
103
- * {@inheritdoc}
94
+ * Fields that should be replaced in debug with '***'
95
+ *
96
+ * @var array
104
97
*/
105
98
protected $ _debugReplacePrivateDataKeys = ['merchantAuthentication ' , 'x_login ' ];
106
99
107
- /**
108
- * @var \Magento\Framework\Xml\Security
109
- */
110
- protected $ xmlSecurityHelper ;
111
-
112
100
/**
113
101
* @param \Magento\Framework\Model\Context $context
114
102
* @param \Magento\Framework\Registry $registry
@@ -122,7 +110,7 @@ abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc
122
110
* @param \Magento\Authorizenet\Helper\Data $dataHelper
123
111
* @param \Magento\Authorizenet\Model\Request\Factory $requestFactory
124
112
* @param \Magento\Authorizenet\Model\Response\Factory $responseFactory
125
- * @param \Magento\Framework\Xml\Security $xmlSecurityHelper
113
+ * @param \Magento\Authorizenet\Model\TransactionService $transactionService
126
114
* @param \Magento\Framework\Model\ModelResource\AbstractResource $resource
127
115
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
128
116
* @param array $data
@@ -141,15 +129,15 @@ public function __construct(
141
129
\Magento \Authorizenet \Helper \Data $ dataHelper ,
142
130
\Magento \Authorizenet \Model \Request \Factory $ requestFactory ,
143
131
\Magento \Authorizenet \Model \Response \Factory $ responseFactory ,
144
- \ Magento \ Framework \ Xml \ Security $ xmlSecurityHelper ,
132
+ TransactionService $ transactionService ,
145
133
\Magento \Framework \Model \ModelResource \AbstractResource $ resource = null ,
146
134
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
147
135
array $ data = []
148
136
) {
149
137
$ this ->dataHelper = $ dataHelper ;
150
138
$ this ->requestFactory = $ requestFactory ;
151
139
$ this ->responseFactory = $ responseFactory ;
152
- $ this ->xmlSecurityHelper = $ xmlSecurityHelper ;
140
+ $ this ->transactionService = $ transactionService ;
153
141
154
142
parent ::__construct (
155
143
$ context ,
@@ -216,7 +204,7 @@ public function cancel(\Magento\Payment\Model\InfoInterface $payment)
216
204
*/
217
205
public function fetchTransactionFraudDetails ($ transactionId )
218
206
{
219
- $ responseXmlDocument = $ this ->getTransactionDetails ($ transactionId );
207
+ $ responseXmlDocument = $ this ->transactionService -> getTransactionDetails ($ this , $ transactionId );
220
208
$ response = new \Magento \Framework \DataObject ();
221
209
222
210
if (empty ($ responseXmlDocument ->transaction ->FDSFilters ->FDSFilter )) {
@@ -443,114 +431,4 @@ protected function isGatewayActionsLocked($payment)
443
431
{
444
432
return $ payment ->getAdditionalInformation (self ::GATEWAY_ACTIONS_LOCKED_STATE_KEY );
445
433
}
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
- }
556
434
}
0 commit comments