Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

dissecting Custom MIGS payment response with ob_get_contents()


xrgt

Recommended Posts

How can i strip the following output and access the variables via an array?

 

The buffered output i'm expecting is always in the following format:

<html><body>
processingError=
<br>
processingErrorMessage=
<br>
transactionApproved=
<br>
responseCode=
<br>
transactionNo=
<br>
receiptNo=
<br>
merchantTXRef=
<br>
transactionDeclined=
<br>
creditCardExpired=
<br>
insufficientFunds=
</body></html>

This is the payment module code i'm trying to work with:

<?php
// Get result
$vpcResponse = ob_get_contents();
// Finish with the buffer
ob_end_clean(); 
// Check for errors
if(strchr($vpcResponse,"<html>")) $errorMessage = $vpcResponse;
else if(curl_error($clientURL)) $errorMessage = "CURL ERROR: " . curl_errno($clientURL) . " " . curl_error($clientURL);
// Close the connection
curl_close($clientURL);
$responseKeyVals = split("&", $vpcResponse);
 foreach ($responseKeyVals as $val) {
	  $param = split("=", $val);
	  $responseArray[urldecode($param[0])] = urldecode($param[1]);
 }
// Process the results and determine the transactions status
$transactionResponse = $responseArray['responseCode'];
?>

 

Thanks.

Link to comment
Share on other sites

In Java i'd do it this way - PHP i have no idea, can anyone assist?:

 

resp = new BufferedReader(new InputStreamReader(gateway.openStream()));

	resp.readLine();
String inputLine2=resp.readLine();
	resp.readLine();
String inputLine4=resp.readLine();
	resp.readLine();
			String inputLine6=resp.readLine();
	resp.readLine();
			String inputLine8=resp.readLine();
//and so on...

paymentDetail.setResponseCode(inputLine8.substring(13,inputLine8.length()));
paymentDetail.setTransactionNo(inputLine10.substring(14,inputLine10.length()));
paymentDetail.setReceiptNo(inputLine12.substring(10,inputLine12.length()));

Link to comment
Share on other sites

For anyone that is interested, this is what i came up with by modifying the existing code:

 

<?php
$content2 = str_replace(array("<html>", "<body>", "<br>"), "", $vpcResponse);

			$responseKeyVals = split("\r\n", $content2);
			foreach ($responseKeyVals as $val) {
				$param = split("=", $val);
				$responseArray[urldecode($param[0])] = urldecode($param[1]);
			}
?>
<?php echo $responseArray['responseCode']; ?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...