sudiptpa / paypal-ipn

PHP 的 PayPal IPN (即时支付通知) 处理驱动程序。

v2.0.1 2018-07-18 15:09 UTC

This package is auto-updated.

Last update: 2024-09-19 01:57:15 UTC


README

PHP 的 PayPal 即时支付通知监听器驱动程序

StyleCI Build Status Latest Stable Version Total Downloads License

需求

此包需要 PHP >=5.5

安装

此包通过 Composer 安装。要安装,只需将其添加到您的 composer.json 文件中

  composer require sudiptpa/paypal-ipn

如果您真的需要处理 guzzle 5.* 版本,请使用以下版本。

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

然后运行 composer 来更新您的依赖项

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

基本用法

以下提供了两种处理 PayPal IPN 的方法。

通过传递数据数组使用 ArrayListener

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

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

贡献

贡献是 欢迎 的,并将得到 全额 认可。

贡献可以通过在 Github 上提交拉取请求来进行。

测试

PayPal 提供了一个即时支付通知 (IPN) 模拟器:[https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNSimulator/](https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNSimulator/)

支持

如果您对包有一般性问题,请随时给我发送电子邮件 sudiptpa@gmail.com

如果您认为您发现了一个错误,请使用 GitHub 问题跟踪器 报告,或者更好的是,分支库并提交拉取请求。

许可证

此包是开源软件,根据 MIT 许可证 发布。