Helcim Logo Support & Tutorials

© Copyright 2006-2018 Helcim Inc.

All Rights Reserved.

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

.NET (C#)


<%@ 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();

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