VirtueMart Forum

VirtueMart 2 + 3 => Plugins: Payment, Shipment and others => Topic started by: gba on June 13, 2018, 14:13:07 pm

Title: Function plgVmOnPaymentNotification in payment plugins without parameter
Post by: gba on June 13, 2018, 14:13:07 pm
Hi plugin developers!

We just ran into problems, if we used the function 'plgVmOnPaymentNotification' in our own payment plugin.
After updating to VM 3.2.14 this function has a new definition now.

Old definition:
Code: [Select]
function plgVmOnPaymentNotification(&$html)
New definition:
Code: [Select]
function plgVmOnPaymentNotification()
As you can see, the function now does not have any parameter anymore.

We found that out, because a payment provider could not notify VM anymore, as the old function definition produces an error now:
"Error: 0 Too few arguments to function plgVmPaymentOurPaymentMethod::plgVmOnPaymentNotification(), 0 passed in /home/www/gmr/libraries/joomla/event/event.php on line 70 and exactly 1 expected"

As soon as we removed the parameter, the problems where gone.
Maybe this information is helpful also for someone else.

BTW:
Do we need to run into problems to find out such (quite essential) code changes in VM, or is there any information source about necessary changes for third party extensions to be able to keep them up-to-date with VM before updating to each next version?

Kind regards,
Gerald
Title: Re: Function plgVmOnPaymentNotification in payment plugins without parameter
Post by: Jörgen on June 13, 2018, 16:27:22 pm
This sounds like a strange issue, how old is Your plugin ?
What VM version have You updated from ?

I can see this so called "new" declaration to be used already in VM version 3.0.6 from may 2015, three years ago....

Who has developed "Your" plugin ?

regards

Jörgen @ Kreativ Fotografi
Title: Re: Function plgVmOnPaymentNotification in payment plugins without parameter
Post by: gba on June 13, 2018, 16:42:08 pm
Hi!

I developed it myself and used it without issues with VM 3.2.12.
But I guess moving from PHP 7.0 to 7.2 now brought that issue up.

Quote
BTW:
Do we need to run into problems to find out such (quite essential) code changes in VM, or is there any information source about necessary changes for third party extensions to be able to keep them up-to-date with VM before updating to each next version?
Do you have any hint for me?

Kind regards,
Gerald
Title: Re: Function plgVmOnPaymentNotification in payment plugins without parameter
Post by: Jörgen on June 13, 2018, 17:18:56 pm
I do not know where You got your declaration from, but this function has not had any parameters as far as I know. Check the PayPal plugin as an example for how to design the calls. PHP seven has a stricter type check than PHP five and but this does not make an badly designed call better. It was wrong from the beginning and most certainly not caused by a VM update.

regards

Jörgen @ Kreativ Fotografi
Title: Re: Function plgVmOnPaymentNotification in payment plugins without parameter
Post by: jenkinhill on June 13, 2018, 17:27:33 pm
AFAIK there are still some issues with PHP7.2, I don't recommend any higher than 7.1 and I'm staying at 7.0 for most of my websites. The advice given on the Joomla facebook group is still to use no higher than 7.1 with the current Joomla version.
Title: Re: Function plgVmOnPaymentNotification in payment plugins without parameter
Post by: gba on June 21, 2018, 10:24:18 am
Thank you very much for your advice - I turned back to PHP 7.1 now.

Quote
BTW:
Do we need to run into problems to find out such (quite essential) code changes in VM, or is there any information source about necessary changes for third party extensions to be able to keep them up-to-date with VM before updating to each next version?
Do you have any hint for me?

Kind regards,
Gerald
Title: Re: Function plgVmOnPaymentNotification in payment plugins without parameter
Post by: Jörgen on June 21, 2018, 10:27:16 am
Read my reply:
Quote
I do not know where You got your declaration from, but this function has not had any parameters as far as I know. Check the PayPal plugin as an example for how to design the calls. PHP seven has a stricter type check than PHP five and but this does not make an badly designed call better. It was wrong from the beginning and most certainly not caused by a VM update.

What more Do you need ?

regards

Jörgen @ Kreativ Fotografi
Title: Re: Function plgVmOnPaymentNotification in payment plugins without parameter
Post by: gba on June 21, 2018, 10:58:34 am
Hi!

I would like to know about necessary code changes in the VM extensions I made before I update to the next VM version.
Is there any information source about that anywhere?

Kind regards,
Gerald
Title: Re: Function plgVmOnPaymentNotification in payment plugins without parameter
Post by: jenkinhill on June 21, 2018, 11:28:02 am
You could check the comments for changes in the repository.  http://dev.virtuemart.net/projects/virtuemart/repository
Title: Re: Function plgVmOnPaymentNotification in payment plugins without parameter
Post by: Studio 42 on June 21, 2018, 22:27:20 pm
check in another payment plugins, paypal, paybox or standard for basic functions.
Title: Re: Function plgVmOnPaymentNotification in payment plugins without parameter
Post by: gba on June 21, 2018, 22:30:39 pm
@jenkinhill: Thank you very much for that hint!
@Studio 42: Thank you, too - a bit off-topic, though  ;)
Title: Re: Function plgVmOnPaymentNotification in payment plugins without parameter
Post by: Studio 42 on June 21, 2018, 22:51:39 pm
@Studio 42: Thank you, too - a bit off-topic, though  ;)
It's the best way to check what to do, when you have not a full doc (and i dont mean that any real doc exist, only some lines )
If you check in paybox plugin for eg. You can understand how it work and compare the function
About
Quote
"Error: 0 Too few arguments to function plgVmPaymentOurPaymentMethod::plgVmOnPaymentNotification(), 0 passed in /home/www/gmr/libraries/joomla/event/event.php on line 70 and exactly 1 expected"
This error is since php 7, because it's bad to not provide same number of arguments and PHP parent/child class should always follow this rule, to prevent mistake.
This can be a problem when a new argument is needed and sometime you cannot follow this rule, it's why you see a warning and not a fatal error, chaneg your PHP error reporting level, if you dont want see this message.