确认opencart 2.0结帐流程中缺少订单按钮

时间:2015-06-11 13:16:02

标签: php opencart opencart2.x

我之前为1.5版本创建了一个支付网关模块,它完美地工作,现在我升级到2.x所以我开始使用我的模块,一切正常,除了最后的确认订单丢失。

这是图片链接 http://i.stack.imgur.com/Ak4B1.png

我用我的新代码替换旧代码,但它仍然不起作用,而且它甚至没有显示错误的大问题让我可以得到任何想法

这是我的旧代码

<form action="<?php echo $action; ?>" method="post" id="payment">

</form>
<div class="buttons">
  <div class="right"><a id="button-confirm" class="button" onclick="$('#payment').submit();"><span><?php echo $button_confirm; ?></span></a></div>
</div>

新代码

 <form action="<?php echo $action; ?>" method="post" id="payment">

    </form>
     <div class="buttons">
        <div class="pull-right">
          <input type="submit" value="<?php echo $button_confirm; ?>" class="btn btn-primary" id="button-confirm" />
        </div>
      </div>

控制器文件代码

<?php
class ControllerPaymentIcicipg extends Controller {

    protected function index() {

        $this->load->language('payment/icicipg');
        $data['action'] = $this->url->link('payment/icicipg/send', '', 'SSL');
        $data['button_confirm'] = $this->language->get('button_confirm');

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/icicipg.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/payment/icicipg.tpl';
        } else {
            $this->template = 'default/template/payment/icicipg.tpl';
        }

        $this->render();

    }

    public function send() {

        include("Sfa/BillToAddress.php");
        include("Sfa/CardInfo.php");
        include("Sfa/Merchant.php");
        include("Sfa/MPIData.php");
        include("Sfa/ShipToAddress.php");
        include("Sfa/PGResponse.php");
        include("Sfa/PostLibPHP.php");
        include("Sfa/PGReserveData.php");

        $this->load->model('checkout/order');

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

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

        $MID = $this->config->get('icicipg_MID');
        $cust_ip = $order_info['forwarded_ip'];
        $RedirectURL = $this->config->get('icicipg_RedirectURL');

        if ($this->currency->getCode()=='INR'){
           $amount = $order_info['total'];
        } else {
           $amount = $this->currency->convert($order_info['total'], $this->currency->getCode(), 'INR') ;
        }
        $amount = round((float)$amount,2);

        $bCustomerId = $order_info['customer_id'];
        $bCustomerName = html_entity_decode($order_info['payment_firstname'] . " " . $order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
        $bAddrLine1 = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
        $bAddrLine2 = html_entity_decode($order_info['payment_address_2'], ENT_QUOTES, 'UTF-8');
        $bAddrLine3 = "";
        $bCity = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
        $bState = html_entity_decode($order_info['payment_zone'], ENT_QUOTES, 'UTF-8');
        $bZip = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
        $bCountryAlpha = $order_info['payment_iso_code_3'];
        $bEmail = html_entity_decode($order_info['email'], ENT_QUOTES, 'UTF-8');


        if ($this->cart->hasShipping()) {
            $sAddrLine1 = html_entity_decode($order_info['shipping_address_1'], ENT_QUOTES, 'UTF-8');
            $sAddrLine2 = html_entity_decode($order_info['shipping_address_2'], ENT_QUOTES, 'UTF-8');
            $sAddrLine3 = "";
            $sCity = html_entity_decode($order_info['shipping_city'], ENT_QUOTES, 'UTF-8');
            $sState = html_entity_decode($order_info['shipping_zone'], ENT_QUOTES, 'UTF-8');
            $sZip = html_entity_decode($order_info['shipping_postcode'], ENT_QUOTES, 'UTF-8');
            $sCountryAlpha = $order_info['shipping_iso_code_3'];
            $sEmail = html_entity_decode($order_info['email'], ENT_QUOTES, 'UTF-8');
        } else {
            $sAddrLine1 = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
            $sAddrLine2 = html_entity_decode($order_info['payment_address_2'], ENT_QUOTES, 'UTF-8');
            $sAddrLine3 = "";
            $sCity = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
            $sState = html_entity_decode($order_info['payment_zone'], ENT_QUOTES, 'UTF-8');
            $sZip = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
            $sCountryAlpha = $order_info['payment_iso_code_3'];
            $sEmail = html_entity_decode($order_info['email'], ENT_QUOTES, 'UTF-8');
        }

        $oMPI           =   new MPIData();
        $oCI            =   new CardInfo();
        $oPostLibphp    =   new PostLibPHP();
        $oMerchant      =   new Merchant();
        $oBTA           =   new BillToAddress();
        $oSTA           =   new ShipToAddress();
        $oPGResp        =   new PGResponse();
        $oPGReserveData =   new PGReserveData();

        $oMerchant->setMerchantDetails($MID,$MID,$MID,$cust_ip,$order_id,$order_id,$RedirectURL,"POST","INR",$order_id,"req.Sale",$amount,"","Ext1","true","Ext3","Ext4","New PHP");

        //$oBTA->setAddressDetails ("CID","Tester","Aline1","Aline2","Aline3","Pune","A.P","48927489","IND","tester@soft.com");
        $oBTA->setAddressDetails ($bCustomerId, $bCustomerName,$bAddrLine1, $bAddrLine2, $bAddrLine3,$bCity, $bState, $bZip, $bCountryAlpha, $bEmail);

        //$oSTA->setAddressDetails ("Add1","Add2","Add3","City","State","443543","IND","sad@df.com");
        $oSTA->setAddressDetails ($sAddrLine1, $sAddrLine2, $sAddrLine3, $sCity, $sState, $sZip, $sCountryAlpha,$sEmail);

        #$oMPI->setMPIRequestDetails("1245","12.45","356","2","2 shirts","12","20011212","12","0","","image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*","Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");

        $oPGResp=$oPostLibphp->postSSL($oBTA,$oSTA,$oMerchant,$oMPI,$oPGReserveData);

        function redirect($url) {
            if(headers_sent()){
            ?>
                <html><head>
                    <script language="javascript" type="text/javascript">
                        window.self.location='<?php print($url);?>';
                    </script>
                </head></html>
            <?php
                exit;
            } else {
                header("Location: ".$url);
                exit;
            }
        }       

        if($oPGResp->getRespCode() == '000'){
            $url    =$oPGResp->getRedirectionUrl();
            #$url =~ s/http/https/;
            #print "Location: ".$url."\n\n";
            #header("Location: ".$url);
            redirect($url);
        }else{
            print "Error Occured.<br>";
            print "Error Code:".$oPGResp->getRespCode()."<br>";
            print "Error Message:".$oPGResp->getRespMessage()."<br>";
        }

    }


    public function callback() {

        include("Sfa/EncryptionUtil.php");

        $strMerchantId=$this->config->get('icicipg_MID');
        $astrFileName=substr(DIR_SYSTEM,0,strlen(DIR_SYSTEM)-7) . 'Sfa/' . $strMerchantId . '.key';
        $astrClearData;
        $ResponseCode = "";
        $Message = "";
        $TxnID = "";
        $ePGTxnID = "";
        $AuthIdCode = "";
        $RRN = "";
        $CVRespCode = "";
        $Reserve1 = "";
        $Reserve2 = "";
        $Reserve3 = "";
        $Reserve4 = "";
        $Reserve5 = "";
        $Reserve6 = "";
        $Reserve7 = "";
        $Reserve8 = "";
        $Reserve9 = "";
        $Reserve10 = "";

        $this->language->load('checkout/success');
        $this->load->language('payment/icicipg');

        if($_POST && $_POST['DATA']!=null){

            if($_POST['DATA']==null){
                print "null is the value";
            }
             $astrResponseData=str_replace("&amp;", "&", $_POST['DATA']);
             $astrDigest = str_replace("&amp;", "&", $_POST['EncryptedData']);
             $oEncryptionUtilenc =  new EncryptionUtil();
             $astrsfaDigest  = $oEncryptionUtilenc->getHMAC($astrResponseData,$astrFileName,$strMerchantId);

            if (strcasecmp($astrDigest, $astrsfaDigest) == 0) {
                parse_str($astrResponseData, $output);
                if( array_key_exists('RespCode', $output) == 1) {
                    $ResponseCode = $output['RespCode'];
                }
                if( array_key_exists('Message', $output) == 1) {
                    $Message = $output['Message'];
                }
                if( array_key_exists('TxnID', $output) == 1) {
                    $TxnID=$output['TxnID'];
                }
                if( array_key_exists('ePGTxnID', $output) == 1) {
                    $ePGTxnID=$output['ePGTxnID'];
                }
                if( array_key_exists('AuthIdCode', $output) == 1) {
                    $AuthIdCode=$output['AuthIdCode'];
                }
                if( array_key_exists('RRN', $output) == 1) {
                    $RRN = $output['RRN'];
                }
                if( array_key_exists('CVRespCode', $output) == 1) {
                    $CVRespCode=$output['CVRespCode'];
                }
            }

            $Order_Id = $TxnID;

            $this->load->model('checkout/order');

            //$order_info = $this->model_checkout_order->getOrder($Order_Id);
            if(trim($TxnID)!=""){
                if((int)$ResponseCode == 0) { 
                    $this->document->setTitle('Payment Transaction Successful');
                    $data['heading_title'] = sprintf($this->language->get('text_order_success'),$TxnID);
                    $order_status_id = $this->config->get('icicipg_success_status_id');
                    $this->model_checkout_order->confirm($Order_Id, $order_status_id);
                    if ($this->customer->isLogged()) {
                        $data['text_message'] = sprintf($this->language->get('text_customer'), $this->url->link('account/account', '', 'SSL'), $this->url->link('account/order', '', 'SSL'), $this->url->link('account/download', '', 'SSL'), $this->url->link('information/contact'));
                    } else {
                        $data['text_message'] = sprintf($this->language->get('text_guest'), $this->url->link('information/contact'));
                    }
                    if (isset($this->session->data['order_id'])) {
                        $this->cart->clear();

                        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']);
                    }   
                    $data['button_continue'] = $this->language->get('button_continue');

                    $data['continue'] = $this->url->link('common/home');

                    //$this->redirect($this->url->link('checkout/success'));
                } else {
                    $this->document->setTitle('Payment Transaction Failed');
                    $data['heading_title'] = sprintf($this->language->get('text_order_failed'),$TxnID);
                    $data['text_message'] = sprintf($this->language->get('text_icicipg_eorror_message'), $this->url->link('information/contact'),$Message);
                    $data['button_continue'] = $this->language->get('button_continue');
                    $data['continue'] = $this->url->link('common/home');
                    $order_status_id = $this->config->get('icicipg_failed_status_id');
                    $this->model_checkout_order->confirm($Order_Id, $order_status_id);
                }
            } else {
                $this->document->setTitle('Payment Transaction Failed');
                $data['heading_title'] = $this->language->get('text_icicipg_error');
                $data['text_message'] = sprintf($this->language->get('text_icicipg_eorror_message'), $this->url->link('information/contact'),'Unspecified');
                $data['button_continue'] = $this->language->get('button_continue');
                $data['continue'] = $this->url->link('common/home');            
            }

        } else {
            $this->document->setTitle('Payment Transaction Failed');
            $data['heading_title'] = $this->language->get('text_icicipg_error');
            $data['text_message'] = sprintf($this->language->get('text_icicipg_eorror_message'), $this->url->link('information/contact'),'Unspecified');
            $data['button_continue'] = $this->language->get('button_continue');
            $data['continue'] = $this->url->link('common/home');



        }
        //$data['text_message'] = $astrDigest . '<br/>' .  $astrsfaDigest . '<br/><pre>' . print_r($_POST ,1) . '</pre>';

        $data['breadcrumbs'] = array();
        $this->children = array(
            'common/column_left',
            'common/column_right',
            'common/content_top',
            'common/content_bottom',
            'common/footer',
            'common/header'
        );

        $data['column_left'] = $this->load->controller('common/column_left');
                $data['column_right'] = $this->load->controller('common/column_right');
                $data['content_top'] = $this->load->controller('common/content_top');
                $data['content_bottom'] = $this->load->controller('common/content_bottom');
                $data['footer'] = $this->load->controller('common/footer');
                $data['header'] = $this->load->controller('common/header');

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/success.tpl')) {
                    $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/common/success.tpl', $data));
                } else {
                    $this->response->setOutput($this->load->view('default/template/common/success.tpl', $data));
                }

    }
}
?>

1 个答案:

答案 0 :(得分:2)

Opencart 2.0+使用不同的方法呈现模板:$this->load->view($template,$data)

所以例如你的看起来像是:

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

此外,我想象您的Index()方法应该是public,而不是protected