对paypal付款真的很困惑

发布于 2024-10-31 07:03:59 字数 2627 浏览 7 评论 0原文

更新1:

$res写入文本文件只会返回单词VERIFIED

<?php  
/*  
mysql_connect("localhost", "user", "password") or die(mysql_error());  
mysql_select_db("PayPal") or die(mysql_error());  
*/

// read the post from PayPal system and add 'cmd'  
$req = 'cmd=_notify-validate';  
foreach ($_POST as $key => $value) {  
$value = urlencode(stripslashes($value));  
$req .= "&$key=$value";  
}  
// post back to PayPal system to validate  
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";  
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";  
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";  

$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);  

if (!$fp) {  
// HTTP ERROR  
} else {  
fputs ($fp, $header . $req);  
while (!feof($fp)) {  
$res = fgets ($fp, 1024);  
if (strcmp ($res, "VERIFIED") == 0) {  

$ourFileName = "payment_successful.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $res);
fclose($ourFileHandle);


}  

else if (strcmp ($res, "INVALID") == 0) {  

$ourFileName = "payment_failed.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $res);
fclose($ourFileHandle);

}  
}  
fclose ($fp);  
}  
?> 

原始问题:

我有以下内容IPN(即时付款通知)脚本,有效,即如果成功则创建成功文件,如果失败则创建失败文件。

paypal 是否会将发布值返回到 IPN 文件,以便我可以确定哪项付款成功或哪项付款失败?

如果是,我如何访问这些值?

如果否,我如何确定哪笔付款已被接受或拒绝?

这是我当前拥有的 IPN 文件中的脚本:

<?php  
// read the post from PayPal system and add 'cmd'  
$req = 'cmd=_notify-validate';  
foreach ($_POST as $key => $value) {  
$value = urlencode(stripslashes($value));  
$req .= "&$key=$value";  
}  
// post back to PayPal system to validate  
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";  
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";  
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";  

$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);  

if (!$fp) {  
// HTTP ERROR  
} else {  
fputs ($fp, $header . $req);  
while (!feof($fp)) {  
$res = fgets ($fp, 1024);  
if (strcmp ($res, "VERIFIED") == 0) {  

$ourFileName = "payment_successful.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

}  

else if (strcmp ($res, "INVALID") == 0) {  

$ourFileName = "payment_failed.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

}  
}  
fclose ($fp);  
}  
?>  

UPDATE 1:

Writing $res to a textfile just returns the word VERIFIED:

<?php  
/*  
mysql_connect("localhost", "user", "password") or die(mysql_error());  
mysql_select_db("PayPal") or die(mysql_error());  
*/

// read the post from PayPal system and add 'cmd'  
$req = 'cmd=_notify-validate';  
foreach ($_POST as $key => $value) {  
$value = urlencode(stripslashes($value));  
$req .= "&$key=$value";  
}  
// post back to PayPal system to validate  
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";  
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";  
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";  

$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);  

if (!$fp) {  
// HTTP ERROR  
} else {  
fputs ($fp, $header . $req);  
while (!feof($fp)) {  
$res = fgets ($fp, 1024);  
if (strcmp ($res, "VERIFIED") == 0) {  

$ourFileName = "payment_successful.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $res);
fclose($ourFileHandle);


}  

else if (strcmp ($res, "INVALID") == 0) {  

$ourFileName = "payment_failed.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $res);
fclose($ourFileHandle);

}  
}  
fclose ($fp);  
}  
?> 

ORIGINAL QUESTION:

I have the following IPN (Instant Payment Notification) script, which works, i.e. it creates a successful file if successful and a failed file if failed.

Does paypal return post values to the IPN file so I can figure out which payment was successful or which payment has failed?

If yes, how do I access these values?

If no, how do I figure out which payment has been accepted or declined?

This is the script in the IPN file I currently have:

<?php  
// read the post from PayPal system and add 'cmd'  
$req = 'cmd=_notify-validate';  
foreach ($_POST as $key => $value) {  
$value = urlencode(stripslashes($value));  
$req .= "&$key=$value";  
}  
// post back to PayPal system to validate  
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";  
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";  
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";  

$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);  

if (!$fp) {  
// HTTP ERROR  
} else {  
fputs ($fp, $header . $req);  
while (!feof($fp)) {  
$res = fgets ($fp, 1024);  
if (strcmp ($res, "VERIFIED") == 0) {  

$ourFileName = "payment_successful.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

}  

else if (strcmp ($res, "INVALID") == 0) {  

$ourFileName = "payment_failed.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

}  
}  
fclose ($fp);  
}  
?>  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

书间行客 2024-11-07 07:03:59

您的通用脚本中有答案。

Paypal 将在字符串中返回单词“VERIFIED”或“INVALID”。

($res, "VERIFIED") == 0

一个好技巧是将 $res 的值写入日志,您将在最后看到返回的结果。

确保您也使用沙箱进行测试。

另外,http://x.com 上还有一个论坛(他们为该域名支付了多少钱?)

FWIW、Paypal 的IPN 是 PITA。

You have the answer in your generic script.

Paypal will return the word VERIFIED or INVALID in the string.

($res, "VERIFIED") == 0

A good trick is to write the value of $res to your log and you will see the returned result right at the end.

Make sure you use the sandbox for testing as well.

Also there is a forum at http://x.com (how much did they pay for THAT domain?)

FWIW, Paypal's IPN is a PITA.

生来就爱笑 2024-11-07 07:03:59

你好,我

foreach ($_POST as $key => $value)
{
    $data[$key] = $value;
}

用这种方式实现了 echo '

'.print_r($data,true).'

';

会产生这样的东西:

cmd=_notify-validate
test_ipn=1
payment_type=echeck
payment_date=22:21:28 Mar 24, 2011 PDT
payment_status=Completed
address_status=confirmed
payer_status=verified
first_name=John
last_name=Smith
[email protected]
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%2C+any+street
[email protected]
[email protected]
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
txn_type=web_accept
txn_id=28325521
notify_version=2.1
custom=xyz123
invoice=abc1234
charset=windows-1252
verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AM3F5ODR-2hb2fIsWPHepIEPzAwg

hi i implemented mine this way

foreach ($_POST as $key => $value)
{
    $data[$key] = $value;
}

doing a echo '<pre>'.print_r($data,true).'</pre>';

would produce something like this :

cmd=_notify-validate
test_ipn=1
payment_type=echeck
payment_date=22:21:28 Mar 24, 2011 PDT
payment_status=Completed
address_status=confirmed
payer_status=verified
first_name=John
last_name=Smith
[email protected]
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%2C+any+street
[email protected]
[email protected]
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
txn_type=web_accept
txn_id=28325521
notify_version=2.1
custom=xyz123
invoice=abc1234
charset=windows-1252
verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AM3F5ODR-2hb2fIsWPHepIEPzAwg
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文