Perform custom operations on gateway notification with Payum

202 views Asked by At

I'm using Symfony with PayumBundle and payum-redsys in order to accept payment through the spanish Redsys gateway.

After every payment attempt (be it successful or not), Redsys sends a notification to a url. I want to catch this notification and take actions according to its payload (was the payment successful? which order number? etc.). For instance, let's say that if the payment was successful I want to mark the corresponding order as paid in the database, otherwise I want to log the error. Something like:

if ($paymentSuccessful) {
    $order = $orderRep->find($notif['Ds_Order']);
    $order->setDatePaid($notif['Ds_Date']);
    $em->flush();
} else {
    $logger->error('Failed payment for order ' . $notif['Ds_Order']);
}

If I let Payum handle the notification request with its default NotifyController, it performs automatic token validation, decoding of parameters, etc. which is perfect but I can't see how to perform my own custom operation (see code above), hence the title of this question.

1

There are 1 answers

0
dbrumann On BEST ANSWER

Payum seems to support listening to events on the gateway as can be seen in PayumEvents. The Event being passed around basically only contains a Context from which you need to gather the information you need. You probably want to look at the actions inside this context, especially the CapturePaymentAction and the Request? How this all ties together is not clear to me as I'm basically deciphering this from the source code.

If you don't want to figure out all the event stuff you could just create a listener that listens to the appropriate event and then use xdebug or var_dump to read out the data from the event and continue from there. Basically the event listener should make sure that you are in the right action, get the Ds_Order and Ds_Date (probably from the request) and then you can add in a snippet like the one you posted above.

If you are not familiar with Symfony's Event System I recommend reading up on the documentation:

edit: Also Payum provides some documentation how it deals with events as well: https://github.com/Payum/Payum/blob/master/docs/event-dispatcher.md