Question

Sometimes PayPal breaks, and it doesn't return a tracking_id. At the same time, it completes the payment on it's own servers. This is a problem for me, because even thought the payment was successful, my server ends up with a blank tracking_id column in the database table, which causes me lots of issues

If this were to happen again, will the following if statement be enough to capture such an event?

if( !isset($trackingId) || empty($trackingId) || $trackingId == null || $trackingId == "" ) {

    // something is wrong

} else {

    // continue as normal

}
Was it helpful?

Solution

Use empty.

Determine whether a variable is considered to be empty. A variable is considered empty if it does not exist or if its value equals FALSE. empty() does not generate a warning if the variable does not exist.

The following things are considered to be empty:

"" (an empty string) 
0 (0 as an integer)
0.0 (0 as a float) 
"0" (0 as a string) 
NULL 
FALSE 
array() (an empty array) 
$var; (a variable declared, but without a value)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top