Payment plugin problems

  • Posts: 8
  • Thank you received: 0
13 years 1 month ago #27185

Hi

I am in process of writing a payment plugin and have a number of problems which have been unable to find answer for as yet.

1. In the 'onAfterOrderConfirm' method I make a SOAP call to payment server and am issued with a transaction id and redirection url. All good but when I try to update order details nothing is happening. I originally traced error with $order->order_url and have implemented your suggestion to place an unset command before the save, still no data goes to database.
2. After returning from the Payment Gateway screen in 'onPaymentNotification' I get all necessary data I was expecting and process and update order in database ( strangely the save works here even though order object looks same as in previous 'onAfterOrderConfirm' call ). One problem is that Joomla is not associating the page with the template correctly so it is reverting to the system template ebven though this is not default. The other problem may be directly related to this as nothing happens after this. I have checked the other payment plugins and seems nothing different, just process, send emails and then save order, yet with the other plugins a screen is displayed with appropriate messages.

The urls I am sending to payment gateway were constructed based on those I saw in other plugins
i.e.
This is what I send
www.website.co.uk/index.php?option=com_h...t&lang=en&Itemid=430

This is after payment gateway appends
www.website.co.uk/index.php?option=com_h...LINED&PageSource=WEB

( website address is on internal server so I cannot give access ).

I may be misunderstanding the process but it seems from looking at the other plugins that 'onPaymentNotification' is called, processes and returns, where and how is it then redirected to display another page?

Thanks in advance!

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #27191

Hi,

1. Do you have the order_id in your variable ? does the save function returns true or false ? Could you copy/paste your code ?

2. The onPaymentNotification function is usually used only for a server to server notification from the payment gateway to HikaShop, in order to notify the website that the payment has been made. That's why there is no redirection in the other payment plugins. There is no need to redirect the payment gateway anywhere.

The users are just redirected to a thank you page which doesn't have any code to validate the order as that is done with the.onPaymentNotification function.

An exception to that is the authorize.net plugin. In the onPaymentNotification function, the thank you page is displayed directly.
That's because authorize.net does not have a different process for the payment notification which has to be done via the user return on the website. So you might want to look at that payment plugin if that's how you have to implement it.

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

  • Posts: 8
  • Thank you received: 0
13 years 1 month ago #27219

Hi

Thanks for reply yesterday, I am currently looking at the authorize code but still getting a problem where Joomla fails to assign a template to the page after 'onPaymentNotification'

function onPaymentNotification(&$statuses){
        $pluginsClass = hikashop_get('class.plugins');
        $elements = $pluginsClass->getMethods('payment','advam');
        if(empty($elements)) return false;
        $element = reset($elements);
        $vars = array();
        $data = array();

   $filter = & JFilterInput::getInstance();
        foreach($_REQUEST as $key => $value){
                $key = $filter->clean($key);
                $value = JRequest::getString($key);
                $vars[$key]=$value;
        }

        $orderClass = hikashop_get('class.order');
        $dbOrder = $orderClass->get((int)@$vars['refid']);
        if(empty($dbOrder)){
                echo "Could not load any order for your notification ".@$vars['refid'];
                return false;
        }

        $order = null;
        $order->order_id = $dbOrder->order_id;
        $order->old_status->order_status=$dbOrder->order_status;

        // Here we need to decide what to do based on the REQUEST variable result
        // And set the email messages up

 switch( $vars['result']  ){

                case 'approved' :
                        /* Here we extract the order id and update order to APPROVED - AWAITING PAYMENT */
                        if($element->payment_params->debug){

                                echo "<br />===========================================================<br$
                                echo "Order has been approved<br/>" ;
                                echo "ORDER ID : ".$vars['refid']."<br />" ;
                                echo "TRANSACTION ID : ".$vars['TransactionId']."<br />" ;
                                echo "<br />===========================================================<br$
                        }
                        $vars['payment_status'] = "approved" ;
                        $order->order_status = "approved";
                        $order->authorisationcomplete = $vars['AuthorisationComplete'];
                        $order->transactionid = $vars['TransactionId'] ;
                        $order->transactionstatus = $vars['Success'] ;
                        $order->paymentid = $vars['PaymentId'] ;
                        $order->responsecode = $vars['ResponseCode'];
                        $order->responsetext = $vars['ResponseText'];

                        $order->history->history_notified=1;

                        break ;

                case  'declined' :

                        /* Here may be the same as below we display the end page with error messge */
                        if($element->payment_params->debug){
                                echo "<br />===========================================================<br$
                                echo "Order has been declined<br/>" ;
                                echo "ORDER ID : ".$vars['refid']."<br />" ;
                                echo "Response Text : ".$vars['ResponseText']."<br />" ;
                                echo "<br />===========================================================<br$
                        }

                        $vars['payment_status'] = "declined" ;
                        $order->order_status = "declined";
                        $order->authorisationcomplete = $vars['AuthorisationComplete'];
                        $order->transactionstatus = $vars['Success'] ;
                        $order->paymentid = $vars['PaymentId'] ;
 $order->responsecode = $vars['ResponseCode'];
                        $order->responsetext = $vars['ResponseText'];

                        break ;

                case  'error' :

                        $vars['payment_status'] = "error" ;
                        $order->order_status = "error";
                        $order->authorisationcomplete = $vars['AuthorisationComplete'];
                        $order->transactionstatus = $vars['Success'] ;
                        $order->paymentid = $vars['PaymentId'] ;
                        $order->responsecode = $vars['ResponseCode'];
                        $order->responsetext = $vars['ResponseText'];

                        // Not sure on this one
                        // Is for the failure email I think

                        if($element->payment_params->debug){
                                echo "<br />===========================================================<br$
                                echo "Order has ERROR<br/>" ;
                                echo "ORDER ID : ".$vars['refid']."<br />" ;
                                echo "ERROR : ".$vars['ErrorMessage']."<br />" ;
                                echo "<br />===========================================================<br$
                        }

                        break ;
        }


        if($element->payment_params->debug){
                echo print_r($dbOrder,true)."\n\n\n";
        }

  // Does this just happen when order Approved
        $order->history->history_reason=JText::sprintf('AUTOMATIC_PAYMENT_NOTIFICATION');
        $order->history->history_notified=0;
        // As this is not passed back do we just use the order full price
        $order->history->history_amount= $dbOrder->order_full_price;    // .$order->currency_id Originally$
        $order->history->history_payment_id = $element->payment_id;
        $order->history->history_payment_method =$element->payment_type;
        $order->history->history_data = ob_get_clean();
        $order->history->history_type = 'payment';
        $currencyClass = hikashop_get('class.currency');
        $currencies=null;
        $currencies = $currencyClass->getCurrencies($dbOrder->order_currency_id,$currencies);
        $currency=$currencies[$dbOrder->order_currency_id];
  unset($order->order_url);
        $orderClass->save($order);

        /* Here all processing complete need to add mail messages and sort redirect to a thank you page.
 Have tried to do same as authorize plugin but Joomla seems to fail to assign the default template to the page and I end up with a blank page.
What I need is to create an appropriate message and display a page to display that message and allow user to click 'CONTINUE SHOPPING'
*/

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #27221

In the onPaymentNotification function of the authorize.net payment plugin, there is the code below which displays the thank you page. I don't see such code in your onPaymentNotification function :

		$app =& JFactory::getApplication();
		$name = $element->payment_type.'_thankyou.php';
    	$path = JPATH_THEMES.DS.$app->getTemplate().DS.'hikashoppayment'.DS.$name;
    	if(!file_exists($path)){
    		if(version_compare(JVERSION,'1.6','<')){
    			$path = JPATH_PLUGINS .DS.'hikashoppayment'.DS.$name;
    		}else{
    			$path = JPATH_PLUGINS .DS.'hikashoppayment'.DS.$element->payment_type.DS.$name;
    		}
    		if(!file_exists($path)){
    			//that should not happen !
    		}
    	}
    	ob_start();
    	require($path);

    	$msg = ob_get_clean();
    	return $msg;

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #27222

Note that this code uses a authorize_thankyou.php file sitting next to the main file of the plugin.

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

  • Posts: 8
  • Thank you received: 0
13 years 1 month ago #27223

Hi

No at present not there as when I tried it did not work just got a blank page. Seems to be that Joomla for some reason assigns the system template to the page and displays nothing?????
I am just debugging now

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
13 years 1 month ago #27224

As you can see in authorize.net, the notification URL does not contain the "&tmpl=component" which indicates to joomla to not display the template around the main area of your website. We use it on the other plugins in order to reduce the time it takes to process the page since the notification page is only called by the payment server.
In your case, you should not have it as you want to display a normal page to your users.

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

Time to create page: 0.072 seconds
Powered by Kunena Forum