wadeshuler/php-paypal-ipn

Forked, Fixed, and Updated on 2-3-2015. A class to listen for and handle Instant Payment Notifications (IPN) from the PayPal server.

dev-main 2022-12-14 18:32 UTC

This package is auto-updated.

Last update: 2024-09-12 15:15:48 UTC


README

你是否看到这个错误?

[RuntimeException]
  Failed to clone https://github.com/WadeShuler/PHP-PayPal-IPN.git via https, ssh protocols, aborting.

  - https://github.com/WadeShuler/PHP-PayPal-IPN.git
    Cloning into '/var/www/appname/vendor/wadeshuler/php-paypal-ipn'...
    remote: Support for password authentication was removed on August 13, 2021.
    remote: Please see https://githubdocs.cn/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommen
  ded modes of authentication.
    fatal: Authentication failed for 'https://github.com/WadeShuler/PHP-PayPal-IPN.git/'

  - git@github.com:WadeShuler/PHP-PayPal-IPN.git
    Cloning into '/var/www/appname/vendor/wadeshuler/php-paypal-ipn'...
    git@github.com: Permission denied (publickey).
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.

GitHub仓库https://github.com/WadeShuler/PHP-PayPal-IPN已被删除,所以如果你有这个依赖项,那么执行composer install将会失败。我已经上传了vendor/wadeshuler/php-paypal-ipn目录的副本,以便你可以修复依赖项。请注意,这只是一个2.5.0版本!这不是原始仓库的Fork。这是从vendor目录的副本。

这些说明为我解决了问题

  • composer.json中删除wadeshuler/php-paypal-ipn
  • 手动从composer.lock中删除"name": "wadeshuler/php-paypal-ipn",部分。
  • 编辑composer.json并添加
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/antriver/wadeshuler-php-paypal-ipn"
        }
    ],
  • 重新添加包
COMPOSER_MEMORY_LIMIT=-1 composer require wadeshuler/php-paypal-ipn:2.5.0

你可能不需要COMPOSER_MEMORY_LIMIT或者前两个步骤,但我在运行此脚本时遇到了内存问题,这可能与此无关。

!!! 我不知道这个包是否仍然有效。我这样做只是为了修复损坏的composer install。请自行承担风险。

原始README如下。

PHP-PayPal-IPN

Forked from: https://github.com/Quixotix/PHP-PayPal-IPN/

Forked from the great Quixotix PayPal IPN script, which is no longer maintained. From now on, you should use this repo instead, as I have adddressed it's issues and brought it back to life.

这个Fork修复了原始仓库中已知的bug,并按照PayPal的文档和当今的标准更新了代码。

通知:SSLv3问题已修复!

这已经修复并可以正常工作,旧的Quixotix仓库不再工作!

请注意:我仍在整理这个包。这些文档仍然包含原始仓库的残留信息,所以请耐心等待。 我不是试图抹去他的名字,我给Quixotix对原始工作的全部认可。他的仓库自2012年以来就没有更新了,现在是2015年,它不再维护了。如果需要我做什么,或者需要重写什么,以确保他得到适当的认可,请告诉我。

@TODO 重构代码以遵循最佳实践(camelCase等)。

@TODO 完成更新README和文档。

@TODO 添加安全性来验证支付状态是否完成以及所有者的PayPal电子邮件地址。

@TODO 更新示例

要求: PHP >= 5.3

PHP >= 5.3的PayPal即时支付通知(IPN)类(如果你至少不是5.3,那么我无法帮助你!我不会支持过时的版本!)

在你的PHP IPN脚本中使用IPNListener类来处理POST数据的编码,将数据发送回PayPal,并解析来自PayPal的响应。

使用Composer安装

Composer现在支持!

Packagist: https://packagist.org.cn/packages/wadeshuler/php-paypal-ipn

composer.json

{
    "require": {
        "wadeshuler/php-paypal-ipn": "*"
    }
}

功能

  • 通过设置use_sandbox属性在实时和沙盒之间切换。
  • 通过设置use_ssl属性支持安全的SSL和不安全的HTTP事务(推荐使用SSL)。
  • 通过设置use_curl属性支持cURL和fsockopen网络库(推荐使用cURL)。
  • 验证PayPal服务器的HTTP "200"响应状态码。
  • 使用getTextReport()方法获取整个IPN的详细纯文本报告,用于发送给管理员和日志记录。
  • 抛出各种异常,以便区分代码或服务器配置中的常见错误与无效的IPN响应。

入门指南

此代码适用于Web开发者。你应该理解IPN过程的概念,以及何时以及为何要使用IPN。阅读PayPal即时支付通知指南是一个很好的起点。

你还应该有一个PayPal沙盒账户,其中包括一个测试买家账户和一个测试卖家账户。登录到您的沙盒账户后,在“测试工具”菜单下有一个IPN模拟器,您可以使用它来测试您的IPN监听器。

一旦您设置了沙盒账户,您只需创建一个PHP脚本来作为您的IPN监听器。在该脚本中,使用以下示例中的IPNListener()类。要查看更详细的示例,请查看源代码中的example/ipn.php脚本。

<?php

require_once('vendor/autoload.php');

$listener = new \WadeShuler\PhpPaypalIpn\IpnListener();
$listener->use_sandbox = true;

if ($verified = $listener->processIpn())
{
    // Valid IPN
    /*
        1. Check that $_POST['payment_status'] is "Completed"
        2. Check that $_POST['txn_id'] has not been previously processed
        3. Check that $_POST['receiver_email'] is your Primary PayPal email
        4. Check that $_POST['payment_amount'] and $_POST['payment_currency'] are correct
    */

} else {

    // Invalid IPN

}

?>

文档

尚未生成文档,但ipnlistener.php中包含phpDocumentor风格的docstrings(注释),解释了重要的公共属性和方法。

我还在我的博客上写了一个更深入的IPN教程:使用PHP的PayPal IPN

示例报告

以下是getTextReport()方法返回的报告示例。通过扩展IpnListener()类或在您的ipn脚本中直接访问数据来创建自己的报告。

--------------------------------------------------------------------------------
[09/09/2011 8:35 AM] - https://www.sandbox.paypal.com/cgi-bin/webscr (curl)
--------------------------------------------------------------------------------
HTTP/1.1 200 OK
Date: Fri, 09 Sep 2011 13:35:39 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Set-Cookie: c9MWDuvPtT9GIMyPc3jwol1VSlO=Ch-NORlHUjlmbEm__KG9LupR4mfMfQTkx1QQ6hHDyc0RImWr88NY_ILeICENiwtVX3iw4jEnT1-1gccYjQafWrQCkDmiykNT8TeDUg7R7L0D9bQm47PTG8MafmrpyrUAxQfst0%7c_jG1ZL6CffJgwrC-stQeqni04tKaYSIZqyqhFU7tKnV520wiYOw0hwk5Ehrh3hLDvBxkpm%7cYTFdl0w0YpEqxu0D1jDTVTlEGXlmLs4wob2Glu9htpZkFV9O2aCyfQ4CvA2kLJmlI6YiXm%7c1315575340; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: cookie_check=yes; expires=Mon, 06-Sep-2021 13:35:40 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navlns=0.0; expires=Thu, 04-Sep-2031 13:35:40 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: Apache=10.72.109.11.1315575339707456; path=/; expires=Sun, 01-Sep-41 13:35:39 GMT
X-Cnection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

VERIFIED
--------------------------------------------------------------------------------
test_ipn                 1
payment_type             instant
payment_date             06:34:51 Sep 09, 2011 PDT
payment_status           Completed
address_status           confirmed
payer_status             verified
first_name               John
last_name                Smith
payer_email              buyer@paypalsandbox.com
payer_id                 TESTBUYERID01
address_name             John Smith
address_country          United States
address_country_code     US
address_zip              95131
address_state            CA
address_city             San Jose
address_street           123, any street
business                 seller@paypalsandbox.com
receiver_email           seller@paypalsandbox.com
receiver_id              TESTSELLERID1
residence_country        US
item_name                something
item_number              AK-1234
quantity                 1
shipping                 3.04
tax                      2.02
mc_currency              USD
mc_fee                   0.44
mc_gross                 12.34
mc_gross_1               9.34
txn_type                 web_accept
txn_id                   51991334
notify_version           2.1
custom                   xyz123
charset                  windows-1252
verify_sign              Ah5rOpfPGo5g6FNg95DMPybP51J5AUEdXS1hqyRAP6WYYwaixKNDgQRR