Unpredictable code: processing HTTP response from bank

This is my first thread here so hello!

Now… Can someone please help me out?

I’m trying to integrate my site with a payment processor and am having some trouble processing their HTTP response.

I’m checking for the word ‘Processed’ in the response string. Every time it’s there, I need my code to echo ‘WORKED’.

The problem is that my code is behaving very unpredictably. Sometimes when the bank returns a ‘Processed’ response, everything goes fine and I get the ‘WORKED’ result I’m looking for; other times, even for a ‘Processed’ response, my code inexplicably returns ‘FAILED’…

Here is the code I’m using:



//the processed response I'm looking for from the bank
$p = "Processed";

//checking the HTTP response string for the 'Processed' response 
$proc = strpos($fgets,$p);

if($proc === false){
	
//the result I'm sometimes getting even if the bank returned a 'Processed' response
echo "FAILED";

}
else if(!$mysqldb->increaseDeposit()){

//not usually getting this error - don't think there's a problem with the database function
echo "DATABASE ERROR";

}
else{

//the result I need every time I get a 'Processed' response from the bank
echo "WORKED";

}	



All my other functions are working fine on the site, just this one which I can’t fathom…

Anyone any ideas why it’s behaving so unpredictably and/or suggestions as to how I could process this response reliably?

It seems evident that the response sometimes doesn’t contain the string Processed even when transactions are successful than. Try printing the response string comparing to the executed condition to debug the issue. Furthermore, I would advise that you collect the response into an object or array key value pair. Authenticating by a string match like that is flawed if keyword processed were to used in another manor. Surly there is a key like paymentstatus or something to make the check more concrete.

Thanks for your advice.

I’ve tried various permutations but it’s still not reliable… When I print the response, the full response string I’m concerned about usually looks the same. I’m exploding it into an array but it makes no difference.

I have a feeling that the PHP code is fine, and the problem lies with the HTTP response - perhaps something to do with encoding?

Sometimes the response from the bank comes back ‘chunked’, other times with a set ‘content-length’.

I’m going to investigate this article I found which shows how to communicate with a payment processor using PHP/cURL. 

I’ve heard that cURL has some built-in functions designed to deal with this kind of thing.

If anyone is a master of HTTP response processing with PHP, you know, just say the word.