PHPackages                             dansmaculotte/paypal-ipn-listener - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. dansmaculotte/paypal-ipn-listener

ActiveLibrary[Payment Processing](/categories/payments)

dansmaculotte/paypal-ipn-listener
=================================

A PayPal IPN (Instant Payment Notification) listener for PHP

1.1.0(4y ago)12.0kMITPHPPHP ^7.2.5||^8.0

Since Apr 6Pushed 4y agoCompare

[ Source](https://github.com/dansmaculotte/paypal-ipn-listener)[ Packagist](https://packagist.org/packages/dansmaculotte/paypal-ipn-listener)[ RSS](/packages/dansmaculotte-paypal-ipn-listener/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (6)Versions (5)Used By (0)

PayPal IPN Listener
===================

[](#paypal-ipn-listener)

[![Packagist](https://camo.githubusercontent.com/d5a72f13c99bcb42246fd2a19c448fe8ed226c2e14384f1db40bfe8378cc4f0b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64616e736d6163756c6f7474652f70617970616c2d69706e2d6c697374656e65722e737667)](https://packagist.org/packages/dansmaculotte/paypal-ipn-listener)[![Status](https://github.com/dansmaculotte/paypal-ipn-listener/workflows/ci/badge.svg?branch=master)](https://github.com/dansmaculotte/paypal-ipn-listener/actions)[![Total Downloads](https://camo.githubusercontent.com/fe1f9fb9641586732909ecc613c12defe1907a5304433f887560c39bffd3ce3b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64616e736d6163756c6f7474652f70617970616c2d69706e2d6c697374656e65722e737667)](https://packagist.org/packages/dansmaculotte/paypal-ipn-listener)[![License](https://camo.githubusercontent.com/4766dcd13df16446562e6fe58222db10881ecab2141a81511f80e9244afce59a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f64616e736d6163756c6f7474652f70617970616c2d69706e2d6c697374656e65722e737667)](https://packagist.org/packages/dansmaculotte/paypal-ipn-listener)

> A PayPal IPN (Instant Payment Notification) listener for PHP

Index
-----

[](#index)

- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Architecture](#architecture)
- [Usage](#usage)
- [Extending](#extending)
- [Notes](#notes)

Prerequisites
-------------

[](#prerequisites)

1. PHP ^7.2
2. A good understanding of how the PayPal Instant Payment Notification system works. See

Installation
------------

[](#installation)

```
composer require dansmaculotte/paypal-ipn-listener
```

Architecture
------------

[](#architecture)

This package is made up of several components that work together:

- `Listener` - Listens for and processes the IPN messages
- `Verifier` - Verifies the IPN message with PayPal
- `Service` - Communicates with PayPal
- `Message` - Wrapper around the IPN message
- `MessageFactory` - Creates a new message instance from a data source
- `EventDispatcher` - Dispatches events

The listener creates a `Message` using a `MessageFactory`. The `Message` is passed to the `Verifier` which uses a `Service` to communicate with PayPal. The `Listener` uses the `EventDispatcher` to dispatch events relating to the outcome of the IPN message verification.

The `MessageFactory` and `Service` components are swappable components.

This package provides 2 message factories:

1. `DansMaCulotte\PayPal\Ipn\MessageFactory\InputStreamMessageFactory` - Creates a message from the `php://input` stream
2. `DansMaCulotte\PayPal\Ipn\MessageFactory\ArrayMessageFactory` - Creates a message from an array passed to the `setData` method

This package provides 1 service:

1. `DansMaCulotte\PayPal\Ipn\Service\GuzzleService` - Uses [Guzzle](https://github.com/guzzle/guzzle) to communicate with PayPal

Usage
-----

[](#usage)

You can either build up the listener object manually or you can use a listener builder. This package provides 2 listener builders:

1. `DansMaCulotte\PayPal\Ipn\ListenerBuilder\Guzzle\InputStreamListenerBuilder` - Builds a listener using the guzzle service and the input stream message factory
2. `DansMaCulotte\PayPal\Ipn\ListenerBuilder\Guzzle\ArrayListenerBuilder` - Builds a listener using the guzzle service and the array message factory

Using a listener builder is the preferred way of building up a listener object.

### Using a listener builder

[](#using-a-listener-builder)

```
use DansMaCulotte\PayPal\Ipn\ListenerBuilder\Guzzle\InputStreamListenerBuilder as ListenerBuilder;

$listener = (new ListenerBuilder)->build();
```

### Building up the listener manually

[](#building-up-the-listener-manually)

```
use GuzzleHttp\Client;
use DansMaCulotte\PayPal\Ipn\InputStream;
use DansMaCulotte\PayPal\Ipn\Listener;
use DansMaCulotte\PayPal\Ipn\MessageFactory\InputStreamMessageFactory;
use DansMaCulotte\PayPal\Ipn\Service\GuzzleService;
use DansMaCulotte\PayPal\Ipn\Verifier;
use Symfony\Component\EventDispatcher\EventDispatcher;

$service = new GuzzleService(
    new Client(),
    'https://www.sandbox.paypal.com/cgi-bin/webscr'
);

$verifier = new Verifier($service);

$messageFactory = new InputStreamMessageFactory(new InputStream());

$listener = new Listener(
    $messageFactory,
    $verifier,
    new EventDispatcher()
);
```

A lot of plumbing is needed to create the listener manually. The job of the listener builder is to abstract away this logic.

### Subscribing to events

[](#subscribing-to-events)

Once you have created the listener object you can subscribe to the events that it will dispatch:

```
use DansMaCulotte\PayPal\Ipn\Event\MessageVerifiedEvent;
use DansMaCulotte\PayPal\Ipn\Event\MessageInvalidEvent;
use DansMaCulotte\PayPal\Ipn\Event\MessageVerificationFailureEvent;

$listener->onVerified(function (MessageVerifiedEvent $event) {
   $ipnMessage = $event->getMessage();

   // IPN message was verified, everything is ok! Do your processing logic here...
});

$listener->onInvalid(function (MessageInvalidEvent $event) {
   $ipnMessage = $event->getMessage();

   // IPN message was was invalid, something is not right! Do your logging here...
});

$listener->onVerificationFailure(function (MessageVerificationFailureEvent $event) {
    $error = $event->getError();

    // Something bad happend when trying to communicate with PayPal! Do your logging here...
});
```

You can use any [callable](https://php.net/manual/en/language.types.callable.php) when subscribing to an event:

```
use DansMaCulotte\PayPal\Ipn\Event\MessageVerifiedEvent;

class IpnProcessor
{
    public function onVerified(MessageVerifiedEvent $event)
    {
        $message = $event->getMessage();

        // ...
    }
}

$listener->onVerified([new Processor, 'onVerified']);
```

```
use DansMaCulotte\PayPal\Ipn\Event\MessageVerifiedEvent;

class IpnProcessor
{
    public static function onVerified(MessageVerifiedEvent $event)
    {
        $message = $event->getMessage();

        // ...
    }
}

$listener->onVerified(['IpnProcessor', 'onVerified']);
```

### Listening for IPN messages

[](#listening-for-ipn-messages)

The last thing you need to do to kick of the process is listen for an IPN message:

```
$listener->listen();
```

### Full Example

[](#full-example)

```
use DansMaCulotte\PayPal\Ipn\Event\MessageVerifiedEvent;
use DansMaCulotte\PayPal\Ipn\Event\MessageInvalidEvent;
use DansMaCulotte\PayPal\Ipn\Event\MessageVerificationFailureEvent;
use DansMaCulotte\PayPal\Ipn\ListenerBuilder\Guzzle\InputStreamListenerBuilder as ListenerBuilder;

$listener = (new ListenerBuilder)->build();

$listener->onVerified(function (MessageVerifiedEvent $event) {
   $ipnMessage = $event->getMessage();

   // IPN message was verified, everything is ok! Do your processing logic here...
});

$listener->onInvalid(function (MessageInvalidEvent $event) {
   $ipnMessage = $event->getMessage();

   // IPN message was was invalid, something is not right! Do your logging here...
});

$listener->onVerificationFailure(function (MessageVerificationFailureEvent $event) {
    $error = $event->getError();

    // Something bad happend when trying to communicate with PayPal! Do your logging here...
});

$listener->listen();
```

#### Sandbox mode

[](#sandbox-mode)

When using one of the provided listener builders you can set your listener to use PayPal's sandbox for testing purposes:

```
use DansMaCulotte\PayPal\Ipn\ListenerBuilder\Guzzle\InputStreamListenerBuilder as ListenerBuilder;

$listenerBuilder = new ListenerBuilder();

$listenerBuilder->useSandbox(); // use PayPal sandbox

$listener = $listenerBuilder->build();
```

You can find some full usage examples in the examples directory.

Extending
---------

[](#extending)

To create your own service you must implement `DansMaCulotte\PayPal\Ipn\Service`.

To create your own message factory you must implement `DansMaCulotte\PayPal\Ipn\MessageFactory`.

To create your own listener builder it is best to extend `DansMaCulotte\PayPal\Ipn\ListenerBuilder` as this provides most of the boilerplate code needed to create a listener builder.

You will notice that when using any of the provided guzzle listener builders that there is a `useSandbox` method exposed. You can add this functionality to your listener builder by using the `DansMaCulotte\PayPal\Ipn\ListenerBuilder\ModeDependentServiceEndpoint` trait (see `DansMaCulotte\PayPal\Ipn\ListenerBuilder\GuzzleListenerBuilder` for usage example).

Notes
-----

[](#notes)

### Testing

[](#testing)

PayPal provides an IPN simulator here: [https://developer.paypal.com/webapps/developer/applications/ipn\_simulator](https://developer.paypal.com/webapps/developer/applications/ipn_simulator)

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 85.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~234 days

Total

4

Last Release

1576d ago

PHP version history (2 changes)1.0.0PHP ^7.2

1.1.0PHP ^7.2.5||^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/498465?v=4)[Gaël Reyrol](/maintainers/GaelReyrol)[@gaelreyrol](https://github.com/gaelreyrol)

![](https://www.gravatar.com/avatar/777575bd441b3393f38a0865d5365a071c18e0989b5a4c9fc90426217876085a?d=identicon)[romain-dmc](/maintainers/romain-dmc)

![](https://www.gravatar.com/avatar/68676c9ce44bfbb47b31c7d157eece7ca315e4ed2d8f7fa0970ed81e354dee88?d=identicon)[Chroq](/maintainers/Chroq)

---

Top Contributors

[![mike182uk](https://avatars.githubusercontent.com/u/991592?v=4)](https://github.com/mike182uk "mike182uk (111 commits)")[![gaelreyrol](https://avatars.githubusercontent.com/u/498465?v=4)](https://github.com/gaelreyrol "gaelreyrol (12 commits)")[![Swader](https://avatars.githubusercontent.com/u/1430603?v=4)](https://github.com/Swader "Swader (4 commits)")[![mablae](https://avatars.githubusercontent.com/u/389360?v=4)](https://github.com/mablae "mablae (2 commits)")[![stefanneubig](https://avatars.githubusercontent.com/u/819735?v=4)](https://github.com/stefanneubig "stefanneubig (1 commits)")

---

Tags

ipnpaypalpaypal-ipnpaypalipn

###  Code Quality

TestsBehat

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/dansmaculotte-paypal-ipn-listener/health.svg)

```
[![Health](https://phpackages.com/badges/dansmaculotte-paypal-ipn-listener/health.svg)](https://phpackages.com/packages/dansmaculotte-paypal-ipn-listener)
```

###  Alternatives

[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M421](/packages/drupal-core-recommended)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
