Php 使用自定义付款方式结账后清除会话

Php 使用自定义付款方式结账后清除会话,php,opencart,session-cookies,opencart2.x,Php,Opencart,Session Cookies,Opencart2.x,我在OpenCart 2.1.0.1中使用信用卡和借记卡的定制支付方式,但我面临一个问题。当我成功购买并重定向到successs.tpl页面时,之后当我继续购物(在同一浏览器会话中)并进行第二次成功购买时-它不会记录为具有新订单id的新订单!我将连接我的控制器,它可以是清除会话的代码 class ControllerPaymentFibank extends Controller { public function index() { $this->load->model('

我在OpenCart 2.1.0.1中使用信用卡和借记卡的定制支付方式,但我面临一个问题。当我成功购买并重定向到
successs.tpl
页面时,之后当我继续购物(在同一浏览器会话中)并进行第二次成功购买时-它不会记录为具有新订单id的新订单!我将连接我的控制器,它可以是清除会话的代码

class ControllerPaymentFibank extends Controller {
public function index() {
    $this->load->model('checkout/order');

    $this->language->load('payment/fibank');

    $data['button_confirm'] = $this->language->get('button_confirm');

    if (!$this->config->get('fibank_test')) {
        $communication_url  = "https://mdpay.fibank.bg:9443/ecomm/MerchantHandler";
        $payment_url        = "https://mdpay.fibank.bg/ecomm/ClientHandler";
    } else {
        $communication_url  = "https://mdpay-test.fibank.bg:9443/ecomm/MerchantHandler";
        $payment_url        = "https://mdpay-test.fibank.bg/ecomm/ClientHandler";
    }

    $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);

    if ($order_info) {



        $data['action'] = $this->session->data['order_id'];

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/fibank.tpl')) {
            return $this->load->view($this->config->get('config_template') . '/template/payment/fibank.tpl', $data);
        } else {
            return $this->load->view('default/template/payment/fibank.tpl', $data);
        }

    }
}

public function make_payment() {
    $this->load->model('checkout/order');

    $this->language->load('payment/fibank');

    $data['button_confirm'] = $this->language->get('button_confirm');

    if (!$this->config->get('fibank_test')) {
        $communication_url  = "https://mdpay.fibank.bg:9443/ecomm/MerchantHandler";
        $payment_url        = "https://mdpay.fibank.bg/ecomm/ClientHandler";
    } else {
        $communication_url  = "https://mdpay-test.fibank.bg:9443/ecomm/MerchantHandler";
        $payment_url        = "https://mdpay-test.fibank.bg/ecomm/ClientHandler";
    }

    $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);

    if ($order_info) {

        $ip = $this->get_client_ip();

        $amount = $this->currency->format($order_info['total'], 'BGN', '', false);
        $amount *= 100;

        $post_request="command=v&amount=".$amount."&currency=975&client_ip_addr=".$ip."&description=".$this->session->data['order_id']."&msg_type=SMS"; 

        $res = $this->execute_fibank_query($communication_url, $post_request);   

        $result = str_replace("TRANSACTION_ID: ", "", $res);

        $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], '1', $result);   

        $_SESSION['order_id']=$this->session->data['order_id'];

        header("location:".$payment_url."?trans_id=".rawurlencode($result));

    }
    exit(); 
}
public function callback() {
    if (isset($this->request->post['trans_id'])) {
        $tranz_id  = $this->request->post['trans_id'];
    } else {
        $tranz_id  = '';
    }

    if (!$this->config->get('fibank_test')) {
        $communication_url  = "https://mdpay.fibank.bg:9443/ecomm/MerchantHandler";
        $payment_url        = "https://mdpay.fibank.bg/ecomm/ClientHandler";
    } else {
        $communication_url  = "https://mdpay-test.fibank.bg:9443/ecomm/MerchantHandler";
        $payment_url        = "https://mdpay-test.fibank.bg/ecomm/ClientHandler";
    }


    if ($tranz_id!="" && $_SESSION['order_id']>0) {
        $ip = $this->get_client_ip();

        $request="command=c&trans_id=".rawurlencode($tranz_id)."&client_ip_addr=".$ip;

        $result = $this->execute_fibank_query($communication_url, $request);

        $res = explode("\n", $result);

        $fibank_info = str_replace("RESULT: ", "", $res[0]);
        $this->load->model('checkout/order');

        $order_info = $this->model_checkout_order->getOrder($_SESSION['order_id']);

        if ($fibank_info=="OK") {

            $order_status = $this->config->get('fibank_order_status_id');
            $this->model_checkout_order->addOrderHistory($_SESSION['order_id'], $order_status, $result);

            $this->cart->clear();

            header("location:/successfull-transaction");

        } 
        else{
            $order_status = $this->config->get('fibank_order_status_denied_id');
            $this->model_checkout_order->addOrderHistory($_SESSION['order_id'], $order_status, $result);

            $this->cart->clear();

            header("location:/transaction-error");
        }


    }   
}

function execute_fibank_query($url, $request){

    // debug
    $fp = fopen(dirname(__FILE__).'/errorlog.txt', 'w');
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 
    // debug
    curl_setopt($ch, CURLOPT_STDERR, $fp);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
    curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
    curl_setopt($ch, CURLOPT_SSLCERT, $this->config->get('fibank_certificate_path')); 
    curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM'); 
    curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $this->config->get('fibank_certificate_pass'));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    $result = curl_exec($ch);

    return $result;

}


function get_client_ip(){
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } 
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } 
    else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }

    return $ip;
}

如果查看文件
catalog/controller/checkout/success.php
,您将看到成功订单之后的标准流程。如果您已经对其进行了修改,那么OpenCart可能没有取消设置会话数据。在该文件中,控制器检查会话中是否有数据集:

if (isset($this->session->data['order_id'])) {
如果为真,将使用以下行清除购物车:

$this->cart->clear();
并且,在用户活动日志记录之后,会话数据是
unset
,使用以下代码:

unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['guest']);
unset($this->session->data['comment']);
unset($this->session->data['order_id']);
unset($this->session->data['coupon']);
unset($this->session->data['reward']);
unset($this->session->data['voucher']);
unset($this->session->data['vouchers']);
unset($this->session->data['totals']);

哇,太棒了!谢谢您!