Post by darth_danny » Thu Aug 04, 2016 8:22 pm

Hi,

I created a custom payment method but keep getting a
Warning: call_user_func_array() expects parameter 1 to be a valid callback, cannot access protected method
error when confirming the order. I have looked through my callback function but cannot see what the problem could be.

Thanks
Last edited by straightlight on Thu Aug 04, 2016 10:04 pm, edited 2 times in total.
Reason: Added quote tags.

New member

Posts

Joined
Wed Jul 27, 2016 5:41 pm

Post by straightlight » Thu Aug 04, 2016 8:27 pm

More information would be needed on your development. Would it be possible to provide your Opencart version as well as the payment controller code you're trying to develop, including the API documentation you're following from the related provider?

In the mean time, I will move this topic into the Extensions Support - > Payments section of the forum.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by darth_danny » Thu Aug 04, 2016 8:44 pm

Hi,

I am using Opencart 2.2.0.0. Full error is:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, cannot access protected method ControllerPaymentMobileMoney::index() in C:\wamp\www\opencart\system\engine\action.php on line 44
My controller code is

Code: Select all

<?php

class ControllerPaymentMobileMoney extends Controller {
  protected function index() {
    $this->load->language('payment/mobile_money');
    
    $data['button_confirm'] = $this->language->get('button_confirm');
    $data['action'] = "localhost/payments_test/process.php";
  
    $this->load->model('checkout/order');
    $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
  
    if ($order_info) {
      $data['text_config_one'] = trim($this->config->get('text_config_one')); 
      $data['text_config_two'] = trim($this->config->get('text_config_two')); 
      $data['orderid'] = date('His') . $this->session->data['order_id'];
      $data['callbackurl'] = $this->url->link('payment/mobile_money/callback');
      $data['orderdate'] = date('YmdHis');
      $data['currency'] = $order_info['currency_code'];
      $data['orderamount'] = $this->currency->format($order_info['total'], $this->data['currency'] , false, false);
      $data['billemail'] = $order_info['email'];
      $data['billphone'] = html_entity_decode($order_info['telephone'], ENT_QUOTES, 'UTF-8');
      $data['billaddress'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
      $data['billcountry'] = html_entity_decode($order_info['payment_iso_code_2'], ENT_QUOTES, 'UTF-8');
      $data['billprovince'] = html_entity_decode($order_info['payment_zone'], ENT_QUOTES, 'UTF-8');;
      $data['billcity'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
      $data['billpost'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
      $data['deliveryname'] = html_entity_decode($order_info['shipping_firstname'] . $order_info['shipping_lastname'], ENT_QUOTES, 'UTF-8');
      $data['deliveryaddress'] = html_entity_decode($order_info['shipping_address_1'], ENT_QUOTES, 'UTF-8');
      $data['deliverycity'] = html_entity_decode($order_info['shipping_city'], ENT_QUOTES, 'UTF-8');
      $data['deliverycountry'] = html_entity_decode($order_info['shipping_iso_code_2'], ENT_QUOTES, 'UTF-8');
      $data['deliveryprovince'] = html_entity_decode($order_info['shipping_zone'], ENT_QUOTES, 'UTF-8');
      $data['deliveryemail'] = $order_info['email'];
      $data['deliveryphone'] = html_entity_decode($order_info['telephone'], ENT_QUOTES, 'UTF-8');
      $data['deliverypost'] = html_entity_decode($order_info['shipping_postcode'], ENT_QUOTES, 'UTF-8');
  
      
      if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/mobile_money.tpl')) {
          $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/payment/mobile_money.tpl', $data));
        } else {
          $this->response->setOutput($this->load->view('default/template/payment/mobile_money.tpl', $data));
        }
      
    }
  }
  
  public function callback() {
    if (isset($this->request->post['orderid'])) {
      $order_id = trim(substr(($this->request->post['orderid']), 6));
    } else {
      die('Illegal Access');
    }
  
    $this->load->model('checkout/order');
    
    $order_info = $this->model_checkout_order->getOrder($order_id);
  
    if ($order_info) {
      $data = array_merge($this->request->post,$this->request->get);
      
      $curl = curl_init( "localhost/payments_test/process.php");


      curl_setopt($curl, CURLOPT_POST, true);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_HEADER, false);
      curl_setopt($curl, CURLOPT_TIMEOUT, 30);
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

      $feedback = curl_exec($curl);
      
      if(!$response)
      {
          /* ERROR MESSAGE*/
      }
      else{
          
          
          if (isset($this->request->post['payment_status'])) {
              
            $order_status_id = $this->config->get('config_order_status_id');
            
            switch($this->request->post['payment_status']) {
					case 'SUCCESSFUL':
						$order_status_id = $this->config->get('pp_standard_refunded_status_id');
						break;
					case 'UNSCUCCESSFUL':
						$order_status_id = $this->config->get('pp_standard_reversed_status_id');
						break;
				}

				$this->model_checkout_order->addOrderHistory($order_id, $order_status_id);
            
            }else {
          
			$this->model_checkout_order->addOrderHistory($order_id, $this->config->get('config_order_status_id'));
            
            }
            curl_close($curl);
        }
    }
  
  }
}

?>
Last edited by darth_danny on Thu Aug 04, 2016 8:58 pm, edited 2 times in total.

New member

Posts

Joined
Wed Jul 27, 2016 5:41 pm

Post by straightlight » Thu Aug 04, 2016 8:46 pm

Please add quote tags to those warnings, not bolded tags.

Can you also provide the API documentation from the related provider you must reach?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Thu Aug 04, 2016 8:58 pm

In addition, the following should not be used:
if (isset($this->request->post['orderid'])) {
$order_id = trim(substr(($this->request->post['orderid']), 6));
} else {
die('Illegal Access');
}
Opencart uses error logs. Using the die() command would prevent you on seeing the source of the problems added to the logs whenever it applies.

This line:

Code: Select all

protected function index() {
should never be declared as: protected. Always use: public with index() :

Code: Select all

public function index() {
This should resolved the problem.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by darth_danny » Thu Aug 04, 2016 9:08 pm

Is there an online resource where I can get a tutorial on creating custom payment modules for OC v.2.2.0.0? I had created mine based on a tutorial for OC v1.5 (http://code.tutsplus.com/tutorials/crea ... -cms-22393) and read another article on converting OC v1.5 modules to work with r OC v2.0 (http://code.tutsplus.com/tutorials/conv ... -cms-25051). That may also have contributed to my problems.

I havent created the API documentation yet but the Order information was to be posted via curl and the API receives the XML post, process the data and send a response with payment confirmation back to OC

New member

Posts

Joined
Wed Jul 27, 2016 5:41 pm

Post by straightlight » Thu Aug 04, 2016 9:11 pm

A solution has been provided above while you were probably typing your last post above. As for this quote:
Order information was to be posted via curl and the API receives the XML post, process the data and send a response with payment confirmation back to OC
this is what I mean. From which location and indications these statements were required? Can you provide those?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by darth_danny » Thu Aug 04, 2016 9:15 pm

API documentation

New member

Posts

Joined
Wed Jul 27, 2016 5:41 pm

Post by straightlight » Thu Aug 04, 2016 9:16 pm

darth_danny wrote:API documentation
Excellent. Have you also followed the above fix instructions to get rid of the error message from the call_user_func_array() ?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by darth_danny » Thu Aug 04, 2016 9:17 pm

Yeah, thanks ALOT! Had not noticed the fuction was protected.
I changed the protected to public but got another set of errors:
Notice: Undefined index: in C:\wamp\www\opencart\system\library\cart\currency.php on line 25Notice: Undefined index: in C:\wamp\www\opencart\system\library\cart\currency.php on line 26Notice: Undefined index: in C:\wamp\www\opencart\system\library\cart\currency.php on line 27Notice: Undefined index: in C:\wamp\www\opencart\system\library\cart\currency.php on line 30Notice: Error: Could not load template C:/wamp/www/opencart/catalog/view/theme/default/template/default/template/payment/mobile_money.tpl! in C:\wamp\www\opencart\system\library\template\basic.php on line 26

New member

Posts

Joined
Wed Jul 27, 2016 5:41 pm

Post by straightlight » Thu Aug 04, 2016 9:22 pm

darth_danny wrote:Yeah, thanks ALOT! Had not noticed the fuction was protected.
I changed the protected to public but got another set of errors:
Notice: Undefined index: in C:\wamp\www\opencart\system\library\cart\currency.php on line 25Notice: Undefined index: in C:\wamp\www\opencart\system\library\cart\currency.php on line 26Notice: Undefined index: in C:\wamp\www\opencart\system\library\cart\currency.php on line 27Notice: Undefined index: in C:\wamp\www\opencart\system\library\cart\currency.php on line 30Notice: Error: Could not load template C:/wamp/www/opencart/catalog/view/theme/default/template/default/template/payment/mobile_money.tpl! in C:\wamp\www\opencart\system\library\template\basic.php on line 26
These used to be known errors back with v2.2.0.0 release of Opencart. I would, then, suggest to upgrade to the latest version in order to get passed issues resolved in the mean time: http://forum.opencart.com/viewtopic.php?f=2&t=166011 . However, the above fixed did work since it no longer provides error messages based on your specific extension.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by darth_danny » Thu Aug 04, 2016 9:30 pm

Okay, I had thought that the error was in some way linked to my custom payment method. Does open cart have auto upgrade feature or does it have to be manual?

New member

Posts

Joined
Wed Jul 27, 2016 5:41 pm

Post by straightlight » Thu Aug 04, 2016 9:33 pm

darth_danny wrote:Okay, I had thought that the error was in some way linked to my custom payment method. Does open cart have auto upgrade feature or does it have to be manual?
Instructions are being addressed on my pointed official topic. It is highly suggested to use the addressed experimental upgrade script from qphoria with followed and provided steps in order to complete the auto-upgrade steps successfully. Also ensure to make a full backup of your site and database before applying the upgrade process.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by darth_danny » Thu Aug 04, 2016 9:36 pm

I found the issue with the currency errors.

I had to replace

Code: Select all

$this->data['currency']
with

Code: Select all

$this->session->data['currency']
. There is one last error though
Notice: Error: Could not load template C:/wamp/www/opencart/catalog/view/theme/default/template/default/template/payment/mobile_money.tpl! in C:\wamp\www\opencart\system\library\template\basic.php on line 26

UPDATE: I realized the issue was with how the template location was written. Though now I have a problem of the
Confirm Order
button missing but the code for it is in my template file

New member

Posts

Joined
Wed Jul 27, 2016 5:41 pm

Post by straightlight » Thu Aug 04, 2016 9:43 pm

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/mobile_money.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/payment/mobile_money.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/payment/mobile_money.tpl', $data));
}
As for Opencart v2.2.0.0 release, it is not implied as the above quote.

Nowadays, it should rather be declared as the following statement:

Code: Select all

if (VERSION >= '2.2.0.0') {
    $this->response->setOutput($this->load->view('product/category', $data));

} else {
   $this->response->setOutput($this->load->view('product/category.tpl', $data));
}
This should resolved the problem.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by darth_danny » Thu Aug 04, 2016 9:55 pm

Thanks for everything :)

New member

Posts

Joined
Wed Jul 27, 2016 5:41 pm

Post by straightlight » Thu Aug 04, 2016 10:05 pm

No problem, enjoy.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 3 guests