PayPal IPN (Instant Payment Notification) handling driver for PHP.
Clone or download
Latest commit 286ac53 Oct 2, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build Adding tests. Dec 14, 2017
src Adding tests. Dec 14, 2017
tests Apply fixes from StyleCI Dec 14, 2017
.editorconfig PayPal IPN Jan 2, 2017
.gitignore Added .php_cs.cache to gitignore Dec 12, 2017
.php_cs Added 2.* version for cs fixer. Dec 12, 2017
.travis.yml Removed php 5.5, 5.6 form travis build Dec 26, 2017
CHANGELOG.md Starting with 3.0 upgrade Dec 12, 2017
LICENSE PayPal IPN Jan 2, 2017
README.md Update README.md Oct 2, 2018
UPGRADE.md Adding tests. Dec 14, 2017
UPGRADING.md Create UPGRADING.md Oct 2, 2018
composer.json Resolved conflict Jul 18, 2018
live.php Removed php 5.5, 5.6 form travis build Dec 26, 2017
phpunit.xml.dist Adding tests. Dec 14, 2017

README.md

PayPal IPN

PayPal Instant Payment Notification Listener driver for PHP

StyleCI Build Status Latest Stable Version Total Downloads License

Requirements

This package requires PHP >=5.5

Installation

This package is installed via Composer. To install, simply add it to your composer.json file:

  composer require sudiptpa/paypal-ipn

If you really need to work on guzzle 5.* pull version below.

  composer require sudiptpa/paypal-ipn:1.0.x-dev

And run composer to update your dependencies:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

Basic Usage

The following are 2 different methods provided by the package to handle PayPal IPN.

Using ArrayListener by passing array of Data

  require __DIR__.'/vendor/autoload.php';

  use PayPal\IPN\Event\IPNInvalid;
  use PayPal\IPN\Event\IPNVerificationFailure;
  use PayPal\IPN\Event\IPNVerified;
  use PayPal\IPN\Listener\Http\ArrayListener;

  $listener = new ArrayListener;
  
  /*
   * Payload received from PayPal end.
   */
  $data = array(
      'foo' => 'bar',
      'bar' => 'baz',
  );

  $listener->setData($data);

  $listener = $listener->run();

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

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

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

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

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

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

  $listener->listen();

Using InputStreamListener

  use PayPal\IPN\Event\IPNInvalid;
  use PayPal\IPN\Event\IPNVerificationFailure;
  use PayPal\IPN\Event\IPNVerified;
  use PayPal\IPN\Listener\Http\InputStreamListener;

  $listener = new InputStreamListener;

  $listener = $listener->run();

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

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

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

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

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

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

  $listener->listen();

Contributing

Contributions are welcome and will be fully credited.

Contributions can be made via a Pull Request on Github.

Testing

PayPal provide an Instant Payment Notification (IPN) simulator here: https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNSimulator/

Support

If you are having general issues with the package, feel free to drop me and email sudiptpa@gmail.com

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.