API for Websites & Apps

Cardknox offers a light but powerful API for many popular development languages. Enabling your POS, custom software, website or app to securely accept payments is so simple.


Overview

The Cardknox API allows you to securely connect with our gateway and process transaction. When you sign up, you will receive a unique id which will identify you on every communication.

The basic idea is simple:

  • Your application sends us a request using our simple api format. There are required and optional values for each type of transaction.
  • The most common request is to process a credit card payment. Cardknox analyzes and routes every transaction based on over a dozen calculations and sends the request to the processor.
  • Cardknox forwards the response back to your server. If approved, we also send a token back to your system so that you do not need to store credit cards, sharply reducing your PCI scope.
  • All future transactions relating to the payment, such as refunds, voids, etc can be sent via the API using the token alone.

Below is sample code for the most popular languages – there is no library needed! Sign up using the button below, and our integration specialists will customize a script which you can use to begin testing.

 'Request
  Dim MyPost As New System.Collections.Specialized.NameValueCollection
  MyPost.Add("xKey", "")
  MyPost.Add("xVersion", "")
  MyPost.Add("xSoftwareName", "")
  MyPost.Add("xSoftwareVersion", "")
  MyPost.Add("xCommand", "")
  MyPost.Add("xCardNum", "")
  MyPost.Add("xExp", "")
  MyPost.Add("xName", "")
  MyPost.Add("xAmount", "")
  Dim MyClient As New Net.WebClient
  Dim MyResponse As String = System.Text.UTF8Encoding.ASCII.GetString(MyClient.UploadValues("https://x1.cardknox.com/gateway", MyPost))
  'Response
  Dim MyResponseData As System.Collections.Specialized.NameValueCollection = System.Web.HttpUtility.ParseQueryString(MyResponse) 'If necessary, add reference to System.Web
  Dim MyResult As String = ""
  If MyResponseData.AllKeys.Contains("xResult") Then MyResult = MyResponseData("xResult")
  Dim MyStatus As String = ""
  If MyResponseData.AllKeys.Contains("xStatus") Then MyStatus = MyResponseData("xStatus")
  Dim MyError As String = ""
  If MyResponseData.AllKeys.Contains("xError") Then MyError = MyResponseData("xError")
  Dim MyRefNum As String = ""
  If MyResponseData.AllKeys.Contains("xRefNum") Then MyRefNum = MyResponseData("xRefNum")

// Request
  System.Collections.Specialized.NameValueCollection MyPost = new System.Collections.Specialized.NameValueCollection();
  MyPost.Add("xKey", "");
  MyPost.Add("xVersion", "");
  MyPost.Add("xSoftwareName", "");
  MyPost.Add("xSoftwareVersion", "");
  MyPost.Add("xCommand", "");
  MyPost.Add("xCardNum", "");
  MyPost.Add("xExp", "");
  MyPost.Add("xName", "");
  MyPost.Add("xAmount", "");
  System.Net.WebClient MyClient = new System.Net.WebClient();
  string MyResponse = System.Text.UTF8Encoding.ASCII.GetString(MyClient.UploadValues("https://x1.cardknox.com/gateway", MyPost));
  // Response
  System.Collections.Specialized.NameValueCollection MyResponseData = System.Web.HttpUtility.ParseQueryString(MyResponse); //If necessary, add reference to System.Web
  string MyResult = "";
  if (MyResponseData.AllKeys.Contains("xResult"))
  MyResult = MyResponseData["xResult"];
  string MyStatus = "";
  if (MyResponseData.AllKeys.Contains("xStatus"))
    MyStatus = MyResponseData["xStatus"];
    string MyError = "";
  if (MyResponseData.AllKeys.Contains("xError"))
    MyError = MyResponseData["xError"];
    string MyRefNum = "";
  if (MyResponseData.AllKeys.Contains("xRefNum"))
    MyRefNum = MyResponseData["xRefNum"];

<?php
    // Request
    $data = array();
    $data["xKey"] = "";
    $data["xVersion"] = "";
    $data["xSoftwareName"] = "";
    $data["xSoftwareVersion"] = "";
    $data["xCommand"] = "";
    $data["xCardNum"] = "";
    $data["xExp"] = "";
    $data["xName"] = "";
    $data["xAmount"] = "";
    function buildQuery($data)
      {
        if(function_exists('http_build_query') && ini_get('arg_separator.output')=='&') return http_build_query($data);
        $tmp = array();
        foreach($data as $key=>$val) $tmp[] = rawurlencode($key) . '=' . rawurlencode($val);
        return implode('&', $tmp);
      }
    $data = buildQuery($data);
    $ch = curl_init("https://x1.cardknox.com/gateway");
    if(!is_resource($ch))
      {
        echo "Error: Unable to initialize CURL ($ch)";
        exit;
      }
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 45);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
    $raw_result = curl_exec($ch);
    if(curl_error($ch) != "")
      {
        echo curl_error($ch);
      }
    elseif(!strlen($raw_result))
      {
        echo "Error reading from card processing gateway. Please contact the merchant to verify whether transaction has been processed.";
        curl_close($ch);
        exit;
      }
    elseif($raw_result == false)
      {
        echo "Blank response from card processing gateway.";
        curl_close($ch);
        exit;
      }
    else
      {
        // SUCCESS
        curl_close($ch);
        // result will be on the last line of the return
        $tmp = explode("\n",$raw_result);
        $result_string = $tmp[count($tmp)-1];
        parse_str($result_string, $result_array);
        echo "<pre>";
        print_r($result_array);
      }
  ?>

public void postData()
  {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("https://x1.cardknox.com/gateway");
    try
      {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(9);
        nameValuePairs.add(new BasicNameValuePair("xKey", ""));
        nameValuePairs.add(new BasicNameValuePair("xVersion", ""));
        nameValuePairs.add(new BasicNameValuePair("xSoftwareName", ""));
        nameValuePairs.add(new BasicNameValuePair("xSoftwareVersion", ""));
        nameValuePairs.add(new BasicNameValuePair("xCommand", ""));
        nameValuePairs.add(new BasicNameValuePair("xCardNum", ""));
        nameValuePairs.add(new BasicNameValuePair("xExp", ""));
        nameValuePairs.add(new BasicNameValuePair("xName", ""));
        nameValuePairs.add(new BasicNameValuePair("xAmount", ""));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        System.out.println("response = " + EntityUtils.toString(response.getEntity()));
      }
    catch (ClientProtocolException e)
      {
        // TODO Auto-generated catch block
      }
    catch (IOException e)
      {
        // TODO Auto-generated catch block
      }
  }