0
votes

FAILED REQUEST

request: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 Jul 10, 2014 PDT&payment_status=Completed&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&[email protected]&address_country=United Kingdom&address_city=Durham&quantity=0&verify_sign=AO3SqMqkkL6g6znCfk.bTx0YGc9QAAC62A.uYD2AR27aMUKA8tjOenQg&[email protected]&txn_id=0V51470288084925M&payment_type=instant&last_name=fake&address_state=&[email protected]&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

Failed 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+PDT&payment_status=Completed&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%40gmail.com&address_country=United+Kingdom&address_city=Durham&quantity=0&verify_sign=AO3SqMqkkL6g6znCfk.bTx0YGc9QAAC62A.uYD2AR27aMUKA8tjOenQg&payer_email=fake%40gmail.com&txn_id=0V51470288084925M&payment_type=instant&last_name=fake&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

So, my PayPal IPN is returning an INVALID response SOMETIMES! ... When I test it on sandbox it works fine. When I test it with my own CC it works fine.

Occasionally when I get a donation however, the money comes through ... but the response from IPN is invalid.

I am in the US ... the particular donator it is currently failing on is from the UK ... I do not know if that has any relevance. This is my code.

$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("[email protected]","paypal response", $message);
        break;
    default:
        $message ="other";
        mail("[email protected]","paypal response", $message);
}

FAILED REQUEST

request: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 Jul 10, 2014 PDT&payment_status=Completed&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&[email protected]&address_country=United Kingdom&address_city=Durham&quantity=0&verify_sign=AO3SqMqkkL6g6znCfk.bTx0YGc9QAAC62A.uYD2AR27aMUKA8tjOenQg&[email protected]&txn_id=0V51470288084925M&payment_type=instant&last_name=Watson&address_state=&[email protected]&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

Failed 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+PDT&payment_status=Completed&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%40gmail.com&address_country=United+Kingdom&address_city=Durham&quantity=0&verify_sign=AO3SqMqkkL6g6znCfk.bTx0YGc9QAAC62A.uYD2AR27aMUKA8tjOenQg&payer_email=fake%40gmail.com&txn_id=0V51470288084925M&payment_type=instant&last_name=Watson&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

1
Can you provide a raw dump of the POST data PayPal sends you as well as a raw dump of the string you're generating and sending back to them when it fails? They must not match for some reason. My guess would be something to do with URL encoding or special characters in the data on particular orders.Drew Angell
This is how the failed request looks: ... posted in main questionAdam Hyubusa
Yeah, you can see that they're different. One is URL encoded and the other is not. You need to get that situated so you send it back to PayPal exactly as they sent it to you.Drew Angell

1 Answers

1
votes
if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()){  
    $varvalue = urlencode(stripslashes($varvalue)); 
}
else { 
    $value = urlencode($value); 
} 

IPN variables are already url encoded, no point of encoding them again to send back to paypal - probably the reason why some transactions work and others don't.