Helcim Gateway

Code Samples

Support - Helcim Gateway

For development support or to acquire a developer test account for the Helcim Gateway, contact us today.


PHP 5 Sample Code (Non-Recurring)

Below is a PHP 5 code sample. Please note that it is for demonstration purposes only and will not work correctly until a valid merchant id and gateway token are acquired.

<?php

// Gateway URL
$Url = 'https://gateway.helcim.com/';

// Required Request Variables
$MerchantId		= '9999111111';
$Token			= '1a2b3c4d5e6f7g8h9i';
$Type			= 'purchase';
$Amount			= '10.00';
$CardNumber		= '4242424242424242';
$ExpiryDate		= '0912';
$CvvIndicator		= '1';
$Cvv			= '645';
$CardholderName		= 'John Doe';
$CardholderAddress		= '#503 - 111 25th Ave SW';
$CardholderPostalCode	= 'T2S3G4';
$Test			= '1';

// Create POST string
$PostFields = "merchantId={$MerchantId}&token={$Token}&type={$Type}".
		 "&amount={$Amount}&cardNumber={$CardNumber}".
		 "&expiryDate={$ExpiryDate}&cvvIndicator={$CvvIndicator}".
		 "&cvv={$Cvv}&cardholderName={$CardholderName}".
		 "&cardholderAddress={$CardholderAddress}".
		 "&cardholderPostalCode={$CardholderPostalCode}&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);

// Check gateway response
if ($ResponseArray['response'] == 1){
	// Transaction completed successfully
} else {
	// Transaction declined
}
?>


PHP 4 Sample Code (Non-Recurring)

The process for sending a payment request to the gateway using PHP 4 is very similar to PHP 5. However you will need to change the method of setting the CURL options. There are two ways of doing this:

Solution #1:

Use this code provided by php.net to simulate the curl_setopt_array function

<?php
if (!function_exists('curl_setopt_array')) {
   function curl_setopt_array(&$Curl, $CurlOptions)
   {
       foreach ($CurlOptions as $Option => $Value) {
           if (!curl_setopt($Curl, $Option, $Value)) {
               return false;
           } 
       }
       return true;
   }
}
?>

Solution #2:

Set each CURL options individually with:

<?php
curl_setopt($Curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($Curl, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($Curl, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($Curl, CURLOPT_HEADER, FALSE);
curl_setopt($Curl, CURLOPT_POST, TRUE);
curl_setopt($Curl, CURLOPT_POSTFIELDS, $PostFields);
curl_setopt($Curl, CURLOPT_TIMEOUT, 30);
?>


.NET Sample Code (Non-Recurring)

Below is an ASP.NET code sample. Please note that it is for demonstration purposes only and will not work correctly until a valid merchant id and gateway token are acquired.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        // Gateway URL
        string Url = "https://gateway.helcim.com/";

        // Required Request Variables
        string MerchantId   = "9999111111";        
        string Token        = "1a2b3c4d5e6f7g8h9i";
        string Type         = "purchase";
        string Amount       = "10.00";
        string CardNumber   = "4242424242424242";
        string ExpiryDate   = "0912";
        string CvvIndicator = "1"; 
        string Cvv          = "432";
        string CardholderName = "John Doe";
        string CardholderAddress = "#503 - 111 25th Ave SW"; 
        string CardholderPostalCode = "T2S3G4";
        string Test = "1";

        string PostData = "merchantId=" + MerchantId + "&token=" + Token + "&type=" + Type +
                          "&amount=" + Amount + "&cardNumber=" + CardNumber +
                          "&expiryDate=" + ExpiryDate + "&cvvIndicator=" + CvvIndicator +
                          "&cvv=" + Cvv + "&cardholderName=" + CardholderName +
                          "&cardholderAddress=" + CardholderAddress +
                          "&cardholderPostalCode=" + CardholderPostalCode + "&test=" + Test;
	 // Create a new web request
        HttpWebRequest GatewayRequest = (HttpWebRequest)WebRequest.Create(Url);

	 // Set HTTP header information
        GatewayRequest.Method = "POST";
        GatewayRequest.ContentType = "application/x-www-form-urlencoded";

        byte[] byteArray = Encoding.UTF8.GetBytes(PostData);
        GatewayRequest.ContentLength = byteArray.Length;

	 // Send request	
        Stream SendStream = GatewayRequest.GetRequestStream();
        SendStream.Write(byteArray, 0, byteArray.Length);
        SendStream.Close();

	 // Get response
        HttpWebResponse GatewayResponse = (HttpWebResponse)GatewayRequest.GetResponse();
        Stream ReceiveStream = GatewayResponse.GetResponseStream();
        StreamReader ReadStream = new StreamReader(ReceiveStream, Encoding.UTF8);
        string Response = ReadStream.ReadToEnd();

continued...

	 // Close resources
        GatewayResponse.Close();
        ReadStream.Close();
	 // Parse response (HttpUtility requires .NET Framework 2.0)
        NameValueCollection Nvc = HttpUtility.ParseQueryString(Response.Replace("\r\n", "&"));
        ResponseLiteral.Text = Nvc["responseMessage"];
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Helcim Gateway Test</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Literal  id="ResponseLiteral"
                  runat="server" />
    </div>
    </form>
</body>
</html>

© Copyright 2006-2010 Helcim Inc. All Rights Reserved.

The Helcim name and logo are trademarks of Helcim Inc. The Interac name and logo are trademarks of Interac Inc. The Visa and MasterCard logos are trademarks of Visa International and MasterCard International Incorporated. Other tradenames may be trademarks of their respective owners. Helcim is a registered MSP/ISO of the Canadian branch of U.S. Bank National Association and GE Money. New applicants are subject to conditions and approval of the application by Helcim and its partnering banks.