JMSPaymentPaypalBundle
JMSPaymentPaypalBundle copied to clipboard
Instant Payment Notifications (IPN)
AFAICT there is no clean way of handling payment notifications with the JMSPayment bundles. The current architecture assumes that any change in a Payment's state will be originated by the bundle itself. However, this is not always true: for instance, in the case of Paypal, a Refund will arguably almost always be done in Paypal's own web interface.
I should be able to easily tell the bundle that a certain payment was refunded as opposed to asking it to Refund it. There is a subtle but important difference. A concrete example of what I mean follows.
If I call
$ppc->credit($credit, $amount)
there will always be an external API call that will ask Paypal for a refund. However, what I need is something functionally equivalent to
$ppc->creditEvent($credit, $amount)
that will only update the local model and make no external API calls.
Is something like this part of the future plans for this bundle?
@schmittjoh After struggling for a few days, I've finally been able to integrate paypal's IPN with this bundle. I have updated this issue's description to reflect the problems I had and I'm reopening it.
For whoever is interested, I created a Service that you can drop into your application and automagically have IPN notifications handled for you. With this Service, you simply do:
<?php namespace Acme\SomeBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller
class OrdersController extends Controller
{
public function paypalIpnAction ()
{
$notification = $this->getRequest()->request->all();
$ipnHandler = $this->get('acme.paypal_ipn.handler');
// This will trigger calls to the correct JMSPaymentCore methods
// according to the type of notification. After this call, the
// JMSPaymentCore DB tables will have been updated.
$ipnHandler->process($notification);
}
}
It uses two dirty hacks to workaround the current architecture but it's functional.
You can get it here: https://gist.github.com/4600319
@regularjack why you don't do a pull request with that changes?
@CayetanoSoriano Because this is not a clean solution for the problem. The correct way is for the bundle to expose an API for payment notifications.