Custom Payment Plugin Notification Not Received

  • Posts: 25
  • Thank you received: 1
8 years 11 months ago #222197

-- HikaShop version -- : HikaShop Starter: 2.6.0
-- Joomla version -- : 3.4.5
-- PHP version -- : 5.4.45

Customising the 'Example' payment plugin to work with the JCC providor here in Cyprus, the Debug for the plugin is turned on.

The plugin posts to the payment gateway ok, i can use their dummy card and receive a success, the gateway then posts the response data to the notify URL i have set (/index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=jcc&tmpl=component) but i get a blank screen and no entry in the plugin log.

Using Chrome i can see the post data send by the gateway are as expected, and looking at my Raw Access Logs from cPanel i get status 200. At a guess the function 'onPaymentNotification' is not being processed, as i would expect to see onscreen debug and entry to logfile ?

What to do ?

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

  • Posts: 25
  • Thank you received: 1
8 years 11 months ago #222266

After much messing about, i realise that the onPaymentNotification function was 'ready' to be fired, i just had to modify it to actually do something!

So, now, i still get a blank page in the front end, but, on checking the backend, the order status is being amended as expected and the debug log file is being populated.

Next step, display something in the front end other than a blank page ... where am i going wrong ?

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
8 years 11 months ago #222271

Hi,

The notification is a function used for "server to server" ; is goal is not to display something.
You have to modify your order status and then perform a redirect ; specially if you're not using the function in the "server to server" but if it's the customer who use the page.

Please do not hesitate to take a look at the HikaShop payment plugins.. You have more than 50 examples in HikaShop.

Regards,


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.
The following user(s) said Thank You: BigDutch

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

  • Posts: 25
  • Thank you received: 1
8 years 11 months ago #222461

Thanks for helpful explanation, i understand now what is happening. In my payment plugin now, if the payment is success or fail, the order status is changed and the user is redirected to one of the two options :

success : HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id='.$order_id.$this->url_itemid;

This option displays "Thank you for your purchase." within the <div id="system-message-container">, the URL shows the order id, what about a menu item id in the URL to add module(s) ? where/how do i 'alter' the message given on this page, to extend it with additional text and variables ?

fail : HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=order&task=cancel_order&order_id='.$order_id.$this->url_itemid;

This option displays "The cart is empty" within the <div id="system-message-container">, but the URL is not showing the order ID but showing the Hikashop category listing menu item. As with the above 'status' i`d like to change message provided, and, not return to Hikashop category listing menu item.

I have seen in some payment plugins that a 'thankyou' page is called, but if possible i`d rather use as much of the built in HIKASHOP function as possible before and after the payment process.

Last edit: 8 years 11 months ago by BigDutch.

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

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
8 years 11 months ago #222470

Hi,

1. Normally, payment plugins have a "return_url" setting. When filled by the merchant, the after_end controller will automatically redirect to that URL. That way, the merchant can display whatever he wants on his thank you page.
But if you want to handle it at the plugin level, that's also possible. Simply change the success URL to go to another page where you would display whatever you want.
There is no mechanism to just change the thank you message from the payment plugin.

2.
That's because you have the setting "Clean cart when order is" set to "created" in the HikaShop configuration. Change it and you'll be back to your checkout so that you can continue the purchase with another payment method.
All, the messages can be modified with a translation override:
hikashop.com/download/languages.html#modify

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

  • Posts: 25
  • Thank you received: 1
8 years 11 months ago #222714

As function stands below, the user is redirected as required, and order status changes, however no debug log

But, if part (6b) and (6c) return are not commented, then the debug log is written, but the redirect doesn't work.

How to achieve redirect AND debug log ?

function onPaymentNotification(&$statuses)
	{
		// (1) Create array from the received gateway response parameters
		$vars = array();
		$filter = JFilterInput::getInstance();
		foreach($_REQUEST as $key => $value)
		{
			$key = $filter->clean($key);
			$value = JRequest::getString($key);
			$vars[$key]=$value;
		}
		
		// (2) We load the parameters of the plugin in $this->payment_params and the order data based on the order_id coming from the payment platform
		$order_id = (int)@$vars['OrderID'];
		$dbOrder = $this->getOrder($order_id);
		$this->loadPaymentParams($dbOrder);
		if(empty($this->payment_params))
			return false;
		$this->loadOrderData($dbOrder);
		
		// (3) Configure the "success/fail URLs" to re-direct in (6)
		$return_url = $this->pluginConfig['return_url'][2].'&order_id='.$order_id; //.$this->url_itemid ;
		$cancel_url = $this->pluginConfig['cancel_url'][2].'&order_id='.$order_id; //.$this->url_itemid ;

		// (4) Recalculate the hash to check for (6)
		$hash = $this->jcc_signature($this->payment_params->password,$vars,false,false);

		// (5) Debug mode activated or not
		if($this->payment_params->debug) 
		{
			//Display debug information in the payment log file
			
			echo print_r($vars,true)."\n\n\n";
			echo print_r($dbOrder,true)."\n\n\n";
			echo print_r($hash,true)."\n\n\n";
		}

		
		// (6) Confirm (or not) the order
		
		if (strcasecmp($hash,$vars['ResponseSignature'])!=0) //Different hash between what we calculate and the hash ent by the payment platform so we do not do anything as we consider that the notification doesn't come from the payment platform.
		{

		// (6a) we display debug information in the payment log file available in the configuration's Files section.
			if($this->payment_params->debug)
				echo 'Hash error '.$vars['ResponseSignature'].' - '.$hash."\n\n\n";
			return false;
		}

		// (6b) If gateway response is not success
		elseif($vars['ResponseCode']!='2')
		{

			$this->modifyOrder($order_id, $this->payment_params->invalid_status, true, true); 
			$JCCResponse = "Report by JCC</br>Error : " . $vars['ReasonCodeDesc'];
			$JCCResponseURL = $cancel_url;
			//return false;
		}

		// (6c) If gateway response is not success
		else	
		{
			$this->modifyOrder($order_id, $this->payment_params->verified_status, true, true);
			$JCCResponse = "Report by JCC</br>Success : " . $vars['ReasonCodeDesc'];
			$JCCResponseURL = $return_url;
			//return true;
		}

	$this->app->redirect($JCCResponseURL, $JCCResponse);
	
	}

Last edit: 8 years 11 months ago by BigDutch.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
8 years 11 months ago #222729

Hi,

Instead of performing "echo", you have to use

$this->writeToLog( $content );

Regards,


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.070 seconds
Powered by Kunena Forum