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

Below is a code sample in PHP5 on how to send a recurring 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 for Form Submitted
if(@$_POST['submit']){

	// Required Request Variables
	$Url = 'https://gateway.helcim.com/';
	$MerchantId			= '9999111111';
	$Token				= '1a2b3c4d5e6f7g8h9i';
	$Type				= 'purchase';
	$Amount				= @$_POST['amount'];
	$CardNumber			= @$_POST['cardNumber'];
	$ExpiryDate			= @$_POST['expiryDate'];
	$CvvIndicator			= '1';
	$Cvv				= @$_POST['cvv'];
	$recurringPeriod		= '1 month';
	$recurringStartDate		= '20131201';
	$recurringAmount		= '100.00';
	$recurringTimes			= '999';
	$Test				= '1';

	// Create POST string
	$PostFields = "merchantId={$MerchantId}&token={$Token}&type={$Type}".
			 "&amount={$Amount}&cardNumber={$CardNumber}".
			 "&expiryDate={$ExpiryDate}&cvvIndicator={$CvvIndicator}".
			 "&cvv={$Cvv}&recurringPeriod={$recurringPeriod}".
			 "&recurringStartDate={$recurringStartDate}".
			 "&recurringAmount={$recurringAmount}".
			 "&recurringTimes={$recurringTimes}&test={$Test}";

	// CURL Options Array
	$CurlOptions = array( CURLOPT_RETURNTRANSFER => 1,
				  CURLOPT_AUTOREFERER => TRUE,
				  CURLOPT_FRESH_CONNECT => TRUE,
				  CURLOPT_HEADER => FALSE,
				  CURLOPT_POST => TRUE,
				  CURLOPT_POSTFIELDS => $PostFields,
				  CURLOPT_TIMEOUT => 30 );

	// New CURL resource					  
	$Curl = curl_init($Url);
	// Set CURL options array
	curl_setopt_array($Curl, $CurlOptions);
	// Get URL response
	$Response = curl_exec($Curl);
	// Close CURL resource
	curl_close($Curl);

	// Parse response into an array
	$Response = eregi_replace("\x0D\x0A", "&", $Response);
	parse_str($Response, $ResponseArray);

}

?>

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

<?php

// Check for Form Not Submitted
if(!@$_POST['submit']){

?>

<h1>Enter Payment Information</h1>

<form action="payment.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>

<?php

// Check for Form Submitted
}else{

?>

<h1>Transaction Receipt</h1>

<?php

	// Check gateway response
	if(@$ResponseArray['response'] == 1){

?>

<h2>APPROVED!</h2>

<?php

	}else{

?>

<h2>DECLINED</h2>
<h3>ERROR: <?= @$ResponseArray['responseMessage'] ?></h3>

<?php

	}

?>

<table>
<tr>
<td>Date & Time:</td>
<td><?= @$ResponseArray['date'] ?> <?= @$ResponseArray['time'] ?></td>
</tr>
<tr>
<td>Invoice Number:</td>
<td><?= @$ResponseArray['orderId'] ?></td>
</tr>
<tr>
<td>Amount:</td>
<td><?= @$ResponseArray['amount'] ?></td>
</tr>
<tr>
<td>Approval Code:</td>
<td><?= @$ResponseArray['approvalCode'] ?></td>
</tr>
<tr>
<td>Card Type:</td>
<td><?= @$ResponseArray['cardType'] ?></td>
</tr>
<tr>
<td>Credit Card #:</td>
<td><?= @$ResponseArray['cardNumber'] ?></td>
</tr>
</table>

<?php

}

?>

</body>
</html>