分析ecshop独立页面调用各种支付方式

2009-10-22 10:26 来源:www.chinab4c.com 作者:ecshop专家

<?php


define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
require(ROOT_PATH . 'includes/lib_order.php');


if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}

if(isset($_REQUEST['act'])&&$_REQUEST['act']){
 $act = $_REQUEST['act'];
}else{
 $act = 'default';
}

if($act == 'default'){
 $payment_list = available_payment_list(1, $cod_fee);
    foreach ($payment_list as $key => $payment)
    {
        if ($payment['is_cod'] == '1')
        {
            $payment_list[$key]['format_pay_fee'] = '<span id="ECS_CODFEE">' . $payment['format_pay_fee'] . '</span>';
        }
        /* 如果有易宝神州行支付 如果订单金额大于300 则不显示 */
        if ($payment['pay_code'] == 'yeepayszx' && $total['amount'] > 300)
        {
            unset($payment_list[$key]);
        }
        /* 如果有余额支付 */
        if ($payment['pay_code'] == 'balance')
        {
            /* 如果未登录,不显示 */
            if ($_SESSION['user_id'] == 0)
            {
                unset($payment_list[$key]);
            }
            else
            {
                if ($_SESSION['flow_order']['pay_id'] == $payment['pay_id'])
                {
                    $smarty->assign('disable_surplus', 1);
                }
            }
        }
    }
  $smarty->assign('payment_list', $payment_list);
  $smarty -> display('order_repair.dwt');
}else if($act == 'sub'){
  include_once('includes/lib_clips.php');
    include_once('includes/lib_payment.php');
 $order['order_amount'] = intval($_POST['count']);
 $order['order_id'] =1;
 $order['order_sn'] = date("YmdHis");
 $order['pay_id'] = $_POST['payment'];
 
  if ($order['order_amount'] > 0)
    {
        $payment = payment_info($order['pay_id']);

        include_once('includes/modules/payment/' . $payment['pay_code'] . '.php');

        $pay_obj    = new $payment['pay_code'];

        $pay_online = $pay_obj->get_code($order, unserialize_config($payment['pay_config']));

        $order['pay_desc'] = $payment['pay_desc'];

        $smarty->assign('pay_online', $pay_online);
    }
 
 preg_match("/window.open\('(.*?)'\)/is",$pay_online,$string);
 if($string[1]){
  echo "<script>location.href=\"$string[1]\"</script>";
 }else{
   show_message('补款失败', '返回继续操作', 'order_repair.php');
 }
 

}
?>

以下是模板

 

<script>
 function get_sub(){
  var frm              = document.forms['form1'];
   var logname     = frm.elements['logname'].value;
    var count      = frm.elements['count'].value;
    if(logname == ''){
   alert('请输入汇款人名称 ');
   frm.elements['logname'].focus();
   return false;
   
    }
    if(count == ''){
   alert('请输入汇款金额');
   frm.elements['count'].focus();
   return false;
    }
    var re = /^-?[1-9]*(\.\d*)?$|^-?d^(\.\d*)?$/;

   if(!re.test(count)){
    alert("请输入合法的金额");
  return false;
   }
   si = false;
    var ser = document.getElementsByName('payment');
  
    for(var i=0;i<ser.length;i++){
   if(ser[i].checked){
   
   si = true;
   break;
  }
  }
  if(si == false){
   alert("请选择支付方式");
   return false;
  }
  
    return true;
 }
</script>
<div class="block clearfix">
 <table width="50%" align="center" border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd" id="paymentTable">
           <form action="?act=sub" method="post" name="form1" onsubmit="return get_sub();">
      <tr>
              <th width="5%" bgcolor="#ffffff">&nbsp;姓 名:</th>
              <th width="20%" bgcolor="#ffffff"><div align="left">
                <input type="text" name="logname">
              </div></th>
            </tr>
    <tr>
              <th width="5%" bgcolor="#ffffff">&nbsp;支付金额</th>
            
              <th bgcolor="#ffffff"><div align="left">
                <input type="text" name="count">
              </div></th>
            </tr>
            <!-- {foreach from=$payment_list item=payment} -->
            <!-- 循环支付方式 -->
            <tr>
              <td valign="top" bgcolor="#ffffff"><input type="radio" name="payment" value="{$payment.pay_id}" {if $order.pay_id eq $payment.pay_id}checked{/if} isCod="{$payment.is_cod}" {if $cod_disabled and $payment.is_cod eq "1"}disabled="true"{/if}/></td>
               <td valign="top" bgcolor="#ffffff">{$payment.pay_desc}</td>
              </tr>
            <!-- {/foreach} 循环支付方式 -->
   <tr>
              <td colspan="2" align="center"><input type="submit" name="" value="提交"></td>
              </tr>
     </form>
          </table>

来源:中国B4C电子商务