【问题标题】:Sandbox Paypal IPN not sending response, works fine with live site Paypal沙盒 Paypal IPN 未发送响应,可与实时网站 Paypal 正常工作
【发布时间】:2014-12-05 23:11:46
【问题描述】:

最近才出现这个问题:我无法从 paypal 沙箱 (IPN) 获得响应。

我使用以下代码:

import requests
params = {} #all params paypal sent via IPN, empty here for sake of brevity
params['cmd'] = "_notify-validate"
r = requests.post("https://www.sandbox.paypal.com/cgi-bin/webscr", params = params)

这会返回一条错误消息,提示“对等方重置连接”

请注意,此代码之前运行良好,如果我使用实时网站 Paypal URL 而不是沙箱,那么我仍然会收到响应而不是连接错误。

谁能验证这是否是 Paypal 端的问题?我的代码都没有改变,但从昨天开始,我使用沙盒的测试都不再起作用了。

【问题讨论】:

  • 我现在也有同样的问题...

标签: python paypal paypal-ipn paypal-sandbox


【解决方案1】:

PayPal 目前在沙盒环境中没有遇到 IPN 问题。我已经测试并且无法重新创建所描述的问题。请您尝试测试下面的代码,看看是否有相同的结果?

<?php

// change email from xxx@xxxx.com to a valid one.

// read the post from PayPal system and add 'cmd'
if($_SERVER['REQUEST_METHOD']!="POST") die("No data");
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$url=(!isset($_POST['test_ipn'])) ? 'https://www.paypal.com/cgi-bin/webscr' : 'https://www.sandbox.paypal.com/cgi-bin/webscr';

    $curl_result=$curl_err='';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
    curl_setopt($ch, CURLOPT_HEADER , 0);  
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    $curl_result = @curl_exec($ch);
    $curl_err = curl_error($ch);
    curl_close($ch);

//are we verified? If so, let's process the IPN
if (strpos($curl_result, "VERIFIED")!==false)
{
//do your IPN stuff here
$mail_From = "From: IPN@domain.com";  // enter an email address alias here example ipn@fiercepc.co.uk please note this does not need to be a real email address
$mail_To = "email@domain.com";  //enter the email address you want to receive the email at
$mail_Subject = "VERIFIED IPN";
$mail_Body = $req;

foreach ($_POST as $key => $value){
$emailtext .= $key . " = " .$value ."\r\n\r\n";
}

mail($mail_To, $mail_Subject, $emailtext . "\r\n\r\n" . $mail_Body, $mail_From);
}
else{
$mail_From = "From: IPN@domain.com";
$mail_To = "email@domain.com";
$mail_Subject = "INVALID IPN";
$mail_Body = $req;

$emailtext = "you didn't get anything";
mail($mail_To, $mail_Subject, $emailtext . "\r\n\r\n" . $mail_Body, $mail_From);
}

?>

或前往 GitHub 存储库查找更多 IPN 示例。

https://github.com/paypal/ipn-code-samples

【讨论】:

    【解决方案2】:

    这实际上是我的 Python 代码的问题。奇怪的是,我没有更改 requests 模块,但它停止使用相同的代码。

    一旦我改为通过“数据”参数而不是“参数”发送 IPN 变量,我就能够像平常一样收到响应。

    r = requests.post("https://www.sandbox.paypal.com/cgi-bin/webscr", data = params)
    

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 2018-08-14
      • 1970-01-01
      • 2012-10-10
      • 2013-07-04
      • 2013-08-07
      • 2012-01-08
      • 2012-04-09
      • 2016-07-13
      相关资源
      最近更新 更多