Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Authorizenet_Block_Directpost_Form
  • Mage_Authorizenet_Block_Directpost_Iframe
  • Mage_Authorizenet_Directpost_PaymentController
  • Mage_Authorizenet_Helper_Data
  • Mage_Authorizenet_Model_Directpost
  • Mage_Authorizenet_Model_Directpost_Observer
  • Mage_Authorizenet_Model_Directpost_Request
  • Mage_Authorizenet_Model_Directpost_Response
  • Mage_Authorizenet_Model_Directpost_Session
  • Overview
  • Package
  • Class
  • Tree
  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_Authorizenet
 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: 
 27: /**
 28:  * Authorize.net request model for DirectPost model.
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_Authorizenet
 32:  * @author     Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Authorizenet_Model_Directpost_Request extends Varien_Object
 35: {
 36:     protected $_transKey = null;
 37: 
 38:     /**
 39:      * Return merchant transaction key.
 40:      * Needed to generate sign.
 41:      *
 42:      * @return string
 43:      */
 44:     protected function _getTransactionKey()
 45:     {
 46:         return $this->_transKey;
 47:     }
 48: 
 49:     /**
 50:      * Set merchant transaction key.
 51:      * Needed to generate sign.
 52:      *
 53:      * @param string $transKey
 54:      * @return Mage_Authorizenet_Model_Directpost_Request
 55:      */
 56:     protected function _setTransactionKey($transKey)
 57:     {
 58:         $this->_transKey = $transKey;
 59:         return $this;
 60:     }
 61: 
 62:     /**
 63:      * Generates the fingerprint for request.
 64:      *
 65:      * @param string $merchantApiLoginId
 66:      * @param string $merchantTransactionKey
 67:      * @param string $amount
 68:      * @param string $fpSequence An invoice number or random number.
 69:      * @param string $fpTimestamp
 70:      * @return string The fingerprint.
 71:      */
 72:     public function generateRequestSign($merchantApiLoginId, $merchantTransactionKey, $amount, $currencyCode, $fpSequence, $fpTimestamp)
 73:     {
 74:         if (phpversion() >= '5.1.2') {
 75:             return hash_hmac("md5",
 76:                 $merchantApiLoginId . "^" .
 77:                 $fpSequence . "^" .
 78:                 $fpTimestamp . "^" .
 79:                 $amount . "^" .
 80:                 $currencyCode, $merchantTransactionKey
 81:             );
 82:         }
 83: 
 84:         return bin2hex(mhash(MHASH_MD5,
 85:             $merchantApiLoginId . "^" .
 86:             $fpSequence . "^" .
 87:             $fpTimestamp . "^" .
 88:             $amount . "^" .
 89:             $currencyCode, $merchantTransactionKey
 90:         ));
 91:     }
 92: 
 93:     /**
 94:      * Set paygate data to request.
 95:      *
 96:      * @param Mage_Authorizenet_Model_Directpost $paymentMethod
 97:      * @return Mage_Authorizenet_Model_Directpost_Request
 98:      */
 99:     public function setConstantData(Mage_Authorizenet_Model_Directpost $paymentMethod)
100:     {
101:         $this->setXVersion('3.1')
102:             ->setXDelimData('FALSE')
103:             ->setXRelayResponse('TRUE');
104: 
105:         $this->setXTestRequest($paymentMethod->getConfigData('test') ? 'TRUE' : 'FALSE');
106: 
107:         $this->setXLogin($paymentMethod->getConfigData('login'))
108:             ->setXType('AUTH_ONLY')
109:             ->setXMethod(Mage_Paygate_Model_Authorizenet::REQUEST_METHOD_CC)
110:             ->setXRelayUrl($paymentMethod->getRelayUrl());
111: 
112:         $this->_setTransactionKey($paymentMethod->getConfigData('trans_key'));
113:         return $this;
114:     }
115: 
116:     /**
117:      * Set entity data to request
118:      *
119:      * @param Mage_Sales_Model_Order $order
120:      * @param Mage_Authorizenet_Model_Directpost $paymentMethod
121:      * @return Mage_Authorizenet_Model_Directpost_Request
122:      */
123:     public function setDataFromOrder(Mage_Sales_Model_Order $order, Mage_Authorizenet_Model_Directpost $paymentMethod)
124:     {
125:         $payment = $order->getPayment();
126: 
127:         $this->setXFpSequence($order->getQuoteId());
128:         $this->setXInvoiceNum($order->getIncrementId());
129:         $this->setXAmount($payment->getBaseAmountAuthorized());
130:         $this->setXCurrencyCode($order->getBaseCurrencyCode());
131:         $this->setXTax(sprintf('%.2F', $order->getBaseTaxAmount()))
132:             ->setXFreight(sprintf('%.2F', $order->getBaseShippingAmount()));
133: 
134:         //need to use strval() because NULL values IE6-8 decodes as "null" in JSON in JavaScript, but we need "" for null values.
135:         $billing = $order->getBillingAddress();
136:         if (!empty($billing)) {
137:             $this->setXFirstName(strval($billing->getFirstname()))
138:                 ->setXLastName(strval($billing->getLastname()))
139:                 ->setXCompany(strval($billing->getCompany()))
140:                 ->setXAddress(strval($billing->getStreet(1)))
141:                 ->setXCity(strval($billing->getCity()))
142:                 ->setXState(strval($billing->getRegion()))
143:                 ->setXZip(strval($billing->getPostcode()))
144:                 ->setXCountry(strval($billing->getCountry()))
145:                 ->setXPhone(strval($billing->getTelephone()))
146:                 ->setXFax(strval($billing->getFax()))
147:                 ->setXCustId(strval($billing->getCustomerId()))
148:                 ->setXCustomerIp(strval($order->getRemoteIp()))
149:                 ->setXCustomerTaxId(strval($billing->getTaxId()))
150:                 ->setXEmail(strval($order->getCustomerEmail()))
151:                 ->setXEmailCustomer(strval($paymentMethod->getConfigData('email_customer')))
152:                 ->setXMerchantEmail(strval($paymentMethod->getConfigData('merchant_email')));
153:         }
154: 
155:         $shipping = $order->getShippingAddress();
156:         if (!empty($shipping)) {
157:             $this->setXShipToFirstName(strval($shipping->getFirstname()))
158:                 ->setXShipToLastName(strval($shipping->getLastname()))
159:                 ->setXShipToCompany(strval($shipping->getCompany()))
160:                 ->setXShipToAddress(strval($shipping->getStreet(1)))
161:                 ->setXShipToCity(strval($shipping->getCity()))
162:                 ->setXShipToState(strval($shipping->getRegion()))
163:                 ->setXShipToZip(strval($shipping->getPostcode()))
164:                 ->setXShipToCountry(strval($shipping->getCountry()));
165:         }
166: 
167:         $this->setXPoNum(strval($payment->getPoNumber()));
168: 
169:         return $this;
170:     }
171: 
172:     /**
173:      * Set sign hash into the request object.
174:      * All needed fields should be placed in the object fist.
175:      *
176:      * @return Mage_Authorizenet_Model_Directpost_Request
177:      */
178:     public function signRequestData()
179:     {
180:         $fpTimestamp = time();
181:         $hash = $this->generateRequestSign(
182:             $this->getXLogin(),
183:             $this->_getTransactionKey(),
184:             $this->getXAmount(),
185:             $this->getXCurrencyCode(),
186:             $this->getXFpSequence(),
187:             $fpTimestamp
188:         );
189:         $this->setXFpTimestamp($fpTimestamp);
190:         $this->setXFpHash($hash);
191:         return $this;
192:     }
193: }
194: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0