VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: rvbgnu on August 27, 2015, 19:06:55 PM

Title: Looking for info about Payment plugins: function plgVmOnSelectCheckPayment + ...
Post by: rvbgnu on August 27, 2015, 19:06:55 PM
Hi,

I am looking further into existing payment plugins, and found an inconsistency, or I did not understand the different contexts (I am not familiar with EVERY payment system).

On both functions plgVmOnSelectCheckPayment() and plgVmOnCheckoutCheckDataPayment(), we can find the test
if (!($this->_currentMethod = $this->getVmPluginMethod($cart->virtuemart_paymentmethod_id))) {

But depending on which payment plugin it is, we have either
if (!($this->_currentMethod = $this->getVmPluginMethod($cart->virtuemart_paymentmethod_id))) {
return NULL; // Another method was selected, do nothing
}


OR

if (!($this->_currentMethod = $this->getVmPluginMethod($cart->virtuemart_paymentmethod_id))) {
return FALSE;
}


My understanding is that this statement should respond null if the event triggered (like "OnSelectCheckPayment") must return null if another payment method is selected.

Here are some links to current plugins versions to see what I mean:
Amazon "always" returns null
http://dev.virtuemart.net/projects/virtuemart/repository/annotate/trunk/virtuemart/plugins/vmpayment/amazon/amazon.php#L846 (http://dev.virtuemart.net/projects/virtuemart/repository/annotate/trunk/virtuemart/plugins/vmpayment/amazon/amazon.php#L846)
http://dev.virtuemart.net/projects/virtuemart/repository/annotate/trunk/virtuemart/plugins/vmpayment/amazon/amazon.php#L2505 (http://dev.virtuemart.net/projects/virtuemart/repository/annotate/trunk/virtuemart/plugins/vmpayment/amazon/amazon.php#L2505)
http://dev.virtuemart.net/projects/virtuemart/repository/annotate/trunk/virtuemart/plugins/vmpayment/amazon/amazon.php#L2679 (http://dev.virtuemart.net/projects/virtuemart/repository/annotate/trunk/virtuemart/plugins/vmpayment/amazon/amazon.php#L2679)

Authorize.net returns false in plgVmOnCheckoutCheckDataPayment() and in plgVmOnSelectCheckPayment()
http://dev.virtuemart.net/projects/virtuemart/repository/annotate/trunk/virtuemart/plugins/vmpayment/authorizenet/authorizenet.php#L350 (http://dev.virtuemart.net/projects/virtuemart/repository/annotate/trunk/virtuemart/plugins/vmpayment/authorizenet/authorizenet.php#L350)
but null in plgVmOnSelectedCalculatePricePayment()
http://dev.virtuemart.net/projects/virtuemart/repository/annotate/trunk/virtuemart/plugins/vmpayment/authorizenet/authorizenet.php#L404 (http://dev.virtuemart.net/projects/virtuemart/repository/annotate/trunk/virtuemart/plugins/vmpayment/authorizenet/authorizenet.php#L404)


So if someone can put a light on it, I will really appreciate it. And also I will be more than happy to provide a patch and to help finding and digging further this inconsistency, if it is a confirmed one.

Kind regards,
Hervé
Title: Re: Looking for info about Payment plugins: function plgVmOnSelectCheckPayment + ...
Post by: alatak on August 31, 2015, 09:59:05 AM
Hello Hervé

Amazon is not the correct payment you should look at .It is not a "classic payment"
And i should remove the plgVmOnSelectCheckPayment trigger since it is not used.

The best is that you get inspiration from Authorize.net payment plugin.
Or from this one administrator/components/com_virtuemart/plugins/vmpsplugin.php which is the class

Those are the 2 lines which are correct:
if (!($this->_currentMethod = $this->getVmPluginMethod($cart->virtuemart_paymentmethod_id))) {
                        return NULL;
                }
if (!$this->selectedThisElement($this->_currentMethod->payment_element)) {
                        return FALSE;
                }


Those triggers should return:
NULL: if it is another method selected
FALSE if the method was selected but the data is not valid
TRUE  if the method was selected but the data is valid