PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/core/Mage/Paygate/Model/Authorizenet.php

https://bitbucket.org/sunil_nextbits/magento2
PHP | 1564 lines | 1036 code | 142 blank | 386 comment | 102 complexity | 19e5bd445d4bace6aa2b95efaef977ae MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Paygate
  23. * @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. class Mage_Paygate_Model_Authorizenet extends Mage_Payment_Model_Method_Cc
  27. {
  28. /*
  29. * AIM gateway url
  30. */
  31. const CGI_URL = 'https://secure.authorize.net/gateway/transact.dll';
  32. /*
  33. * Transaction Details gateway url
  34. */
  35. const CGI_URL_TD = 'https://apitest.authorize.net/xml/v1/request.api';
  36. const REQUEST_METHOD_CC = 'CC';
  37. const REQUEST_METHOD_ECHECK = 'ECHECK';
  38. const REQUEST_TYPE_AUTH_CAPTURE = 'AUTH_CAPTURE';
  39. const REQUEST_TYPE_AUTH_ONLY = 'AUTH_ONLY';
  40. const REQUEST_TYPE_CAPTURE_ONLY = 'CAPTURE_ONLY';
  41. const REQUEST_TYPE_CREDIT = 'CREDIT';
  42. const REQUEST_TYPE_VOID = 'VOID';
  43. const REQUEST_TYPE_PRIOR_AUTH_CAPTURE = 'PRIOR_AUTH_CAPTURE';
  44. const ECHECK_ACCT_TYPE_CHECKING = 'CHECKING';
  45. const ECHECK_ACCT_TYPE_BUSINESS = 'BUSINESSCHECKING';
  46. const ECHECK_ACCT_TYPE_SAVINGS = 'SAVINGS';
  47. const ECHECK_TRANS_TYPE_CCD = 'CCD';
  48. const ECHECK_TRANS_TYPE_PPD = 'PPD';
  49. const ECHECK_TRANS_TYPE_TEL = 'TEL';
  50. const ECHECK_TRANS_TYPE_WEB = 'WEB';
  51. const RESPONSE_DELIM_CHAR = '(~)';
  52. const RESPONSE_CODE_APPROVED = 1;
  53. const RESPONSE_CODE_DECLINED = 2;
  54. const RESPONSE_CODE_ERROR = 3;
  55. const RESPONSE_CODE_HELD = 4;
  56. const RESPONSE_REASON_CODE_APPROVED = 1;
  57. const RESPONSE_REASON_CODE_NOT_FOUND = 16;
  58. const RESPONSE_REASON_CODE_PARTIAL_APPROVE = 295;
  59. const RESPONSE_REASON_CODE_PENDING_REVIEW_AUTHORIZED = 252;
  60. const RESPONSE_REASON_CODE_PENDING_REVIEW = 253;
  61. const RESPONSE_REASON_CODE_PENDING_REVIEW_DECLINED = 254;
  62. const PARTIAL_AUTH_CARDS_LIMIT = 5;
  63. const PARTIAL_AUTH_LAST_SUCCESS = 'last_success';
  64. const PARTIAL_AUTH_LAST_DECLINED = 'last_declined';
  65. const PARTIAL_AUTH_ALL_CANCELED = 'all_canceled';
  66. const PARTIAL_AUTH_CARDS_LIMIT_EXCEEDED = 'card_limit_exceeded';
  67. const PARTIAL_AUTH_DATA_CHANGED = 'data_changed';
  68. const METHOD_CODE = 'authorizenet';
  69. const TRANSACTION_STATUS_EXPIRED = 'expired';
  70. protected $_code = self::METHOD_CODE;
  71. /**
  72. * Form block type
  73. */
  74. protected $_formBlockType = 'Mage_Paygate_Block_Authorizenet_Form_Cc';
  75. /**
  76. * Info block type
  77. */
  78. protected $_infoBlockType = 'Mage_Paygate_Block_Authorizenet_Info_Cc';
  79. /**
  80. * Availability options
  81. */
  82. protected $_isGateway = true;
  83. protected $_canAuthorize = true;
  84. protected $_canCapture = true;
  85. protected $_canCapturePartial = false;
  86. protected $_canRefund = true;
  87. protected $_canRefundInvoicePartial = true;
  88. protected $_canVoid = true;
  89. protected $_canUseInternal = true;
  90. protected $_canUseCheckout = true;
  91. protected $_canUseForMultishipping = true;
  92. protected $_canSaveCc = false;
  93. protected $_canFetchTransactionInfo = true;
  94. protected $_allowCurrencyCode = array('USD');
  95. /**
  96. * Fields that should be replaced in debug with '***'
  97. *
  98. * @var array
  99. */
  100. protected $_debugReplacePrivateDataKeys = array('x_login', 'x_tran_key',
  101. 'x_card_num', 'x_exp_date',
  102. 'x_card_code', 'x_bank_aba_code',
  103. 'x_bank_name', 'x_bank_acct_num',
  104. 'x_bank_acct_type','x_bank_acct_name',
  105. 'x_echeck_type');
  106. /**
  107. * Key for storing fraud transaction flag in additional information of payment model
  108. * @var string
  109. */
  110. protected $_isTransactionFraud = 'is_transaction_fraud';
  111. /**
  112. * Key for storing transaction id in additional information of payment model
  113. * @var string
  114. */
  115. protected $_realTransactionIdKey = 'real_transaction_id';
  116. /**
  117. * Key for storing split tender id in additional information of payment model
  118. * @var string
  119. */
  120. protected $_splitTenderIdKey = 'split_tender_id';
  121. /**
  122. * Key for storing locking gateway actions flag in additional information of payment model
  123. * @var string
  124. */
  125. protected $_isGatewayActionsLockedKey = 'is_gateway_actions_locked';
  126. /**
  127. * Key for storing partial authorization last action state in session
  128. * @var string
  129. */
  130. protected $_partialAuthorizationLastActionStateSessionKey = 'paygate_authorizenet_last_action_state';
  131. /**
  132. * Key for storing partial authorization checksum in session
  133. * @var string
  134. */
  135. protected $_partialAuthorizationChecksumSessionKey = 'paygate_authorizenet_checksum';
  136. /**
  137. * Fields for creating place request checksum
  138. *
  139. * @var array
  140. */
  141. protected $_partialAuthorizationChecksumDataKeys = array(
  142. 'x_version', 'x_test_request', 'x_login', 'x_test_request', 'x_allow_partial_auth', 'x_amount',
  143. 'x_currency_code', 'x_type', 'x_first_name', 'x_last_name', 'x_company', 'x_address', 'x_city', 'x_state',
  144. 'x_zip', 'x_country', 'x_phone', 'x_fax', 'x_cust_id', 'x_customer_ip', 'x_customer_tax_id', 'x_email',
  145. 'x_email_customer', 'x_merchant_email', 'x_ship_to_first_name', 'x_ship_to_last_name', 'x_ship_to_company',
  146. 'x_ship_to_address', 'x_ship_to_city', 'x_ship_to_state', 'x_ship_to_zip', 'x_ship_to_country', 'x_po_num',
  147. 'x_tax', 'x_freight'
  148. );
  149. /**
  150. * Centinel cardinal fields map
  151. *
  152. * @var array
  153. */
  154. protected $_centinelFieldMap = array(
  155. 'centinel_cavv' => 'x_cardholder_authentication_value',
  156. 'centinel_eci' => 'x_authentication_indicator'
  157. );
  158. /**
  159. * @var Mage_Paygate_Model_Authorizenet_Cards
  160. */
  161. protected $_cardsStorage = null;
  162. /**
  163. * Check method for processing with base currency
  164. *
  165. * @param string $currencyCode
  166. * @return boolean
  167. */
  168. public function canUseForCurrency($currencyCode)
  169. {
  170. if (!in_array($currencyCode, $this->getAcceptedCurrencyCodes())) {
  171. return false;
  172. }
  173. return true;
  174. }
  175. /**
  176. * Return array of currency codes supplied by Payment Gateway
  177. *
  178. * @return array
  179. */
  180. public function getAcceptedCurrencyCodes()
  181. {
  182. if (!$this->hasData('_accepted_currency')) {
  183. $acceptedCurrencyCodes = $this->_allowCurrencyCode;
  184. $acceptedCurrencyCodes[] = $this->getConfigData('currency');
  185. $this->setData('_accepted_currency', $acceptedCurrencyCodes);
  186. }
  187. return $this->_getData('_accepted_currency');
  188. }
  189. /**
  190. * Check capture availability
  191. *
  192. * @return bool
  193. */
  194. public function canCapture()
  195. {
  196. if ($this->_isGatewayActionsLocked($this->getInfoInstance())) {
  197. return false;
  198. }
  199. if ($this->_isPreauthorizeCapture($this->getInfoInstance())) {
  200. return true;
  201. }
  202. /**
  203. * If there are not transactions it is placing order and capturing is available
  204. */
  205. foreach($this->getCardsStorage()->getCards() as $card) {
  206. $lastTransaction = $this->getInfoInstance()->getTransaction($card->getLastTransId());
  207. if ($lastTransaction) {
  208. return false;
  209. }
  210. }
  211. return true;
  212. }
  213. /**
  214. * Check refund availability
  215. *
  216. * @return bool
  217. */
  218. public function canRefund()
  219. {
  220. if ($this->_isGatewayActionsLocked($this->getInfoInstance())
  221. || $this->getCardsStorage()->getCardsCount() <= 0
  222. ) {
  223. return false;
  224. }
  225. foreach($this->getCardsStorage()->getCards() as $card) {
  226. $lastTransaction = $this->getInfoInstance()->getTransaction($card->getLastTransId());
  227. if ($lastTransaction
  228. && $lastTransaction->getTxnType() == Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE
  229. && !$lastTransaction->getIsClosed()
  230. ) {
  231. return true;
  232. }
  233. }
  234. return false;
  235. }
  236. /**
  237. * Check void availability
  238. *
  239. * @param Varien_Object $invoicePayment
  240. * @return bool
  241. */
  242. public function canVoid(Varien_Object $payment)
  243. {
  244. if ($this->_isGatewayActionsLocked($this->getInfoInstance())) {
  245. return false;
  246. }
  247. return $this->_isPreauthorizeCapture($this->getInfoInstance());
  248. }
  249. /**
  250. * Set partial authorization last action state into session
  251. *
  252. * @param string $message
  253. * @return Mage_Paygate_Model_Authorizenet
  254. */
  255. public function setPartialAuthorizationLastActionState($state)
  256. {
  257. $this->_getSession()->setData($this->_partialAuthorizationLastActionStateSessionKey, $state);
  258. return $this;
  259. }
  260. /**
  261. * Return partial authorization last action state from session
  262. *
  263. * @return string
  264. */
  265. public function getPartialAuthorizationLastActionState()
  266. {
  267. return $this->_getSession()->getData($this->_partialAuthorizationLastActionStateSessionKey);
  268. }
  269. /**
  270. * Unset partial authorization last action state in session
  271. *
  272. * @return Mage_Paygate_Model_Authorizenet
  273. */
  274. public function unsetPartialAuthorizationLastActionState()
  275. {
  276. $this->_getSession()->setData($this->_partialAuthorizationLastActionStateSessionKey, false);
  277. return $this;
  278. }
  279. /**
  280. * Send authorize request to gateway
  281. *
  282. * @param Mage_Payment_Model_Info $payment
  283. * @param decimal $amount
  284. * @return Mage_Paygate_Model_Authorizenet
  285. */
  286. public function authorize(Varien_Object $payment, $amount)
  287. {
  288. if ($amount <= 0) {
  289. Mage::throwException(Mage::helper('Mage_Paygate_Helper_Data')->__('Invalid amount for authorization.'));
  290. }
  291. $this->_initCardsStorage($payment);
  292. if ($this->isPartialAuthorization($payment)) {
  293. $this->_partialAuthorization($payment, $amount, self::REQUEST_TYPE_AUTH_ONLY);
  294. $payment->setSkipTransactionCreation(true);
  295. return $this;
  296. }
  297. $this->_place($payment, $amount, self::REQUEST_TYPE_AUTH_ONLY);
  298. $payment->setSkipTransactionCreation(true);
  299. return $this;
  300. }
  301. /**
  302. * Send capture request to gateway
  303. *
  304. * @param Mage_Payment_Model_Info $payment
  305. * @param decimal $amount
  306. * @return Mage_Paygate_Model_Authorizenet
  307. */
  308. public function capture(Varien_Object $payment, $amount)
  309. {
  310. if ($amount <= 0) {
  311. Mage::throwException(Mage::helper('Mage_Paygate_Helper_Data')->__('Invalid amount for capture.'));
  312. }
  313. $this->_initCardsStorage($payment);
  314. if ($this->_isPreauthorizeCapture($payment)) {
  315. $this->_preauthorizeCapture($payment, $amount);
  316. } else if ($this->isPartialAuthorization($payment)) {
  317. $this->_partialAuthorization($payment, $amount, self::REQUEST_TYPE_AUTH_CAPTURE);
  318. } else {
  319. $this->_place($payment, $amount, self::REQUEST_TYPE_AUTH_CAPTURE);
  320. }
  321. $payment->setSkipTransactionCreation(true);
  322. return $this;
  323. }
  324. /**
  325. * Void the payment through gateway
  326. *
  327. * @param Mage_Payment_Model_Info $payment
  328. * @return Mage_Paygate_Model_Authorizenet
  329. */
  330. public function void(Varien_Object $payment)
  331. {
  332. $cardsStorage = $this->getCardsStorage($payment);
  333. $messages = array();
  334. $isSuccessful = false;
  335. $isFiled = false;
  336. foreach($cardsStorage->getCards() as $card) {
  337. try {
  338. $newTransaction = $this->_voidCardTransaction($payment, $card);
  339. $messages[] = $newTransaction->getMessage();
  340. $isSuccessful = true;
  341. } catch (Exception $e) {
  342. $messages[] = $e->getMessage();
  343. $isFiled = true;
  344. continue;
  345. }
  346. $cardsStorage->updateCard($card);
  347. }
  348. if ($isFiled) {
  349. $this->_processFailureMultitransactionAction($payment, $messages, $isSuccessful);
  350. }
  351. $payment->setSkipTransactionCreation(true);
  352. return $this;
  353. }
  354. /**
  355. * Cancel the payment through gateway
  356. *
  357. * @param Mage_Payment_Model_Info $payment
  358. * @return Mage_Paygate_Model_Authorizenet
  359. */
  360. public function cancel(Varien_Object $payment)
  361. {
  362. return $this->void($payment);
  363. }
  364. /**
  365. * Refund the amount with transaction id
  366. *
  367. * @param Mage_Payment_Model_Info $payment
  368. * @param decimal $amount
  369. * @return Mage_Paygate_Model_Authorizenet
  370. * @throws Mage_Core_Exception
  371. */
  372. public function refund(Varien_Object $payment, $requestedAmount)
  373. {
  374. $cardsStorage = $this->getCardsStorage($payment);
  375. if ($this->_formatAmount(
  376. $cardsStorage->getCapturedAmount() - $cardsStorage->getRefundedAmount()
  377. ) < $requestedAmount
  378. ) {
  379. Mage::throwException(Mage::helper('Mage_Paygate_Helper_Data')->__('Invalid amount for refund.'));
  380. }
  381. $messages = array();
  382. $isSuccessful = false;
  383. $isFiled = false;
  384. foreach($cardsStorage->getCards() as $card) {
  385. if ($requestedAmount > 0) {
  386. $cardAmountForRefund = $this->_formatAmount($card->getCapturedAmount() - $card->getRefundedAmount());
  387. if ($cardAmountForRefund <= 0) {
  388. continue;
  389. }
  390. if ($cardAmountForRefund > $requestedAmount) {
  391. $cardAmountForRefund = $requestedAmount;
  392. }
  393. try {
  394. $newTransaction = $this->_refundCardTransaction($payment, $cardAmountForRefund, $card);
  395. $messages[] = $newTransaction->getMessage();
  396. $isSuccessful = true;
  397. } catch (Exception $e) {
  398. $messages[] = $e->getMessage();
  399. $isFiled = true;
  400. continue;
  401. }
  402. $card->setRefundedAmount($this->_formatAmount($card->getRefundedAmount() + $cardAmountForRefund));
  403. $cardsStorage->updateCard($card);
  404. $requestedAmount = $this->_formatAmount($requestedAmount - $cardAmountForRefund);
  405. } else {
  406. $payment->setSkipTransactionCreation(true);
  407. return $this;
  408. }
  409. }
  410. if ($isFiled) {
  411. $this->_processFailureMultitransactionAction($payment, $messages, $isSuccessful);
  412. }
  413. $payment->setSkipTransactionCreation(true);
  414. return $this;
  415. }
  416. /**
  417. * Cancel partial authorizations and flush current split_tender_id record
  418. *
  419. * @param Mage_Payment_Model_Info $payment
  420. */
  421. public function cancelPartialAuthorization(Mage_Payment_Model_Info $payment) {
  422. if (!$payment->getAdditionalInformation($this->_splitTenderIdKey)) {
  423. Mage::throwException(Mage::helper('Mage_Paygate_Helper_Data')->__('Invalid split tenderId ID.'));
  424. }
  425. $request = $this->_getRequest();
  426. $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey));
  427. $request
  428. ->setXType(self::REQUEST_TYPE_VOID)
  429. ->setXMethod(self::REQUEST_METHOD_CC);
  430. $result = $this->_postRequest($request);
  431. switch ($result->getResponseCode()) {
  432. case self::RESPONSE_CODE_APPROVED:
  433. $payment->setAdditionalInformation($this->_splitTenderIdKey, null);
  434. $this->_getSession()->setData($this->_partialAuthorizationChecksumSessionKey, null);
  435. $this->getCardsStorage($payment)->flushCards();
  436. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_ALL_CANCELED);
  437. return;
  438. default:
  439. Mage::throwException(Mage::helper('Mage_Paygate_Helper_Data')->__('Payment canceling error.'));
  440. }
  441. }
  442. /**
  443. * Send request with new payment to gateway
  444. *
  445. * @param Mage_Payment_Model_Info $payment
  446. * @param decimal $amount
  447. * @param string $requestType
  448. * @return Mage_Paygate_Model_Authorizenet
  449. * @throws Mage_Core_Exception
  450. */
  451. protected function _place($payment, $amount, $requestType)
  452. {
  453. $payment->setAnetTransType($requestType);
  454. $payment->setAmount($amount);
  455. $request= $this->_buildRequest($payment);
  456. $result = $this->_postRequest($request);
  457. switch ($requestType) {
  458. case self::REQUEST_TYPE_AUTH_ONLY:
  459. $newTransactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH;
  460. $defaultExceptionMessage = Mage::helper('Mage_Paygate_Helper_Data')->__('Payment authorization error.');
  461. break;
  462. case self::REQUEST_TYPE_AUTH_CAPTURE:
  463. $newTransactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE;
  464. $defaultExceptionMessage = Mage::helper('Mage_Paygate_Helper_Data')->__('Payment capturing error.');
  465. break;
  466. }
  467. switch ($result->getResponseCode()) {
  468. case self::RESPONSE_CODE_APPROVED:
  469. $this->getCardsStorage($payment)->flushCards();
  470. $card = $this->_registerCard($result, $payment);
  471. $this->_addTransaction(
  472. $payment,
  473. $card->getLastTransId(),
  474. $newTransactionType,
  475. array('is_transaction_closed' => 0),
  476. array($this->_realTransactionIdKey => $card->getLastTransId()),
  477. Mage::helper('Mage_Paygate_Helper_Data')->getTransactionMessage(
  478. $payment, $requestType, $card->getLastTransId(), $card, $amount
  479. )
  480. );
  481. if ($requestType == self::REQUEST_TYPE_AUTH_CAPTURE) {
  482. $card->setCapturedAmount($card->getProcessedAmount());
  483. $this->getCardsStorage($payment)->updateCard($card);
  484. }
  485. return $this;
  486. case self::RESPONSE_CODE_HELD:
  487. if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_PENDING_REVIEW_AUTHORIZED
  488. || $result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_PENDING_REVIEW
  489. ) {
  490. $card = $this->_registerCard($result, $payment);
  491. $this->_addTransaction(
  492. $payment,
  493. $card->getLastTransId(),
  494. $newTransactionType,
  495. array('is_transaction_closed' => 0),
  496. array(
  497. $this->_realTransactionIdKey => $card->getLastTransId(),
  498. $this->_isTransactionFraud => true
  499. ),
  500. Mage::helper('Mage_Paygate_Helper_Data')->getTransactionMessage(
  501. $payment, $requestType, $card->getLastTransId(), $card, $amount
  502. )
  503. );
  504. if ($requestType == self::REQUEST_TYPE_AUTH_CAPTURE) {
  505. $card->setCapturedAmount($card->getProcessedAmount());
  506. $this->getCardsStorage()->updateCard($card);
  507. }
  508. $payment
  509. ->setIsTransactionPending(true)
  510. ->setIsFraudDetected(true);
  511. return $this;
  512. }
  513. if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_PARTIAL_APPROVE) {
  514. $checksum = $this->_generateChecksum($request, $this->_partialAuthorizationChecksumDataKeys);
  515. $this->_getSession()->setData($this->_partialAuthorizationChecksumSessionKey, $checksum);
  516. if ($this->_processPartialAuthorizationResponse($result, $payment)) {
  517. return $this;
  518. }
  519. }
  520. Mage::throwException($defaultExceptionMessage);
  521. case self::RESPONSE_CODE_DECLINED:
  522. case self::RESPONSE_CODE_ERROR:
  523. Mage::throwException($this->_wrapGatewayError($result->getResponseReasonText()));
  524. default:
  525. Mage::throwException($defaultExceptionMessage);
  526. }
  527. return $this;
  528. }
  529. /**
  530. * Send request with new payment to gateway during partial authorization process
  531. *
  532. * @param Mage_Payment_Model_Info $payment
  533. * @param decimal $amount
  534. * @param string $requestType
  535. * @return Mage_Paygate_Model_Authorizenet
  536. */
  537. protected function _partialAuthorization($payment, $amount, $requestType)
  538. {
  539. $payment->setAnetTransType($requestType);
  540. /*
  541. * Try to build checksum of first request and compare with current checksum
  542. */
  543. if ($this->getConfigData('partial_authorization_checksum_checking')) {
  544. $payment->setAmount($amount);
  545. $firstPlacingRequest= $this->_buildRequest($payment);
  546. $newChecksum = $this->_generateChecksum($firstPlacingRequest, $this->_partialAuthorizationChecksumDataKeys);
  547. $previosChecksum = $this->_getSession()->getData($this->_partialAuthorizationChecksumSessionKey);
  548. if ($newChecksum != $previosChecksum) {
  549. $quotePayment = $payment->getOrder()->getQuote()->getPayment();
  550. $this->cancelPartialAuthorization($payment);
  551. $this->_clearAssignedData($quotePayment);
  552. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_DATA_CHANGED);
  553. $quotePayment->setAdditionalInformation($payment->getAdditionalInformation());
  554. throw new Mage_Payment_Model_Info_Exception(
  555. Mage::helper('Mage_Paygate_Helper_Data')->__('Shopping cart contents and/or address has been changed.')
  556. );
  557. }
  558. }
  559. $amount = $amount - $this->getCardsStorage()->getProcessedAmount();
  560. if ($amount <= 0) {
  561. Mage::throwException(Mage::helper('Mage_Paygate_Helper_Data')->__('Invalid amount for partial authorization.'));
  562. }
  563. $payment->setAmount($amount);
  564. $request = $this->_buildRequest($payment);
  565. $result = $this->_postRequest($request);
  566. $this->_processPartialAuthorizationResponse($result, $payment);
  567. switch ($requestType) {
  568. case self::REQUEST_TYPE_AUTH_ONLY:
  569. $newTransactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH;
  570. break;
  571. case self::REQUEST_TYPE_AUTH_CAPTURE:
  572. $newTransactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE;
  573. break;
  574. }
  575. foreach ($this->getCardsStorage()->getCards() as $card) {
  576. $this->_addTransaction(
  577. $payment,
  578. $card->getLastTransId(),
  579. $newTransactionType,
  580. array('is_transaction_closed' => 0),
  581. array($this->_realTransactionIdKey => $card->getLastTransId()),
  582. Mage::helper('Mage_Paygate_Helper_Data')->getTransactionMessage(
  583. $payment, $requestType, $card->getLastTransId(), $card, $card->getProcessedAmount()
  584. )
  585. );
  586. if ($requestType == self::REQUEST_TYPE_AUTH_CAPTURE) {
  587. $card->setCapturedAmount($card->getProcessedAmount());
  588. $this->getCardsStorage()->updateCard($card);
  589. }
  590. }
  591. $this->_getSession()->setData($this->_partialAuthorizationChecksumSessionKey, null);
  592. return $this;
  593. }
  594. /**
  595. * Return true if there are authorized transactions
  596. *
  597. * @param Mage_Payment_Model_Info $payment
  598. * @return bool
  599. */
  600. protected function _isPreauthorizeCapture($payment)
  601. {
  602. if ($this->getCardsStorage()->getCardsCount() <= 0) {
  603. return false;
  604. }
  605. foreach($this->getCardsStorage()->getCards() as $card) {
  606. $lastTransaction = $payment->getTransaction($card->getLastTransId());
  607. if (!$lastTransaction
  608. || $lastTransaction->getTxnType() != Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH
  609. ) {
  610. return false;
  611. }
  612. }
  613. return true;
  614. }
  615. /**
  616. * Send capture request to gateway for capture authorized transactions
  617. *
  618. * @param Mage_Payment_Model_Info $payment
  619. * @param decimal $amount
  620. * @return Mage_Paygate_Model_Authorizenet
  621. */
  622. protected function _preauthorizeCapture($payment, $requestedAmount)
  623. {
  624. $cardsStorage = $this->getCardsStorage($payment);
  625. if ($this->_formatAmount(
  626. $cardsStorage->getProcessedAmount() - $cardsStorage->getCapturedAmount()
  627. ) < $requestedAmount
  628. ) {
  629. Mage::throwException(Mage::helper('Mage_Paygate_Helper_Data')->__('Invalid amount for capture.'));
  630. }
  631. $messages = array();
  632. $isSuccessful = false;
  633. $isFiled = false;
  634. foreach($cardsStorage->getCards() as $card) {
  635. if ($requestedAmount > 0) {
  636. $cardAmountForCapture = $card->getProcessedAmount();
  637. if ($cardAmountForCapture > $requestedAmount) {
  638. $cardAmountForCapture = $requestedAmount;
  639. }
  640. try {
  641. $newTransaction = $this->_preauthorizeCaptureCardTransaction(
  642. $payment, $cardAmountForCapture , $card
  643. );
  644. $messages[] = $newTransaction->getMessage();
  645. $isSuccessful = true;
  646. } catch (Exception $e) {
  647. $messages[] = $e->getMessage();
  648. $isFiled = true;
  649. continue;
  650. }
  651. $card->setCapturedAmount($cardAmountForCapture);
  652. $cardsStorage->updateCard($card);
  653. $requestedAmount = $this->_formatAmount($requestedAmount - $cardAmountForCapture);
  654. } else {
  655. /**
  656. * This functional is commented because partial capture is disable. See self::_canCapturePartial.
  657. */
  658. //$this->_voidCardTransaction($payment, $card);
  659. }
  660. }
  661. if ($isFiled) {
  662. $this->_processFailureMultitransactionAction($payment, $messages, $isSuccessful);
  663. }
  664. return $this;
  665. }
  666. /**
  667. * Send capture request to gateway for capture authorized transactions of card
  668. *
  669. * @param Mage_Payment_Model_Info $payment
  670. * @param decimal $amount
  671. * @param Varien_Object $card
  672. * @return Mage_Sales_Model_Order_Payment_Transaction
  673. */
  674. protected function _preauthorizeCaptureCardTransaction($payment, $amount, $card)
  675. {
  676. $authTransactionId = $card->getLastTransId();
  677. $authTransaction = $payment->getTransaction($authTransactionId);
  678. $realAuthTransactionId = $authTransaction->getAdditionalInformation($this->_realTransactionIdKey);
  679. $payment->setAnetTransType(self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE);
  680. $payment->setXTransId($realAuthTransactionId);
  681. $payment->setAmount($amount);
  682. $request= $this->_buildRequest($payment);
  683. $result = $this->_postRequest($request);
  684. switch ($result->getResponseCode()) {
  685. case self::RESPONSE_CODE_APPROVED:
  686. if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_APPROVED) {
  687. $captureTransactionId = $result->getTransactionId() . '-capture';
  688. $card->setLastTransId($captureTransactionId);
  689. return $this->_addTransaction(
  690. $payment,
  691. $captureTransactionId,
  692. Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE,
  693. array(
  694. 'is_transaction_closed' => 0,
  695. 'parent_transaction_id' => $authTransactionId
  696. ),
  697. array($this->_realTransactionIdKey => $result->getTransactionId()),
  698. Mage::helper('Mage_Paygate_Helper_Data')->getTransactionMessage(
  699. $payment, self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE, $result->getTransactionId(), $card, $amount
  700. )
  701. );
  702. }
  703. $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
  704. break;
  705. case self::RESPONSE_CODE_HELD:
  706. case self::RESPONSE_CODE_DECLINED:
  707. case self::RESPONSE_CODE_ERROR:
  708. $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
  709. break;
  710. default:
  711. $exceptionMessage = Mage::helper('Mage_Paygate_Helper_Data')->__('Payment capturing error.');
  712. break;
  713. }
  714. $exceptionMessage = Mage::helper('Mage_Paygate_Helper_Data')->getTransactionMessage(
  715. $payment, self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE, $realAuthTransactionId, $card, $amount, $exceptionMessage
  716. );
  717. Mage::throwException($exceptionMessage);
  718. }
  719. /**
  720. * Void the card transaction through gateway
  721. *
  722. * @param Mage_Payment_Model_Info $payment
  723. * @param Varien_Object $card
  724. * @return Mage_Sales_Model_Order_Payment_Transaction
  725. */
  726. protected function _voidCardTransaction($payment, $card)
  727. {
  728. $authTransactionId = $card->getLastTransId();
  729. $authTransaction = $payment->getTransaction($authTransactionId);
  730. $realAuthTransactionId = $authTransaction->getAdditionalInformation($this->_realTransactionIdKey);
  731. $payment->setAnetTransType(self::REQUEST_TYPE_VOID);
  732. $payment->setXTransId($realAuthTransactionId);
  733. $request= $this->_buildRequest($payment);
  734. $result = $this->_postRequest($request);
  735. switch ($result->getResponseCode()) {
  736. case self::RESPONSE_CODE_APPROVED:
  737. if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_APPROVED) {
  738. $voidTransactionId = $result->getTransactionId() . '-void';
  739. $card->setLastTransId($voidTransactionId);
  740. return $this->_addTransaction(
  741. $payment,
  742. $voidTransactionId,
  743. Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID,
  744. array(
  745. 'is_transaction_closed' => 1,
  746. 'should_close_parent_transaction' => 1,
  747. 'parent_transaction_id' => $authTransactionId
  748. ),
  749. array($this->_realTransactionIdKey => $result->getTransactionId()),
  750. Mage::helper('Mage_Paygate_Helper_Data')->getTransactionMessage(
  751. $payment, self::REQUEST_TYPE_VOID, $result->getTransactionId(), $card
  752. )
  753. );
  754. }
  755. $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
  756. break;
  757. case self::RESPONSE_CODE_DECLINED:
  758. case self::RESPONSE_CODE_ERROR:
  759. if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_NOT_FOUND
  760. && $this->_isTransactionExpired($realAuthTransactionId)
  761. ) {
  762. $voidTransactionId = $realAuthTransactionId . '-void';
  763. return $this->_addTransaction(
  764. $payment,
  765. $voidTransactionId,
  766. Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID,
  767. array(
  768. 'is_transaction_closed' => 1,
  769. 'should_close_parent_transaction' => 1,
  770. 'parent_transaction_id' => $authTransactionId
  771. ),
  772. array(),
  773. Mage::helper('Mage_Paygate_Helper_Data')->getExtendedTransactionMessage(
  774. $payment,
  775. self::REQUEST_TYPE_VOID,
  776. null,
  777. $card,
  778. false,
  779. false,
  780. Mage::helper('Mage_Paygate_Helper_Data')->__(
  781. 'Parent Authorize.Net transaction (ID %s) expired',
  782. $realAuthTransactionId
  783. )
  784. )
  785. );
  786. }
  787. $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
  788. break;
  789. default:
  790. $exceptionMessage = Mage::helper('Mage_Paygate_Helper_Data')->__('Payment voiding error.');
  791. break;
  792. }
  793. $exceptionMessage = Mage::helper('Mage_Paygate_Helper_Data')->getTransactionMessage(
  794. $payment, self::REQUEST_TYPE_VOID, $realAuthTransactionId, $card, false, $exceptionMessage
  795. );
  796. Mage::throwException($exceptionMessage);
  797. }
  798. /**
  799. * Check if transaction is expired
  800. *
  801. * @param string $realAuthTransactionId
  802. * @return bool
  803. */
  804. protected function _isTransactionExpired($realAuthTransactionId)
  805. {
  806. $transactionDetails = $this->_getTransactionDetails($realAuthTransactionId);
  807. return $transactionDetails->getTransactionStatus() == self::TRANSACTION_STATUS_EXPIRED;
  808. }
  809. /**
  810. * Refund the card transaction through gateway
  811. *
  812. * @param Mage_Payment_Model_Info $payment
  813. * @param Varien_Object $card
  814. * @return Mage_Sales_Model_Order_Payment_Transaction
  815. */
  816. protected function _refundCardTransaction($payment, $amount, $card)
  817. {
  818. /**
  819. * Card has last transaction with type "refund" when all captured amount is refunded.
  820. * Until this moment card has last transaction with type "capture".
  821. */
  822. $captureTransactionId = $card->getLastTransId();
  823. $captureTransaction = $payment->getTransaction($captureTransactionId);
  824. $realCaptureTransactionId = $captureTransaction->getAdditionalInformation($this->_realTransactionIdKey);
  825. $payment->setAnetTransType(self::REQUEST_TYPE_CREDIT);
  826. $payment->setXTransId($realCaptureTransactionId);
  827. $payment->setAmount($amount);
  828. $request = $this->_buildRequest($payment);
  829. $request->setXCardNum($card->getCcLast4());
  830. $result = $this->_postRequest($request);
  831. switch ($result->getResponseCode()) {
  832. case self::RESPONSE_CODE_APPROVED:
  833. if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_APPROVED) {
  834. $refundTransactionId = $result->getTransactionId() . '-refund';
  835. $shouldCloseCaptureTransaction = 0;
  836. /**
  837. * If it is last amount for refund, transaction with type "capture" will be closed
  838. * and card will has last transaction with type "refund"
  839. */
  840. if ($this->_formatAmount($card->getCapturedAmount() - $card->getRefundedAmount()) == $amount) {
  841. $card->setLastTransId($refundTransactionId);
  842. $shouldCloseCaptureTransaction = 1;
  843. }
  844. return $this->_addTransaction(
  845. $payment,
  846. $refundTransactionId,
  847. Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND,
  848. array(
  849. 'is_transaction_closed' => 1,
  850. 'should_close_parent_transaction' => $shouldCloseCaptureTransaction,
  851. 'parent_transaction_id' => $captureTransactionId
  852. ),
  853. array($this->_realTransactionIdKey => $result->getTransactionId()),
  854. Mage::helper('Mage_Paygate_Helper_Data')->getTransactionMessage(
  855. $payment, self::REQUEST_TYPE_CREDIT, $result->getTransactionId(), $card, $amount
  856. )
  857. );
  858. }
  859. $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
  860. break;
  861. case self::RESPONSE_CODE_DECLINED:
  862. case self::RESPONSE_CODE_ERROR:
  863. $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
  864. break;
  865. default:
  866. $exceptionMessage = Mage::helper('Mage_Paygate_Helper_Data')->__('Payment refunding error.');
  867. break;
  868. }
  869. $exceptionMessage = Mage::helper('Mage_Paygate_Helper_Data')->getTransactionMessage(
  870. $payment, self::REQUEST_TYPE_CREDIT, $realCaptureTransactionId, $card, $amount, $exceptionMessage
  871. );
  872. Mage::throwException($exceptionMessage);
  873. }
  874. /**
  875. * Init cards storage model
  876. *
  877. * @param Mage_Payment_Model_Info $payment
  878. */
  879. protected function _initCardsStorage($payment)
  880. {
  881. $this->_cardsStorage = Mage::getModel('Mage_Paygate_Model_Authorizenet_Cards')->setPayment($payment);
  882. }
  883. /**
  884. * Return cards storage model
  885. *
  886. * @param Mage_Payment_Model_Info $payment
  887. * @return Mage_Paygate_Model_Authorizenet_Cards
  888. */
  889. public function getCardsStorage($payment = null)
  890. {
  891. if (is_null($payment)) {
  892. $payment = $this->getInfoInstance();
  893. }
  894. if (is_null($this->_cardsStorage)) {
  895. $this->_initCardsStorage($payment);
  896. }
  897. return $this->_cardsStorage;
  898. }
  899. /**
  900. * If parial authorization is started method will returne true
  901. *
  902. * @param Mage_Payment_Model_Info $payment
  903. * @return bool
  904. */
  905. public function isPartialAuthorization($payment = null)
  906. {
  907. if (is_null($payment)) {
  908. $payment = $this->getInfoInstance();
  909. }
  910. return $payment->getAdditionalInformation($this->_splitTenderIdKey);
  911. }
  912. /**
  913. * Mock capture transaction id in invoice
  914. *
  915. * @param Mage_Sales_Model_Order_Invoice $invoice
  916. * @param Mage_Sales_Model_Order_Payment $payment
  917. * @return Mage_Payment_Model_Method_Abstract
  918. */
  919. public function processInvoice($invoice, $payment)
  920. {
  921. $invoice->setTransactionId(1);
  922. return $this;
  923. }
  924. /**
  925. * Set transaction ID into creditmemo for informational purposes
  926. * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
  927. * @param Mage_Sales_Model_Order_Payment $payment
  928. * @return Mage_Payment_Model_Method_Abstract
  929. */
  930. public function processCreditmemo($creditmemo, $payment)
  931. {
  932. $creditmemo->setTransactionId(1);
  933. return $this;
  934. }
  935. /**
  936. * Fetch transaction details info
  937. *
  938. * Update transaction info if there is one placing transaction only
  939. *
  940. * @param Mage_Payment_Model_Info $payment
  941. * @param string $transactionId
  942. * @return array
  943. */
  944. public function fetchTransactionInfo(Mage_Payment_Model_Info $payment, $transactionId)
  945. {
  946. $cardsStorage = $this->getCardsStorage($payment);
  947. if ($cardsStorage->getCardsCount() != 1) {
  948. return parent::fetchTransactionInfo($payment, $transactionId);
  949. }
  950. $cards = $cardsStorage->getCards();
  951. $card = array_shift($cards);
  952. $transactionId = $card->getLastTransId();
  953. $transaction = $payment->getTransaction($transactionId);
  954. if (!$transaction->getAdditionalInformation($this->_isTransactionFraud)) {
  955. return parent::fetchTransactionInfo($payment, $transactionId);
  956. }
  957. $response = $this->_getTransactionDetails($transactionId);
  958. if ($response->getResponseCode() == self::RESPONSE_CODE_APPROVED) {
  959. $transaction->setAdditionalInformation($this->_isTransactionFraud, false);
  960. $payment->setIsTransactionApproved(true);
  961. } elseif ($response->getResponseReasonCode() == self::RESPONSE_REASON_CODE_PENDING_REVIEW_DECLINED) {
  962. $payment->setIsTransactionDenied(true);
  963. }
  964. return parent::fetchTransactionInfo($payment, $transactionId);
  965. }
  966. /**
  967. * Set split_tender_id to quote payment if neeeded
  968. *
  969. * @param Varien_Object $response
  970. * @param Mage_Sales_Model_Order_Payment $payment
  971. * @return bool
  972. */
  973. protected function _processPartialAuthorizationResponse($response, $orderPayment) {
  974. if (!$response->getSplitTenderId()) {
  975. return false;
  976. }
  977. $quotePayment = $orderPayment->getOrder()->getQuote()->getPayment();
  978. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED);
  979. $exceptionMessage = null;
  980. try {
  981. switch ($response->getResponseCode()) {
  982. case self::RESPONSE_CODE_APPROVED:
  983. $this->_registerCard($response, $orderPayment);
  984. $this->_clearAssignedData($quotePayment);
  985. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_SUCCESS);
  986. return true;
  987. case self::RESPONSE_CODE_HELD:
  988. if ($response->getResponseReasonCode() != self::RESPONSE_REASON_CODE_PARTIAL_APPROVE) {
  989. return false;
  990. }
  991. if ($this->getCardsStorage($orderPayment)->getCardsCount() + 1 >= self::PARTIAL_AUTH_CARDS_LIMIT) {
  992. $this->cancelPartialAuthorization($orderPayment);
  993. $this->_clearAssignedData($quotePayment);
  994. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_CARDS_LIMIT_EXCEEDED);
  995. $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
  996. $exceptionMessage = Mage::helper('Mage_Paygate_Helper_Data')->__('You have reached the maximum number of credit card allowed to be used for the payment.');
  997. break;
  998. }
  999. $orderPayment->setAdditionalInformation($this->_splitTenderIdKey, $response->getSplitTenderId());
  1000. $this->_registerCard($response, $orderPayment);
  1001. $this->_clearAssignedData($quotePayment);
  1002. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_SUCCESS);
  1003. $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
  1004. $exceptionMessage = null;
  1005. break;
  1006. case self::RESPONSE_CODE_DECLINED:
  1007. case self::RESPONSE_CODE_ERROR:
  1008. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED);
  1009. $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
  1010. $exceptionMessage = $this->_wrapGatewayError($response->getResponseReasonText());
  1011. break;
  1012. default:
  1013. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED);
  1014. $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
  1015. $exceptionMessage = $this->_wrapGatewayError(
  1016. Mage::helper('Mage_Paygate_Helper_Data')->__('Payment partial authorization error.')
  1017. );
  1018. }
  1019. } catch (Exception $e) {
  1020. $exceptionMessage = $e->getMessage();
  1021. }
  1022. throw new Mage_Payment_Model_Info_Exception($exceptionMessage);
  1023. }
  1024. /**
  1025. * Return authorize payment request
  1026. *
  1027. * @return Mage_Paygate_Model_Authorizenet_Request
  1028. */
  1029. protected function _getRequest()
  1030. {
  1031. $request = Mage::getModel('Mage_Paygate_Model_Authorizenet_Request')
  1032. ->setXVersion(3.1)
  1033. ->setXDelimData('True')
  1034. ->setXRelayResponse('False')
  1035. ->setXTestRequest($this->getConfigData('test') ? 'TRUE' : 'FALSE')
  1036. ->setXLogin($this->getConfigData('login'))
  1037. ->setXTranKey($this->getConfigData('trans_key'));
  1038. return $request;
  1039. }
  1040. /**
  1041. * Prepare request to gateway
  1042. *
  1043. * @link http://www.authorize.net/support/AIM_guide.pdf
  1044. * @param Mage_Payment_Model_Info $payment
  1045. * @return Mage_Paygate_Model_Authorizenet_Request
  1046. */
  1047. protected function _buildRequest(Varien_Object $payment)
  1048. {
  1049. $order = $payment->getOrder();
  1050. $this->setStore($order->getStoreId());
  1051. $request = $this->_getRequest()
  1052. ->setXType($payment->getAnetTransType())
  1053. ->setXMethod(self::REQUEST_METHOD_CC);
  1054. if ($order && $order->getIncrementId()) {
  1055. $request->setXInvoiceNum($order->getIncrementId());
  1056. }
  1057. if($payment->getAmount()){
  1058. $request->setXAmount($payment->getAmount(),2);
  1059. $request->setXCurrencyCode($order->getBaseCurrencyCode());
  1060. }
  1061. switch ($payment->getAnetTransType()) {
  1062. case self::REQUEST_TYPE_AUTH_CAPTURE:
  1063. $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False');
  1064. if ($payment->getAdditionalInformation($this->_splitTenderIdKey)) {
  1065. $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey));
  1066. }
  1067. break;
  1068. case self::REQUEST_TYPE_AUTH_ONLY:
  1069. $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False');
  1070. if ($payment->getAdditionalInformation($this->_splitTenderIdKey)) {
  1071. $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey));
  1072. }
  1073. break;
  1074. case self::REQUEST_TYPE_CREDIT:
  1075. /**
  1076. * Send last 4 digits of credit card number to authorize.net
  1077. * otherwise it will give an error
  1078. */
  1079. $request->setXCardNum($payment->getCcLast4());
  1080. $request->setXTransId($payment->getXTransId());
  1081. break;
  1082. case self::REQUEST_TYPE_VOID:
  1083. $request->setXTransId($payment->getXTransId());
  1084. break;
  1085. case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE:
  1086. $request->setXTransId($payment->getXTransId());
  1087. break;
  1088. case self::REQUEST_TYPE_CAPTURE_ONLY:
  1089. $request->setXAuthCode($payment->getCcAuthCode());
  1090. break;
  1091. }
  1092. if ($this->getIsCentinelValidationEnabled()){
  1093. $params = $this->getCentinelValidator()->exportCmpiData(array());
  1094. $request = Varien_Object_Mapper::accumulateByMap($params, $request, $this->_centinelFieldMap);
  1095. }
  1096. if (!empty($order)) {
  1097. $billing = $order->getBillingAddress();
  1098. if (!empty($billing)) {
  1099. $request->setXFirstName($billing->getFirstname())
  1100. ->setXLastName($billing->getLastname())
  1101. ->setXCompany($billing->getCompany())
  1102. ->setXAddress($billing->getStreet(1))
  1103. ->setXCity($billing->getCity())
  1104. ->setXState($billing->getRegion())
  1105. ->setXZip($billing->getPostcode())
  1106. ->setXCountry($billing->getCountry())
  1107. ->setXPhone($billing->getTelephone())
  1108. ->setXFax($billing->getFax())
  1109. ->setXCustId($order->getCustomerId())
  1110. ->setXCustomerIp($order->getRemoteIp())
  1111. ->setXCustomerTaxId($billing->getTaxId())
  1112. ->setXEmail($order->getCustomerEmail())
  1113. ->setXEmailCustomer($this->getConfigData('email_customer'))
  1114. ->setXMerchantEmail($this->getConfigData('merchant_email'));
  1115. }
  1116. $shipping = $order->getShippingAddress();
  1117. if (!empty($shipping)) {
  1118. $request->setXShipToFirstName($shipping->getFirstname())
  1119. ->setXShipToLastName($shipping->getLastname())
  1120. ->setXShipToCompany($shipping->getCompany())
  1121. ->setXShipToAddress($shipping->getStreet(1))
  1122. ->setXShipToCity($shipping->getCity())
  1123. ->setXShipToState($shipping->getRegion())
  1124. ->setXShipToZip($shipping->getPostcode())
  1125. ->setXShipToCountry($shipping->getC

Large files files are truncated, but you can click here to view the full file