westpay.php
来自「全新且完善的强大网上商店系统」· PHP 代码 · 共 201 行
PHP
201 行
<?php
class westpay {
var $code, $title, $description, $enabled,$result;
function westpay() {
global $order;
$this->code = 'westpay';
$this->title = MODULE_PAYMENT_WESTPAY_TEXT_TITLE;
$this->description = MODULE_PAYMENT_WESTPAY_TEXT_DESCRIPTION;
$this->sort_order = MODULE_PAYMENT_WESTPAY_SORT_ORDER;
$this->enabled = ((MODULE_PAYMENT_WESTPAY_STATUS == 'True') ? true : false);
if ((int)MODULE_PAYMENT_WESTPAY_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_WESTPAY_ORDER_STATUS_ID;
}
if (is_object($order)) $this->update_status();
$this->form_action_url = 'http://www.WestPay.com.cn/Pay/WestPayReceiveOrderFromMerchant.asp';
}
function update_status() {
global $order;
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_WESTPAY_ZONE > 0) ) {
$check_flag = false;
$check_query = $db->query("select zone_id from $table_zones_to_geo_zones where geo_zone_id = '" . MODULE_PAYMENT_WESTPAY_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
while ($check = $db->fetch_array($check_query)) {
if ($check['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check['zone_id'] == $order->billing['zone_id']) {
$check_flag = true;
break;
}
}
if ($check_flag == false) {
$this->enabled = false;
}
}
}
function javascript_validation() {
return false;
}
function selection() {
return array('id' => $this->code,
'module' => $this->title);
}
function pre_confirmation_check() {
return false;
}
function confirmation() {
return false;
}
function process_button() {
global $order, $currencies, $currency,$customer_id;
$my_currency = $currency;
$v_amount=number_format(($order->info['total'] - $order->info['shipping_cost']) * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
$process_button_string = '<input name="OrderAmount" value="'.$v_amount.'" type="hidden">'. // 订单总金额
'<input name="OrderNumber" value="'.date("Ymd",time()).$customer_id.'" type="hidden">'. // 订单编号
'<input name="MerchantID" value="'.MODULE_PAYMENT_WESTPAY_ID.'" type="hidden">'. //商户编号
'<input name="PostBackURL" value="'.tep_href_link('checkout_process.php', '', 'SSL').'" type="hidden">' //支付动作完成后返回到该url,支付结果以GET方式发送
;
return $process_button_string;
}
function before_process() {
global $_POST, $order, $currencies, $currency;
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// 把WestPay传来的通知内容再传回到WestPay作验证以确保通知信息的真实性
$header .= "POST /pay/ISPN.asp HTTP/1.0\r\n";
// ISPN: Instant Secure Payment Notification
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.WestPay.com.cn', 80, $errno, $errstr, 30);
// 取出来自WestPay的支付通知中的内容
$MerchantOrderNumber = $_POST['MerchantOrderNumber']; //和商户支付命令中的订单号相同
$WestPayOrderNumber = $_POST['WestPayOrderNumber'];
$PaidAmount = $_POST['PaidAmount']; //WestPay传回的实际支付金额。
$MerchantID =$_POST['MerchantID'];
if (!$fp) {
// HTTP 错误处理
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if ($MerchantID=MODULE_PAYMENT_WESTPAY_ID) //'判断此订单是不是该商户的订单。
$state= 1;
//支付通知验证成 功
//把订单状态修改为支付成功,给用户增加所购买的点值,等等...
else
$state= 2;
//失败
} else if (strcmp ($res, "INVALID") == 0) {
// 支付通知验证失败
$state= 3;
}else {
$state= 4;
// 支付通知验证过程中出现错误
}
}
fclose ($fp);
}
if ($state==1){
//注:商户必须根据我们传回商户原始订单号找到原始订单,比较实付金额和原始订单金额,相同才是支付成功。
$my_currency = $currency;
if (!in_array($my_currency, array('0', '1'))) {
$my_currency = '0';
}
$v_amount=number_format(($order->info['total'] - $order->info['shipping_cost']) * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
if($v_amount==$PaidAmount){
if ((int)MODULE_PAYMENT_WESTPAY_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_WESTPAY_ORDER_STATUS_ID;
}
}else{
//失败
$this->result='fail';
$this->email_footer = MODULE_PAYMENT_WESTPAY_TEXT_EMAIL_FOOTER_FAIL;
$this->order_status=MODULE_PAYMENT_COD_ORDER_STATUS_ID;
}
}
}
function after_process() {
global $cart;
if($this->result=='fail'){
$cart->reset(true);
tep_session_unregister('sendto');
tep_session_unregister('billto');
tep_session_unregister('shipping');
tep_session_unregister('payment');
tep_session_unregister('comments');
tep_session_unregister('comments2');
tep_redirect(tep_href_link('checkout_fail.php', '', 'SSL'));
tep_session_close();
}else{
return false;
}
}
function output_error() {
return false;
}
function check() {
global $db, $table_configuration;
if (!isset($this->_check)) {
$check_query = $db->query("select configuration_value from $table_configuration where configuration_key = 'MODULE_PAYMENT_WESTPAY_STATUS'");
$this->_check = $db->num_rows($check_query);
}
return $this->_check;
}
function install() {
global $db, $table_configuration;
$db->query("insert into $table_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('是否支持西部支付付款模块', 'MODULE_PAYMENT_WESTPAY_STATUS', 'True', '你是否接受网银支付付款方式?', '6', '3', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
$db->query("insert into $table_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('商户账号', 'MODULE_PAYMENT_WESTPAY_ID', '1001', '商户在西部支付上注册的ID', '6', '4', now())");
$db->query("insert into $table_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('排列顺序', 'MODULE_PAYMENT_WESTPAY_SORT_ORDER', '0', '越小越靠前', '6', '0', now())");
$db->query("insert into $table_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('支付区域', 'MODULE_PAYMENT_WESTPAY_ZONE', '0', '如果选择了一个区域,那么这种支付方式只支持这个区域.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
$db->query("insert into $table_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('确定订购状态', 'MODULE_PAYMENT_WESTPAY_ORDER_STATUS_ID', '0', '设定这种支付方式的定购状态值', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
}
function remove() {
global $db, $table_configuration;
$db->query("delete from $table_configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array('MODULE_PAYMENT_WESTPAY_STATUS', 'MODULE_PAYMENT_WESTPAY_ID','MODULE_PAYMENT_WESTPAY_ZONE', 'MODULE_PAYMENT_WESTPAY_ORDER_STATUS_ID', 'MODULE_PAYMENT_WESTPAY_SORT_ORDER');
}
}
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?