Question

im trying to build a custom payment module. I have 80% completed it. But im having a few issues with it.

In the callback, when the user is returned to the site if a payment is successful or failed. It shows me as

The page you requested cannot be found! The page you requested cannot be found.

when i try to directly access the callback page it gives me a blank page.

index.php?route=payment/hyperion/callback

and when a payment is successful and returned to my page (which gives me the page cannot be found). i dont see the order in the "Orders" page. It doesn't update if the payment is successful

below is my callback function

           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());
        }
    }
}

can someone help me on this?

No correct solution

OTHER TIPS

For OpenCart version 2.3 a valid url for callback is

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

because internal opencartv2.3 structure has next form: my_site/catalog/controller/extension/payment/my_controller.php

For default success and fail (but opencart mean fail as return to checkout process) actions there are standard links:

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

Why are you trying to get the order info with an order_id from the session and not from the data that you got back, there seems to lie the problem also from my point of view as the only possibility that your code will return a blank page from logical point of view is if not order info are specified, and the case that this may happen is if there is a problem with the order id from the session you try to get.

Other than that nothing else seemed wrong with your code.

My advice if there is a order id returned, i do not think any payment method does not return one, try and use that order id and see how things go from there.

You can do some things to debug.
* You can put echo 'hello' or var_dump('hello') inside your function to see if your function is even getting called and executed.
* If it is then you should put the echo/var_dump after every line to see where the code stopped.

Further, the url passed to the payment for callback needs to be $this->url->link('payment/{module_name}/callback', '', 'SSL'); supposing your file directory is in catalog/controller/payment.

This is for opencart version 2.1.x and less. For above you can easily change the url checking the directory structure.

NOTE: One more thing that could happen is the order id you are getting in your session is not there when the function gets executed. Do the var_dump debug method to see in which line the code stopped working.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top