Finally got a response from PayPal support.
They have let us know that "The IPNs are sent for refunded payments, but the refunded payments have a different transaction id."
So, if a different transaction ID is returned for the refund, that would explain why the database isn't updating, because it can't reconcile the transaction ID because the whole basis of the script is that it identifies by the transaction ID:
<?php
//if (!WA_isValidPayPal()) return;
if ($_POST["payment_status"] == "Refunded") {
$UpdateQuery = new WA_MySQLi_Query($csdbmysqli);
$UpdateQuery->Action = "update";
$UpdateQuery->Table = "ORDERTABLENAME";
$UpdateQuery->bindColumn("SMCorderSTATUSID", "i", "1", "WA_DEFAULT");
$UpdateQuery->addFilter("SMCorderPAYPALID", "=", "s", "".($_POST['txn_id']) ."");
$UpdateQuery->execute();
$UpdateGoTo = "";
if (function_exists("rel2abs")) $UpdateGoTo = $UpdateGoTo?rel2abs($UpdateGoTo,dirname(__FILE__)):"";
$UpdateQuery->redirect($UpdateGoTo);
}
?>
I've asked PayPal how we reconcile these two things, but have you come across this before?
Thank you.
NJ