PHP code example of sudiptpa / paypal-ipn

1. Go to this page and download the library: Download sudiptpa/paypal-ipn library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sudiptpa / paypal-ipn example snippets


    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();

  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();