Trying to get variable from WP table and toggle its value

There are two issues I see in your code:

  1. The $searchIP is actually outside of the $wpdb->prepare(): (I didn’t use the full query so that you’d see the issue clearer)

    $StatusCheck = $wpdb->get_var( $wpdb->prepare("SELECT payment_status ..."),$searchIP);
    

    So you should correct that, like so: (reindented for clarity)

    $StatusCheck = $wpdb->get_var( $wpdb->prepare( "
        SELECT payment_status FROM {$ipn_tables}
        WHERE serial_no = %s
    ", $searchIP ) );
    
  2. Your if should use the equality operator (== or ===) and not the basic assignment operator (=).

    So for examples, use if ($StatusCheck == "Completed") and if ($StatusCheck == "Refunded") instead of what you currently have in your code.