Custom Payment Method, problem with cancellation of orders

  • Posts: 47
  • Thank you received: 0
6 years 8 months ago #276086

-- url of the page with the problem -- : biosinar.com
-- HikaShop version -- : 3.1.1
-- Joomla version -- : 3.7.4
-- PHP version -- : 7.0.22

Hi guys,

I am developing a custom payment method for Hikashop. a couple of things are not working.

1. When i use this line in my code for function onPaymentNotification(&$statuses)...

$this->modifyOrder($order_id, $this->payment_params->invalid_status, true, true);

Two things happen ie
a) It does NOT change the order status to the defaut for cancellations ie CANCELLED, instead the order remains as CREATED
b) It prevent a redirect to the cancel_url, instead the user is brought back to the last stage of the shopping cart

If I replace the same line with this

//$this->modifyOrder($order_id, $this->payment_params->verified_status, true, true);


Everything works, but of course, that line makes cancelled orders become CONFIRMED. It also takes the user to the right cancel_url.

Here's the relevant codes
		if($vars['EXECCODE'] != 0000)
		{
			
			// Here we display debug information which will be catched by HikaShop and stored in the payment log file available in the configuration's Files section.
			//print "EXECCODE is non-zero";
			if($this->payment_params->debug)
				print 'payment '.$vars['MESSAGE']."\n\n\n";
				
			// This function modifies the order with the id $order_id, to attribute it the status invalid_status.
			//$this->modifyOrder($order_id, $this->payment_params->verified_status, true, true);			
			$this->modifyOrder($order_id, $this->payment_params->invalid_status, true, true);
			
			//To redirect the user, if needed. Here the redirection is useless : we are on server side (and not user side, so the redirect won't work), and the cancel url has been set on the payment platform merchant account
			$this->app->redirect($cancel_url);
			return false;
		}
		//If everything's OK, the payment has been done. Order is validated -> success
		else
		{
			//print "All OK";
			$this->modifyOrder($order_id, $this->payment_params->verified_status, true, true);
			
			$this->app->redirect($return_url);
			return true;
		}

Last edit: 6 years 8 months ago by Jerome. Reason: using [code] tag to display code

Please Log in or Create an account to join the conversation.

  • Posts: 81633
  • Thank you received: 13085
  • MODERATOR
6 years 8 months ago #276092

Hi,

The modifyOrder function doesn't do any redirection.
It does only two things:
- it saves the new order status by calling the save function of class.order
- it sends the payment notification email to the administrator

If the status is not changed, then either there is a problem with the rest of your code when you test it, or there is another plugin, implementing the onAfterOrderUpdate or onBeforeOrderUpdate triggers (which are called during the saving of the order) which does something it shouldn't.
And more specifically, the onBeforeOrderUpdate trigger has a $do parameter which can cancel the change of the order status. So a plugin can cancel your modification of the order status for some reason.
For example, if you've configured a mass action to change the status of orders that are being cancelled to created, the mass action plugin will be able to cancel you order status change.
Also, if such plugin does a redirect, the redirect stops the processing of the page and anything after the redirect will be skipped.
So if a plugin implementing the onBeforeOrderUpdate trigger does a redirect, it will skip the save of the order and your own redirect.

Please Log in or Create an account to join the conversation.

  • Posts: 47
  • Thank you received: 0
6 years 8 months ago #276162

Thank you Nicholas. After doing some checking, I found out that the following line of code based oncallback in the Example Payment Method does not work and has to be replaced with the second. Then it works.

First, set the return and cancel URLs to make callbacks to

	$qrystr = $_SERVER["QUERY_STRING"];
	$actionok = "http://unicomms-emall.com/index.php?option=com_hikashop&ctrl=checkout&task=n"."otify&notif_payment=unicommspayment&tmpl=component&".$qrystr;
	$actionnok = "http://unicomms-emall.com/index.php?option=com_hikashop&ctrl=order&task=cancel_order&".$qrystr;

Then implement the return value in a GET variable to be returned to the return URL
if ($_REQUEST["choiceLst"] == "Ok")

Finally, make the callback making sure that both the success and cancel calls be made to the return_url and DO NOT use the Cancel_url
	if ($_REQUEST["choiceLst"] == "Ok")
	{
		$actionurl = $actionok . '&EXECCODE=0000'; //Signifies that the trasaction is okay
	}
	else
	{
		$actionurl = $actionok . '&EXECCODE=9999'; //Signifies that the transaction is rejected
	}
Now it works.

I have now encountered another, different problem but I'll raise another issue on that matter.

Last edit: 6 years 8 months ago by Jerome. Reason: using [code] tag to display code

Please Log in or Create an account to join the conversation.

  • Posts: 26024
  • Thank you received: 4005
  • MODERATOR
6 years 8 months ago #276165

Hello,

Please use the code tag to post code.
Thank you for your understanding.


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

Time to create page: 0.060 seconds
Powered by Kunena Forum