【问题标题】:opencart payment extension callback not workingopencart付款扩展回调不起作用
【发布时间】:2014-03-03 16:39:17
【问题描述】:

我正在尝试构建自定义支付模块。我已经完成了 80%。但是我有一些问题。

在回调中,当用户支付成功或失败返回站点时。它显示我为

找不到您请求的页面!您请求的页面不能 找到了。

当我尝试直接访问回调页面时,它给了我一个空白页面。

index.php?route=payment/hyperion/callback

当付款成功并返回到我的页面时(这使我无法找到该页面)。我没有在“订单”页面看到订单。支付成功不更新

下面是我的回调函数

           public function callback() {

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

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

    $order_id = $order_info['order_id'];

    if ($order_info) {
        $this->language->load('payment/hyper');

        $this->data['title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_name'));

        if (!isset($this->request->server['HTTPS']) || ($this->request->server['HTTPS'] != 'on')) {
            $this->data['base'] = HTTP_SERVER;
        } else {
            $this->data['base'] = HTTPS_SERVER;
        }

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

        $this->data['heading_title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_name'));

        $this->data['text_response'] = $this->language->get('text_response');
        $this->data['text_success'] = $this->language->get('text_success');
        $this->data['text_success_wait'] = sprintf($this->language->get('text_success_wait'), $this->url->link('checkout/success'));
        $this->data['text_failure'] = $this->language->get('text_failure');
        $this->data['text_failure_wait'] = sprintf($this->language->get('text_failure_wait'), $this->url->link('checkout/cart'));

        if (isset($_POST['flag_msg']) && $_POST['flag_msg'] == 'Status_Success') {
            $this->load->model('checkout/order');

            $this->model_checkout_order->confirm($order_id, $this->config->get('config_order_status_id'));

            $message = '';

            if (isset($_POST['flag_msg'])) {
                $message .= 'Payment Status = ' . $_POST['flag_msg'] . "\n";
                }

                if (isset($_POST['Response'])) {
                $message .= 'Response = ' . $_POST['Response'] . "\n";
                }

                if (isset($_POST['Result'])) {
                $message .= 'Result= ' . $_POST['Result'] . "\n";

                }

            $this->model_checkout_order->update($order_id, $this->config->get('hyper_order_status_id'), $message, false);

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

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

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

            $this->response->setOutput($this->render());
        }
        else if (isset($_POST['flag_msg']) && $_POST['flag_msg'] == 'Status_Fail') {
            $this->load->model('checkout/order');

            $this->model_checkout_order->confirm($order_id, $this->config->get('config_order_status_id'));

            $message = '';

            if (isset($_POST['flag_msg'])) {
                $message .= 'Payment Status = ' . $_POST['flag_msg'] . "\n";
                }

                if (isset($_POST['message'])) {
                $message .= 'Reason= ' . $_POST['message'] . "\n";
                }


            $this->model_checkout_order->update($order_id, 'Failed', $message, false);

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

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

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

            $this->response->setOutput($this->render());
        } else {
            $this->data['continue'] = $this->url->link('checkout/cart');

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

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

            $this->response->setOutput($this->render());
        }
    }
}

有人可以帮我解决这个问题吗?

【问题讨论】:

  • 打开display_errorserror_log 然后检查那里出了什么问题呢?尽管您提供了整个回调代码,但是要一一检查以发现您在某处缺少结束括号或分号...这甚至应该在此处发布问题之前进行检查...如果您这样做了,那么您应该提到没有错误但空白页面(表示有错误但显示错误设置为false)...
  • @shadyyx 我打开了error_display,但是没有错误。我在错误日志中没有看到任何错误。到目前为止没有语法错误。但我仍然得到空白页,直接访问时没有错误..
  • 您确定您已允许报告所有类型的错误(包括通知、警告、已弃用等)吗?
  • 您是否尝试了一些简单的调试以确保该操作真正执行?就像echo "Yes, I am here"; 就在callback 函数左括号之后?

标签: php opencart


【解决方案1】:

对于 OpenCart 2.3 版,回调的有效 url 是

index.php?route=extension/payment/my_controller/callback

因为内部的 opencartv2.3 结构具有下一种形式:my_site/catalog/controller/extension/payment/my_controller.php

对于默认的成功和失败(但 opencart 意味着失败作为返回结帐过程)操作有标准链接:

index.php?route=checkout/success
index.php?route=checkout/checkout

【讨论】:

    【解决方案2】:

    您为什么要尝试从会话中获取带有 order_id 的订单信息,而不是从您返回的数据中获取,从我的角度来看,问题似乎也存在,因为您的代码将返回一个唯一的可能性从逻辑的角度来看,空白页是如果未指定订单信息,则可能发生这种情况的情况是您尝试获取的会话中的订单 ID 存在问题。

    除此之外,您的代码似乎没有其他问题。

    我的建议是,如果返回了订单 ID,我认为任何付款方式都不会返回一个,请尝试使用该订单 ID,然后看看情况如何。

    【讨论】:

      【解决方案3】:

      你可以做一些调试。
      * 你可以将 echo 'hello' 或 var_dump('hello') 放在你的函数中,看看你的函数是否被调用和执行。
      * 如果是,那么您应该在每一行之后放置 echo/var_dump 以查看代码停止的位置。

      此外,传递给回调支付的url需要是 $this->url->link('payment/{module_name}/callback', '', 'SSL'); 假设您的文件目录位于目录/控制器/付款中。

      这适用于 opencart 版本 2.1.x 及更低版本。对于以上内容,您可以轻松更改 url 检查目录结构。

      注意:可能发生的另一件事是,当函数执行时,您在会话中获得的订单 ID 不存在。执行 var_dump 调试方法,查看代码在哪一行停止工作。

      【讨论】:

        猜你喜欢
        • 2015-05-27
        • 2021-06-07
        • 2017-08-23
        • 2020-12-19
        • 2017-08-01
        • 2013-08-31
        • 2017-11-20
        • 2014-06-26
        • 1970-01-01
        相关资源
        最近更新 更多