- Posts: 23
- Thank you received: 1
create Ajax function in hikashop payment plugin
8 years 8 months ago - 8 years 8 months ago #285590
by plnabais
create Ajax function in hikashop payment plugin was created by plnabais
-- HikaShop version -- : 3.2.1
-- Joomla version -- : 3.7
-- PHP version -- : 7.0
I'm trying to create a payment plugin that uses ajax, but when I create the function onAjax[plugin] it not register in the trigger array, there is any solution for that?
function created in the braintree.php file in the Hikashoppayment group plugin
call to the function in the javascript
-- Joomla version -- : 3.7
-- PHP version -- : 7.0
I'm trying to create a payment plugin that uses ajax, but when I create the function onAjax[plugin] it not register in the trigger array, there is any solution for that?
function created in the braintree.php file in the Hikashoppayment group plugin
Code:
class plgHikashoppaymentBraintree extends hikashopPaymentPlugin
{
...
public function onAjaxBraintree(){
echo '<script> alert("onAjaxBraintree") </script>';
}
...
}
Code:
function brain_execute(action){
var w_data = {
'option' : 'com_ajax',
'group' : 'Hikashoppayment',
'plugin' : 'Braintree',
'format' : 'json',
'token' : w_card_activ,
'nonce' : w_card_nonce,
'action' : action
};
jQuery.ajax({
type : 'POST',
data : w_data,
success : function (response) { console.log(response);},
error : function (response) { console.log(response);}
});
};
Last edit: 8 years 8 months ago by Jerome. Reason: [code] tag is so nice !
Please Log in or Create an account to join the conversation.
8 years 8 months ago #285592
by nicolas
Replied by nicolas on topic create Ajax function in hikashop payment plugin
Hi,
Payment plugins are standard Joomla plugins so you can use com_ajax with them the same way you would for any joomla plugin.
There is nothing particular to do.
However, I see that you have :
'group' : 'Hikashoppayment',
but the first character should be lowercase.
Also, I see that you didn't set any "url" parameter when calling jQuery.ajax
Payment plugins are standard Joomla plugins so you can use com_ajax with them the same way you would for any joomla plugin.
There is nothing particular to do.
However, I see that you have :
'group' : 'Hikashoppayment',
but the first character should be lowercase.
Also, I see that you didn't set any "url" parameter when calling jQuery.ajax
Please Log in or Create an account to join the conversation.
8 years 8 months ago - 8 years 8 months ago #285632
by plnabais
Replied by plnabais on topic create Ajax function in hikashop payment plugin
hello Nicolas,
I have tried with the hikashoppayment all in lowercase and result is the same. The problem is in the
the function onAjaxBraintree is not registred in the triggers array of Joomla and I do not understand why.
I have debugged the array and the onajaxbraintree entry does not exist.
if you verify in the
$dispatcher = JEventDispatcher::getInstance();
at line 140 of com_ajax\ajax.php the array _methods of the $dispatcher do not include the onajaxbraintree so it's not executed.
I have hacked the system hikashoppayment plugin and add at the end the following code:
and I have used the following javascript function, and it works.
but if it's possible I prefer the solution to include the ajax function directly in the plugin.
If I have understood correctly, with the new Joomla router and JSON format there is no need to specify the url, we only have to define the option, the group and the plugin in the data to be passed in the jQuery call.
I have tried with the hikashoppayment all in lowercase and result is the same. The problem is in the
Code:
class plgHikashoppaymentBraintree extends hikashopPaymentPlugin
{
...
public function onAjaxBraintree(){
echo '<script> alert("onAjaxBraintree") </script>';
}
...
}
I have debugged the array and the onajaxbraintree entry does not exist.
if you verify in the
$dispatcher = JEventDispatcher::getInstance();
at line 140 of com_ajax\ajax.php the array _methods of the $dispatcher do not include the onajaxbraintree so it's not executed.
I have hacked the system hikashoppayment plugin and add at the end the following code:
Code:
public function onAjaxHikashoppayment() {
if(!include_once(rtrim(JPATH_PLUGINS,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'Hikashoppayment'.DIRECTORY_SEPARATOR.$_POST["dir"].DIRECTORY_SEPARATOR.$_POST["file"]))
return;
$manageToken = new $_POST['class'];
$func=$_POST['func'];
$manageToken->{$func}();
}
Code:
function brain_execute(action){
var w_data = {
'option' : 'com_ajax',
'group' : 'system',
'plugin' : 'Hikashoppayment',
'format' : 'json',
'dir' : 'Braintree',
'file' : 'helper.php',
'class' : 'plgHikashoppaymentBraintreeHelper',
'func' : 'onAjaxBraintree',
'token' : w_card_activ,
'nonce' : w_card_nonce,
'action' : action
};
jQuery.ajax({
type : 'POST',
data : w_data,
success : function (response) { console.log(response);},
error : function (response) { console.log(response);}
});
};
If I have understood correctly, with the new Joomla router and JSON format there is no need to specify the url, we only have to define the option, the group and the plugin in the data to be passed in the jQuery call.
Last edit: 8 years 8 months ago by Jerome. Reason: [code] tag is awesome !
Please Log in or Create an account to join the conversation.
8 years 8 months ago #285637
by nicolas
Replied by nicolas on topic create Ajax function in hikashop payment plugin
Hi,
Functions are automatically registered in the dispatcher. Make sure that you don't have a __construct function and if you do, make sure that you call the parent::_construct function from it so that Joomla can do its thing.
Functions are automatically registered in the dispatcher. Make sure that you don't have a __construct function and if you do, make sure that you call the parent::_construct function from it so that Joomla can do its thing.
Please Log in or Create an account to join the conversation.
8 years 8 months ago - 8 years 8 months ago #285693
by plnabais
Replied by plnabais on topic create Ajax function in hikashop payment plugin
I have a construct function, and I call the parent::__construct function
Code:
function __construct(&$subject, $config) {
// Calling the parent Constructor
parent::__construct($subject, $config);
// Do some extra initialisation in this constructor if required
$this->manageToken = new plgHikashoppaymentBraintreeHelper;
}
Last edit: 8 years 8 months ago by plnabais.
Please Log in or Create an account to join the conversation.
8 years 8 months ago #285695
by Jerome
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.
Replied by Jerome on topic create Ajax function in hikashop payment plugin
Hello,
Why not simply using the notification URL and add some parameters in order to "dispatch" the processings ?
Hacking the HikaShop core with such kind of specific code will not be good for the long run because you cannot update anymore (without loosing your modifications).
Regards,
PS :The plugin group "hikashoppayment" do not have any uppercase.
Why not simply using the notification URL and add some parameters in order to "dispatch" the processings ?
Hacking the HikaShop core with such kind of specific code will not be good for the long run because you cannot update anymore (without loosing your modifications).
Regards,
PS :The plugin group "hikashoppayment" do not have any uppercase.
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.
8 years 8 months ago - 8 years 8 months ago #285720
by plnabais
Replied by plnabais on topic create Ajax function in hikashop payment plugin
Hello Jerome
I agree totally with you, hacking the hikashop core is not good for upgrading, but I need an ajax function to interact with the user when he chooses the payments methods saved in the braintree vault.
I have spent 1-week trying com_ajax directly in the plugin with all the variant of upper and lowercases, and It not works by any means. So the only solution I found was this, change the system plugin of hikashop. I would like to find a workaround to have no concerns regarding future updates, and eventually be able to sell the plugin.
Best regards
I agree totally with you, hacking the hikashop core is not good for upgrading, but I need an ajax function to interact with the user when he chooses the payments methods saved in the braintree vault.
I have spent 1-week trying com_ajax directly in the plugin with all the variant of upper and lowercases, and It not works by any means. So the only solution I found was this, change the system plugin of hikashop. I would like to find a workaround to have no concerns regarding future updates, and eventually be able to sell the plugin.
Best regards
Last edit: 8 years 8 months ago by plnabais.
Please Log in or Create an account to join the conversation.
8 years 8 months ago #285724
by Jerome
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.
Replied by Jerome on topic create Ajax function in hikashop payment plugin
Hello,
As I wrote in my previous message : The work around is to use the notify URL, there are already several plugins doing that.
Regards,
As I wrote in my previous message : The work around is to use the notify URL, there are already several plugins doing that.
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.
8 years 8 months ago #286060
by plnabais
Replied by plnabais on topic create Ajax function in hikashop payment plugin
Hello,
Is there any code example of using AJAX in a plugin for hikashop?
Regards
Is there any code example of using AJAX in a plugin for hikashop?
Regards
Please Log in or Create an account to join the conversation.
8 years 8 months ago #286063
by nicolas
Replied by nicolas on topic create Ajax function in hikashop payment plugin
Hi,
No.
But there is nothing complex.
Just call in Ajax the notification URL of the plugin with an extra parameter.
For example:
And in your onPaymentNotification function of the plugin, you can do such code at the beginning:
No.
But there is nothing complex.
Just call in Ajax the notification URL of the plugin with an extra parameter.
For example:
Code:
index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=braintree&tmpl=component&specialparam=1
Code:
if(!empty($_REQUEST['specialparam'])){
//PHP ajax process... echo stuff you want for your javascript...
exit;
}
Please Log in or Create an account to join the conversation.
Time to create page: 0.214 seconds