我已为Prestashop安装了付款模块。并出现此错误: 无法重新声明类PaymentModuleCore 。我看到了什么,我尝试在第26行重新声明扩展Class,但我不知道如何解决这个问题。请帮帮我......谢谢您的理解!
<?php
/*
* AirPay - Payment System
* Contact: Vitaliy Andrianov <v@airpay.lv>; www.airpay.lv
* Version: 1.2
* Date: 23.05.2012
* Updated: 23.05.2012
*/
require_once(dirname(__FILE__).'/airpay.class.php');
/* For debugging */
if (!(defined('AIRPAY_DEBUG') && AIRPAY_DEBUG == true) || !isset($_fpp))
{
class fpp_airpay
{
public function log() { }
public function info() { }
public function warn() { }
}
$_fpp = new fpp_airpay();
}
class AIRPAY extends PaymentModuleCore
{
private $_html = '';
private $_postErrors = array();
public function __construct()
{
$this->name = 'airpay';
$this->tab = 'payments_gateways';
$this->version = '1.0.0';
parent::__construct();
/* The parent construct is required for translations */
$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('AirPay');
$this->description = $this->l('Accepts payments by AirPay');
$this->confirmUninstall = $this->l('Are you sure you want to delete your details?');
$config = Configuration::getMultiple(array('AIRPAY_MERCHANTID', 'AIRPAY_SECRETKEY'));
if (isset($config['AIRPAY_MERCHANTID']))
{
$this->merchantid = $config['AIRPAY_MERCHANTID'];
}
if (isset($config['AIRPAY_SECRETKEY']))
{
$this->secretkey = $config['AIRPAY_SECRETKEY'];
}
if (!isset($this->merchantid) OR !isset($this->secretkey))
{
$this->warning = $this->l('Merchant ID and secret key must be configured in order to use this module correctly');
}
}
public function install()
{
/* This is for logging payment selection events */
$query = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'airpay_orders` (
`id` int(11) NOT NULL auto_increment,
`order_id` varchar(30) NOT NULL default \'\',
`rel_order_id` varchar(25) NOT NULL default \'\' COMMENT \'order_num\',
`email` varchar(70) NOT NULL default \'\',
`amount` int(10) default \'0\',
`currency` varchar(3) NOT NULL default \'EUR\',
`date` datetime default \'0000-00-00 00:00:00\',
`statuss` varchar(25) default NULL,
`ip` varchar(15) default NULL,
PRIMARY KEY (`id`),
KEY `email` (`email`),
KEY `started` (`date`),
KEY `result` (`statuss`),
KEY `currency` (`currency`),
KEY `rel_order_id` (`rel_order_id`),
KEY `ip` (`ip`)
) ENGINE=MyISAM AUTO_INCREMENT=64 DEFAULT CHARSET=utf8';
//Check version for prestashop 1.4
$version_mask = explode('.', _PS_VERSION_, 3);
$version_test = $version_mask[0] == 1 && $version_mask[1] == 4;
if (!$version_test)
return false;
if (!parent::install() OR !Db::getInstance()->Execute($query)
OR !Configuration::updateValue('AIRPAY_CURRENCY', 'customer')
OR !Configuration::updateValue('AIRPAY_SANDBOX', 'sandbox')
OR !$this->registerHook('payment'))
{
return false;
}
return true;
}
public function uninstall()
{
if (!Configuration::deleteByName('AIRPAY_MERCHANTID') OR !Configuration::deleteByName('AIRPAY_SECRETKEY')
OR !Configuration::deleteByName('AIRPAY_CURRENCY') OR !Configuration::deleteByName('AIRPAY_SANDBOX') OR !parent::uninstall())
{
return false;
}
return true;
}
public function getContent()
{
$this->_html = '<h2>AirPay</h2>';
if (isset($_POST['submitAirpay']))
{
if (empty($_POST['merchantid']))
{
$this->_postErrors[] = $this->l('AirPay merchant ID is required.');
}
if (empty($_POST['secretkey']))
{
$this->_postErrors[] = $this->l('AirPay secret key is required.');
}
if (empty($_POST['currency']))
{
$_POST['currency'] = 'customer';
}
if (empty($_POST['sandbox']))
{
$_POST['sandbox'] = 'sandbox';
}
if (!sizeof($this->_postErrors))
{
Configuration::updateValue('AIRPAY_MERCHANTID', $_POST['merchantid']);
Configuration::updateValue('AIRPAY_SECRETKEY', $_POST['secretkey']);
Configuration::updateValue('AIRPAY_CURRENCY', $_POST['currency']);
Configuration::updateValue('AIRPAY_SANDBOX', $_POST['sandbox']);
$this->displayConf();
}
else
{
$this->displayErrors();
}
}
$this->displayAirpay();
$this->displayFormSettings();
return $this->_html;
}
public function displayConf()
{
$this->_html .= '
<div class="conf confirm">
<img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />
'.$this->l('Settings updated').'
</div>';
}
public function displayErrors()
{
$nbErrors = sizeof($this->_postErrors);
$this->_html .= '
<div class="alert error">
<h3>'.($nbErrors > 1 ? $this->l('There are') : $this->l('There is')).' '.$nbErrors.' '.($nbErrors > 1 ? $this->l('errors') : $this->l('error')).'</h3>
<ol>';
foreach ($this->_postErrors AS $error)
{
$this->_html .= '<li>'.$error.'</li>';
}
$this->_html .= '
</ol>
</div>';
}
/* Does the same as mysql_real_escape_string(), only better */
public function myres($str)
{
if (get_magic_quotes_gpc())
{
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
public function displayAirpay()
{
$this->_html .= '
<img src="../modules/airpay/airpay.gif" style="float:left; margin-right:15px;" />
<b>'.$this->l('This module allows you to accept payments by AirPay.').'</b><br /><br />
'.$this->l('If the client chooses this payment mode, your AirPay account will be automatically credited.').'<br />
'.$this->l('You need to configure your AirPay account first before using this module.').'
<br /><br /><br />';
}
public function displayFormSettings()
{
$conf = Configuration::getMultiple(array('AIRPAY_MERCHANTID', 'AIRPAY_CURRENCY', 'AIRPAY_SECRETKEY', 'AIRPAY_SANDBOX'));
$merchantid = array_key_exists('merchantid', $_POST) ? $_POST['merchantid'] : (array_key_exists('AIRPAY_MERCHANTID', $conf) ? $conf['AIRPAY_MERCHANTID'] : '');
$secretkey = array_key_exists('secretkey', $_POST) ? $_POST['secretkey'] : (array_key_exists('AIRPAY_SECRETKEY', $conf) ? $conf['AIRPAY_SECRETKEY'] : '');
$currency = array_key_exists('currency', $_POST) ? $_POST['currency'] : (array_key_exists('AIRPAY_CURRENCY', $conf) ? $conf['AIRPAY_CURRENCY'] : 'prestashop');
$sandbox = array_key_exists('sandbox', $_POST) ? $_POST['sandbox'] : (array_key_exists('AIRPAY_SANDBOX', $conf) ? $conf['AIRPAY_SANDBOX'] : 'sandbox');
//$currency_default = new Currency(intval( Configuration::get('PS_CURRENCY_DEFAULT') ))->iso_code;
$this->_html .= '
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
<fieldset class="width3">
<legend><img src="../img/admin/contact.gif" />'.$this->l('Settings').'</legend>
<label for="airpay_merchantid">'.$this->l('AirPay merchant ID').'</label>
<div class="margin-form"><input type="text" size="33" name="merchantid" id="airpay_merchantid" value="'.htmlentities($merchantid, ENT_COMPAT, 'UTF-8').'" /></div>
<label for="airpay_secretkey">'.$this->l('AirPay secret key ').'</label>
<div class="margin-form"><input type="password" size="33" name="secretkey" id="airpay_secretkey" value="'.htmlentities($secretkey, ENT_COMPAT, 'UTF-8').'" /></div>
<label>'.$this->l('Currency').'</label>
<div class="margin-form">
<input type="radio" name="currency" id="airpay_currency1" value="prestashop" '.($currency == 'prestashop' ? 'checked="checked"' : '').' /> '.
'<label style="float: none; font-weight: normal;" for="airpay_currency1">'.$this->l('Use PrestaShop default currency').' (<b>'.$currency_default.'</b>)</label>
<br /><input type="radio" name="currency" id="airpay_currency2" value="customer" '.($currency == 'customer' ? 'checked="checked"' : '').' /> '.
'<label style="float: none; font-weight: normal;" for="airpay_currency2">'.$this->l('Use customer selected currency').'</label>
</div>
<label>'.$this->l('Sandbox').'</label>
<div class="margin-form">
<input type="radio" name="sandbox" id="airpay_sandbox1" value="sandbox" '.($sandbox == 'sandbox' ? 'checked="checked"' : '').' /> '.
'<label style="float: none; font-weight: normal;" for="airpay_sandbox1">'.$this->l('Use TEST mode - fake AirPay transactions)').'</label>
<br /><input type="radio" name="sandbox" id="airpay_sandbox2" value="live" '.($sandbox == 'live' ? 'checked="checked"' : '').' /> '.
'<label style="float: none; font-weight: normal;" for="airpay_sandbox2">'.$this->l('Use LIVE mode - Real AirPay transactions').'</label>
</div>
<br /><center><input type="submit" name="submitAirpay" value="'.$this->l('Update settings').'" class="button" /></center>
</fieldset>
</form><br /><br />
<fieldset class="width3">
<legend><img src="../img/admin/warning.gif" />'.$this->l('Information').'</legend>'
.$this->l('In order to use this module, you need to complete the following steps:').'<ol><li>'
.$this->l('Register as a merchant with').' <a href="http://www.airpay.lv/" target="_blank" style="color: blue; text-decoration: underline;">www.airpay.lv</a>'
.'</li><li>'
.$this->l('Recieve your merchant ID, choose a secret key and fill in the fields above').'</li><li>'
.$this->l('Send an email to').' <a href="mailto:welcome@airpay.lv?subject=PrestaShop%20module" style="color: blue; text-decoration: underline;">welcome@airpay.lv</a> '
.$this->l('with this data:').'<br /><br />'
.'<strong>RETURN_URL</strong>: '.(Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/airpay/return.php<br />'
.'<strong>STATUS_URL</strong>: '.(Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/airpay/confirm.php<br /><br />'
.'</li></ol>'
.$this->l('If there are any questions, you\'re welcome to contact AirPay by email')
.' (<a href="mailto:welcome@airpay.lv?subject=PrestaShop%20module" style="color: blue; text-decoration: underline;">welcome@airpay.lv</a>) '
.'</fieldset>'.$this->getActivities();
}
/* Queries the DB for AirPay module log entries and formats the results */
public function getActivities($start = 0, $limit = 101)
{
$total = DB::getInstance()->ExecuteS('SELECT COUNT(*) FROM `'._DB_PREFIX_.'airpay_orders`;');
$total = intval($total[0]['COUNT(*)']);
// Don't display anything if there are no log entries
if ($total == 0)
{
return '';
}
$query = 'SELECT *, (amount*0.01) as amount FROM `'._DB_PREFIX_.'airpay_orders` ORDER BY `'._DB_PREFIX_."airpay_orders`.`id` DESC LIMIT $start, $limit;";
$entries = Db::getInstance()->ExecuteS($query);
global $smarty;
$smarty->assign(array(
'entries' => $entries,
// This belongs in the presentation layer, but Smarty doesn't make it easy to define it there
'codes' => array('SUCCESS' => 'green', 'ERROR' => 'red'),
'total_count' => $total,
'current_count' => count($entries),
));
return $this->display(__FILE__, 'log.tpl');
}
public function hookPayment($params)
{
global $smarty, $_fpp;
$address = new Address(intval($params['cart']->id_address_invoice));
$customer = new Customer(intval($params['cart']->id_customer));
$merchantid = Configuration::get('AIRPAY_MERCHANTID');
$currency_cart = new Currency(intval( $params['cart']->id_currency ));
if (Configuration::get('AIRPAY_CURRENCY') == 'customer')
{
$id_currency = intval($params['cart']->id_currency);
$no_convert = true;
}
else
{
$id_currency = intval(Configuration::get('PS_CURRENCY_DEFAULT'));
$no_convert = false;
}
$currency = new Currency(intval($id_currency));
if (!Validate::isLoadedObject($address) OR !Validate::isLoadedObject($customer)
OR !Validate::isLoadedObject($currency))
{
return $this->l('AirPay error: (invalid address or customer)');
}
$products = $params['cart']->getProducts();
$product_names = array();
foreach ($products as $key => $product)
{
$products[$key]['name'] = str_replace('"', '\'', $product['name']);
if (isset($product['attributes']))
$products[$key]['attributes'] = str_replace('"', '\'', $product['attributes']);
$products[$key]['name'] = htmlspecialchars($product['name']);
$amount = number_format(Tools::convertPrice($product['price_wt'], $currency), 2, '.', '');
$products[$key]['airpayAmount'] = $amount;
$product_names[] = $products[$key]['name'].' ('.$products[$key]['cart_quantity'].'x)';
}
$product_names = join(', ', $product_names);
if (strlen($product_names) > 255)
{
$product_names = substr($product_names, 0, 245).'…';
}
$cart_id = $params['cart']->id;
$order_id = date('ymdHi').$cart_id.rand(1000,9999);
if (!$no_convert) $total = Tools::convertPrice($params['cart']->getOrderTotal(true, 3), $currency_cart, false) / 0.01;
else $total = $params['cart']->getOrderTotal(true, 3) / 0.01;
$smarty->assign(array(
'address' => $address,
'country' => new Country(intval($address->id_country)),
'customer' => $customer,
'currency' => $currency,
'm_cart_id' => $cart_id,
'airpayUrl' => __PS_BASE_URI__.'modules/airpay/order.php',
'product_name' => $product_names,
'total' => $total,
'id_order' => $order_id,
'description' => Configuration::get('PS_SHOP_NAME'),
'hash' => md5(Configuration::get('AIRPAY_SECRETKEY').$order_id.$total.Configuration::get('AIRPAY_MERCHANTID').$currency->iso_code)
));
return $this->display(__FILE__, 'airpay.tpl');
}
/* Updates the AirPay module payment status log */
public function logOrder($order_id, $cart_id, $email, $total, $currency, $status, $ip=NULL)
{
global $_fpp;
if (!isset($ip))
$ip = $_SERVER['REMOTE_ADDR'];
$query = 'INSERT INTO `'._DB_PREFIX_.'airpay_orders` '
."VALUES (NULL, '".mysql_real_escape_string($order_id)."', '"
.mysql_real_escape_string($cart_id)."', '"
.mysql_real_escape_string($email)."', '".mysql_real_escape_string($total)."',"
."'".mysql_real_escape_string($currency)."', NOW(), '$status', '$ip');";
$result = Db::getInstance()->Execute($query);
if (!$result)
{
$_fpp->warn($query, 'Query failed');
}
else
{
$_fpp->info($query);
}
return $result;
}
public function getOrderDetails($order_id)
{
global $_fpp;
$query = sprintf("SELECT * FROM `%sairpay_orders` WHERE order_id = '%s' AND statuss = 'ORDER';",
_DB_PREFIX_, $this->myres($order_id));
$results = Db::getInstance()->ExecuteS($query);
return empty($results) ? false : $results[0];
}
public function getCompletedOrder($order_id)
{
$query = sprintf("SELECT * FROM `%sairpay_orders` WHERE order_id = '%s' AND statuss = 'SUCCESS' ORDER BY `id` DESC;",
_DB_PREFIX_, $this->myres($order_id));
$results = Db::getInstance()->ExecuteS($query);
return empty($results) ? false : $results[0];
}
}
答案 0 :(得分:1)
第26行应为:
class AIRPAY extends PaymentModule
{
...
}
如果你还没有弄明白的话,那就是。