问题描述
我无法获取Paypal的IPN集成到我的PHP,我有以下脚本,它继续下降到默认情况下,在Paypal沙箱中进行付款。
任何帮助将不胜感激!
$ request =cmd = _notify-validate;
foreach($ _POST as $ varname => $ varvalue){
$ email。=$ varname:$ varvalue\\\
;
if(function_exists('get_magic_quotes_gpc')and get_magic_quotes_gpc()){
$ varvalue = urlencode(stripslashes($ varvalue));
}
else {
$ value = urlencode($ value);
}
$ request。=& $ varname = $ varvalue;
}
$ ch = curl_init();
curl_setopt($ ch,CURLOPT_URL,https://www.sandbox.paypal.com/cgi-bin/webscr);
//curl_setopt($ch,CURLOPT_URL,\"https://www.paypal.com);
curl_setopt($ ch,CURLOPT_POST,true);
curl_setopt($ ch,CURLOPT_POSTFIELDS,$ request);
curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,false);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true);
$ result = curl_exec($ ch);
curl_close($ ch);
switch($ result){
caseVERIFIED:
mail('test@test.com','worked','worked');
break;
caseINVALID:
mail('test@test.com','invaild','invaild');
break;
默认值:
mail('test@test.com','failed','failed');
}
如果我给自己发电子邮件$ result只是空白。
编辑:我发现它是我的LAMP的服务器端问题,但不确定如何解决它。
注意
我建议使用curl安装在服务器上,但我不知道是否配置正确。使用位于此处的var_dump和Paypal测试工具进行一些调试:
我可以理解,工作时会变得困难和耗时与第三方服务。
可能值得抓取POST数据,序列化它并将其应用到一个变量,所以你可以测试没有PayPal打回你的回调。 p>
我最初会这样做,以获取PayPal POST。
<?php
file_put_contents(serialize($ _ POST),'post.log');
//现在你有post请求序列化,我们可以抓取内容,并将其应用到一个变量进行快速测试。
?>
代码开始:
<?php
$ _POST = unserialize(file_get_content('post.log'));
//现在你可以通过命令行或浏览器执行脚本,而不需要PayPal的测试工具。使用var_dump调查问题是什么。
$ request =cmd = _notify-validate;
foreach($ _POST as $ varname => $ varvalue){
$ email。=$ varname:$ varvalue\\\
;
if(function_exists('get_magic_quotes_gpc')and get_magic_quotes_gpc()){
$ varvalue = urlencode(stripslashes($ varvalue));
}
else {
$ value = urlencode($ value);
}
$ request。=& $ varname = $ varvalue;
}
?>
现在:这是一个更有效和高效的测试。在你的例子中,你通过电子邮件发送自己,但不包括邮件功能正文中的任何地方的$ result。
PayPal的IPN示例使用fsock,虽然CURL更有效,更易于使用。也有一些最近的问题,PayPal的沙盒的变化。
另外:要确定主要原因是什么,正如你所说的,它似乎是你的LAMP堆栈。检查你的日志目录(一般是/ var / log /)一般从他们你可以找出什么失败。
I am having trouble getting Paypal's IPN integrated into my php, i have the following script and it keeps falling through to the default case when a payment is made in the paypal sandbox.
Any help would be appreciated!
$request = "cmd=_notify-validate";
foreach ($_POST as $varname => $varvalue){
$email .= "$varname: $varvalue\n";
if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()){
$varvalue = urlencode(stripslashes($varvalue));
}
else {
$value = urlencode($value);
}
$request .= "&$varname=$varvalue";
}
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://www.sandbox.paypal.com/cgi-bin/webscr");
//curl_setopt($ch,CURLOPT_URL,"https://www.paypal.com");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$request);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$result = curl_exec($ch);
curl_close($ch);
switch($result){
case "VERIFIED":
mail('test@test.com','worked','worked');
break;
case "INVALID":
mail('test@test.com','invaild','invaild');
break;
default:
mail('test@test.com','failed','failed');
}
if i email myself $result it is just blank.
EDIT: I found out it is a server-side issue with my LAMP but am unsure of how to fix it.
Note: i do have curl installed on the server, but i am not sure if it is configured properly.
I'd suggest doing some debugging using var_dump and Paypal's test tool located here: https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session
I can understand it becomes difficult and time consuming when working with Third Party Services.
It may be worth simply grabbing the POST data, serializing it and applying it to a variable so you can test without PayPal hitting your callback.
I'd do something like this initially to grab the PayPal POST.
<?php
file_put_contents(serialize($_POST), 'post.log');
//Now you have the post request serialized we can grab the contents and apply it to a variable for fast testing.
?>
Start of your code:
<?php
$_POST = unserialize(file_get_content('post.log'));
//Now you can execute the script via command line or within your browser without requiring PayPal's testing tool. Use var_dump to investigate what's the issue.
$request = "cmd=_notify-validate";
foreach ($_POST as $varname => $varvalue){
$email .= "$varname: $varvalue\n";
if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()){
$varvalue = urlencode(stripslashes($varvalue));
}
else {
$value = urlencode($value);
}
$request .= "&$varname=$varvalue";
}
?>
NOW: This is a bit more effective and efficient when it comes to testing. In your example you were emailing yourself, but not including $result anywhere within the body of the mail function.http://php.net/manual/en/function.mail.php
PayPal's IPN example uses fsock, although CURL is more effective and easier to use. Also there have been some recent issues with PayPal's sandbox changing. https://www.paypal-community.com/t5/Selling-on-your-website/IPN-response-problem/m-p/519862/message-uid/519862#U519862
Also : To determine what the main cause is, as you've said it appears to be your LAMP stack. Check your logs directory (generally /var/log/) generally from their you'll be able to pinpoint what's failing.
这篇关于Paypal IPN集成到PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!