Payment success on return from gateway

  • Posts: 10
  • Thank you received: 0
4 years 2 months ago #324092

-- HikaShop version -- : HikaShop Business 4.2.1
-- Joomla version -- : 3.9.21
-- PHP version -- : 7.2

I'm developing a payment plugin for a gatewayfor wich no plugin for hikashop exists following the documentation and looking at other plugins .
The code works well, but i have one issue / question:
The gateway sends the payment result via get-parameter (success=OK or success=KO).
As return url i've added the following url:
xxx.xxx/index.php?option=com_hikashop&am...n=xxx&Itemid=xxx

How do i set the payment success inside the hikashop plugin when the user returns to the site?
Since it always shows "Thank you, the order is complete" or similar.
How do i read the parameter and set the order / payment as failed? Is there a callback and an api how to set the payment-success / failure?

Thanks in advance!

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 2 months ago #324093

Hi,

You should provide the "payment notification URL" to the gateway for the return URL. That way, you'll be able to do the confirmation of the order in the onPaymentNotification function of your plugin, and based on the success value, you'll be able to then do a redirect to either the return URL, or the cancel URL.
If you didn't see it yet, I would recommend to check on the example payment plugin available on the documentation. It is heavily commented to better understand what does what.

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

  • Posts: 10
  • Thank you received: 0
4 years 1 month ago #324154

Thanks, i managed to save the order depending on the gateway-result and also sent the confirmation mail to the shop admin.
However, how do i redirect the user from the "onPaymentNotification" action to the success or failure page? In the example this method simply returns false or true, wich in my case doesn't redirect anywhere.
So i tried to use a manual redirect like this (the url taken from the moneybookers gateway):
header('Location: '.HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=order&task=after_end&order_id='.$dbOrder->order_id);

It does redirect the user to the url and also the order-id is passed correctly, but i get a 403 access denied...
Where do i need to redirect the user?

Thanks in advance!

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 1 month ago #324159

Hi,

Again, please check the code of the example payment plugin.
You'll see there such line:
//$this->app->redirect($return_url);
The line is commented so that no redirect happens as it is not needed when it's the payment gateway server directly sending a payment notification request.
But when the payment gateway gateway redirects the customer to the notification URL, you want to use that redirect to move the user to the thank you page.

Your line of code doesn't work properly because you don't set the Itemid parameter in the URL. On some websites, this can lead to Joomla choosing a menu item not accessible and thus you get an error.
as you can see in the example plugin code, the URL has a $this->url_itemid parameter added to it which is there precisely to avoid that:
$return_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id='.$order_id.$this->url_itemid;

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

  • Posts: 10
  • Thank you received: 0
4 years 1 month ago #324185

Thanks, i managed to make it work that way.

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

Time to create page: 0.058 seconds
Powered by Kunena Forum