Helcim Logo Support & Tutorials

© Copyright 2006-2018 Helcim Inc.

All Rights Reserved.

Legacy Platforms » Helcim Virtual Terminal » Helcim Gateway API » Code Samples »

PHP - Auto-Void based on AVS Results

This is a code sample on how to automatically void a transaction based on the AVS response. The code is an addition to PHP Transaction Code Sample and assumes that certain variables and CURL settings are already set.

<?php

	// SET ACCEPTABLE AVS RESPONSE
	$acceptableArray[] = 'W'; // 9 digit Zip matches, Address (Street) does not
	$acceptableArray[] = 'X'; // Exact AVS Match
	$acceptableArray[] = 'Y'; // Address (Street) and 5 digit Zip match
	$acceptableArray[] = 'Z'; // 5 digit Zip matches, Address (Street) does not

	// DEFAULT AVS RESULT
	$avsGood = false;

	// GO THROUGH RESULTS
	foreach($acceptableArray as $avs){

		// CHECK FOR AVS RESPONSE
		if($responseArray['avsResponse'] == $avs){

			// SET AVS
			$avsGood = true;

			// END FOREACH LOOP
			break;

		}

	}

	// CHECK AVS
	if($avsGood){

		// DISPLAY
		echo 'APPROVED';

	}else{

		// SETTINGS
		$type = 'void';
		$transactionId = $responseArray['transactionId'];

		// CREATE POST STRING
		$postString =	'merchantId='.$merchantId.'&'.
						'token='.$token.'&'.
						'type='.$type.'&'.
						'transactionId='.$transactionId.'&'.
						'test='.$test;

		// CREATE NEW CURL RESOURCE
		$curl = curl_init($url);

		// SET CURL OPTIONS
		curl_setopt_array($curl,$curlOptions);

		// PROCESS TRANSACTION - GET RESPONSE
		$response = curl_exec($curl);

		// CLOSE CURL REOURCE
		curl_close($curl);

		// DISPLAY
		echo 'TRANSACTION REVERSED - BAD AVS';

	}

?>