-1

我正在为 opencart 创建一个自定义网关模块,但代码中有一些问题。你能告诉我我做错了什么吗?

opencart 调试器显示错误:

[03-Oct-2013 06:50:02 America/Chicago] PHP Fatal error:  Call to undefined method ControllerPaymentMyBank::check_order() in /home/***/public_html/catalog/controller/payment/mybank.php on line 207
[03-Oct-2013 06:50:34 America/Chicago] PHP Fatal error:  Call to undefined method ControllerPaymentMyBank::ResponseToBank() in /home/***/public_html/catalog/controller/payment/mybank.php on line 225

我使用的功能:

public function callback() {

        //SOME CODE HERE WORKS....


        $xml = xml_parser_create('UTF-8');
                   xml_parse_into_struct($xml, html_entity_decode($_POST['ConfirmRequest']), $vals);
                   xml_parser_free($xml);

                  foreach ($vals as $data)
                          {
                           if ($data['tag']=='STATUS')
                           $Status=$data['value'];
                           if ($data['tag']=='PAYMENTID')
                           $PaymentId=$data['value'];
                           if ($data['tag']=='PAYMENTDATE')
                           $PaymentDate=$data['value'];
                           if ($data['tag']=='TRANSACTIONID')
                           $TransactionId=$data['value'];
                           if ($data['tag']=='AMOUNT')
                           $Amount=$data['value'];
                           if ($data['tag']=='REASON')
                           $Reason=$data['value'];
                       if ($data['tag']=='CARDTYPE')
                           $CardType=$data['value'];

                          }


                    if($Status=='C')
                    {
                    if($this->check_order($TransactionId,$Amount))
                    $this->ResponseToBank($TransactionId,$PaymentId,'ACCEPTED');             
                    else
                    $this->ResponseToBank($TransactionId,$PaymentId,'DECLINED');   
                    }


                    if($Status=='Y')                             
                      {

                           if( $this->success_order($TransactionId) )
                                             $this->ResponseToBank($TransactionId,$PaymentId,'ACCEPTED');   
                                                        else
                                  $this->ResponseToBank($TransactionId,$PaymentId,'DECLINED');

                    }


                    $this->ResponseToBank($TransactionId,$PaymentId,'ACCEPTED');      


                    function ResponseToBank($TransactionId,$PaymentId,$Status)
                             {

                                         $xmlstr = "<ConfirmResponse>";
                                         $xmlstr .= "<TransactionId>".$TransactionId."</TransactionId>";
                                         $xmlstr .= "<PaymentId>".$PaymentId."</PaymentId>";
                                         $xmlstr .= "<Status>".$Status."</Status>";
                                         $xmlstr .= "</ConfirmResponse>";

                                        header('Content-type: text/xml');
                                        die($xmlstr);
                                 }            





                    function check_order($orderid,$amount)
                              {
                                    return true;

                              }



                    function success_order($orderid)
                              {


                                return true;

                              }




    }

我该如何定义这些方法?

4

2 回答 2

3

除非我遗漏了什么,否则这是一个简单的 PHP 语法问题。如果你这样做:

$this->check_order($TransactionId,$Amount)

...假设您在当前类中有一个类方法:

class ControllerPaymentMyBank{
    private function check_order($orderid, $amount){
        return true;
    }
}

但是,您有一个恰好在另一个类方法中定义的常规函数​​:

class ControllerPaymentMyBank{
    public function callback()
        function check_order($orderid,$amount){
            return true;
        }
    }
}

这不是纯粹的面向对象编程,它是 OOP 和过程代码的混合体,相当于:

class ControllerPaymentMyBank{
    public function callback()
    }
}

function check_order($orderid,$amount){
    return true;
}

定义check_order()为适当的类方法,你应该完成。

于 2013-10-03T12:18:36.047 回答
2

您已经在函数内部定义了方法callback。将它们移到这个函数之外,使它们成为封闭类的一部分。

于 2013-10-03T12:15:41.880 回答