Adam Hyubusa Adam Hyubusa - 4 months ago 10
MySQL Question

PayPal IPN returns "INVALID" even though payment was processed

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&business=fake@gmail.com&address_country=United
Kingdom&address_city=Durham&quantity=0&verify_sign=AO3SqMqkkL6g6znCfk.bTx0YGc9QAAC62A.uYD2AR27aMUKA8tjOenQg&payer_email=fake@gmail.com&txn_id=0V51470288084925M&payment_type=instant&last_name=fake&address_state=&receiver_email=fake@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


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("fakeemail@fake.com","paypal response", $message);
break;
default:
$message ="other";
mail("fakeemail@fake.com","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&business=fake@gmail.com&address_country=United
Kingdom&address_city=Durham&quantity=0&verify_sign=AO3SqMqkkL6g6znCfk.bTx0YGc9QAAC62A.uYD2AR27aMUKA8tjOenQg&payer_email=fake@gmail.com&txn_id=0V51470288084925M&payment_type=instant&last_name=Watson&address_state=&receiver_email=fake@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


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

Answer
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.

Comments