Paypal 与 PHP 的逐步集成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12889094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Paypal integration with PHP step by step
提问by Antoniraj
I am new to Paypal integration with PHP, i have searched in the internet i am not able to get correct one to implement in my website.
我是 Paypal 与 PHP 集成的新手,我在互联网上进行了搜索,但无法在我的网站中找到正确的方法。
Can anyone help to to integration of paypal for my website with step by step including the test account creation .
任何人都可以帮助我的网站一步一步地集成贝宝,包括测试帐户的创建。
Thanks in advance.
提前致谢。
回答by Adam
When I made my first paypal script one of the most useful things that I did was to log every piece of information that came through. I just dumped everything into a text file whenever Paypal called the confirmation page. It was incredibly helpfull to see what they were passing over and to debug. Paypal sends a POST of the transaction.
当我制作我的第一个 paypal 脚本时,我所做的最有用的事情之一就是记录通过的每一条信息。每当 Paypal 调用确认页面时,我只是将所有内容都转储到一个文本文件中。查看他们传递的内容并进行调试非常有帮助。Paypal 发送交易的 POST。
$dumpfile = "=== post fields\n";
foreach($_POST as $k=>$v)
$dumpfile .= "[$k] => $v\n";
$dumpfile .= "=== http request headers\n";
foreach(apache_request_headers() as $k=>$v)
$dumpfile .= "[$k] => $v\n";
file_put_contents('pathToAWritableFile', $dumpfile);
I hope this saves you some headache. As a side note, I still keep all the paypal request info in a database in case the purchase logic fails after I update the paypal confirmation script, that has saved me a couple of times.
我希望这可以为您节省一些头痛。作为旁注,我仍然将所有贝宝请求信息保存在数据库中,以防在我更新贝宝确认脚本后购买逻辑失败,这已经为我节省了几次。
回答by Dean Rather
https://developer.paypal.com/is a great place to start.
https://developer.paypal.com/是一个很好的起点。
They offer guides and code libraries and examples there.
他们在那里提供指南、代码库和示例。
回答by Marin Sagovac
All what you need is learning how PayPal uses and recreate account mail on sandbox.paypal.comin other word https://developer.paypal.com/. For creating testing (sandbox) account with virtual money you need for main account on sandbox register on a developer.paypal.com.
所有你需要的是学习上的PayPal应用并重新创建帐户的邮件如何sandbox.paypal.com在其他词https://developer.paypal.com/。要使用虚拟货币创建测试(沙箱)帐户,您需要在 developer.paypal.com 上的沙箱注册主帐户。
After processing you should configure properly of data on PayPal account and step on guides of sandbox developer. For example how is checking out of buyers uses (look code ECSetExpressCheckout).
处理后,您应该正确配置 PayPal 帐户上的数据,并按照沙盒开发人员的指南进行操作。例如如何结帐买家使用(查看代码 ECSetExpressCheckout)。
First look of guide PayPal (this is general):
PayPal 指南的第一眼(这是通用的):
Looking for paypal payments tutorial
This is main site how manipulate with PayPal:
这是主要站点如何使用 PayPal 进行操作:
https://cms.paypal.com/ca/cgi-bin/?cmd=_render-content&content_ID=developer/library_code
https://cms.paypal.com/ca/cgi-bin/?cmd=_render-content&content_ID=developer/library_code
You want manipulate for success payment (look at ECSetExpressCheckout, MOSTLY COMMON FOR TRANSACTIONS):
您想要成功付款的操作(查看 ECSetExpressCheckout,最常见的交易):
Source code here: https://cms.paypal.com/cms_content/CA/en_US/files/developer/nvp_ECSetExpressCheckout_php.txt
源代码在这里:https: //cms.paypal.com/cms_content/CA/en_US/files/developer/nvp_ECSetExpressCheckout_php.txt
Focus on code:
专注于代码:
$paymentAmount = urlencode('30'); // 30 USD if you set on sandbox default
$currencyID = urlencode('USD'); // or other currency code ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
$paymentType = urlencode('Order');
$returnURL = urlencode("my_return_url"); // YOUR URL IF SUCCESS
$cancelURL = urlencode('my_cancel_url'); // YOUR URL IF FAILED
If you need check a transaction after payment grab via TRANSACTION_ID with GetTransactionDetails function: https://cms.paypal.com/cms_content/CA/en_US/files/developer/nvp_GetTransactionDetails_php.txt
如果您需要使用 GetTransactionDetails 函数通过 TRANSACTION_ID 付款抓取后检查交易:https: //cms.paypal.com/cms_content/CA/en_US/files/developer/nvp_GetTransactionDetails_php.txt

