VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: smashingpumpkins on October 05, 2011, 22:42:26 PM

Title: Payment plugin development
Post by: smashingpumpkins on October 05, 2011, 22:42:26 PM
Hi,

I am about to migrate an existing payment solution from virtuemart 1.x to 2. I have three questions.

I see that everything is different, and the module should now be implemented as a plugin.

1. Does any guides exist for porting from old payment extensions to new payment plugins?

Also i have looked a bit at the standard and paypal solution for v2 - a method called "plgVmAfterCheckoutDoPayment" is used.  But i cannot find any documentation at all about this function.

2. Any fresh documentation that describes plgVmAfterCheckoutDoPayment?

3. Should i wait with the implementation until v2 is more mature and documented, or can i expect the current release to be close to the final thing?

Regards Jens


Title: Re: Payment plugin development
Post by: alatak on October 06, 2011, 10:02:15 AM
Hi,

I rewrote the payment workflow last week.
QuoteAlso i have looked a bit at the standard and paypal solution for v2 - a method called "plgVmAfterCheckoutDoPayment" is used.  But i cannot find any documentation at all about this function.

And added some functions. I still need to update the wiki ...

I will tell you as soon as i have done it.
If you use the SVN you can have a look at the new paypal plugin.

Title: Re: Payment plugin development
Post by: DannyM on October 07, 2011, 15:16:47 PM
i have question :)
how to get paramters in plgVmOnPaymentNotification?

$params->get('some_param');
Title: Re: Payment plugin development
Post by: alatak on October 07, 2011, 15:46:38 PM
Hi,

Please have a look at the paypal plugin.
Title: Re: Payment plugin development
Post by: DannyM on October 07, 2011, 16:02:53 PM
yes, but in PP function > plgVmOnPaymentNotification dont have parametrs :)
Title: Re: Payment plugin development
Post by: alatak on October 08, 2011, 13:30:23 PM
Hi,


Quoteyes, but in PP function > plgVmOnPaymentNotification dont have parametrs :)
Are we looking at the same code?

here are the parameters for that function
    function plgVmOnPaymentNotification($pelement, $virtuemart_paymentmethod_id, $return_context, $virtuemart_order_id, $new_status) 


The method called plgVmAfterCheckoutDoPayment has been replaced by:
function plgVmOnConfirmedOrderGetPaymentForm($virtuemart_order_id, $orderData, $return_context, $html)

All the bank payment i know have a return context parameter in their forms. You must send it.
And afaik, this parameter is always sent back with the notification.
This parameter actually contains the session id. It is used when the shopper did not return to the shop after his payment, to delete his cart.

Quote1. Does any guides exist for porting from old payment extensions to new payment plugins?
plgVmOnPaymentNotification corresponds to the notify.php for paypal for example in VM1.
plgVmOnConfirmedOrderGetPaymentForm correspond to the code that was excuted in the "more payment info" in VM1





Title: Re: Payment plugin development
Post by: DannyM on October 10, 2011, 13:10:00 PM
thx, but my mistake
I try add to function plgVmOnPaymentNotification param $params->get('debug')
Title: Re: Payment plugin development
Post by: DannyM on October 10, 2011, 19:30:09 PM
enyone?
Title: Re: Payment plugin development
Post by: alatak on October 10, 2011, 19:31:28 PM
Hi,

Yes i can help.
But what is the question?
Title: Re: Payment plugin development
Post by: DannyM on October 10, 2011, 19:34:30 PM
:)
how add paramter

$params->get('debug')

to plgVmOnPaymentNotification?

I add

$params = new JParameter($paramstring);
$params->get('debug')


Title: Re: Payment plugin development
Post by: alatak on October 11, 2011, 08:08:04 AM
Hi,
Payment methods are joomla plugins.
The parameters you have in $params come from the xml file.
Please read this
http://docs.joomla.org/Creating_a_Plugin_for_Joomla_1.5

and ofc
http://dev.virtuemart.net/projects/virtuemart/wiki/Plugin_system
Title: Re: Payment plugin development
Post by: DannyM on October 11, 2011, 11:40:53 AM
ok i know
but tell me - why the double set param?

1. once in plugin
2. second in vm payments
Title: Re: Payment plugin development
Post by: alatak on October 12, 2011, 08:21:55 AM
Hi,

No there is no double set of parameters. There is only one xml file. There is one Joomla plugin.
But you can use several times the same plugin.

Look at the shipping. You have one Joomla plugin, but you can reuse the same ode to create several rates.

You can do the same with the payment.


Title: Re: Payment plugin development
Post by: Milbo on October 12, 2011, 22:27:11 PM
The xml gives you the possible params, as in joomla

But the values must be stored in the datebase, for this we provide some tools, so that plugins can use their own tables.
Title: Re: Payment plugin development
Post by: DannyM on November 03, 2011, 14:31:26 PM
ok thx
how to send post_variables  method="post"? :)
Title: Re: Payment plugin development
Post by: DannyM on November 04, 2011, 14:58:16 PM
I don't know what happen but after installation com_virtuemart.1.9.8k my payment plugin not working :(

Title: Re: Payment plugin development
Post by: alatak on November 04, 2011, 15:49:28 PM
Hi,

did you see that post:
http://forum.virtuemart.net/index.php?topic=92568.0
Title: Re: Payment plugin development
Post by: DannyM on November 04, 2011, 16:40:37 PM
yes, but i have different problem.
VM (k)
1. On start front page -> white page - > helped turn off vm cart module
When I go to cart I see white page (J1.5 & 1.7) - new/clear installation vm (k).
2. my payment plugin not working (based on PPal from vm (g) )
:(
Title: Re: Payment plugin development
Post by: alatak on November 04, 2011, 16:45:14 PM
Hi,

You cannot mix G plugin versions with the component version J.
Title: Re: Payment plugin development
Post by: alatak on November 07, 2011, 09:56:38 AM
Hi,

The payment form is displayed by the function plgVmOnConfirmedOrderGetPaymentForm().
Title: Re: Payment plugin development
Post by: DannyM on November 07, 2011, 14:38:47 PM
Please explain to me:

Before notify:
paymentnotification&pelement=paypal
now is:
paymentnotification&tmpl=component

What is a "component"?

How do you identify a payment?
Title: Re: Payment plugin development
Post by: alatak on November 07, 2011, 18:25:53 PM
Hi,

&tmpl=component is used in the query string when there is no need to call the modules, menus, and any other template stuff, which is the case in Payment notification.

In the case of Paypal, in the call plgVmOnConfirmedOrderGetPaymentForm(),  some data is stored in the paypal payment table, and specially the order number.

On receiving the paypal Notification, you get data in a POST. And in the POST you get back the order number.
By looking in the paypal payment table, you can identify your payment with the order number.
If you don't find the order number, that means that it is not the correct payment method.
And if you find it, then you can process the notification.

This is payment dependant. You can add what you want/need in the query string.



Title: Re: Payment plugin development
Post by: DannyM on November 08, 2011, 09:59:35 AM
Quote from: alatak on November 07, 2011, 18:25:53 PM
Hi,

&tmpl=component is used in the query string when there is no need to call the modules, menus, and any other template stuff, which is the case in Payment notification.

Hi,

I see but how identifies the payment plugin: This is PayPal but no LLoyds, DUpay etc.

Before notify:
paymentnotification&pelement=paypal
paymentnotification&pelement=LLoyds
paymentnotification&pelement=DUpay

Can I add &pelement= to URL?
Title: Re: Payment plugin development
Post by: alatak on November 08, 2011, 14:04:00 PM
Hi,

Yes you can, if you need it.
But anyway Joomla scans all payment.
If you need to have the pelement to make sure that it is the correct payment plugin, you can add it.

For Paypal, i use the order number to find out if it is the correct payment plugin.
Title: Re: Payment plugin development
Post by: DannyM on November 08, 2011, 14:17:29 PM
ok thx i try ;)
Title: Re: Payment plugin development
Post by: DannyM on January 11, 2012, 17:35:36 PM
Hi I'm back :)
I have question

function plgVmOnPaymentNotification() {

if (!class_exists('VirtueMartModelOrders'))
require( JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php' );
$data = JRequest::get('post');

$order_number = $data['control'];
$virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number);

$method = $this->getVmPluginMethod($payment->virtuemart_paymentmethod_id);

echo $method->status_success;

return true;
    }


My  $method->status_success is empty ... but why?
Title: Re: Payment plugin development
Post by: alatak on January 11, 2012, 19:56:08 PM
hi
look how it is done in paypal. And do the same :)

because in your code $payment is not set

you forgot that line
$payment = $this->getDataByOrderId($virtuemart_order_id);
Title: Re: Payment plugin development
Post by: DannyM on January 12, 2012, 14:29:39 PM
THX now works fine ;)
Title: Re: Payment plugin development
Post by: ZhenIT Sofware on January 26, 2012, 17:57:54 PM
Paypal pluging exits if there is no parameter  named invoice in the post or if it doesn't macth any order id.

I'm trying to develop a payment module that also need an asynchronous notification and I want it to be compatible with paypal plugin so that the shop owners can have both instaled and published at the same time.

If I use JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginnotification&tmpl=component'), as notification URL in my plugin and the paypal plugin is also installed paypal plugin spoils the process because my bank doesn't send any parameter named "invoice" and the plgVmOnPaymentNotification methos of my plugin is never executed.

Everithing works fine If I uninstall the paypal plugin  or if i comment the line 365 in the paypal.php. But this is not valid for me because I would like to distribute my pluging and its installation shouldn't interfere with other plugins.

Is this a bug in paypal plginc or is thera any workaround?
Title: Re: Payment plugin development
Post by: DannyM on January 27, 2012, 11:24:21 AM
Quote from: ZhenIT Sofware on January 26, 2012, 17:57:54 PM
If I use JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginnotification&tmpl=component'), as notification URL in my plugin and the paypal plugin is also installed paypal plugin spoils the process because my bank doesn't send any parameter named "invoice" and the plgVmOnPaymentNotification methos of my plugin is never executed.

Your bank must send to you order_id or order_number to identify payment.
This is a "strange" solution. Some bank have problem with redirect this url/param
Title: Re: Payment plugin development
Post by: ZhenIT Sofware on January 27, 2012, 20:05:30 PM
Of course, our bank sends us the order_number but in the POST but the parameter name is not "invoice".

At index.php?option=com_virtuemart&view=pluginresponse&task=pluginnotification&tmpl=component  the plgVmOnPaymentNotification of all installed plugins are called, if it happens that the plgVmOnPaymentNotification of paypal plugin is called before  the plgVmOnPaymentNotification of my method as there is no pamrameter named "invoice" the paypal plugin exits (line 365) and the plgVmOnPaymentNotification of all other plugings are not called.

Let's say that paypal plugin has some kind of egocentric behaviour.
Title: Re: Payment plugin development
Post by: ZhenIT Sofware on January 27, 2012, 20:22:02 PM
Well, what I mean is that paypal's puging behaviour should be more like "Oh! there's no parameter named invoice. Ok, then this notification might not be addressed to me let's return it" but what it does is "There is no parameter named invoice, this must be an error I'll abort"
Title: Re: Payment plugin development
Post by: jgpage on January 30, 2012, 16:37:01 PM
I have reported the same issue. The PayPal module should do a check to see if it is the correct payment method to action the IPN request. Better yet, the correct IPN request should be called outright and not run through all the modules that have that function.