Payum making inroads into PHP Ecommerce – Notifications: Series I

My friend Maksim is making great inroads in an ecommerce component for abstracting payment processing. The library is called Payum and it is being integrated into popular Ecommerce frameworks such as Vespolina and Sylius. We have successfully integrated it with Sylius and soon will be in Vespolina.

Here is his write up on how to handle notifications with Payum:

Untitled (1)

Managing notifications.

The notification is a callback. A payment can send it back to us to let us know about changes.
It could be Paypal Instant Payment Notification (IPN) or Payex Transaction Callback for example.
Here in this chapter we show you how to store it somewhere and process it later (with a cron script for example).


First we have to create a model where we would store all the info:

class Notification extends \ArrayObject
    protected $id;
    public function getId()
        return $this->id;

Then we have to do our notification action which would actually do all the job:

use Payum\Action\ActionInterface;
use Payum\Request\SecuredNotifyRequest;
class StoreNotificationAction implements ActionInterface
    protected $notificationStorage;
    public function __constructor(StorageInterface $notificationStorage)
        $this->notificationStorage = $notificationStorage;
    public function execute($request)
        $notification = $this->notificationStorage->createModel();
        foreach ($request->getNotification() as $name => $value) {
            $paymentNotification[$name] => $value;
    public function supports($request)
        return $request instanceof SecuredNotifyRequest;

In the code above we created payum custom action.
The main purpose of the action to store notification that with a request.
To do so it requires a storage.
Now we can update `config.php` described in the documentation.

use Payum\Extension\StorageExtension;
use Payum\Storage\FilesystemStorage;
$storeNotificationAction = new StoreNotificationAction(
    new FilesystemStorage('/path/to/storage', 'Notification', 'id')

Now we have to implement `notify.php` script which must be accessible from the internet.

use Payum\Request\SecuredNotifyRequest;
include 'config.php';
$token = $requestVerifier->verify();
$payment = $registry->getPayment($token->getPaymentName());
$payment->execute(new SecuredNotifyRequest($_REQUEST, $token));

Setup Paypal IPN.

The code above could be reused by any payment.
Now I want to show changes need to enable Paypal IPN. To do so we have to modify `prepare.php` a bit:

$notifyToken = $tokenStorage->createModel();
$paymentDetails['NOTIFYURL'] = $notifyToken->getTargetUrl();

Here we created one more token: `notify` and tell paypal to use its target url for notifications.

You can find more on and the official site here.

It is comming to you soon in too!

Thanks to Maksim’s fine abstractions!

One thought on “Payum making inroads into PHP Ecommerce – Notifications: Series I

  1. $paymentNotification[$name] => $value;

    I think this should be.

    $notification[$name] => $value;

    And is not a link 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *