PageRenderTime 55ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/jit_bec/shopifine
PHP | 1559 lines | 1035 code | 141 blank | 383 comment | 102 complexity | ebd4bc08e1cc9e8321ad561175a4cb38 MD5 | raw file
Possible License(s): LGPL-3.0

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 Magento 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 = 'paygate/authorizenet_form_cc';
  75. /**
  76. * Info block type
  77. */
  78. protected $_infoBlockType = 'paygate/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. * Check method for processing with base currency
  160. *
  161. * @param string $currencyCode
  162. * @return boolean
  163. */
  164. public function canUseForCurrency($currencyCode)
  165. {
  166. if (!in_array($currencyCode, $this->getAcceptedCurrencyCodes())) {
  167. return false;
  168. }
  169. return true;
  170. }
  171. /**
  172. * Return array of currency codes supplied by Payment Gateway
  173. *
  174. * @return array
  175. */
  176. public function getAcceptedCurrencyCodes()
  177. {
  178. if (!$this->hasData('_accepted_currency')) {
  179. $acceptedCurrencyCodes = $this->_allowCurrencyCode;
  180. $acceptedCurrencyCodes[] = $this->getConfigData('currency');
  181. $this->setData('_accepted_currency', $acceptedCurrencyCodes);
  182. }
  183. return $this->_getData('_accepted_currency');
  184. }
  185. /**
  186. * Check capture availability
  187. *
  188. * @return bool
  189. */
  190. public function canCapture()
  191. {
  192. if ($this->_isGatewayActionsLocked($this->getInfoInstance())) {
  193. return false;
  194. }
  195. if ($this->_isPreauthorizeCapture($this->getInfoInstance())) {
  196. return true;
  197. }
  198. /**
  199. * If there are not transactions it is placing order and capturing is available
  200. */
  201. foreach($this->getCardsStorage()->getCards() as $card) {
  202. $lastTransaction = $this->getInfoInstance()->getTransaction($card->getLastTransId());
  203. if ($lastTransaction) {
  204. return false;
  205. }
  206. }
  207. return true;
  208. }
  209. /**
  210. * Check refund availability
  211. *
  212. * @return bool
  213. */
  214. public function canRefund()
  215. {
  216. if ($this->_isGatewayActionsLocked($this->getInfoInstance())
  217. || $this->getCardsStorage()->getCardsCount() <= 0
  218. ) {
  219. return false;
  220. }
  221. foreach($this->getCardsStorage()->getCards() as $card) {
  222. $lastTransaction = $this->getInfoInstance()->getTransaction($card->getLastTransId());
  223. if ($lastTransaction
  224. && $lastTransaction->getTxnType() == Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE
  225. && !$lastTransaction->getIsClosed()
  226. ) {
  227. return true;
  228. }
  229. }
  230. return false;
  231. }
  232. /**
  233. * Check void availability
  234. *
  235. * @param Varien_Object $invoicePayment
  236. * @return bool
  237. */
  238. public function canVoid(Varien_Object $payment)
  239. {
  240. if ($this->_isGatewayActionsLocked($this->getInfoInstance())) {
  241. return false;
  242. }
  243. return $this->_isPreauthorizeCapture($this->getInfoInstance());
  244. }
  245. /**
  246. * Set partial authorization last action state into session
  247. *
  248. * @param string $message
  249. * @return Mage_Paygate_Model_Authorizenet
  250. */
  251. public function setPartialAuthorizationLastActionState($state)
  252. {
  253. $this->_getSession()->setData($this->_partialAuthorizationLastActionStateSessionKey, $state);
  254. return $this;
  255. }
  256. /**
  257. * Return partial authorization last action state from session
  258. *
  259. * @return string
  260. */
  261. public function getPartialAuthorizationLastActionState()
  262. {
  263. return $this->_getSession()->getData($this->_partialAuthorizationLastActionStateSessionKey);
  264. }
  265. /**
  266. * Unset partial authorization last action state in session
  267. *
  268. * @return Mage_Paygate_Model_Authorizenet
  269. */
  270. public function unsetPartialAuthorizationLastActionState()
  271. {
  272. $this->_getSession()->setData($this->_partialAuthorizationLastActionStateSessionKey, false);
  273. return $this;
  274. }
  275. /**
  276. * Send authorize request to gateway
  277. *
  278. * @param Mage_Payment_Model_Info $payment
  279. * @param decimal $amount
  280. * @return Mage_Paygate_Model_Authorizenet
  281. */
  282. public function authorize(Varien_Object $payment, $amount)
  283. {
  284. if ($amount <= 0) {
  285. Mage::throwException(Mage::helper('paygate')->__('Invalid amount for authorization.'));
  286. }
  287. $this->_initCardsStorage($payment);
  288. if ($this->isPartialAuthorization($payment)) {
  289. $this->_partialAuthorization($payment, $amount, self::REQUEST_TYPE_AUTH_ONLY);
  290. $payment->setSkipTransactionCreation(true);
  291. return $this;
  292. }
  293. $this->_place($payment, $amount, self::REQUEST_TYPE_AUTH_ONLY);
  294. $payment->setSkipTransactionCreation(true);
  295. return $this;
  296. }
  297. /**
  298. * Send capture request to gateway
  299. *
  300. * @param Mage_Payment_Model_Info $payment
  301. * @param decimal $amount
  302. * @return Mage_Paygate_Model_Authorizenet
  303. */
  304. public function capture(Varien_Object $payment, $amount)
  305. {
  306. if ($amount <= 0) {
  307. Mage::throwException(Mage::helper('paygate')->__('Invalid amount for capture.'));
  308. }
  309. $this->_initCardsStorage($payment);
  310. if ($this->_isPreauthorizeCapture($payment)) {
  311. $this->_preauthorizeCapture($payment, $amount);
  312. } else if ($this->isPartialAuthorization($payment)) {
  313. $this->_partialAuthorization($payment, $amount, self::REQUEST_TYPE_AUTH_CAPTURE);
  314. } else {
  315. $this->_place($payment, $amount, self::REQUEST_TYPE_AUTH_CAPTURE);
  316. }
  317. $payment->setSkipTransactionCreation(true);
  318. return $this;
  319. }
  320. /**
  321. * Void the payment through gateway
  322. *
  323. * @param Mage_Payment_Model_Info $payment
  324. * @return Mage_Paygate_Model_Authorizenet
  325. */
  326. public function void(Varien_Object $payment)
  327. {
  328. $cardsStorage = $this->getCardsStorage($payment);
  329. $messages = array();
  330. $isSuccessful = false;
  331. $isFiled = false;
  332. foreach($cardsStorage->getCards() as $card) {
  333. try {
  334. $newTransaction = $this->_voidCardTransaction($payment, $card);
  335. $messages[] = $newTransaction->getMessage();
  336. $isSuccessful = true;
  337. } catch (Exception $e) {
  338. $messages[] = $e->getMessage();
  339. $isFiled = true;
  340. continue;
  341. }
  342. $cardsStorage->updateCard($card);
  343. }
  344. if ($isFiled) {
  345. $this->_processFailureMultitransactionAction($payment, $messages, $isSuccessful);
  346. }
  347. $payment->setSkipTransactionCreation(true);
  348. return $this;
  349. }
  350. /**
  351. * Cancel the payment through gateway
  352. *
  353. * @param Mage_Payment_Model_Info $payment
  354. * @return Mage_Paygate_Model_Authorizenet
  355. */
  356. public function cancel(Varien_Object $payment)
  357. {
  358. return $this->void($payment);
  359. }
  360. /**
  361. * Refund the amount with transaction id
  362. *
  363. * @param Mage_Payment_Model_Info $payment
  364. * @param decimal $amount
  365. * @return Mage_Paygate_Model_Authorizenet
  366. * @throws Mage_Core_Exception
  367. */
  368. public function refund(Varien_Object $payment, $requestedAmount)
  369. {
  370. $cardsStorage = $this->getCardsStorage($payment);
  371. if ($this->_formatAmount(
  372. $cardsStorage->getCapturedAmount() - $cardsStorage->getRefundedAmount()
  373. ) < $requestedAmount
  374. ) {
  375. Mage::throwException(Mage::helper('paygate')->__('Invalid amount for refund.'));
  376. }
  377. $messages = array();
  378. $isSuccessful = false;
  379. $isFiled = false;
  380. foreach($cardsStorage->getCards() as $card) {
  381. if ($requestedAmount > 0) {
  382. $cardAmountForRefund = $this->_formatAmount($card->getCapturedAmount() - $card->getRefundedAmount());
  383. if ($cardAmountForRefund <= 0) {
  384. continue;
  385. }
  386. if ($cardAmountForRefund > $requestedAmount) {
  387. $cardAmountForRefund = $requestedAmount;
  388. }
  389. try {
  390. $newTransaction = $this->_refundCardTransaction($payment, $cardAmountForRefund, $card);
  391. $messages[] = $newTransaction->getMessage();
  392. $isSuccessful = true;
  393. } catch (Exception $e) {
  394. $messages[] = $e->getMessage();
  395. $isFiled = true;
  396. continue;
  397. }
  398. $card->setRefundedAmount($this->_formatAmount($card->getRefundedAmount() + $cardAmountForRefund));
  399. $cardsStorage->updateCard($card);
  400. $requestedAmount = $this->_formatAmount($requestedAmount - $cardAmountForRefund);
  401. } else {
  402. $payment->setSkipTransactionCreation(true);
  403. return $this;
  404. }
  405. }
  406. if ($isFiled) {
  407. $this->_processFailureMultitransactionAction($payment, $messages, $isSuccessful);
  408. }
  409. $payment->setSkipTransactionCreation(true);
  410. return $this;
  411. }
  412. /**
  413. * Cancel partial authorizations and flush current split_tender_id record
  414. *
  415. * @param Mage_Payment_Model_Info $payment
  416. */
  417. public function cancelPartialAuthorization(Mage_Payment_Model_Info $payment) {
  418. if (!$payment->getAdditionalInformation($this->_splitTenderIdKey)) {
  419. Mage::throwException(Mage::helper('paygate')->__('Invalid split tenderId ID.'));
  420. }
  421. $request = $this->_getRequest();
  422. $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey));
  423. $request
  424. ->setXType(self::REQUEST_TYPE_VOID)
  425. ->setXMethod(self::REQUEST_METHOD_CC);
  426. $result = $this->_postRequest($request);
  427. switch ($result->getResponseCode()) {
  428. case self::RESPONSE_CODE_APPROVED:
  429. $payment->setAdditionalInformation($this->_splitTenderIdKey, null);
  430. $this->_getSession()->setData($this->_partialAuthorizationChecksumSessionKey, null);
  431. $this->getCardsStorage($payment)->flushCards();
  432. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_ALL_CANCELED);
  433. return;
  434. default:
  435. Mage::throwException(Mage::helper('paygate')->__('Payment canceling error.'));
  436. }
  437. }
  438. /**
  439. * Send request with new payment to gateway
  440. *
  441. * @param Mage_Payment_Model_Info $payment
  442. * @param decimal $amount
  443. * @param string $requestType
  444. * @return Mage_Paygate_Model_Authorizenet
  445. * @throws Mage_Core_Exception
  446. */
  447. protected function _place($payment, $amount, $requestType)
  448. {
  449. $payment->setAnetTransType($requestType);
  450. $payment->setAmount($amount);
  451. $request= $this->_buildRequest($payment);
  452. $result = $this->_postRequest($request);
  453. switch ($requestType) {
  454. case self::REQUEST_TYPE_AUTH_ONLY:
  455. $newTransactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH;
  456. $defaultExceptionMessage = Mage::helper('paygate')->__('Payment authorization error.');
  457. break;
  458. case self::REQUEST_TYPE_AUTH_CAPTURE:
  459. $newTransactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE;
  460. $defaultExceptionMessage = Mage::helper('paygate')->__('Payment capturing error.');
  461. break;
  462. }
  463. switch ($result->getResponseCode()) {
  464. case self::RESPONSE_CODE_APPROVED:
  465. $this->getCardsStorage($payment)->flushCards();
  466. $card = $this->_registerCard($result, $payment);
  467. $this->_addTransaction(
  468. $payment,
  469. $card->getLastTransId(),
  470. $newTransactionType,
  471. array('is_transaction_closed' => 0),
  472. array($this->_realTransactionIdKey => $card->getLastTransId()),
  473. Mage::helper('paygate')->getTransactionMessage(
  474. $payment, $requestType, $card->getLastTransId(), $card, $amount
  475. )
  476. );
  477. if ($requestType == self::REQUEST_TYPE_AUTH_CAPTURE) {
  478. $card->setCapturedAmount($card->getProcessedAmount());
  479. $this->getCardsStorage($payment)->updateCard($card);
  480. }
  481. return $this;
  482. case self::RESPONSE_CODE_HELD:
  483. if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_PENDING_REVIEW_AUTHORIZED
  484. || $result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_PENDING_REVIEW
  485. ) {
  486. $card = $this->_registerCard($result, $payment);
  487. $this->_addTransaction(
  488. $payment,
  489. $card->getLastTransId(),
  490. $newTransactionType,
  491. array('is_transaction_closed' => 0),
  492. array(
  493. $this->_realTransactionIdKey => $card->getLastTransId(),
  494. $this->_isTransactionFraud => true
  495. ),
  496. Mage::helper('paygate')->getTransactionMessage(
  497. $payment, $requestType, $card->getLastTransId(), $card, $amount
  498. )
  499. );
  500. if ($requestType == self::REQUEST_TYPE_AUTH_CAPTURE) {
  501. $card->setCapturedAmount($card->getProcessedAmount());
  502. $this->getCardsStorage()->updateCard($card);
  503. }
  504. $payment
  505. ->setIsTransactionPending(true)
  506. ->setIsFraudDetected(true);
  507. return $this;
  508. }
  509. if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_PARTIAL_APPROVE) {
  510. $checksum = $this->_generateChecksum($request, $this->_partialAuthorizationChecksumDataKeys);
  511. $this->_getSession()->setData($this->_partialAuthorizationChecksumSessionKey, $checksum);
  512. if ($this->_processPartialAuthorizationResponse($result, $payment)) {
  513. return $this;
  514. }
  515. }
  516. Mage::throwException($defaultExceptionMessage);
  517. case self::RESPONSE_CODE_DECLINED:
  518. case self::RESPONSE_CODE_ERROR:
  519. Mage::throwException($this->_wrapGatewayError($result->getResponseReasonText()));
  520. default:
  521. Mage::throwException($defaultExceptionMessage);
  522. }
  523. return $this;
  524. }
  525. /**
  526. * Send request with new payment to gateway during partial authorization process
  527. *
  528. * @param Mage_Payment_Model_Info $payment
  529. * @param decimal $amount
  530. * @param string $requestType
  531. * @return Mage_Paygate_Model_Authorizenet
  532. */
  533. protected function _partialAuthorization($payment, $amount, $requestType)
  534. {
  535. $payment->setAnetTransType($requestType);
  536. /*
  537. * Try to build checksum of first request and compare with current checksum
  538. */
  539. if ($this->getConfigData('partial_authorization_checksum_checking')) {
  540. $payment->setAmount($amount);
  541. $firstPlacingRequest= $this->_buildRequest($payment);
  542. $newChecksum = $this->_generateChecksum($firstPlacingRequest, $this->_partialAuthorizationChecksumDataKeys);
  543. $previosChecksum = $this->_getSession()->getData($this->_partialAuthorizationChecksumSessionKey);
  544. if ($newChecksum != $previosChecksum) {
  545. $quotePayment = $payment->getOrder()->getQuote()->getPayment();
  546. $this->cancelPartialAuthorization($payment);
  547. $this->_clearAssignedData($quotePayment);
  548. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_DATA_CHANGED);
  549. $quotePayment->setAdditionalInformation($payment->getAdditionalInformation());
  550. throw new Mage_Payment_Model_Info_Exception(
  551. Mage::helper('paygate')->__('Shopping cart contents and/or address has been changed.')
  552. );
  553. }
  554. }
  555. $amount = $amount - $this->getCardsStorage()->getProcessedAmount();
  556. if ($amount <= 0) {
  557. Mage::throwException(Mage::helper('paygate')->__('Invalid amount for partial authorization.'));
  558. }
  559. $payment->setAmount($amount);
  560. $request = $this->_buildRequest($payment);
  561. $result = $this->_postRequest($request);
  562. $this->_processPartialAuthorizationResponse($result, $payment);
  563. switch ($requestType) {
  564. case self::REQUEST_TYPE_AUTH_ONLY:
  565. $newTransactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH;
  566. break;
  567. case self::REQUEST_TYPE_AUTH_CAPTURE:
  568. $newTransactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE;
  569. break;
  570. }
  571. foreach ($this->getCardsStorage()->getCards() as $card) {
  572. $this->_addTransaction(
  573. $payment,
  574. $card->getLastTransId(),
  575. $newTransactionType,
  576. array('is_transaction_closed' => 0),
  577. array($this->_realTransactionIdKey => $card->getLastTransId()),
  578. Mage::helper('paygate')->getTransactionMessage(
  579. $payment, $requestType, $card->getLastTransId(), $card, $card->getProcessedAmount()
  580. )
  581. );
  582. if ($requestType == self::REQUEST_TYPE_AUTH_CAPTURE) {
  583. $card->setCapturedAmount($card->getProcessedAmount());
  584. $this->getCardsStorage()->updateCard($card);
  585. }
  586. }
  587. $this->_getSession()->setData($this->_partialAuthorizationChecksumSessionKey, null);
  588. return $this;
  589. }
  590. /**
  591. * Return true if there are authorized transactions
  592. *
  593. * @param Mage_Payment_Model_Info $payment
  594. * @return bool
  595. */
  596. protected function _isPreauthorizeCapture($payment)
  597. {
  598. if ($this->getCardsStorage()->getCardsCount() <= 0) {
  599. return false;
  600. }
  601. foreach($this->getCardsStorage()->getCards() as $card) {
  602. $lastTransaction = $payment->getTransaction($card->getLastTransId());
  603. if (!$lastTransaction
  604. || $lastTransaction->getTxnType() != Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH
  605. ) {
  606. return false;
  607. }
  608. }
  609. return true;
  610. }
  611. /**
  612. * Send capture request to gateway for capture authorized transactions
  613. *
  614. * @param Mage_Payment_Model_Info $payment
  615. * @param decimal $amount
  616. * @return Mage_Paygate_Model_Authorizenet
  617. */
  618. protected function _preauthorizeCapture($payment, $requestedAmount)
  619. {
  620. $cardsStorage = $this->getCardsStorage($payment);
  621. if ($this->_formatAmount(
  622. $cardsStorage->getProcessedAmount() - $cardsStorage->getCapturedAmount()
  623. ) < $requestedAmount
  624. ) {
  625. Mage::throwException(Mage::helper('paygate')->__('Invalid amount for capture.'));
  626. }
  627. $messages = array();
  628. $isSuccessful = false;
  629. $isFiled = false;
  630. foreach($cardsStorage->getCards() as $card) {
  631. if ($requestedAmount > 0) {
  632. $cardAmountForCapture = $card->getProcessedAmount();
  633. if ($cardAmountForCapture > $requestedAmount) {
  634. $cardAmountForCapture = $requestedAmount;
  635. }
  636. try {
  637. $newTransaction = $this->_preauthorizeCaptureCardTransaction(
  638. $payment, $cardAmountForCapture , $card
  639. );
  640. $messages[] = $newTransaction->getMessage();
  641. $isSuccessful = true;
  642. } catch (Exception $e) {
  643. $messages[] = $e->getMessage();
  644. $isFiled = true;
  645. continue;
  646. }
  647. $card->setCapturedAmount($cardAmountForCapture);
  648. $cardsStorage->updateCard($card);
  649. $requestedAmount = $this->_formatAmount($requestedAmount - $cardAmountForCapture);
  650. } else {
  651. /**
  652. * This functional is commented because partial capture is disable. See self::_canCapturePartial.
  653. */
  654. //$this->_voidCardTransaction($payment, $card);
  655. }
  656. }
  657. if ($isFiled) {
  658. $this->_processFailureMultitransactionAction($payment, $messages, $isSuccessful);
  659. }
  660. return $this;
  661. }
  662. /**
  663. * Send capture request to gateway for capture authorized transactions of card
  664. *
  665. * @param Mage_Payment_Model_Info $payment
  666. * @param decimal $amount
  667. * @param Varien_Object $card
  668. * @return Mage_Sales_Model_Order_Payment_Transaction
  669. */
  670. protected function _preauthorizeCaptureCardTransaction($payment, $amount, $card)
  671. {
  672. $authTransactionId = $card->getLastTransId();
  673. $authTransaction = $payment->getTransaction($authTransactionId);
  674. $realAuthTransactionId = $authTransaction->getAdditionalInformation($this->_realTransactionIdKey);
  675. $payment->setAnetTransType(self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE);
  676. $payment->setXTransId($realAuthTransactionId);
  677. $payment->setAmount($amount);
  678. $request= $this->_buildRequest($payment);
  679. $result = $this->_postRequest($request);
  680. switch ($result->getResponseCode()) {
  681. case self::RESPONSE_CODE_APPROVED:
  682. if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_APPROVED) {
  683. $captureTransactionId = $result->getTransactionId() . '-capture';
  684. $card->setLastTransId($captureTransactionId);
  685. return $this->_addTransaction(
  686. $payment,
  687. $captureTransactionId,
  688. Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE,
  689. array(
  690. 'is_transaction_closed' => 0,
  691. 'parent_transaction_id' => $authTransactionId
  692. ),
  693. array($this->_realTransactionIdKey => $result->getTransactionId()),
  694. Mage::helper('paygate')->getTransactionMessage(
  695. $payment, self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE, $result->getTransactionId(), $card, $amount
  696. )
  697. );
  698. }
  699. $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
  700. break;
  701. case self::RESPONSE_CODE_HELD:
  702. case self::RESPONSE_CODE_DECLINED:
  703. case self::RESPONSE_CODE_ERROR:
  704. $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
  705. break;
  706. default:
  707. $exceptionMessage = Mage::helper('paygate')->__('Payment capturing error.');
  708. break;
  709. }
  710. $exceptionMessage = Mage::helper('paygate')->getTransactionMessage(
  711. $payment, self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE, $realAuthTransactionId, $card, $amount, $exceptionMessage
  712. );
  713. Mage::throwException($exceptionMessage);
  714. }
  715. /**
  716. * Void the card transaction through gateway
  717. *
  718. * @param Mage_Payment_Model_Info $payment
  719. * @param Varien_Object $card
  720. * @return Mage_Sales_Model_Order_Payment_Transaction
  721. */
  722. protected function _voidCardTransaction($payment, $card)
  723. {
  724. $authTransactionId = $card->getLastTransId();
  725. $authTransaction = $payment->getTransaction($authTransactionId);
  726. $realAuthTransactionId = $authTransaction->getAdditionalInformation($this->_realTransactionIdKey);
  727. $payment->setAnetTransType(self::REQUEST_TYPE_VOID);
  728. $payment->setXTransId($realAuthTransactionId);
  729. $request= $this->_buildRequest($payment);
  730. $result = $this->_postRequest($request);
  731. switch ($result->getResponseCode()) {
  732. case self::RESPONSE_CODE_APPROVED:
  733. if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_APPROVED) {
  734. $voidTransactionId = $result->getTransactionId() . '-void';
  735. $card->setLastTransId($voidTransactionId);
  736. return $this->_addTransaction(
  737. $payment,
  738. $voidTransactionId,
  739. Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID,
  740. array(
  741. 'is_transaction_closed' => 1,
  742. 'should_close_parent_transaction' => 1,
  743. 'parent_transaction_id' => $authTransactionId
  744. ),
  745. array($this->_realTransactionIdKey => $result->getTransactionId()),
  746. Mage::helper('paygate')->getTransactionMessage(
  747. $payment, self::REQUEST_TYPE_VOID, $result->getTransactionId(), $card
  748. )
  749. );
  750. }
  751. $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
  752. break;
  753. case self::RESPONSE_CODE_DECLINED:
  754. case self::RESPONSE_CODE_ERROR:
  755. if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_NOT_FOUND
  756. && $this->_isTransactionExpired($realAuthTransactionId)
  757. ) {
  758. $voidTransactionId = $realAuthTransactionId . '-void';
  759. return $this->_addTransaction(
  760. $payment,
  761. $voidTransactionId,
  762. Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID,
  763. array(
  764. 'is_transaction_closed' => 1,
  765. 'should_close_parent_transaction' => 1,
  766. 'parent_transaction_id' => $authTransactionId
  767. ),
  768. array(),
  769. Mage::helper('paygate')->getExtendedTransactionMessage(
  770. $payment,
  771. self::REQUEST_TYPE_VOID,
  772. null,
  773. $card,
  774. false,
  775. false,
  776. Mage::helper('paygate')->__(
  777. 'Parent Authorize.Net transaction (ID %s) expired',
  778. $realAuthTransactionId
  779. )
  780. )
  781. );
  782. }
  783. $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
  784. break;
  785. default:
  786. $exceptionMessage = Mage::helper('paygate')->__('Payment voiding error.');
  787. break;
  788. }
  789. $exceptionMessage = Mage::helper('paygate')->getTransactionMessage(
  790. $payment, self::REQUEST_TYPE_VOID, $realAuthTransactionId, $card, false, $exceptionMessage
  791. );
  792. Mage::throwException($exceptionMessage);
  793. }
  794. /**
  795. * Check if transaction is expired
  796. *
  797. * @param string $realAuthTransactionId
  798. * @return bool
  799. */
  800. protected function _isTransactionExpired($realAuthTransactionId)
  801. {
  802. $transactionDetails = $this->_getTransactionDetails($realAuthTransactionId);
  803. return $transactionDetails->getTransactionStatus() == self::TRANSACTION_STATUS_EXPIRED;
  804. }
  805. /**
  806. * Refund the card transaction through gateway
  807. *
  808. * @param Mage_Payment_Model_Info $payment
  809. * @param Varien_Object $card
  810. * @return Mage_Sales_Model_Order_Payment_Transaction
  811. */
  812. protected function _refundCardTransaction($payment, $amount, $card)
  813. {
  814. /**
  815. * Card has last transaction with type "refund" when all captured amount is refunded.
  816. * Until this moment card has last transaction with type "capture".
  817. */
  818. $captureTransactionId = $card->getLastTransId();
  819. $captureTransaction = $payment->getTransaction($captureTransactionId);
  820. $realCaptureTransactionId = $captureTransaction->getAdditionalInformation($this->_realTransactionIdKey);
  821. $payment->setAnetTransType(self::REQUEST_TYPE_CREDIT);
  822. $payment->setXTransId($realCaptureTransactionId);
  823. $payment->setAmount($amount);
  824. $request = $this->_buildRequest($payment);
  825. $request->setXCardNum($card->getCcLast4());
  826. $result = $this->_postRequest($request);
  827. switch ($result->getResponseCode()) {
  828. case self::RESPONSE_CODE_APPROVED:
  829. if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_APPROVED) {
  830. $refundTransactionId = $result->getTransactionId() . '-refund';
  831. $shouldCloseCaptureTransaction = 0;
  832. /**
  833. * If it is last amount for refund, transaction with type "capture" will be closed
  834. * and card will has last transaction with type "refund"
  835. */
  836. if ($this->_formatAmount($card->getCapturedAmount() - $card->getRefundedAmount()) == $amount) {
  837. $card->setLastTransId($refundTransactionId);
  838. $shouldCloseCaptureTransaction = 1;
  839. }
  840. return $this->_addTransaction(
  841. $payment,
  842. $refundTransactionId,
  843. Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND,
  844. array(
  845. 'is_transaction_closed' => 1,
  846. 'should_close_parent_transaction' => $shouldCloseCaptureTransaction,
  847. 'parent_transaction_id' => $captureTransactionId
  848. ),
  849. array($this->_realTransactionIdKey => $result->getTransactionId()),
  850. Mage::helper('paygate')->getTransactionMessage(
  851. $payment, self::REQUEST_TYPE_CREDIT, $result->getTransactionId(), $card, $amount
  852. )
  853. );
  854. }
  855. $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
  856. break;
  857. case self::RESPONSE_CODE_DECLINED:
  858. case self::RESPONSE_CODE_ERROR:
  859. $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
  860. break;
  861. default:
  862. $exceptionMessage = Mage::helper('paygate')->__('Payment refunding error.');
  863. break;
  864. }
  865. $exceptionMessage = Mage::helper('paygate')->getTransactionMessage(
  866. $payment, self::REQUEST_TYPE_CREDIT, $realCaptureTransactionId, $card, $amount, $exceptionMessage
  867. );
  868. Mage::throwException($exceptionMessage);
  869. }
  870. /**
  871. * Init cards storage model
  872. *
  873. * @param Mage_Payment_Model_Info $payment
  874. */
  875. protected function _initCardsStorage($payment)
  876. {
  877. $this->_cardsStorage = Mage::getModel('paygate/authorizenet_cards')->setPayment($payment);
  878. }
  879. /**
  880. * Return cards storage model
  881. *
  882. * @param Mage_Payment_Model_Info $payment
  883. * @return Mage_Paygate_Model_Authorizenet_Cards
  884. */
  885. public function getCardsStorage($payment = null)
  886. {
  887. if (is_null($payment)) {
  888. $payment = $this->getInfoInstance();
  889. }
  890. if (is_null($this->_cardsStorage)) {
  891. $this->_initCardsStorage($payment);
  892. }
  893. return $this->_cardsStorage;
  894. }
  895. /**
  896. * If parial authorization is started method will returne true
  897. *
  898. * @param Mage_Payment_Model_Info $payment
  899. * @return bool
  900. */
  901. public function isPartialAuthorization($payment = null)
  902. {
  903. if (is_null($payment)) {
  904. $payment = $this->getInfoInstance();
  905. }
  906. return $payment->getAdditionalInformation($this->_splitTenderIdKey);
  907. }
  908. /**
  909. * Mock capture transaction id in invoice
  910. *
  911. * @param Mage_Sales_Model_Order_Invoice $invoice
  912. * @param Mage_Sales_Model_Order_Payment $payment
  913. * @return Mage_Payment_Model_Method_Abstract
  914. */
  915. public function processInvoice($invoice, $payment)
  916. {
  917. $invoice->setTransactionId(1);
  918. return $this;
  919. }
  920. /**
  921. * Set transaction ID into creditmemo for informational purposes
  922. * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
  923. * @param Mage_Sales_Model_Order_Payment $payment
  924. * @return Mage_Payment_Model_Method_Abstract
  925. */
  926. public function processCreditmemo($creditmemo, $payment)
  927. {
  928. $creditmemo->setTransactionId(1);
  929. return $this;
  930. }
  931. /**
  932. * Fetch transaction details info
  933. *
  934. * Update transaction info if there is one placing transaction only
  935. *
  936. * @param Mage_Payment_Model_Info $payment
  937. * @param string $transactionId
  938. * @return array
  939. */
  940. public function fetchTransactionInfo(Mage_Payment_Model_Info $payment, $transactionId)
  941. {
  942. $cardsStorage = $this->getCardsStorage($payment);
  943. if ($cardsStorage->getCardsCount() != 1) {
  944. return parent::fetchTransactionInfo($payment, $transactionId);
  945. }
  946. $cards = $cardsStorage->getCards();
  947. $card = array_shift($cards);
  948. $transactionId = $card->getLastTransId();
  949. $transaction = $payment->getTransaction($transactionId);
  950. if (!$transaction->getAdditionalInformation($this->_isTransactionFraud)) {
  951. return parent::fetchTransactionInfo($payment, $transactionId);
  952. }
  953. $response = $this->_getTransactionDetails($transactionId);
  954. if ($response->getResponseCode() == self::RESPONSE_CODE_APPROVED) {
  955. $transaction->setAdditionalInformation($this->_isTransactionFraud, false);
  956. $payment->setIsTransactionApproved(true);
  957. } elseif ($response->getResponseReasonCode() == self::RESPONSE_REASON_CODE_PENDING_REVIEW_DECLINED) {
  958. $payment->setIsTransactionDenied(true);
  959. }
  960. return parent::fetchTransactionInfo($payment, $transactionId);
  961. }
  962. /**
  963. * Set split_tender_id to quote payment if neeeded
  964. *
  965. * @param Varien_Object $response
  966. * @param Mage_Sales_Model_Order_Payment $payment
  967. * @return bool
  968. */
  969. protected function _processPartialAuthorizationResponse($response, $orderPayment) {
  970. if (!$response->getSplitTenderId()) {
  971. return false;
  972. }
  973. $quotePayment = $orderPayment->getOrder()->getQuote()->getPayment();
  974. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED);
  975. $exceptionMessage = null;
  976. try {
  977. switch ($response->getResponseCode()) {
  978. case self::RESPONSE_CODE_APPROVED:
  979. $this->_registerCard($response, $orderPayment);
  980. $this->_clearAssignedData($quotePayment);
  981. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_SUCCESS);
  982. return true;
  983. case self::RESPONSE_CODE_HELD:
  984. if ($response->getResponseReasonCode() != self::RESPONSE_REASON_CODE_PARTIAL_APPROVE) {
  985. return false;
  986. }
  987. if ($this->getCardsStorage($orderPayment)->getCardsCount() + 1 >= self::PARTIAL_AUTH_CARDS_LIMIT) {
  988. $this->cancelPartialAuthorization($orderPayment);
  989. $this->_clearAssignedData($quotePayment);
  990. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_CARDS_LIMIT_EXCEEDED);
  991. $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
  992. $exceptionMessage = Mage::helper('paygate')->__('You have reached the maximum number of credit card allowed to be used for the payment.');
  993. break;
  994. }
  995. $orderPayment->setAdditionalInformation($this->_splitTenderIdKey, $response->getSplitTenderId());
  996. $this->_registerCard($response, $orderPayment);
  997. $this->_clearAssignedData($quotePayment);
  998. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_SUCCESS);
  999. $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
  1000. $exceptionMessage = null;
  1001. break;
  1002. case self::RESPONSE_CODE_DECLINED:
  1003. case self::RESPONSE_CODE_ERROR:
  1004. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED);
  1005. $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
  1006. $exceptionMessage = $this->_wrapGatewayError($response->getResponseReasonText());
  1007. break;
  1008. default:
  1009. $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED);
  1010. $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
  1011. $exceptionMessage = $this->_wrapGatewayError(
  1012. Mage::helper('paygate')->__('Payment partial authorization error.')
  1013. );
  1014. }
  1015. } catch (Exception $e) {
  1016. $exceptionMessage = $e->getMessage();
  1017. }
  1018. throw new Mage_Payment_Model_Info_Exception($exceptionMessage);
  1019. }
  1020. /**
  1021. * Return authorize payment request
  1022. *
  1023. * @return Mage_Paygate_Model_Authorizenet_Request
  1024. */
  1025. protected function _getRequest()
  1026. {
  1027. $request = Mage::getModel('paygate/authorizenet_request')
  1028. ->setXVersion(3.1)
  1029. ->setXDelimData('True')
  1030. ->setXRelayResponse('False')
  1031. ->setXTestRequest($this->getConfigData('test') ? 'TRUE' : 'FALSE')
  1032. ->setXLogin($this->getConfigData('login'))
  1033. ->setXTranKey($this->getConfigData('trans_key'));
  1034. return $request;
  1035. }
  1036. /**
  1037. * Prepare request to gateway
  1038. *
  1039. * @link http://www.authorize.net/support/AIM_guide.pdf
  1040. * @param Mage_Payment_Model_Info $payment
  1041. * @return Mage_Paygate_Model_Authorizenet_Request
  1042. */
  1043. protected function _buildRequest(Varien_Object $payment)
  1044. {
  1045. $order = $payment->getOrder();
  1046. $this->setStore($order->getStoreId());
  1047. $request = $this->_getRequest()
  1048. ->setXType($payment->getAnetTransType())
  1049. ->setXMethod(self::REQUEST_METHOD_CC);
  1050. if ($order && $order->getIncrementId()) {
  1051. $request->setXInvoiceNum($order->getIncrementId());
  1052. }
  1053. if($payment->getAmount()){
  1054. $request->setXAmount($payment->getAmount(),2);
  1055. $request->setXCurrencyCode($order->getBaseCurrencyCode());
  1056. }
  1057. switch ($payment->getAnetTransType()) {
  1058. case self::REQUEST_TYPE_AUTH_CAPTURE:
  1059. $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False');
  1060. if ($payment->getAdditionalInformation($this->_splitTenderIdKey)) {
  1061. $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey));
  1062. }
  1063. break;
  1064. case self::REQUEST_TYPE_AUTH_ONLY:
  1065. $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False');
  1066. if ($payment->getAdditionalInformation($this->_splitTenderIdKey)) {
  1067. $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey));
  1068. }
  1069. break;
  1070. case self::REQUEST_TYPE_CREDIT:
  1071. /**
  1072. * Send last 4 digits of credit card number to authorize.net
  1073. * otherwise it will give an error
  1074. */
  1075. $request->setXCardNum($payment->getCcLast4());
  1076. $request->setXTransId($payment->getXTransId());
  1077. break;
  1078. case self::REQUEST_TYPE_VOID:
  1079. $request->setXTransId($payment->getXTransId());
  1080. break;
  1081. case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE:
  1082. $request->setXTransId($payment->getXTransId());
  1083. break;
  1084. case self::REQUEST_TYPE_CAPTURE_ONLY:
  1085. $request->setXAuthCode($payment->getCcAuthCode());
  1086. break;
  1087. }
  1088. if ($this->getIsCentinelValidationEnabled()){
  1089. $params = $this->getCentinelValidator()->exportCmpiData(array());
  1090. $request = Varien_Object_Mapper::accumulateByMap($params, $request, $this->_centinelFieldMap);
  1091. }
  1092. if (!empty($order)) {
  1093. $billing = $order->getBillingAddress();
  1094. if (!empty($billing)) {
  1095. $request->setXFirstName($billing->getFirstname())
  1096. ->setXLastName($billing->getLastname())
  1097. ->setXCompany($billing->getCompany())
  1098. ->setXAddress($billing->getStreet(1))
  1099. ->setXCity($billing->getCity())
  1100. ->setXState($billing->getRegion())
  1101. ->setXZip($billing->getPostcode())
  1102. ->setXCountry($billing->getCountry())
  1103. ->setXPhone($billing->getTelephone())
  1104. ->setXFax($billing->getFax())
  1105. ->setXCustId($order->getCustomerId())
  1106. ->setXCustomerIp($order->getRemoteIp())
  1107. ->setXCustomerTaxId($billing->getTaxId())
  1108. ->setXEmail($order->getCustomerEmail())
  1109. ->setXEmailCustomer($this->getConfigData('email_customer'))
  1110. ->setXMerchantEmail($this->getConfigData('merchant_email'));
  1111. }
  1112. $shipping = $order->getShippingAddress();
  1113. if (!empty($shipping)) {
  1114. $request->setXShipToFirstName($shipping->getFirstname())
  1115. ->setXShipToLastName($shipping->getLastname())
  1116. ->setXShipToCompany($shipping->getCompany())
  1117. ->setXShipToAddress($shipping->getStreet(1))
  1118. ->setXShipToCity($shipping->getCity())
  1119. ->setXShipToState($shipping->getRegion())
  1120. ->setXShipToZip($shipping->getPostcode())
  1121. ->setXShipToCountry($shipping->getCountry());
  1122. }
  1123. $request->setXPoNum($payment->getPoNumber())
  1124. ->setXTax($order->getBaseTaxAmount())
  1125. ->setXFreight($order->getBaseShippingAmount());
  1126. }
  1127. if($payment->getCcNumber()){
  1128. $request->setXCardNum($payment->getCcNumber())
  1129. ->setXExpDate(sprintf('%02d-%04d', $payment->getCcExpMonth(), $payment->getCcExpYear()))
  1130. ->setXCardCode($payment->getCcCid());
  1131. }
  1132. return $request;
  1133. }
  1134. /**
  1135. * Post request to gateway and return responce
  1136. *
  1137. * @param Mageā€¦

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