Helcim Logo Support & Tutorials

© Copyright 2006-2018 Helcim Inc.

All Rights Reserved.

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

PHP5 (Using CURL)


<?php

	// CHECK IF THE FORM WAS SUBMITTED
	if(@$_POST['submit']){

		// SET URL
		$url = 'https://gateway.helcim.com/';

		// SET TRANSACTION VALUES
		$merchantId		= '9999111111';
		$token			= '1a2b3c4d5e6f7g8h9i';
		$type			= 'purchase';
		$amount			= '100.00';
		$cardNumber		= '5454545454545454';
		$expiryDate		= '1020';
		$cvvIndicator	= '1';
		$cvv			= '200';
		$orderId		= 'INV091293123';
		$test			= '1';

		// CREATE POST STRING
		$postString =	'merchantId='.$merchantId.'&'.
						'token='.$token.'&'.
						'type='.$type.'&'.
						'amount='.$amount.'&'.
						'cardNumber='.$cardNumber.'&'.
						'expiryDate='.$expiryDate.'&'.
						'cvvIndicator='.$cvvIndicator.'&'.
						'cvv='.$cvv.'&'.
						'orderId='.$orderId.'&'.
						'test='.$test;

		// SET CURL OPTIONS
		$curlOptions = array(	CURLOPT_RETURNTRANSFER => 1,
								CURLOPT_AUTOREFERER => TRUE,
								CURLOPT_FRESH_CONNECT => TRUE,
								CURLOPT_HEADER => FALSE,
								CURLOPT_POST => TRUE,
								CURLOPT_POSTFIELDS => $postString,
								CURLOPT_TIMEOUT => 30 );

		// 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);

		// CONVERT CARRIAGE RETURN LINE FEED TO AMPERSAND
		$response = preg_replace("/\x0D/",'&',$response);
		$response = preg_replace("/\x0A/",'&',$response);

		// PARSE RESPONSE INTO AN ARRAY
		parse_str($response,$responseArray);

		// CHECK FOR APPROVAL
		if($responseArray['response'] == 1){

			// APPROVED
			echo 'TRANSACTION APPROVED!';

			// DISPLAY RESPONSE ARRAY
			print_r($responseArray);

			// KILL PROCESS
			exit;

		}else{

			// DECLINED
			echo 'TRANSACTION DECLINED!';

			// DISPLAY RESPONSE ARRAY
			print_r($responseArray);

			// KILL PROCESS
			exit;

		}

	}

?>