fahim / laravel5-paypal-ipn
Laravel 5 的 Paypal IPN 类
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-14 17:42:52 UTC
README
此包只是此存储库中 IPN 类的实现
https://github.com/Quixotix/PHP-PayPal-IPN
将此添加到 composer.json 中的 "require-dev" 部分
"fahim/laravel5-paypal-ipn": "1.0.*"
PHP-PayPal-IPN
PHP 5 的 PayPal 即时支付通知 (IPN) 类。
在您的 PHP IPN 脚本中使用 PaypalIPNListener
类来处理 POST 数据的编码、将数据回传给 PayPal 以及解析 PayPal 的响应。
Laravel 服务
'Fahim\PaypalIPN\PaypalIPNServiceProvider',
用例
use Fahim\PaypalIPN\PaypalIPNListener; public function paypalIpn() { $ipn = new PaypalIPNListener(); $ipn->use_sandbox = true; $verified = $ipn->processIpn(); $report = $ipn->getTextReport(); Log::info("-----new payment-----"); Log::info($report); if ($verified) { if ($_POST['address_status'] == 'confirmed') { // Check outh POST variable and insert your logic here Log::info("payment verified and inserted to db"); } } else { Log::info("Some thing went wrong in the payment !"); } }
特性
- 通过设置
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
脚本。
文档
尚未生成文档,但,在 ipnlistener.php
中有 phpDocumentor 风格的 docstrings(注释),其中解释了重要的公共属性和方法。
我还在我的博客上写了一个更深入的 IPN 教程:使用 PHP 的 PayPal IPN
已知问题
问题
processIpn()
方法抛出以下异常
cURL error: [52] GnuTLS recv error (-9): A TLS packet with unexpected length was received.
解决方案
当 cURL 与 GnuTLS 配置时,如果未明确设置 SSL 版本作为 cURL 选项,则调用 PayPal 将失败。将 force_ssl_v3
属性设置为强制 SSL 3
$listener = new IpnListener(); $listener->force_ssl_v3 = true;
注意:force_ssl_v3 现已默认为 true
问题
PHP Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION
cannot be activated when in safe_mode or an open_basedir is set in ...
解决方案
如果您需要 PHP 安全模式,可以使用 follow_location
属性禁用 CURLOPT_FOLLOWLOCATION。
$listener = new IpnListener(); $listener->follow_location = false;
注意:follow_location 现已默认为 false
示例报告
以下是 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