[Skip to main content](#vessel-content)

#   Ajax call to custom payment plugin

##

- **[Ramio91](/forum/user/60285-ramio91 "View Ramio91's Profile")**
- [![Ramio91's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/60285-ramio91 "View Ramio91's Profile") Topic Author
- [ Offline](/forum/user/60285-ramio91)

Less More

- Posts: 2
- Thank you received: 0
-
-

6 years 1 week ago [\#325526](#325526) by [Ramio91](/forum/user/60285-ramio91 "View Ramio91's Profile")  *[Ajax call to custom payment plugin](/forum/31-development/901132-ajax-call-to-custom-payment-plugin#325526 "-- HikaShop version -- : HikaShop Starter 4.3.0 -- Joomla version -- : 3.9 -- PHP version -- : 7.3.0  Hi,  I'm trying to develope a REST paypal payment process. The payment process works fine in sandbox and I can see the transactions between accounts. When Paypal return me a success, I made a pretty simpre AJAX call to my plugin to test ajax url and it works fine  but now there's the trick, when i'm inside my plugin I can't access hikashop environment/method/variable/class in any way  I read ther doc, and I found out that I need this line  now I tried to access to the user&#95;id using the helper method  but, when I log the response into the console I get an empty string  I'm a novice developing plugin, I had more experience developing joomla modules and components. I read about the trigger topic for plugin but thats a topic to study later. I need now to get data from cart &amp;&amp; user in order to create an order and create a payment  Would be a easier choise to get data from dbo? I can easily access joomla's environment/methods and so on from my custom plugin  thanks in advance")* was created by *[Ramio91](/forum/user/60285-ramio91 "View Ramio91's Profile")*

-- HikaShop version -- : HikaShop Starter 4.3.0
-- Joomla version -- : 3.9
-- PHP version -- : 7.3.0

Hi,

I'm trying to develope a REST paypal payment process. The payment process works fine in sandbox and I can see the transactions between accounts.
When Paypal return me a success, I made a pretty simpre AJAX call to my plugin to test ajax url and it works fine
Code:

jQuery("#ok").on("click", function(){ var formdata = new FormData(); formdata.append('cmd','payment'); jQuery.ajax({ url: 'index.php?option=com_hikashop&amp;ctrl=checkout&amp;task=notify&amp;notif_payment=paypal_api&amp;tmpl=component&amp;lang=IT', async: false, data: formdata, type: 'POST', contentType: false, processData: false, success: function(response) { console.log(response); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert("Status: " + textStatus); alert("Error: " + errorThrown); console.log(XMLHttpRequest); } }); });

but now there's the trick, when i'm inside my plugin I can't access hikashop environment/method/variable/class in any way

I read ther doc, and I found out that I need this line Code:

if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }

now I tried to access to the user_id using the helper method
Code:

$user = hikashop_loadUser(); return($user);

but, when I log the response into the console I get an empty string

I'm a novice developing plugin, I had more experience developing joomla modules and components. I read about the trigger topic for plugin but thats a topic to study later. I need now to get data from cart &amp;&amp; user in order to create an order and create a payment

Would be a easier choise to get data from dbo? I can easily access joomla's environment/methods and so on from my custom plugin
Code:

&lt;?php defined('_JEXEC') or die('Restricted access'); class plgHikashoppaymentpaypal_api extends hikashopPaymentPlugin { ... function onPaymentNotification(&amp;$statuses) { include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php'); $user = hikashop_loadUser(); return($user); //return empty string on response } ... }

thanks in advance

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwMTEzMi1hamF4LWNhbGwtdG8tY3VzdG9tLXBheW1lbnQtcGx1Z2luP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

6 years 1 week ago [\#325541](#325541) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Ajax call to custom payment plugin](/forum/31-development/901132-ajax-call-to-custom-payment-plugin#325541 "-- HikaShop version -- : HikaShop Starter 4.3.0 -- Joomla version -- : 3.9 -- PHP version -- : 7.3.0  Hi,  I'm trying to develope a REST paypal payment process. The payment process works fine in sandbox and I can see the transactions between accounts. When Paypal return me a success, I made a pretty simpre AJAX call to my plugin to test ajax url and it works fine  but now there's the trick, when i'm inside my plugin I can't access hikashop environment/method/variable/class in any way  I read ther doc, and I found out that I need this line  now I tried to access to the user&#95;id using the helper method  but, when I log the response into the console I get an empty string  I'm a novice developing plugin, I had more experience developing joomla modules and components. I read about the trigger topic for plugin but thats a topic to study later. I need now to get data from cart &amp;&amp; user in order to create an order and create a payment  Would be a easier choise to get data from dbo? I can easily access joomla's environment/methods and so on from my custom plugin  thanks in advance")*

Hi,

The onPaymentNotification function is called by the checkout controller which himself is called by the helper.php file.
So the helper.php file of HikaShop is already loaded in memory when the onPaymentNotification starts.
And, thus all the HikaShop functions and environment are already loaded and available for you to use.
That's not your problem here.
The problem is that in the checkout controller, for the notification mechanism, a buffer is started before the onPaymentNotification function is called and after the function is called, it get the information in the buffer and stores it in the payment log file (that you can access in the Files section of the HikaShop configuration).
That's because the code run in the onPaymentNotification function is normally a server to server HTTP request and thus when you output something, it would go to the payment gateway server, which you normally do not want. So the output gets logged instead.
So you should find your $user variable content in the payment log file.
If you want to output something back to the browser in the onPaymentNotifiation, you should echo it, and before returning, you should add an exit; or die() so that the checkout controller doesn't log the output but PHP directly sends it back to the browser.

The following user(s) said Thank You: [Ramio91](/forum/user/60285-ramio91 "View Ramio91's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwMTEzMi1hamF4LWNhbGwtdG8tY3VzdG9tLXBheW1lbnQtcGx1Z2luP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Ramio91](/forum/user/60285-ramio91 "View Ramio91's Profile")**
- [![Ramio91's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/60285-ramio91 "View Ramio91's Profile") Topic Author
- [ Offline](/forum/user/60285-ramio91)

Less More

- Posts: 2
- Thank you received: 0
-
-

6 years 1 week ago -  6 years 1 week ago [\#325570](#325570) by [Ramio91](/forum/user/60285-ramio91 "View Ramio91's Profile")  Replied by *[Ramio91](/forum/user/60285-ramio91 "View Ramio91's Profile")* on topic *[Ajax call to custom payment plugin](/forum/31-development/901132-ajax-call-to-custom-payment-plugin#325570 "-- HikaShop version -- : HikaShop Starter 4.3.0 -- Joomla version -- : 3.9 -- PHP version -- : 7.3.0  Hi,  I'm trying to develope a REST paypal payment process. The payment process works fine in sandbox and I can see the transactions between accounts. When Paypal return me a success, I made a pretty simpre AJAX call to my plugin to test ajax url and it works fine  but now there's the trick, when i'm inside my plugin I can't access hikashop environment/method/variable/class in any way  I read ther doc, and I found out that I need this line  now I tried to access to the user&#95;id using the helper method  but, when I log the response into the console I get an empty string  I'm a novice developing plugin, I had more experience developing joomla modules and components. I read about the trigger topic for plugin but thats a topic to study later. I need now to get data from cart &amp;&amp; user in order to create an order and create a payment  Would be a easier choise to get data from dbo? I can easily access joomla's environment/methods and so on from my custom plugin  thanks in advance")*

Thank you very much for your reply, it was really useful. Dealing with ajax call is always a pain because you cannot see well what's happening server side

Can I ask you which are the major steps to records a purchase on my system?

By abstraction I can think them as:

Order demand
Payment
Payment and Order insertion on database
Order creation
Notification

I'm I missing some steps inside hikashop environment?

//EDIT

return_url, cancel_url, and similar can be dealt easily with jQuery with a proper response to AJAX call so I don't need them as step

Last edit: 6 years 1 week ago by [Ramio91](/forum/user/60285-ramio91 "View Ramio91's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwMTEzMi1hamF4LWNhbGwtdG8tY3VzdG9tLXBheW1lbnQtcGx1Z2luP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

6 years 4 days ago [\#325613](#325613) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Ajax call to custom payment plugin](/forum/31-development/901132-ajax-call-to-custom-payment-plugin#325613 "-- HikaShop version -- : HikaShop Starter 4.3.0 -- Joomla version -- : 3.9 -- PHP version -- : 7.3.0  Hi,  I'm trying to develope a REST paypal payment process. The payment process works fine in sandbox and I can see the transactions between accounts. When Paypal return me a success, I made a pretty simpre AJAX call to my plugin to test ajax url and it works fine  but now there's the trick, when i'm inside my plugin I can't access hikashop environment/method/variable/class in any way  I read ther doc, and I found out that I need this line  now I tried to access to the user&#95;id using the helper method  but, when I log the response into the console I get an empty string  I'm a novice developing plugin, I had more experience developing joomla modules and components. I read about the trigger topic for plugin but thats a topic to study later. I need now to get data from cart &amp;&amp; user in order to create an order and create a payment  Would be a easier choise to get data from dbo? I can easily access joomla's environment/methods and so on from my custom plugin  thanks in advance")*

Hi,

I'm not sure what you mean by each point in

> Order demand
> Payment
> Payment and Order insertion on database
> Order creation
> Notification

I'm actually not even sure of what you mean by "the major steps to records a purchase on my system".
Because, to record an order in HikaShop, all you need is to call the save function of class.order with the necessary $order object properly formatted as it is done in the createFromCart function in class.order.
HikaShop will then handle the rest for you.

Now regarding the general workflow when an order is created at the end of the checkout, here is how it goes:
- the customer clicks on the "finish" button of the checkout
- the checkout system checks that everything has been properly entered/selected in the checkout
- it loads the cart and converts it into an order object
- the order creation process starts
- plugins are called with the onBeforeOrderCreate trigger
- if there was a credit card form on the checkout, the payment plugin will usually do the payment at that point and if the payment fails, it will cancel the order creation. If it succeeds, it ill usually change the status of the order to confirmed
- the order is added in the database
- the stock is updated for each order
- plugins are called with the onAfterOrderCreate trigger
- the order creation notification email is sent
- the onAfterOrderConfirm trigger of the selected payment plugin is called
- the plugin usually returns a redirect HTML form so that HikaShop displays it to the customer to be redirected to the payment gateway
- the customer fill his credit card information on the payment gateway
- the payment gateway sends a notification to the onPaymentNotification trigger of the payment plugin so that it can change the status of the order to confirmed and HikaShop will then send the order status notification email to the customer.
- the customer is redirected back to the website with the thank you page.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwMTEzMi1hamF4LWNhbGwtdG8tY3VzdG9tLXBheW1lbnQtcGx1Z2luP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.059 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
