Mage_Paygate_Model_Authorizenet Class Reference

Inheritance diagram for Mage_Paygate_Model_Authorizenet:

Mage_Payment_Model_Method_Cc Mage_Payment_Model_Method_Abstract Varien_Object

List of all members.

Public Member Functions

 canUseForCurrency ($currencyCode)
 authorize (Varien_Object $payment, $amount)
 capture (Varien_Object $payment, $amount)
 void (Varien_Object $payment)
 refund (Varien_Object $payment, $amount)

Public Attributes

const CGI_URL = 'https://secure.authorize.net/gateway/transact.dll'
const REQUEST_METHOD_CC = 'CC'
const REQUEST_METHOD_ECHECK = 'ECHECK'
const REQUEST_TYPE_AUTH_CAPTURE = 'AUTH_CAPTURE'
const REQUEST_TYPE_AUTH_ONLY = 'AUTH_ONLY'
const REQUEST_TYPE_CAPTURE_ONLY = 'CAPTURE_ONLY'
const REQUEST_TYPE_CREDIT = 'CREDIT'
const REQUEST_TYPE_VOID = 'VOID'
const REQUEST_TYPE_PRIOR_AUTH_CAPTURE = 'PRIOR_AUTH_CAPTURE'
const ECHECK_ACCT_TYPE_CHECKING = 'CHECKING'
const ECHECK_ACCT_TYPE_BUSINESS = 'BUSINESSCHECKING'
const ECHECK_ACCT_TYPE_SAVINGS = 'SAVINGS'
const ECHECK_TRANS_TYPE_CCD = 'CCD'
const ECHECK_TRANS_TYPE_PPD = 'PPD'
const ECHECK_TRANS_TYPE_TEL = 'TEL'
const ECHECK_TRANS_TYPE_WEB = 'WEB'
const RESPONSE_DELIM_CHAR = ','
const RESPONSE_CODE_APPROVED = 1
const RESPONSE_CODE_DECLINED = 2
const RESPONSE_CODE_ERROR = 3
const RESPONSE_CODE_HELD = 4

Protected Member Functions

 _buildRequest (Varien_Object $payment)
 _postRequest (Varien_Object $request)

Protected Attributes

 $_code = 'authorizenet'
 $_isGateway = true
 $_canAuthorize = true
 $_canCapture = true
 $_canCapturePartial = false
 $_canRefund = false
 $_canVoid = true
 $_canUseInternal = true
 $_canUseCheckout = true
 $_canUseForMultishipping = true
 $_canSaveCc = false
 $_allowCurrencyCode = array('USD')
 $_debugReplacePrivateDataKeys


Detailed Description

Definition at line 28 of file Authorizenet.php.


Member Function Documentation

_buildRequest ( Varien_Object payment  )  [protected]

Prepare request to gateway

Mage_Sales_Model_Document $order unknown

Definition at line 257 of file Authorizenet.php.

00258     {
00259         $order = $payment->getOrder();
00260 
00261         $this->setStore($order->getStoreId());
00262 
00263         if (!$payment->getAnetTransMethod()) {
00264             $payment->setAnetTransMethod(self::REQUEST_METHOD_CC);
00265         }
00266 
00267         $request = Mage::getModel('paygate/authorizenet_request')
00268             ->setXVersion(3.1)
00269             ->setXDelimData('True')
00270             ->setXDelimChar(self::RESPONSE_DELIM_CHAR)
00271             ->setXRelayResponse('False');
00272 
00273         if ($order && $order->getIncrementId()) {
00274             $request->setXInvoiceNum($order->getIncrementId());
00275         }
00276 
00277         $request->setXTestRequest($this->getConfigData('test') ? 'TRUE' : 'FALSE');
00278 
00279         $request->setXLogin($this->getConfigData('login'))
00280             ->setXTranKey($this->getConfigData('trans_key'))
00281             ->setXType($payment->getAnetTransType())
00282             ->setXMethod($payment->getAnetTransMethod());
00283 
00284         if($payment->getAmount()){
00285             $request->setXAmount($payment->getAmount(),2);
00286             $request->setXCurrencyCode($order->getBaseCurrencyCode());
00287         }
00288         switch ($payment->getAnetTransType()) {
00289             case self::REQUEST_TYPE_CREDIT:
00290             case self::REQUEST_TYPE_VOID:
00291             case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE:
00292                 $request->setXTransId($payment->getCcTransId());
00293                 break;
00294 
00295             case self::REQUEST_TYPE_CAPTURE_ONLY:
00296                 $request->setXAuthCode($payment->getCcAuthCode());
00297                 break;
00298         }
00299 
00300         if (!empty($order)) {
00301             $billing = $order->getBillingAddress();
00302             if (!empty($billing)) {
00303                 $request->setXFirstName($billing->getFirstname())
00304                     ->setXLastName($billing->getLastname())
00305                     ->setXCompany($billing->getCompany())
00306                     ->setXAddress($billing->getStreet(1))
00307                     ->setXCity($billing->getCity())
00308                     ->setXState($billing->getRegion())
00309                     ->setXZip($billing->getPostcode())
00310                     ->setXCountry($billing->getCountry())
00311                     ->setXPhone($billing->getTelephone())
00312                     ->setXFax($billing->getFax())
00313                     ->setXCustId($billing->getCustomerId())
00314                     ->setXCustomerIp($order->getRemoteIp())
00315                     ->setXCustomerTaxId($billing->getTaxId())
00316                     ->setXEmail($order->getCustomerEmail())
00317                     ->setXEmailCustomer($this->getConfigData('email_customer'))
00318                     ->setXMerchantEmail($this->getConfigData('merchant_email'));
00319             }
00320 
00321             $shipping = $order->getShippingAddress();
00322             if (!empty($shipping)) {
00323                 $request->setXShipToFirstName($shipping->getFirstname())
00324                     ->setXShipToLastName($shipping->getLastname())
00325                     ->setXShipToCompany($shipping->getCompany())
00326                     ->setXShipToAddress($shipping->getStreet(1))
00327                     ->setXShipToCity($shipping->getCity())
00328                     ->setXShipToState($shipping->getRegion())
00329                     ->setXShipToZip($shipping->getPostcode())
00330                     ->setXShipToCountry($shipping->getCountry());
00331             }
00332 
00333             $request->setXPoNum($payment->getPoNumber())
00334                 ->setXTax($order->getTaxAmount())
00335                 ->setXFreight($order->getShippingAmount());
00336         }
00337 
00338         switch ($payment->getAnetTransMethod()) {
00339             case self::REQUEST_METHOD_CC:
00340                 if($payment->getCcNumber()){
00341                     $request->setXCardNum($payment->getCcNumber())
00342                         ->setXExpDate(sprintf('%02d-%04d', $payment->getCcExpMonth(), $payment->getCcExpYear()))
00343                         ->setXCardCode($payment->getCcCid());
00344                 }
00345                 break;
00346 
00347             case self::REQUEST_METHOD_ECHECK:
00348                 $request->setXBankAbaCode($payment->getEcheckRoutingNumber())
00349                     ->setXBankName($payment->getEcheckBankName())
00350                     ->setXBankAcctNum($payment->getEcheckAccountNumber())
00351                     ->setXBankAcctType($payment->getEcheckAccountType())
00352                     ->setXBankAcctName($payment->getEcheckAccountName())
00353                     ->setXEcheckType($payment->getEcheckType());
00354                 break;
00355         }
00356 
00357         return $request;
00358     }

_postRequest ( Varien_Object request  )  [protected]

Definition at line 360 of file Authorizenet.php.

00361     {
00362         $result = Mage::getModel('paygate/authorizenet_result');
00363 
00364         $client = new Varien_Http_Client();
00365 
00366         $uri = $this->getConfigData('cgi_url');
00367         $client->setUri($uri ? $uri : self::CGI_URL);
00368         $client->setConfig(array(
00369             'maxredirects'=>0,
00370             'timeout'=>30,
00371             //'ssltransport' => 'tcp',
00372         ));
00373         $client->setParameterPost($request->getData());
00374         $client->setMethod(Zend_Http_Client::POST);
00375 
00376         if ($this->getConfigData('debug')) {
00377             $requestDebug = clone $request;
00378 
00379             foreach ($this->_debugReplacePrivateDataKeys as $key) {
00380                 if ($requestDebug->hasData($key)) {
00381                     $requestDebug->setData($key, '***');
00382                 }
00383             }
00384 
00385             foreach( $requestDebug->getData() as $key => $value ) {
00386                 $requestData[] = strtoupper($key) . '=' . $value;
00387             }
00388 
00389             $requestData = join('&', $requestData);
00390 
00391             $debug = Mage::getModel('paygate/authorizenet_debug')
00392                 ->setRequestBody($requestData)
00393                 ->setRequestSerialized(serialize($requestDebug->getData()))
00394                 ->setRequestDump(print_r($requestDebug->getData(),1))
00395                 ->save();
00396         }
00397 
00398         try {
00399             $response = $client->request();
00400         } catch (Exception $e) {
00401             $result->setResponseCode(-1)
00402                 ->setResponseReasonCode($e->getCode())
00403                 ->setResponseReasonText($e->getMessage());
00404 
00405             if (!empty($debug)) {
00406                 $debug
00407                     ->setResultSerialized(serialize($result->getData()))
00408                     ->setResultDump(print_r($result->getData(),1))
00409                     ->save();
00410             }
00411             Mage::throwException(
00412                 Mage::helper('paygate')->__('Gateway request error: %s', $e->getMessage())
00413             );
00414         }
00415 
00416         $responseBody = $response->getBody();
00417 
00418         $r = explode(self::RESPONSE_DELIM_CHAR, $responseBody);
00419 
00420         if ($r) {
00421             $result->setResponseCode((int)str_replace('"','',$r[0]))
00422                 ->setResponseSubcode((int)str_replace('"','',$r[1]))
00423                 ->setResponseReasonCode((int)str_replace('"','',$r[2]))
00424                 ->setResponseReasonText($r[3])
00425                 ->setApprovalCode($r[4])
00426                 ->setAvsResultCode($r[5])
00427                 ->setTransactionId($r[6])
00428                 ->setInvoiceNumber($r[7])
00429                 ->setDescription($r[8])
00430                 ->setAmount($r[9])
00431                 ->setMethod($r[10])
00432                 ->setTransactionType($r[11])
00433                 ->setCustomerId($r[12])
00434                 ->setMd5Hash($r[37])
00435                 ->setCardCodeResponseCode($r[39]);
00436         } else {
00437              Mage::throwException(
00438                 Mage::helper('paygate')->__('Error in payment gateway')
00439             );
00440         }
00441 
00442         if (!empty($debug)) {
00443             $debug
00444                 ->setResponseBody($responseBody)
00445                 ->setResultSerialized(serialize($result->getData()))
00446                 ->setResultDump(print_r($result->getData(),1))
00447                 ->save();
00448         }
00449 
00450         return $result;
00451     }

authorize ( Varien_Object payment,
amount 
)

Send authorize request to gateway

Parameters:
Varien_Object $payment
decimal $amount
Returns:
Mage_Paygate_Model_Authorizenet

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 109 of file Authorizenet.php.

00110     {
00111         $error = false;
00112 
00113         if($amount>0){
00114             $payment->setAnetTransType(self::REQUEST_TYPE_AUTH_ONLY);
00115             $payment->setAmount($amount);
00116 
00117             $request= $this->_buildRequest($payment);
00118             $result = $this->_postRequest($request);
00119 
00120             $payment->setCcApproval($result->getApprovalCode())
00121                 ->setLastTransId($result->getTransactionId())
00122                 ->setCcTransId($result->getTransactionId())
00123                 ->setCcAvsStatus($result->getAvsResultCode())
00124                 ->setCcCidStatus($result->getCardCodeResponseCode());
00125 
00126             switch ($result->getResponseCode()) {
00127                 case self::RESPONSE_CODE_APPROVED:
00128                     $payment->setStatus(self::STATUS_APPROVED);
00129                     break;
00130                 case self::RESPONSE_CODE_DECLINED:
00131                     $error = Mage::helper('paygate')->__('Payment authorization transaction has been declined.');
00132                     break;
00133                 default:
00134                     $error = Mage::helper('paygate')->__('Payment authorization error.');
00135                     break;
00136             }
00137         }else{
00138             $error = Mage::helper('paygate')->__('Invalid amount for authorization.');
00139         }
00140 
00141         if ($error !== false) {
00142             Mage::throwException($error);
00143         }
00144         return $this;
00145     }

canUseForCurrency ( currencyCode  ) 

Check method for processing with base currency

Parameters:
string $currencyCode
Returns:
boolean

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 94 of file Authorizenet.php.

00095     {
00096         if (!in_array($currencyCode, $this->_allowCurrencyCode)) {
00097             return false;
00098         }
00099         return true;
00100     }

capture ( Varien_Object payment,
amount 
)

Capture payment

Parameters:
Varien_Object $orderPayment
Returns:
Mage_Payment_Model_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 148 of file Authorizenet.php.

00149     {
00150         $error = false;
00151 
00152         if ($payment->getCcTransId()) {
00153             $payment->setAnetTransType(self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE);
00154         } else {
00155             $payment->setAnetTransType(self::REQUEST_TYPE_AUTH_CAPTURE);
00156         }
00157 
00158         $payment->setAmount($amount);
00159 
00160         $request= $this->_buildRequest($payment);
00161         $result = $this->_postRequest($request);
00162 
00163         if ($result->getResponseCode() == self::RESPONSE_CODE_APPROVED) {
00164             $payment->setStatus(self::STATUS_APPROVED);
00165             //$payment->setCcTransId($result->getTransactionId());
00166             $payment->setLastTransId($result->getTransactionId());
00167         }
00168         else {
00169             if ($result->getResponseReasonText()) {
00170                 $error = $result->getResponseReasonText();
00171             }
00172             else {
00173                 $error = Mage::helper('paygate')->__('Error in capturing the payment');
00174             }
00175         }
00176 
00177         if ($error !== false) {
00178             Mage::throwException($error);
00179         }
00180 
00181         return $this;
00182     }

refund ( Varien_Object payment,
amount 
)

refund the amount with transaction id

public

Parameters:
string $payment Varien_Object object
Returns:
Mage_Payment_Model_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 225 of file Authorizenet.php.

00226     {
00227         $error = false;
00228         if ($payment->getRefundTransactionId() && $amount>0) {
00229             $payment->setAnetTransType(self::REQUEST_TYPE_CREDIT);
00230             $request = $this->_buildRequest($payment);
00231             $request->setXTransId($payment->getRefundTransactionId());
00232             $result = $this->_postRequest($request);
00233 
00234             if ($result->getResponseCode()==self::RESPONSE_CODE_APPROVED) {
00235                 $payment->setStatus(self::STATUS_SUCCESS);
00236             } else {
00237                 $error = $result->getResponseReasonText();
00238             }
00239 
00240         } else {
00241             $error = Mage::helper('paygate')->__('Error in refunding the payment');
00242         }
00243 
00244         if ($error !== false) {
00245             Mage::throwException($error);
00246         }
00247         return $this;
00248     }

void ( Varien_Object payment  ) 

void

Author:
Magento Core Team <core@magentocommerce.com> public
Parameters:
string $payment Varien_Object object
Returns:
Mage_Payment_Model_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 193 of file Authorizenet.php.

00194     {
00195         $error = false;
00196         if($payment->getVoidTransactionId()){
00197             $payment->setAnetTransType(self::REQUEST_TYPE_VOID);
00198             $request = $this->_buildRequest($payment);
00199                         $request->setXTransId($payment->getVoidTransactionId());
00200             $result = $this->_postRequest($request);
00201             if($result->getResponseCode()==self::RESPONSE_CODE_APPROVED){
00202                  $payment->setStatus(self::STATUS_SUCCESS );
00203             }
00204             else{
00205                 $payment->setStatus(self::STATUS_ERROR);
00206                 $error = $result->getResponseReasonText();
00207             }
00208         }else{
00209             $payment->setStatus(self::STATUS_ERROR);
00210             $error = Mage::helper('paygate')->__('Invalid transaction id');
00211         }
00212         if ($error !== false) {
00213             Mage::throwException($error);
00214         }
00215         return $this;
00216     }


Member Data Documentation

$_allowCurrencyCode = array('USD') [protected]

Definition at line 74 of file Authorizenet.php.

$_canAuthorize = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 64 of file Authorizenet.php.

$_canCapture = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 65 of file Authorizenet.php.

$_canCapturePartial = false [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 66 of file Authorizenet.php.

$_canRefund = false [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 67 of file Authorizenet.php.

$_canSaveCc = false [protected]

Reimplemented from Mage_Payment_Model_Method_Cc.

Definition at line 72 of file Authorizenet.php.

$_canUseCheckout = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 70 of file Authorizenet.php.

$_canUseForMultishipping = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 71 of file Authorizenet.php.

$_canUseInternal = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 69 of file Authorizenet.php.

$_canVoid = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 68 of file Authorizenet.php.

$_code = 'authorizenet' [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 58 of file Authorizenet.php.

$_debugReplacePrivateDataKeys [protected]

Initial value:

 array('x_login', 'x_tran_key',
                                                    'x_card_num', 'x_exp_date',
                                                    'x_card_code', 'x_bank_aba_code',
                                                    'x_bank_name', 'x_bank_acct_num',
                                                    'x_bank_acct_type','x_bank_acct_name',
                                                    'x_echeck_type')

Definition at line 81 of file Authorizenet.php.

$_isGateway = true [protected]

Availability options

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 63 of file Authorizenet.php.

const CGI_URL = 'https://secure.authorize.net/gateway/transact.dll'

Definition at line 30 of file Authorizenet.php.

const ECHECK_ACCT_TYPE_BUSINESS = 'BUSINESSCHECKING'

Definition at line 43 of file Authorizenet.php.

const ECHECK_ACCT_TYPE_CHECKING = 'CHECKING'

Definition at line 42 of file Authorizenet.php.

const ECHECK_ACCT_TYPE_SAVINGS = 'SAVINGS'

Definition at line 44 of file Authorizenet.php.

const ECHECK_TRANS_TYPE_CCD = 'CCD'

Definition at line 46 of file Authorizenet.php.

const ECHECK_TRANS_TYPE_PPD = 'PPD'

Definition at line 47 of file Authorizenet.php.

const ECHECK_TRANS_TYPE_TEL = 'TEL'

Definition at line 48 of file Authorizenet.php.

const ECHECK_TRANS_TYPE_WEB = 'WEB'

Definition at line 49 of file Authorizenet.php.

const REQUEST_METHOD_CC = 'CC'

Definition at line 32 of file Authorizenet.php.

const REQUEST_METHOD_ECHECK = 'ECHECK'

Definition at line 33 of file Authorizenet.php.

const REQUEST_TYPE_AUTH_CAPTURE = 'AUTH_CAPTURE'

Definition at line 35 of file Authorizenet.php.

const REQUEST_TYPE_AUTH_ONLY = 'AUTH_ONLY'

Definition at line 36 of file Authorizenet.php.

const REQUEST_TYPE_CAPTURE_ONLY = 'CAPTURE_ONLY'

Definition at line 37 of file Authorizenet.php.

const REQUEST_TYPE_CREDIT = 'CREDIT'

Definition at line 38 of file Authorizenet.php.

const REQUEST_TYPE_PRIOR_AUTH_CAPTURE = 'PRIOR_AUTH_CAPTURE'

Definition at line 40 of file Authorizenet.php.

const REQUEST_TYPE_VOID = 'VOID'

Definition at line 39 of file Authorizenet.php.

Definition at line 53 of file Authorizenet.php.

Definition at line 54 of file Authorizenet.php.

Definition at line 55 of file Authorizenet.php.

const RESPONSE_CODE_HELD = 4

Definition at line 56 of file Authorizenet.php.

const RESPONSE_DELIM_CHAR = ','

Definition at line 51 of file Authorizenet.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:31 2009 for Magento by  doxygen 1.5.8