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

Clear session after checkout with custom payment method

我在 OpenCart 2.1.0.1 中使用自定义支付方式通过信用卡和借记卡进行支付,但我遇到了问题。当我成功购买并重定向到 succsess.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();

并且,在 UserActivity 日志记录之后,会话数据是 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']);