* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7732 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) exit; class authorizeAIM extends PaymentModule { public function __construct() { $this->name = 'authorizeaim'; $this->tab = 'payments_gateways'; $this->version = '1.0'; $this->author = 'PrestaShop'; $this->limited_countries = array('us'); $this->need_instance = 0; parent::__construct(); $this->displayName = 'Authorize.net AIM (Advanced Integration Method)'; $this->description = $this->l('Receive payment with Authorize.net'); } public function install() { return (parent::install() AND $this->registerHook('orderConfirmation') AND $this->registerHook('payment') AND Configuration::updateValue('AUTHORIZE_AIM_DEMO', 1)); } public function uninstall() { Configuration::deleteByName('AUTHORIZE_AIM_LOGIN_ID'); Configuration::deleteByName('AUTHORIZE_AIM_KEY'); Configuration::deleteByName('AUTHORIZE_AIM_DEMO'); Configuration::deleteByName('AUTHORIZE_AIM_CARD_VISA'); Configuration::deleteByName('AUTHORIZE_AIM_CARD_MASTERCARD'); Configuration::deleteByName('AUTHORIZE_AIM_CARD_DISCOVER'); Configuration::deleteByName('AUTHORIZE_AIM_CARD_AX'); return parent::uninstall(); } public function hookOrderConfirmation($params) { global $smarty; if ($params['objOrder']->module != $this->name) return; if ($params['objOrder']->getCurrentState() != Configuration::get('PS_OS_ERROR')) $smarty->assign(array('status' => 'ok', 'id_order' => intval($params['objOrder']->id))); else $smarty->assign('status', 'failed'); return $this->display(__FILE__, 'hookorderconfirmation.tpl'); } public function getContent() { if (Tools::isSubmit('submitModule')) { Configuration::updateValue('AUTHORIZE_AIM_LOGIN_ID', Tools::getvalue('authorizeaim_login_id')); Configuration::updateValue('AUTHORIZE_AIM_KEY', Tools::getvalue('authorizeaim_key')); Configuration::updateValue('AUTHORIZE_AIM_DEMO', Tools::getvalue('authorizeaim_demo_mode')); Configuration::updateValue('AUTHORIZE_AIM_CARD_VISA', Tools::getvalue('authorizeaim_card_visa')); Configuration::updateValue('AUTHORIZE_AIM_CARD_MASTERCARD', Tools::getvalue('authorizeaim_card_mastercard')); Configuration::updateValue('AUTHORIZE_AIM_CARD_DISCOVER', Tools::getvalue('authorizeaim_card_discover')); Configuration::updateValue('AUTHORIZE_AIM_CARD_AX', Tools::getvalue('authorizeaim_card_ax')); echo $this->displayConfirmation($this->l('Configuration updated')); } return '

'.$this->displayName.'

'.$this->l('Help').'

'.$this->l('In your PrestaShop admin panel').'

- '.$this->l('Fill the Login ID field with the one provided by Authorize.net').'
- '.$this->l('Fill the key field with the transaction key provided by Authorize.net').'
- '.$this->l('Warning: Your website must possess a SSL certificate to use the Authorize.net AIM payment system. You are responsible for the safety of your customers\' bank information. PrestaShop cannot be blamed for any security issue on your website.').'


'.$this->l('Settings').'
'.$this->l('Production').' '.$this->l('Test').'
visa visa visa visa

'; } public function hookPayment($params) { global $cookie, $smarty; if (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off' AND Configuration::get('PS_SSL_ENABLED')) { $invoiceAddress = new Address((int)$params['cart']->id_address_invoice); $customer = new Customer((int)$cookie->id_customer); $authorizeAIMParams = array(); $authorizeAIMParams['x_login'] = Configuration::get('AUTHORIZE_AIM_LOGIN_ID'); $authorizeAIMParams['x_tran_key'] = Configuration::get('AUTHORIZE_AIM_KEY'); $authorizeAIMParams['x_version'] = '3.1'; $authorizeAIMParams['x_delim_data'] = 'TRUE'; $authorizeAIMParams['x_delim_char'] = '|'; $authorizeAIMParams['x_relay_response'] = 'FALSE'; $authorizeAIMParams['x_type'] = 'AUTH_CAPTURE'; $authorizeAIMParams['x_method'] = 'CC'; $authorizeAIMParams['x_test_request'] = Configuration::get('AUTHORIZE_AIM_DEMO'); $authorizeAIMParams['x_invoice_num'] = (int)$params['cart']->id; $authorizeAIMParams['x_amount'] = number_format($params['cart']->getOrderTotal(true, 3), 2, '.', ''); $authorizeAIMParams['x_address'] = $invoiceAddress->address1.' '.$invoiceAddress->address2; $authorizeAIMParams['x_zip'] = $invoiceAddress->postcode; $authorizeAIMParams['x_first_name'] = $customer->firstname; $authorizeAIMParams['x_last_name'] = $customer->lastname; $isFailed = Tools::getValue('aimerror'); $cards = array(); $cards['visa'] = Configuration::get('AUTHORIZE_AIM_CARD_VISA') == 'on' ? 1 : 0; $cards['mastercard'] = Configuration::get('AUTHORIZE_AIM_CARD_MASTERCARD') == 'on' ? 1 : 0; $cards['discover'] = Configuration::get('AUTHORIZE_AIM_CARD_DISCOVER') == 'on' ? 1 : 0; $cards['ax'] = Configuration::get('AUTHORIZE_AIM_CARD_AX') == 'on' ? 1 : 0; $smarty->assign('p', $authorizeAIMParams); $smarty->assign('cards', $cards); $smarty->assign('isFailed', $isFailed); return $this->display(__FILE__, 'authorizeaim.tpl'); } } } ?>