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) with Full HTML

Below is a code sample in PHP5 on how to send a transaction to our payment gateway using CURL. The page includes full HTML to provide a base on how to create your own payment page (hosted on your own website). Under this solutions, customers would never leave your site at the time of payment.

<?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			= @$_POST['amount'];
		$cardNumber		= @$_POST['cardNumber'];
		$expiryDate		= @$_POST['expiryDate'];
		$cvvIndicator	= '1';
		$cvv			= @$_POST['cvv'];
		$orderId		= @$_POST['orderId'];
		$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;

		}

	}

?>

<html>
<head>
<title>Payment Form</title>
<body>

<h1>Enter Payment Information</h1>

<form action="your-checkout-page.php" method="POST">

<table>
<tr>
<td>Credit Card #:</td>
<td><input type="text" name="cardNumber" value=""></td>
</tr>
<tr>
<td>Expiry Date (MMYY):</td>
<td><input type="text" name="expiryDate" value=""></td>
</tr>
<tr>
<td>CVV Security Code:</td>
<td><input type="text" name="cvv" value=""></td>
</tr>
<tr>
<td>Amount:</td>
<td><input type="text" name="amount" value="0.00"></td>
</tr>
<tr>
<td>Invoice #:</td>
<td><input type="text" name="orderId" value=""></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Submit Payment"></td>
</tr>
</table>

</form>

</body>
</html>