如何 实现再zencart1.55版本 checkout_payment页面一页提交支付功能


下载zencart模板安装,安装教程省略

再目录下includes/modules/payment编写好自己的支付插件

1:我们只需要修改支付插件的selection方法,这个方法的作用是:checkout_payment页面中将支付名称等信息展示

    function selection() {
        global $current_page_base,$template;
        //$this->my_confirmation_check();
        $m_fieldsArray [] = array (
                'title' =>'',
                'field' =>'',
                'tag' => '' 
        );
      return array('id' => $this->code,
                   'module' =>'
        <div class="display-table" id="selectioncoke"> 
        //此处为您的信用卡支付表单代码,直接写入即可,css,js都可以再此处引入
        <div>
    <style>
    .notice__text{padding:0px;margin:0px}
    fieldset .section--payment-method div{margin:0px !important; }
       </style>
',
          'fields' =>$m_fieldsArray);
    }

2:找到includes/modules/pages/checkout_process/header_php.php文件,全部复制里面的代码,将代码覆盖到includes/modules/pages/checkout_confirmation/header_php.php

<?php
/**
 * Checkout Process Page
 *
 * @package page
 * @copyright Copyright 2003-2016 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart/license/2_0.txt GNU Public License V2.0
 * @version $Id: Author: DrByte  Tue Oct 13 15:33:13 2015 -0400 Modified in v1.5.5 $
 */
// This should be first line of the script:
$zco_notifier->notify('NOTIFY_HEADER_START_CHECKOUT_PROCESS');
//在这里添加form表单所提交提交的字段,例如input卡号,买家留言
$_SESSION['comments'] = zen_output_string_protected($_POST['comments']);
$_SESSION['number'] = zen_output_string_protected($_POST['number']);


  require(DIR_WS_MODULES . zen_get_module_directory('checkout_process.php'));


// load the after_process function from the payment modules
  $payment_modules->after_process();

  $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_BEFORE_CART_RESET', $insert_id);
  $_SESSION['cart']->reset(true);

// unregister session variables used during checkout
  unset($_SESSION['sendto']);
  unset($_SESSION['billto']);
  unset($_SESSION['shipping']);
  unset($_SESSION['payment']);
  unset($_SESSION['comments']);
  $order_total_modules->clear_posts();//ICW ADDED FOR CREDIT CLASS SYSTEM

  // This should be before the zen_redirect:
  $zco_notifier->notify('NOTIFY_HEADER_END_CHECKOUT_PROCESS');

  zen_redirect(zen_href_link(FILENAME_CHECKOUT_SUCCESS, (isset($_GET['action']) && $_GET['action'] == 'confirm' ? 'action=confirm' : ''), 'SSL'));

  require(DIR_WS_INCLUDES . 'application_bottom.php');

为什么要修改这个页面的代码呢?

zencart的数据提交是checkout_payment->checkout_confirmation->checkout_process,

我们是要在第二步checkout_payment直接提交数据支付,后续的步骤我们是用不到的,但是有一个问题就是checkout_payment提交的数据我们需要在checkout_confirmation中才能获取,所以需要修改checkout_confirmation的header_php.php文件

3:添加JQ提交from表单,这里是为了做卡号等信息的验证,如果不需要验证可忽略这一步

$(function(){   

   $("#paymentSubmit input").click(function(){
            var number = $("#number").val();
            if(number.length<19){
            $("#error-for-number").css("display","block");
            $("#numberinput").css("border-color","#e22120");
            $('#error-for-number').html('Wrong card number length');
                return false;
            }

        $("#checkoutPayment form").submit();
   })  
})  

完成。

有问题请记得联系我。后续将会发布zencart1.55以上支付插件的开发教程

更多推荐

zencart1.55stripe信用卡内嵌支付获取卡号