News:

Support the VirtueMart project and become a member

Main Menu

Help developing HiPay payment plugin.

Started by fmp.martins, October 23, 2012, 23:47:15 PM

Previous topic - Next topic

fmp.martins

I'm having trouble in developing a plugin payment for HiPay.

It's flow is similar to PayPal: on user checkout, he/she is redirect to HiPay secure payment website and after the operation is completed, he/she returns to the web site.

I have two payment methods configured:
- standard (that actually does nothing except show the back account number for transfer)
- hipay

The plugin seems to work fine when a payment is done.


The problem is when the user is on the HiPay website and cancels the payment.
My return URL is http://localhost/MYWEBSITE/index.php?option=com_virtuemart&view=pluginresponse&task=pluginUserPaymentCancel&on=e84206&pm=5&Itemid=0

Somehow the plgVmOnUserPaymentCancel event is not triggered for HiPay, instead it triggers the plgVmOnUserPaymentCancel PayPal event, which is not even configured!
More awkward, it tries to read data from PayPal and heidekpay database tables, both not configured!

After some debugging, I found out that the dispatcher (JDispatcher in libraries/joomla/event/dispatcher.php) function trigger (around line 130), looped for all observers (following the observer pattern) that have the  plgVmOnUserPaymentCancel event, which my HiPay plugin has as I confirmed by looping for all observers with the plgVmOnUserPaymentCancel event.
But the dispatcher triggers the first observer that it founds, in this case PayPal, causing a critical application error.


Am I doing something wrong?
Do I have to make something special for the user payment cancel event?

All help and guidance is appreciated...


EDIT:
I forgot to mention, I'm using VM 2.0.12 with Joomla! 2.5.7.

alatak


fmp.martins

Yes.

SELECT vm.*
  FROM `pb_virtuemart_paymentmethods` AS vm, pb_extensions AS j
  WHERE vm.`virtuemart_paymentmethod_id` = "5"
  AND vm.payment_jplugin_id = j.extension_id

Returns (CVS format):

virtuemart_paymentmethod_id, virtuemart_vendor_id, payment_jplugin_id, slug, payment_element, payment_params, shared, ordering, published, created_on, created_by, modified_on, modified_by, locked_on, locked_by
5, 1, 10076, , hipay, " ... PARAMS REMOVED ... ", 0, 0, 1, "0000-00-00 00:00:00", 0, "2012-10-18 14:35:06", 43, "0000-00-00 00:00:00", 0


But the query being called is

SELECT vm.*
  FROM `pb_virtuemart_paymentmethods` AS vm, pb_extensions AS j
  WHERE vm.`virtuemart_paymentmethod_id` = "5"
  AND vm.payment_jplugin_id = j.extension_id
  AND j.element = "paypal"

And I don't know where the "paypal" came from...

fmp.martins

Any help on this subject is highly appreciated...
Even the execution trace of the event user payment cancel event is welcome...

fmp.martins

New information...
I was wrong when I stated that the plugin worked well when a payment was done. Actually it has the same problem that I stated for the user payment cancel, the difference is that it, somehow, calls the standard payment method and, by chance, it works!...


So, let's go back to the basics.


1. Right now I'm not sure that I've created the plugin correctly. I've follow the information in http://dev.virtuemart.net/projects/virtuemart/wiki/Plugin_system for Payment plugins for J1.6 or J1.7, so I've executed  the following command on the database:

INSERT INTO `jos_extensions` (`extension_id`,  `type`, `name`, `element`, `folder`, `access`, `ordering`  , `enabled`, `protected`, `client_id`, `checked_out`, `checked_out_time`, `params`)
VALUES (NULL, 'plugin', 'HiPay', 'plg_vmpayment_hipay', 'vmpayment', 1, 0, 1, 0, 0, 0, '0000-00-00 00:00:00', '')


Is this correct?


2. My plugin class is defined the same way as PayPal:
class plgVmPaymentHiPay extends vmPSPlugin {
...
}


Is this correct?


3. The return URLs are defined as follow (also following PayPal plugin):
As for the HiPay return addresses, I'm passing:

Payment OK I'm passing:
   'index.php?option=com_virtuemart&view=pluginresponse&task=pluginresponsereceived&on=' . $order['details']['BT']->order_number . '&pm=' . $order['details']['BT']->virtuemart_paymentmethod_id . '&Itemid=' . JRequest::getInt ('Itemid')

plgVmOnUserPaymentCancel event:
   'index.php?option=com_virtuemart&view=pluginresponse&task=pluginUserPaymentCancel&on=' . $order['details']['BT']->order_number . '&pm=' . $order['details']['BT']->virtuemart_paymentmethod_id . '&Itemid=' . JRequest::getInt ('Itemid')

Is this correct?

fmp.martins

It seems hard to get an answer from my problem...

Let's start with something simpler...

I have the class plgVmPaymentHiPay class that extends vmPSPlugin and implements, amongst others, the plgVmOnUserPaymentCancel event to respond to the
index.php?option=com_virtuemart&view=pluginresponse&task=pluginUserPaymentCancel&on=a5e803&pm=5 URL call.


In /libraries/joomla/event/dispatcher.php, function trigger (line 129), the trigger loops through all the observers that have the plgVmOnUserPaymentCancel method specified and calls them
On my system this means that I have calls like

   plgVmPaymentPaypal -> plgVmOnUserPaymentCancel
   plgVMPaymentPayzen -> plgVmOnUserPaymentCancel
   plgVMPaymentSystempay -> plgVmOnUserPaymentCancel
   ...
   plgVmPaymentHiPay -> plgVmOnUserPaymentCancel

even if such payment systems are not configured on the shop (which they are not, none of them).
My plugin is the last one on the list being iterated, probably because it was the last one to be installed on the system.

This would not be a problem if the call to plgVmPaymentPaypal->plgVmOnUserPaymentCancel did not crashed! If PayPal, or VM recognized that there was an error because the order number (where is it anyway and why do we keep it if it's seems t be discarded?) does not belong to a PayPal payment.
Even worst, I have no PayPal payments configured on the the shop.

I've forced the dispatcher to ignore all other payment methods except mine and everything worked as expected.

Why is this happening?
Why are these triggers being called for plugins that aren't configured on the shop?

fmp.martins

To who it may interest, I've kind of solved it.
Since my client does not need any other payment methods, I've just deactivated all the payment plugins, making mine HiPay plugin the only active payment plugin.

Since the problem was the plugin selection, having only one plugin solves this routing problem.

daniel__


fmp.martins

Yes.
I've made it work with some workarounds that I really don't like...

You can see it in production here: http://pinkbacci.com/ (sorry, Portuguese site only).

daniel__

Well, probably i need to do the same. I need the hipay for virtuemart 2.x

I am portuguese too  :)

I will update the topic with news about the development.

fmp.martins

Daniel,

se quiseres, estou disposto a vender-te o plugin tal e qual está!.

Peter Pillen

Interesting... I also used Hipay in my old VM site, but since changing to VM2, I couldn't use it anymore. It would be great if someone could help solve this.

But! I must say that there quite a few bugs in the VM1 Hipay plugin.
1. Sometimes for no apparent reason, the hipay module added 1 cent to the final billing. The VM order stated $74 and the recieved payment was $74.01
2. Hipay also had a fawlty calculation rule for taxes on orders with a discount.

I never found the cause of both problems. You should checkup/test that as well.

simoesdaniel

Hey daniel,

Também me encontro com o problema de instalar o hipay no meu site, será que me podes dar umas dicas para faze-lo. É que no teu site está a funcionar muito bem e vinha saber se me podias ajudar.

daniel__

Quote from: P2 Peter on January 11, 2013, 12:21:31 PM
It would be great if someone could help solve this.
If I do the module, I will release the plugin in open source. For now , i don't have any prevision and i never developed for joomla and virtuemart.


brunoazevedo

Hi,
I'm interested in this plugin, how many euros?

Sou Portugues, pode me responder em Portugues pelo PM.

Obrigado
Bruno Azevedo