即使付款已处理,PayPal IPN 仍返回“INVALID”

Posted

技术标签:

【中文标题】即使付款已处理,PayPal IPN 仍返回“INVALID”【英文标题】:PayPal IPN returns "INVALID" even though payment was processed 【发布时间】:2014-08-31 02:41:18 【问题描述】:

请求失败

请求:cmd=_notify-validate&mc_gross=2.00&protection_eligibility=Eligible&address_status=confirmed&payer_id=LDYM496TZ5PMS&tax=0.00&address_street=7 Malcom Ave Quarrington Hill&payment_date=10:56:23 2014 年 7 月 10 日 PDT&payment_status=已完成&charset=windows-1252&address_zip=DH6 4QT&first_name=fake&mc_fee=0.38&address_country_code=GB&address_name=fake fake&notify_version=3.8&custom=168&payer_status=unverified&business=fake@gmail.com&address_country=United 英国及ADDRESS_CITY =达勒姆&量= 0&verify_sign = AO3SqMqkkL6g6znCfk.bTx0YGc9QAAC62A.uYD2AR27aMUKA8tjOenQg&PAYER_EMAIL =假@ gmail.com&txn_id = 0V51470288084925M&payment_type =即时与姓氏=假&ADDRESS_STATE = RECEIVER_EMAIL =假@ gmail.com&payment_fee = 0.38 receiver_id = 43PTLVVM58JD4&txn_type = web_accept&ITEM_NAME = Hyubusa&mc_currency = USD&ITEM_NUMBER = residence_country = GB&transaction_subject = 168&payment_gross = 2.00 &ipn_track_id=8f6ab718d71f2

POST 失败

mc_gross=2.00&protection_eligibility=Eligible&address_status=confirmed&payer_id=LDYM496TZ5PMS&tax=0.00&address_street=7+Malcom+Ave%0D%0AQuarrington+Hill&payment_date=10%3A56%3A23+Jul+10%2C+2014&char_set=windows-status&char_set=windows-1 = DH6 + 4QT与FIRST_NAME =假&mc_fee = 0.38 address_country_code = GB&ADDRESS_NAME =假+假&notify_version = 3.8&定制= 168&payer_status =未经验证和业务=假%40gmail.com&ADDRESS_COUNTRY =美国+英国及ADDRESS_CITY =达勒姆&量= 0&verify_sign = AO3SqMqkkL6g6znCfk.bTx0YGc9QAAC62A.uYD2AR27aMUKA8tjOenQg&PAYER_EMAIL =假%40gmail.com&txn_id = 0V51470288084925M&payment_type =即时&姓氏=假&ADDRESS_STATE =&RECEIVER_EMAIL = adamhyubusa%40gmail.com&payment_fee = 0.38&receiver_id = 43PTLVVM58JD4&txn_type = web_accept&ITEM_NAME = Hyubusa&mc_currency = USD&ITEM_NUMBER =&residence_country = GB&transaction_subject = 168&payment_gross = 2.00&ipn_track_id = 8f6ab718d71f2

所以,我的 PayPal IPN 有时会返回无效响应! ...当我在沙盒上测试它时,它工作正常。当我用自己的 CC 测试它时,它工作正常。

然而,有时当我收到捐款时,钱会通过……但 IPN 的回复无效。

我在美国......它目前失败的特定捐赠者来自英国......我不知道这是否有任何相关性。这是我的代码。

$request = "cmd=_notify-validate"; 
foreach ($_POST as $varname => $varvalue)
$email .= "$varnamefake: $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/cgi-bin/webscr");
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":
        $message = "good: $".$_POST['mc_gross']." | ".$_POST['custom'];
        $amt = str_replace("$", "", $_POST['mc_gross']);
        $data = array(
               'STATUS' => 1,
               'AMOUNT' => $amt
        );

        $this->db->where('ID', $_POST['custom']);
        $this->db->update('donations', $data);        

    case "INVALID":
        $message ="bad";
        mail("fakeemail@fake.com","paypal response", $message);
        break;
    default:
        $message ="other";
        mail("fakeemail@fake.com","paypal response", $message);

请求失败

请求:cmd=_notify-validate&mc_gross=2.00&protection_eligibility=Eligible&address_status=confirmed&payer_id=LDYM496TZ5PMS&tax=0.00&address_street=7 Malcom Ave Quarrington Hill&payment_date=10:56:23 2014 年 7 月 10 日 PDT&payment_status=已完成&charset=windows-1252&address_zip=DH6 4QT&first_name=fake&mc_fee=0.38&address_country_code=GB&address_name=Brendan fake&notify_version=3.8&custom=168&payer_status=unverified&business=fake@gmail.com&address_country=United 英国及ADDRESS_CITY =达勒姆&量= 0&verify_sign = AO3SqMqkkL6g6znCfk.bTx0YGc9QAAC62A.uYD2AR27aMUKA8tjOenQg&PAYER_EMAIL =假@ gmail.com&txn_id = 0V51470288084925M&payment_type =即时与姓氏=屈臣氏ADDRESS_STATE = RECEIVER_EMAIL =假@ gmail.com&payment_fee = 0.38 receiver_id = 43PTLVVM58JD4&txn_type = web_accept&ITEM_NAME = Hyubusa&mc_currency = USD&ITEM_NUMBER = residence_country = GB&transaction_subject = 168&payment_gross = 2.00 &ipn_track_id=8f6ab718d71f2

POST 失败

mc_gross=2.00&protection_eligibility=Eligible&address_status=confirmed&payer_id=LDYM496TZ5PMS&tax=0.00&address_street=7+Malcom+Ave%0D%0AQuarrington+Hill&payment_date=10%3A56%3A23+Jul+10%2C+2014&char_set=windows-status&char_set=windows-1 = DH6 + 4QT与FIRST_NAME =假&mc_fee = 0.38 address_country_code = GB&ADDRESS_NAME =假+假&notify_version = 3.8&定制= 168&payer_status =未经验证和业务=假%40gmail.com&ADDRESS_COUNTRY =美国+英国及ADDRESS_CITY =达勒姆&量= 0&verify_sign = AO3SqMqkkL6g6znCfk.bTx0YGc9QAAC62A.uYD2AR27aMUKA8tjOenQg&PAYER_EMAIL =假%40gmail.com&txn_id = 0V51470288084925M&payment_type =即时&姓氏=沃森&ADDRESS_STATE =&RECEIVER_EMAIL = adamhyubusa%40gmail.com&payment_fee = 0.38&receiver_id = 43PTLVVM58JD4&txn_type = web_accept&ITEM_NAME = Hyubusa&mc_currency = USD&ITEM_NUMBER =&residence_country = GB&transaction_subject = 168&payment_gross = 2.00&ipn_track_id = 8f6ab718d71f2

【问题讨论】:

您能否提供 PayPal 发送给您的 POST 数据的原始转储以及您正在生成并在失败时发回给他们的字符串的原始转储?由于某种原因,它们不能匹配。我的猜测可能与 URL 编码或特定订单数据中的特殊字符有关。 这就是失败请求的样子:...发布在主要问题中 是的,你可以看到它们是不同的。一个是 URL 编码的,另一个不是。你需要把它放在合适的位置,这样你就可以把它发回 PayPal,就像他们发给你的一样。 【参考方案1】:
if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc())  
    $varvalue = urlencode(stripslashes($varvalue)); 

else  
    $value = urlencode($value); 
 

IPN 变量已经进行了 url 编码,没有必要再次对其进行编码以发送回 paypal - 这可能是某些交易有效而其他交易无效的原因。

【讨论】:

谢谢......这似乎已经解决了......需要更多的现场测试,但它似乎工作,谢谢。

以上是关于即使付款已处理,PayPal IPN 仍返回“INVALID”的主要内容,如果未能解决你的问题,请参考以下文章

在数据库连接错误时处理PayPal IPN

Paypal IPN payment_status 说已完成但付款被拒绝

PayPal IPN 返回购物车或订单 ID 以进行后处理

Paypal IPN 不适用于 woocommerce

Paypal 发送了 IPN 的警告电子邮件

paypal 验证付款