尽管订阅成功,Paypal 仍返回“INVALID”
Posted
技术标签:
【中文标题】尽管订阅成功,Paypal 仍返回“INVALID”【英文标题】:Paypal Returns "INVALID" inspite of successful payment for subscription 【发布时间】:2019-02-20 01:37:16 【问题描述】:我正在使用 Paypal 沙盒试用订阅功能,并且付款已成功处理。但是,当尝试验证响应时,Paypal 会返回 INVALID 响应。
这是我要发送的数据 -
Array
(
[cmd] => _notify-validate
[txn_type] => subscr_signup
[subscr_id] => I-3R009NJ6JYS9
[last_name] => buyer
[residence_country] => GB
[mc_currency] => USD
[item_name] => Sellacious_Git
[business] => aditya-facilitator@codeacious.tech
[amount3] => 52.50
[recurring] => 1
[payer_status] => verified
[payer_email] => aditya-buyer@codeacious.tech
[first_name] => test
[receiver_email] => aditya-facilitator@codeacious.tech
[payer_id] => LCLETGLHU5H7A
[reattempt] => 1
[item_number] => 123
[subscr_date] => 06:35:57 Sep 15, 2018 PDT
[charset] => windows-1252
[period3] => 1 D
[mc_amount3] => 52.50
[auth] => AyB1VOVssxLlLE177ha.etTVC3E8ZWDZOAEu.e9Wezio0ciVvog4UXvI6ODZq-ZxS2tearHH1MAiO.U7E0k.IBg
[form_charset] => UTF-8
)
这是我得到的回应 -
(
[code] => 200
[headers] => Array
(
[Date] => Sat, 15 Sep 2018 14:05:29 GMT
[Server] => Apache
[X-Frame-Options] => SAMEORIGIN
[Set-Cookie] => Apache=10.72.108.11.1537020329139856; path=/; expires=Mon, 07-Sep-48 14:05:29 GMT
[Vary] => Accept-Encoding,User-Agent
[Connection] => close
[Transfer-Encoding] => chunked
[Content-Type] => text/html; charset=UTF-8
)
[body] => INVALID
)
我试图通过 cURL 的 url 是 -
https://ipnpb.sandbox.paypal.com/cgi-bin/webscr
我还在配置文件 > PayPal 按钮语言编码的 Paypal 卖家设置中将字符编码设置为 UTF-8。
请帮忙。
【问题讨论】:
能否分享您实现并发送 CURL 的完整代码? 【参考方案1】:我已经实现了如下,并且工作正常:
只需在下面的代码中更改电子邮件地址并尝试,它应该可以工作。
function paymentIpnlistener()
// 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";
// If testing on Sandbox use:
$header .= "Host: www.sandbox.paypal.com:443\r\n";
//$header .= "Host: ipnpb.paypal.com:443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
if (strpos('ssl://www.sandbox.paypal.com', 'sandbox') !== FALSE && function_exists('openssl_open'))
$fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
else
// The old "normal" way of validating an IPN.
$fp = fsockopen('ssl://www.sandbox.paypal.com', 80, $errno, $errstr, 30);
// If testing on Sandbox use:
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
//$fp = fsockopen ('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp)
// HTTP ERROR
else
fputs ($fp, $header . $req);
while (!feof($fp))
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0)
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
$mail_From = "// add here your working email address";
$mail_To = "// add here your working email address";
$mail_Subject = "VERIFIED IPN";
$mail_Body = $req;
foreach ($_POST as $key => $value)
$emailtext .= $key . " = " .$value ."\n\n";
mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From);
else if (strcmp ($res, "INVALID") == 0)
// log for manual investigation
$mail_From = "From: // add here your working email address";
$mail_To = "// add here your working email address";
$mail_Subject = "INVALID IPN";
$mail_Body = $req;
foreach ($_POST as $key => $value)
$emailtext .= $key . " = " .$value ."\n\n";
mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From);
// while end
fclose ($fp);
请使用上面的函数我希望它能解决你的问题,我已经用 php 实现了。如果需要任何帮助,请告诉我。
【讨论】:
另外请确认您是否在您的 PayPal 帐户中设置了 IPN URL? @Aditya Chakraborty 检查我的答案并给我发消息寻求帮助。 另见这里,我已经给出了答案并且工作正常:***.com/questions/47323426/…以上是关于尽管订阅成功,Paypal 仍返回“INVALID”的主要内容,如果未能解决你的问题,请参考以下文章
IPN 验证返回 INVALID,因为 PayPal 在 POST 中向 IPN 侦听器发送了不正确的字符集
Paypal IPN 现在返回 INVALID - PHP 代码以前工作正常