Display a nottification alert after order has been made successfully

  • Posts: 12
  • Thank you received: 0
3 years 1 month ago #330201

-- Joomla version -- : 3.9

Hi,

I am developing a payment plugin for Hikashop, based in example plugin provided by Hika.

In my case, in onAfterOrderConfirm function some curl request will be made, if everything is fine, the user will be redirected in a page for writing his card credentials. If everything is fine, The user will be redirected back in the shop, where a nottification success alert should appear.

My question is how to display a success nottification or alert that notify user that order has been made successfully.

Regards.

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

  • Posts: 81484
  • Thank you received: 13062
  • MODERATOR
3 years 1 month ago #330202

Hi,

There are two scenarios:
- after the payment, the payment gateway sends a server to server request to your website to confirm the payment.
In that case, you can directly redirect back the user to the "after_end" URL of HikaShop. HikaShop will display its thank you page automatically. And you can provide the payment notification URL to your payment gateway for the server to server request so that ht will reach the onPaymentNotification function of your plugin to confirm the order.
- after the payment, the payment gateway doesn't send a server to server request to your website but directly includes the data of the payment when redirecting the customer back to your website.
In that case, you want to give the payment notification URL to the payment gateway so that the customer will be redirected back to it after the payment. Then, in the onPaymentNotification you can confirm the order, and after that redirect the customer to the "after_end" URL of HikaShop.

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

  • Posts: 12
  • Thank you received: 0
3 years 1 month ago #330234

Hi,

In my case, i should send URLs to server via http using curl. The URLs I should send are: ApproveURL, CancelURL, DeclineURL.

What Url should I send to server (to the payment endpoint) to notify user if everything is OK.

*Worth mentioning that the requests to payment server I am making inside onAfterOrderConfirmFunction.

Last edit: 3 years 1 month ago by lirimimeri.

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

  • Posts: 81484
  • Thank you received: 13062
  • MODERATOR
3 years 1 month ago #330235

Hi,

You should give the payment notification URL for the approveURL:

$notify_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify&notif_payment='.$this->name.'&tmpl=component';
That way, when the user comes back to your website after the payment, your plugin onPaymentNotification function will be called.
There, you can confirm the order with a call to the modifyOrder function (as per the example payment plugin on our developer documentation) and then you can redirect the customer to the thank you page with the after_end URL:
$return_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id='.$order_id.$this->url_itemid;
For the CancelURL and the DeclineURL, you can provide the cancel URL:
$cancel_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=order&task=cancel_order&order_id='.$order_id.$this->url_itemid;
That way, when the payment fails, the customer will be redirected back to the checkout with an error message and he will be able to try again, select another payment method, etc.

Just in case you didn't see it yet, I would recommend to check on the example payment plugin that we provide there:
www.hikashop.com/support/documentation/6...on.html#howtopayment
It's heavily commented and explains the different parts of the code including the pieces I'm talking about here.

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

  • Posts: 12
  • Thank you received: 0
3 years 1 month ago #330272

Hi.

I have downloaded the example plugin and I'm expanding it for my purposes.

Those links doesn't work as expected for me. The first one, redirecting me from payment page back to shop, shows me a blank white page, others redirect me back in the shop, but doesn't show any error message.

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

  • Posts: 81484
  • Thank you received: 13062
  • MODERATOR
3 years 1 month ago #330289

Hi,

It's normal that the first link displays a blank page.
As I said, it will call the onPaymentNotification function of your plugin.
And then, as I said, in that function, after you confirm the order, you need to redirect the customer to the thank you page.

If you check the example plugin's code in the onPaymentNotification, when everything is OK, you can see two lines of code:

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

			//$this->app->redirect($return_url);
The first one is to confirm the order.
The second one is to redirect the customer to the thank you page. It is commented out in the example plugin because we wrote the code as if the onPaymentNotification function would be called in a server to server request. And in that case, you don't want a redirect.
Bu if it is called by a redirect of the customer, you want to have that line uncommented.

Regarding the other links, if you don't get any message, it could be that your template is not displaying the messages. That's a common issue:
www.hikashop.com/support/documentation/6...tibility-issues.html
But it could also be that it's because you need to display the message yourself with such code:
$app = JFactory::getApplication();
$app->enqueueMessage('My message');

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

  • Posts: 12
  • Thank you received: 0
3 years 1 month ago #330296

Hi.

If I understood correctly, I should also make any simple thank you page, as I saw it in another payment plugin.

I have another issue right now, $this->payment_params is always null in onPaymentNotification.

Thank you in advance.

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

  • Posts: 81484
  • Thank you received: 13062
  • MODERATOR
3 years 1 month ago #330298

Hi,

No, you don't need to have your own thank you page (although you could).
you can simply redirect to the thank you page of HikaShop with such code:

$return_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id='.$order_id.$this->url_itemid;
$this->app->redirect($return_url);
HikaShop will display a thank you message for you, with a link to the order details page.

Regarding your question about $this>payment_params, it is initialized by the line:
$this->loadPaymentParams($dbOrder);
So before that line, $this>payment_params is indeed null. After that, if that variable is still null it's either that the payment method of the order doesn't correspond to the current payment plugin, or that the variable $dbOrder is empty so make sure that $dbOrder contains the information about the order.

The following user(s) said Thank You: lirimimeri

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

Time to create page: 0.068 seconds
Powered by Kunena Forum