Custom plugin

  • Posts: 32
  • Thank you received: 0
10 years 4 months ago #162531

Hi guys

I have successfully set up hikashop with the worldpay payment gateway and it all works great. However, I'd like to be able to run a little but of custom code ideally when worldpay silently posts back to my site or if not when the customer returns to my site by clicking on the button on worldpay to return to my site. I'm thinking that ill have to write a custom plugin to achieve this? If so which plugin event would I have to write a plugin for? I'd like to fire the code in the same execution cycle that the basket is cleared out and the order status is updated after the customer makes a successful payment on worldpay if possible?

Thanks for your help

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

  • Posts: 82909
  • Thank you received: 13379
  • MODERATOR
10 years 4 months ago #162541

Hi,

You can create a HikaShop implementing the onAfterOrderUpdate trigger.
In it, just check the old and new status of the order:

function onAfterOrderUpdate(&$order){
 if(@$order->order_status == 'confirmed' && @$order->old->order_status=='created'){
  //your custom code
 }
}

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

  • Posts: 32
  • Thank you received: 0
10 years 4 months ago #162647

Hi Nicolas,

Thanks for your help. That bit of code worked perfectly. However, for some reason i cannot seem to access the session data within this function. Is there a reason for this? I wanted to clear out some custom session data when after the user has paid for his order and when he his returned to the site...So my function now looks like:-

    public function onAfterOrderUpdate(&$order,&$send_email) {
        if((@$order->old->order_status=='created') && (@$order->order_status == 'verified')) {
            $session =& JFactory::getSession();

            $session->clear('samplebox_cid');
            $session->clear('samplebox_img');
            $session->clear('samplebox_name');
        }

        return true;
    }

Thanks for all your help

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

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
10 years 4 months ago #162650

Hi,

The order can be updated in different context : a validation in backend, a payment gateway notification, etc.
So, yes you can't access to the user session because you're not running in the same session that the user.

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.

  • Posts: 27
  • Thank you received: 4
9 years 1 month ago #218489

It's understandable that the event can be triggered from anywhere, therefore the session can't be the same as the one the user has. However, what if I wanted to enqueue a system message to display back to the user?

How could something like this work?:

public function onAfterOrderUpdate(&$order, &$sendmail)
{
     parent::onAfterOrderUpdate($order, $sendmail);
     // do some other stuff

     // This message won't make it to after_end.php
     JFactory::getApplication()->enqueueMessage('critical message here');
}

Last edit: 9 years 1 month ago by fengel.

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

  • Posts: 82909
  • Thank you received: 13379
  • MODERATOR
9 years 1 month ago #218494

The short answer is : it depends :)

The long answer is:
Normally, with most payment methods, you're redirected to the payment gateway's payment page after the checkout. Then, once the payment is done, you're brought back to the after_end page where you see the thank you message.
The onAfterOrderUpdate trigger is called during the payment notification which is a server-to-server call from the payment gateway to the payment plugin. So it's not the same session as the session of the customer and thus, if you enqueueMessage a message in the onAfterOrderUpdate, that message will be displayed to the payment gateway server, not your customer.
Thus, that's not a good approach.
The best is to directly edit the file "after_end" of the view "checkout" via the menu Display>Views and directly add your message there.
If it has to be dynamic based on data that you can only get in the onAfterOrderUpdate trigger, you can always store it in the hikashop_order table with a MySQL query and then retrieve it in the after_end view file. However, there is also a slim possibility that the payment notification will be received only after the customer is redirected to the after_end view file (that shouldn't be the case with most payment gateways in normal conditions, but it will likely happen (it happened a few times with PayPal in the past few years for example) ) and in that case, you won't be able to do a dynamic message based on the onAfterOrderUpdate available data.

The following user(s) said Thank You: fengel

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

Time to create page: 0.067 seconds
Powered by Kunena Forum