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_Centinel_Adminhtml_Centinel_IndexController
  • Mage_Centinel_Block_Adminhtml_Validation
  • Mage_Centinel_Block_Adminhtml_Validation_Form
  • Mage_Centinel_Block_Authentication
  • Mage_Centinel_Block_Authentication_Complete
  • Mage_Centinel_Block_Authentication_Start
  • Mage_Centinel_Block_Logo
  • Mage_Centinel_Helper_Data
  • Mage_Centinel_IndexController
  • Mage_Centinel_Model_Api
  • Mage_Centinel_Model_Config
  • Mage_Centinel_Model_Observer
  • Mage_Centinel_Model_Service
  • Mage_Centinel_Model_Session
  • Mage_Centinel_Model_State_Jcb
  • Mage_Centinel_Model_State_Mastercard
  • Mage_Centinel_Model_State_Visa
  • Mage_Centinel_Model_StateAbstract
  • 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_Centinel
 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:  * 3D Secure Validation Library for Payment
 29:  */
 30: include_once '3Dsecure/CentinelClient.php';
 31: 
 32: /**
 33:  * 3D Secure Validation Api
 34:  */
 35: class Mage_Centinel_Model_Api extends Varien_Object
 36: {
 37:     /**
 38:      * Fields that should be replaced in debug with '***'
 39:      *
 40:      * @var array
 41:      */
 42:     protected $_debugReplacePrivateDataKeys = array('TransactionPwd', 'CardNumber', 'CardExpMonth', 'CardExpYear');
 43: 
 44:     protected static $_iso4217Currencies = array(
 45:         'AED' => '784', 'AFN' => '971',
 46:         'ALL' => '008', 'AMD' => '051', 'ANG' => '532', 'AOA' => '973', 'ARS' => '032', 'AUD' => '036', 'AWG' => '533',
 47:         'AZN' => '944', 'BAM' => '977', 'BBD' => '052', 'BDT' => '050', 'BGN' => '975', 'BHD' => '048', 'BIF' => '108',
 48:         'BMD' => '060', 'BND' => '096', 'BOB' => '068', 'BOV' => '984', 'BRL' => '986', 'BSD' => '044', 'BTN' => '064',
 49:         'BWP' => '072', 'BYR' => '974', 'BZD' => '084', 'CAD' => '124', 'CDF' => '976', 'CHE' => '947', 'CHF' => '756',
 50:         'CHW' => '948', 'CLF' => '990', 'CLP' => '152', 'CNY' => '156', 'COP' => '170', 'COU' => '970', 'CRC' => '188',
 51:         'CUC' => '931', 'CUP' => '192', 'CVE' => '132', 'CZK' => '203', 'DJF' => '262', 'DKK' => '208', 'DOP' => '214',
 52:         'DZD' => '012', 'EEK' => '233', 'EGP' => '818', 'ERN' => '232', 'ETB' => '230', 'EUR' => '978', 'FJD' => '242',
 53:         'FKP' => '238', 'GBP' => '826', 'GEL' => '981', 'GHS' => '936', 'GIP' => '292', 'GMD' => '270', 'GNF' => '324',
 54:         'GTQ' => '320', 'GYD' => '328', 'HKD' => '344', 'HNL' => '340', 'HRK' => '191', 'HTG' => '332', 'HUF' => '348',
 55:         'IDR' => '360', 'ILS' => '376', 'INR' => '356', 'IQD' => '368', 'IRR' => '364', 'ISK' => '352', 'JMD' => '388',
 56:         'JOD' => '400', 'JPY' => '392', 'KES' => '404', 'KGS' => '417', 'KHR' => '116', 'KMF' => '174', 'KPW' => '408',
 57:         'KRW' => '410', 'KWD' => '414', 'KYD' => '136', 'KZT' => '398', 'LAK' => '418', 'LBP' => '422', 'LKR' => '144',
 58:         'LRD' => '430', 'LSL' => '426', 'LTL' => '440', 'LVL' => '428', 'LYD' => '434', 'MAD' => '504', 'MDL' => '498',
 59:         'MGA' => '969', 'MKD' => '807', 'MMK' => '104', 'MNT' => '496', 'MOP' => '446', 'MRO' => '478', 'MUR' => '480',
 60:         'MVR' => '462', 'MWK' => '454', 'MXN' => '484', 'MXV' => '979', 'MYR' => '458', 'MZN' => '943', 'NAD' => '516',
 61:         'NGN' => '566', 'NIO' => '558', 'NOK' => '578', 'NPR' => '524', 'NZD' => '554', 'OMR' => '512', 'PAB' => '590',
 62:         'PEN' => '604', 'PGK' => '598', 'PHP' => '608', 'PKR' => '586', 'PLN' => '985', 'PYG' => '600', 'QAR' => '634',
 63:         'RON' => '946', 'RSD' => '941', 'RUB' => '643', 'RWF' => '646', 'SAR' => '682', 'SBD' => '090', 'SCR' => '690',
 64:         'SDG' => '938', 'SEK' => '752', 'SGD' => '702', 'SHP' => '654', 'SLL' => '694', 'SOS' => '706', 'SRD' => '968',
 65:         'STD' => '678', 'SYP' => '760', 'SZL' => '748', 'THB' => '764', 'TJS' => '972', 'TMT' => '934', 'TND' => '788',
 66:         'TOP' => '776', 'TRY' => '949', 'TTD' => '780', 'TWD' => '901', 'TZS' => '834', 'UAH' => '980', 'UGX' => '800',
 67:         'USD' => '840', 'USN' => '997', 'USS' => '998', 'UYU' => '858', 'UZS' => '860', 'VEF' => '937', 'VND' => '704',
 68:         'VUV' => '548', 'WST' => '882', 'XAF' => '950', 'XAG' => '961', 'XAU' => '959', 'XBA' => '955', 'XBB' => '956',
 69:         'XBC' => '957', 'XBD' => '958', 'XCD' => '951', 'XDR' => '960', 'XOF' => '952', 'XPD' => '964', 'XPF' => '953',
 70:         'XPT' => '962', 'XTS' => '963', 'XXX' => '999', 'YER' => '886', 'ZAR' => '710', 'ZMK' => '894', 'ZWL' => '932',
 71:     );
 72: 
 73:     /**
 74:      * Centinel validation client
 75:      *
 76:      * @var CentinelClient
 77:      */
 78:     protected $_clientInstance = null;
 79: 
 80:     /**
 81:      * Return Centinel thin client object
 82:      *
 83:      * @return CentinelClient
 84:      */
 85:     protected function _getClientInstance()
 86:     {
 87:         if (empty($this->_clientInstance)) {
 88:             $this->_clientInstance = new CentinelClient();
 89:         }
 90:         return $this->_clientInstance;
 91:     }
 92: 
 93:     /**
 94:      * Return Centinel Api version
 95:      *
 96:      * @return string
 97:      */
 98:     protected function _getVersion()
 99:     {
100:         return '1.7';
101:     }
102: 
103:     /**
104:      * Return transaction type. according centinel documetation it should be "C"
105:      *
106:      * @return "C"
107:      */
108:     protected function _getTransactionType()
109:     {
110:         return 'C';
111:     }
112: 
113:     /**
114:      * Return Timeout Connect
115:      *
116:      * @return int
117:      */
118:     protected function _getTimeoutConnect()
119:     {
120:         return 100;
121:     }
122: 
123:     /**
124:      * Return Timeout Read
125:      *
126:      * @return int
127:      */
128:     protected function _getTimeoutRead()
129:     {
130:         return 100;
131:     }
132: 
133:     /**
134:      * Call centinel api methods by given method name and data
135:      *
136:      * @param $method string
137:      * @param $data array
138:      *
139:      * @return CentinelClient
140:      */
141:     protected function _call($method, $data)
142:     {
143:         $client = $this->_getClientInstance();
144:         $request = array_merge(array(
145:             'MsgType'         => $method,
146:             'Version'         => $this->_getVersion(),
147:             'ProcessorId'     => $this->getProcessorId(),
148:             'MerchantId'      => $this->getMerchantId(),
149:             'TransactionPwd'  => $this->getTransactionPwd(),
150:             'TransactionType' => $this->_getTransactionType(),
151:         ), $data);
152: 
153:         $debugData = array('request' => $request);
154: 
155:         try {
156:             foreach($request as $key => $val) {
157:                 $client->add($key, $val);
158:             }
159:             $client->sendHttp($this->_getApiEndpointUrl(), $this->_getTimeoutConnect(), $this->_getTimeoutRead());
160:         } catch (Exception $e) {
161:             $debugData['response'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
162:             $this->_debug($debugData);
163:             throw $e;
164:         }
165: 
166:         $debugData['response'] = $client->response;
167:         $this->_debug($debugData);
168: 
169:         return $client;
170:     }
171: 
172:     /**
173:      * Getter for API call URL
174:      *
175:      * @return string
176:      * @throws Exception
177:      */
178:     protected function _getApiEndpointUrl()
179:     {
180:         if ($this->getIsTestMode()) {
181:             return 'https://centineltest.cardinalcommerce.com/maps/txns.asp';
182:         }
183:         $url = $this->getApiEndpointUrl();
184:         if (!$url) {
185:             throw new Exception('Centinel API endpoint URL is not configured properly.');
186:         }
187:         return $url;
188:     }
189: 
190:     /**
191:      * Call centinel api lookup method
192:      *
193:      * @return Mage_Centinel_Model_Api
194:      */
195:     public function callLookup($data)
196:     {
197:         $result = new Varien_Object();
198: 
199:         $month = strlen($data->getCardExpMonth()) == 1 ? '0' . $data->getCardExpMonth() : $data->getCardExpMonth();
200:         $currencyCode = $data->getCurrencyCode();
201:         $currencyNumber = isset(self::$_iso4217Currencies[$currencyCode]) ? self::$_iso4217Currencies[$currencyCode] : '';
202:         if (!$currencyNumber) {
203:             return $result->setErrorNo(1)->setErrorDesc(
204:                 Mage::helper('payment')->__('Unsupported currency code: %s.', $currencyCode)
205:             );
206:         }
207: 
208:         $clientResponse = $this->_call('cmpi_lookup', array(
209:             'Amount' => round($data->getAmount() * 100),
210:             'CurrencyCode' => $currencyNumber,
211:             'CardNumber' =>  $data->getCardNumber(),
212:             'CardExpMonth'=> $month,
213:             'CardExpYear' =>  $data->getCardExpYear(),
214:             'OrderNumber' => $data->getOrderNumber()
215:         ));
216: 
217:         $result->setErrorNo($clientResponse->getValue('ErrorNo'));
218:         $result->setErrorDesc($clientResponse->getValue('ErrorDesc'));
219:         $result->setTransactionId($clientResponse->getValue('TransactionId'));
220:         $result->setEnrolled($clientResponse->getValue('Enrolled'));
221:         $result->setAcsUrl($clientResponse->getValue('ACSUrl'));
222:         $result->setPayload($clientResponse->getValue('Payload'));
223:         $result->setEciFlag($clientResponse->getValue('EciFlag'));
224: 
225:         return $result;
226:     }
227: 
228:     /**
229:      * Call centinel api authentication method
230:      *
231:      * @return Mage_Centinel_Model_Api
232:      */
233:     public function callAuthentication($data)
234:     {
235:         $result = new Varien_Object();
236: 
237:         $clientResponse = $this->_call('cmpi_authenticate', array(
238:             'TransactionId' => $data->getTransactionId(),
239:             'PAResPayload'  => $data->getPaResPayload(),
240:         ));
241: 
242:         $result->setErrorNo($clientResponse->getValue('ErrorNo'));
243:         $result->setErrorDesc($clientResponse->getValue('ErrorDesc'));
244:         $result->setPaResStatus($clientResponse->getValue('PAResStatus'));
245:         $result->setSignatureVerification($clientResponse->getValue('SignatureVerification'));
246:         $result->setCavv($clientResponse->getValue('Cavv'));
247:         $result->setEciFlag($clientResponse->getValue('EciFlag'));
248:         $result->setXid($clientResponse->getValue('Xid'));
249: 
250:         return $result;
251:     }
252: 
253:     /**
254:      * Log debug data to file
255:      *
256:      * @param mixed $debugData
257:      */
258:     protected function _debug($debugData)
259:     {
260:         if ($this->getDebugFlag()) {
261:             Mage::getModel('core/log_adapter', 'card_validation_3d_secure.log')
262:                ->setFilterDataKeys($this->_debugReplacePrivateDataKeys)
263:                ->log($debugData);
264:         }
265:     }
266: }
267: 
268: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0