发布:2016/12/23 1:11:39作者:管理员 来源:本站 浏览次数:1623
paypal IPN and PDT 相关文档说明:
https://developer.paypal.com/docs/classic/ipn/gs_IPN/
https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNTesting/
https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNPDTAnAlternativetoIPN/
https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/
中文介绍:
http://ppdev.ebay.cn/files/developer/PayPal_PDT_Token_CHN.pdf
http://wenku.baidu.com/link?url=Fgv-l09iCnGQGDuMgdTT94c8YiwuqLEB5qT8tfzBseRdlGICHXsD00N_Zx9q5vbFdydQPXlQFRssgI65ac_4g0RzBHygsWU8V7f5cKjo8AW
PDT:Auto Return for Website Payments brings your buyers back to your website immediately after payment completion. Auto Return applies to PayPal Website Payments, including Buy Now, Subscriptions, and Shopping Cart. Learn More。
如果是网站按钮方式付款,PDT通知的url也可以用表单的return值设置,会被按钮设置中第三部设置的成功返回的url覆盖。
IPN:Instant Payment Notification (IPN)
You have turned on the IPN feature. You can view your IPNs on the IPN
History page. If necessary, you can resend IPN messages from that page.
For more information on using and troubleshooting this feature, read
more about Instant Payment Notification (IPN).
Your listener must respond to every IPN message it gets, whether you take action on it or not. If you do not respond, PayPal assumes the IPN was not received and re-sends it. Further, PayPal continues to re-send the message periodically until your listener responds, although the interval between retries increases with each attempt. An IPN will be resent for up to four days, with a maximum of 15 retries.
IPN可以通过模拟器触发,针对网站按钮方式付款,可以被表单的notify_url覆盖。
处理PDT关键是获取 PayPal 交易流水号 tx , 另外需要token。如果是IPN 和 PDT 是互补的关系,IPN优点:可以获取各种通知,会重发,The maximum number of retries is 15。缺点:异步,延迟。PDT实时,但是只能获取付款完成的通知。
测试方法:
用PHP程序测试,使用paypal的sanbox环境测试。
安装php
略
安装curl
wget http://curl.haxx.se/download/curl-7.39.0.zip
unzip curl-7.39.0.zip
cd curl-7.39.0
configure
make
make install
安装curl扩展
../../../php/bin/phpize
./configure --with-php-config=../../../php/bin/php-config
make
make install
生成 /home/pig/php/lib/php/extensions/no-debug-non-zts-20131226/curl.so
复制,修改php.ini
cp /home/pig/php-5.6.3/php.ini-development /home/pig/php/lib/php.ini
extension=curl.so
测试curl扩展安装是否成功
/home/pig/php/bin/php -r "var_dump(curl_init());"
resource(4) of type (curl)
安装openssl扩展,否则fopensocket不支持ssl
cd php-5.6.3/ext/openssl/
mv config0.m4 config.m4
/home/pig/php/bin/phpize
./configure --with-php-config=/home/pig/php/bin/php-config
make
make install
修改php.ini, 加上extension=openssl.so
检查openssl扩展是否装好:
/home/dog/php/bin/php -r 'var_dump(fsockopen("tls://www.sandbox.paypal.com", 443, $errno, $errstr, 30));'
resource(4) of type (stream)
启动server:
/home/pig/php/bin/php -S 0.0.0.0:5000 -t ./
配置nginx:
location ^~ /paytest/ {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://localhost:5000;
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------
运用paypal的sandbox环境测试paypent,测试IPN和PDT,思路是写一个程序部署到外网环境,把请求的参数全部记录到日志里面,然后过程一目了然。
输出如下:
[pig@ip-10-236-139-149 paytest]$ cat ok.txt
array (
'act' => 'ok',
'tx' => '8NG39315CL727724E',
'st' => 'Completed',
'amt' => '55.90',
'cc' => 'USD',
'cm' => '',
'item_number' => '',
)
2014-12-06 20:41:43
[pig@ip-10-236-139-149 paytest]$ cat pdt.txt
array (
'address_city' => 'Shanghai',
'address_country' => 'China',
'address_country_code' => 'CN',
'address_name' => 'Buyer Test',
'address_state' => 'Shanghai',
'address_status' => 'unconfirmed',
'address_street' => 'NO 1 Nan Jin Road',
'address_zip' => '200000',
'btn_id' => '3042078',
'business' => 'xxx.2013.03-facilitator@gmail.com',
'charset' => 'UTF-8',
'charset_original' => 'gb2312',
'custom' => '',
'discount' => '0.00',
'first_name' => 'Test',
'handling_amount' => '0.00',
'insurance_amount' => '0.00',
'item_name' => 'sandbox_item111',
'item_number' => '',
'last_name' => 'Buyer',
'mc_currency' => 'USD',
'mc_fee' => '2.20',
'mc_gross' => '55.90',
'payer_email' => 'xxx2013.03-buyer@gmail.com',
'payer_id' => 'JARYJK2TES6C6',
'payer_status' => 'unverified',
'payment_date' => '04:26:00 Dec 06, 2014 PST',
'payment_fee' => '2.20',
'payment_gross' => '55.90',
'payment_status' => 'Completed',
'payment_type' => 'instant',
'protection_eligibility' => 'Eligible',
'quantity' => '1',
'receiver_email' => 'yxw.2013.03-facilitator@gmail.com',
'receiver_id' => '2XP27KEMUVN8A',
'residence_country' => 'CN',
'shipping' => '10.00',
'shipping_discount' => '0.00',
'shipping_method' => 'Default',
'tax' => '0.90',
'transaction_subject' => '',
'txn_id' => '8NG39315CL727724E',
'txn_type' => 'web_accept',
)
2014-12-06 20:41:44
[pig@ip-10-236-139-149 paytest]$ cat ipn.txt
array (
'act' => 'ipn',
'mc_gross' => '55.90',
'protection_eligibility' => 'Eligible',
'address_status' => 'unconfirmed',
'payer_id' => 'JARYJK2TES6C6',
'tax' => '0.90',
'address_street' => 'NO 1 Nan Jin Road',
'payment_date' => '04:49:05 Dec 06, 2014 PST',
'payment_status' => 'Completed',
'charset' => 'gb2312',
'address_zip' => '200000',
'first_name' => 'Test',
'mc_fee' => '2.20',
'address_country_code' => 'CN',
'address_name' => 'Buyer Test',
'notify_version' => '3.8',
'custom' => '',
'payer_status' => 'unverified',
'business' => 'yxw.2013.03-facilitator@gmail.com',
'address_country' => 'China',
'address_city' => 'Shanghai',
'quantity' => '1',
'verify_sign' => 'A7SNeSYl88fJlq0RDkCQ4EljfLsAAMJ6OYFDH1nYVB0-NYyynmZyPh.1',
'payer_email' => 'xxx.2013.03-buyer@gmail.com',
'txn_id' => '61P15910PR196164M',
'payment_type' => 'instant',
'btn_id' => '3042078',
'last_name' => 'Buyer',
'address_state' => 'Shanghai',
'receiver_email' => 'xxx2013.03-facilitator@gmail.com',
'payment_fee' => '2.20',
'shipping_discount' => '0.00',
'insurance_amount' => '0.00',
'receiver_id' => '2XP27KEMUVN8A',
'txn_type' => 'web_accept',
'item_name' => 'sandbox_item111',
'discount' => '0.00',
'mc_currency' => 'USD',
'item_number' => '',
'residence_country' => 'CN',
'test_ipn' => '1',
'shipping_method' => 'Default',
'handling_amount' => '0.00',
'transaction_subject' => '',
'payment_gross' => '55.90',
'shipping' => '10.00',
'ipn_track_id' => '755ef8ff304e1',
)
2014-12-06 20:49:16
[pig@ip-10-236-139-149 paytest]$ cat ipn.log
[2014-12-06 22:21 PRC] HTTP request of validation request:POST /cgi-bin/webscr HTTP/1.1
Host: www.sandbox.paypal.com
Accept: */*
Connection: Close
Content-Length: 1089
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue
for IPN payload:
cmd=_notify-validate&mc_gross=55.90&protection_eligibility=Eligible&address_status=unconfirmed&payer_id=JARYJK2TES6C6&tax=0.90&address_street=NO+1+Nan+Jin+Road&payment_date=06%3A21%3A54+Dec+06%2C+2014+PST&payment_status=Completed&charset=gb2312&address_zip=200000&first_name=Test&mc_fee=2.20&address_country_code=CN&address_name=Buyer+Test¬ify_version=3.8&custom=&payer_status=unverified&business=yxw.2013.03-facilitator%40gmail.com&address_country=China&address_city=Shanghai&quantity=1&verify_sign=AUaxvSojqajxsiGA9qXfGuCulUctAIsI7u6BJGTRbntLsB6UI3lGIXb0&payer_email=yxw.2013.03-buyer%40gmail.com&txn_id=1TM13495A76848512&payment_type=instant&btn_id=3042078&last_name=Buyer&address_state=Shanghai&receiver_email=yxw.2013.03-facilitator%40gmail.com&payment_fee=2.20&shipping_discount=0.00&insurance_amount=0.00&receiver_id=2XP27KEMUVN8A&txn_type=web_accept&item_name=sandbox_item111&discount=0.00&mc_currency=USD&item_number=&residence_country=CN&test_ipn=1&shipping_method=Default&handling_amount=0.00&transaction_subject=&payment_gross=55.90&shipping=10.00&ipn_track_id=a6f9e0f859c1c
[2014-12-06 22:21 PRC] HTTP response of validation request: HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Sat, 06 Dec 2014 14:22:01 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Set-Cookie:
c9MWDuvPtT9GIMyPc3jwol1VSlO=cHblkEi54DzGTLa5JlkZ5k5rwA9ZRS9I13Waw_UNEnN3n4qBax3-drCD_5VrYo1lvRJWmHQOPn7bYide5LEYmFvSQ-CEsd2RJH6JycTVU3-AiEY9dBVxSVYXMxP6eEtKoknENSGh-ppAYRKLbw40OnC7_FO57RDSBMB3ttpAXqan8xSmdvjcfpezvl3810OK51XEyiIkyXHYQiLTIVqDBJhpgPSAz5jcqGZSF-ZvJIXohmvOJekwuyAgf_R7-QmdEiZgjrG5-msjx2kn6ATUC4Cm-NFOsQgmKa0ecWhOgFEqzjgS8juVMHizUC786G3D0krGR0e5SLzNS9GwwzXk-fIkEzEO75dEoEre9VFK4TfMnygkrdtJV637BSwzqNYyULaF6dHFCTxeEeJ1Xrq9TI5sRssDxQdzcmfE8sCwKZ1L4bgH71CjkI0SU1i;
domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: cookie_check=yes; expires=Tue, 03-Dec-2024 14:22:02 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navlns=0.0; expires=Mon, 05-Dec-2016 14:22:02 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: Apache=10.72.108.11.1417875722013081; path=/; expires=Mon, 28-Nov-44 14:22:02 GMT
Vary: Accept-Encoding,User-Agent
Connection: close
Set-Cookie:
X-PP-SILOVER=name%3DSANDBOX3.WEB.1%26silo_version%3D880%26app%3Dslingshot%26TIME%3D168919892;
domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
Set-Cookie: Apache=10.72.128.11.1417875721998036; path=/; expires=Mon, 28-Nov-44 14:22:01 GMT
Strict-Transport-Security: max-age=14400
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
VERIFIED
[2014-12-06 22:21 PRC] Verified IPN:
cmd=_notify-validate&mc_gross=55.90&protection_eligibility=Eligible&address_status=unconfirmed&payer_id=JARYJK2TES6C6&tax=0.90&address_street=NO+1+Nan+Jin+Road&payment_date=06%3A21%3A54+Dec+06%2C+2014+PST&payment_status=Completed&charset=gb2312&address_zip=200000&first_name=Test&mc_fee=2.20&address_country_code=CN&address_name=Buyer+Test¬ify_version=3.8&custom=&payer_status=unverified&business=yxw.2013.03-facilitator%40gmail.com&address_country=China&address_city=Shanghai&quantity=1&verify_sign=AUaxvSojqajxsiGA9qXfGuCulUctAIsI7u6BJGTRbntLsB6UI3lGIXb0&payer_email=yxw.2013.03-buyer%40gmail.com&txn_id=1TM13495A76848512&payment_type=instant&btn_id=3042078&last_name=Buyer&address_state=Shanghai&receiver_email=yxw.2013.03-facilitator%40gmail.com&payment_fee=2.20&shipping_discount=0.00&insurance_amount=0.00&receiver_id=2XP27KEMUVN8A&txn_type=web_accept&item_name=sandbox_item111&discount=0.00&mc_currency=USD&item_number=&residence_country=CN&test_ipn=1&shipping_method=Default&handling_amount=0.00&transaction_subject=&payment_gross=55.90&shipping=10.00&ipn_track_id=a6f9e0f859c1c
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4