Links
Comment on page

Code Samples

Programming Language

Code Examples: Sale

C#

1
//Request
2
System.Collections.Specialized.NameValueCollection
3
MyPost = new System.Collections.Specialized.NameValueCollection();
4
MyPost.Add("xKey", ""); // Credential
5
MyPost.Add("xVersion", "4.5.5"); // API version
6
MyPost.Add("xSoftwareName", My.Application.Info.Title); // Name of your software
7
MyPost.Add("xSoftwareVersion", My.Application.Info.Version.ToString); // Version of your software
8
MyPost.Add("xCommand", "cc:sale");
9
MyPost.Add("xCardNum", "");
10
MyPost.Add("xExp", "");
11
MyPost.Add("xName", "");
12
MyPost.Add("xAmount", "");
13
MyPost.Add("xAccount", "");
14
MyPost.Add("xMagstripe", "");
15
MyPost.Add("xToken", "");
16
MyPost.Add("xCustom01", "");
17
MyPost.Add("xCVV", "");
18
MyPost.Add("xStreet", "");
19
MyPost.Add("xZip", "");
20
MyPost.Add("xBillFirstName", "");
21
MyPost.Add("xBillMiddleName", "");
22
MyPost.Add("xBillLastName", "");
23
MyPost.Add("xBillCompany", "");
24
MyPost.Add("xBillStreet", "");
25
MyPost.Add("xBillStreet2", "");
26
MyPost.Add("xBillCity", "");
27
MyPost.Add("xBillZip", "");
28
MyPost.Add("xBillCountry", "");
29
MyPost.Add("xBillPhone", "");
30
MyPost.Add("xBillMobile", "");
31
MyPost.Add("xShipFirstName", "");
32
MyPost.Add("xShipMiddleName", "");
33
MyPost.Add("xShipLastName", "");
34
MyPost.Add("xShipCompany", "");
35
MyPost.Add("xShipStreet", "");
36
MyPost.Add("xShipStreet2", "");
37
MyPost.Add("xShipCity", "");
38
MyPost.Add("xShipState", "");
39
MyPost.Add("xShipZip", "");
40
MyPost.Add("xShipCountry", "");
41
MyPost.Add("xShipPhone", "");
42
MyPost.Add("xShipMobile", "");
43
MyPost.Add("xRefNum", "");
44
MyPost.Add("xAuthCode", "");
45
MyPost.Add("xIP", "");
46
MyPost.Add("xRouting", "");
47
MyPost.Add("xCardpresent", "");
48
MyPost.Add("xDUKPT", "");
49
MyPost.Add("xTax", "");
50
MyPost.Add("xTip", "");
51
MyPost.Add("xInvoice", "");
52
MyPost.Add("xPONum", "");
53
MyPost.Add("xComments", "");
54
MyPost.Add("xDescription", "");
55
MyPost.Add("xEmail", "");
56
MyPost.Add("xFax", "");
57
MyPost.Add("xBillState", "");
58
MyPost.Add("xAllowPartialAuth", "");
59
MyPost.Add("xRxAmount", "");
60
MyPost.Add("xDentalAmount", "");
61
MyPost.Add("xVisionAmount", "");
62
MyPost.Add("xTransitAmount", "");
63
MyPost.Add("xCopayAmount", "");
64
MyPost.Add("xClinicalAmount", "");
65
MyPost.Add("xOrderID", "");
66
MyPost.Add("xExistingCustomer", "");
67
MyPost.Add("xAllowDuplicate", "");
68
MyPost.Add("xMICR", "");
69
MyPost.Add("xCheckNum", "");
70
MyPost.Add("xCheckImageFront", "");
71
MyPost.Add("xCheckImageBack", "");
72
MyPost.Add("xVoucherApproval", "");
73
MyPost.Add("xVoucherSerial", "");
74
MyPost.Add("xGatewayRefNum", "");
75
MyPost.Add("xGatewayResult", "");
76
MyPost.Add("xGatewayError", "");
77
MyPost.Add("xGatewayCVV", "");
78
MyPost.Add("xGatewayAVS", "");
79
MyPost.Add("xOrderItems", "");
80
MyPost.Add("xOrderType", "");
81
MyPost.Add("xCustomerComments", "");
82
MyPost.Add("xShipMethod", "");
83
MyPost.Add("xShipAmount", "");
84
85
System.Net.WebClient MyClient = new System.Net.WebClient();
86
string MyResponse = System.Text.UTF8Encoding.ASCII.GetString(MyClient.UploadValues("https://x1.cardknox.com/gateway", MyPost));
87
// Response
88
System.Collections.Specialized.NameValueCollection MyResponseData = System.Web.HttpUtility.ParseQueryString(MyResponse); // If necessary, add reference to System.Web
89
string MyResult = "";
90
if (MyResponseData.AllKeys.Contains("xResult"))
91
MyResult = MyResponseData["xResult"];
92
string MyStatus = "";
93
if (MyResponseData.AllKeys.Contains("xStatus"))
94
MyStatus = MyResponseData["xStatus"];
95
string MyError = "";
96
if (MyResponseData.AllKeys.Contains("xError"))
97
MyError = MyResponseData["xError"];
98
string MyRefNum = "";
99
if (MyResponseData.AllKeys.Contains("xRefNum"))
100
MyRefNum = MyResponseData["xRefNum"];

Java/Android

1
public void postData()
2
{
3
// Create a new HttpClient and Post Header Java/Android
4
HttpClient httpclient = new DefaultHttpClient();
5
HttpPost httppost = new HttpPost("https://x1.cardknox.com/gateway");
6
try
7
{
8
// Add your data
9
List nameValuePairs = new ArrayList(9);
10
nameValuePairs.add(new BasicNameValuePair("xKey", "")); // Credential
11
nameValuePairs.add(new BasicNameValuePair("xVersion", "4.5.5")); // API Version
12
nameValuePairs.add(new BasicNameValuePair("xSoftwareName", "")); // Name of your software
13
nameValuePairs.add(new BasicNameValuePair("xSoftwareVersion", "")); // Version of your software
14
nameValuePairs.add(new BasicNameValuePair("xCommand", "cc:sale"));
15
nameValuePairs.add(new BasicNameValuePair("xCardNum", ""));
16
nameValuePairs.add(new BasicNameValuePair("xExp", ""));
17
nameValuePairs.add(new BasicNameValuePair("xName", ""));
18
nameValuePairs.add(new BasicNameValuePair("xAmount", ""));
19
nameValuePairs.add(new BasicNameValuePair("xAccount", ""));
20
nameValuePairs.add(new BasicNameValuePair("xMagstripe", ""));
21
nameValuePairs.add(new BasicNameValuePair("xToken", ""));
22
nameValuePairs.add(new BasicNameValuePair("xCustom01", ""));
23
nameValuePairs.add(new BasicNameValuePair("xCVV", ""));
24
nameValuePairs.add(new BasicNameValuePair("xStreet", ""));
25
nameValuePairs.add(new BasicNameValuePair("xZip", ""));
26
nameValuePairs.add(new BasicNameValuePair("xBillFirstName", ""));
27
nameValuePairs.add(new BasicNameValuePair("xBillMiddleName", ""));
28
nameValuePairs.add(new BasicNameValuePair("xBillLastName", ""));
29
nameValuePairs.add(new BasicNameValuePair("xBillCompany", ""));
30
nameValuePairs.add(new BasicNameValuePair("xBillStreet", ""));
31
nameValuePairs.add(new BasicNameValuePair("xBillStreet2", ""));
32
nameValuePairs.add(new BasicNameValuePair("xBillCity", ""));
33
nameValuePairs.add(new BasicNameValuePair("xBillZip", ""));
34
nameValuePairs.add(new BasicNameValuePair("xBillCountry", ""));
35
nameValuePairs.add(new BasicNameValuePair("xBillPhone", ""));
36
nameValuePairs.add(new BasicNameValuePair("xBillMobile", ""));
37
nameValuePairs.add(new BasicNameValuePair("xShipFirstName", ""));
38
nameValuePairs.add(new BasicNameValuePair("xShipMiddleName", ""));
39
nameValuePairs.add(new BasicNameValuePair("xShipLastName", ""));
40
nameValuePairs.add(new BasicNameValuePair("xShipCompany", ""));
41
nameValuePairs.add(new BasicNameValuePair("xShipStreet", ""));
42
nameValuePairs.add(new BasicNameValuePair("xShipStreet2", ""));
43
nameValuePairs.add(new BasicNameValuePair("xShipCity", ""));
44
nameValuePairs.add(new BasicNameValuePair("xShipState", ""));
45
nameValuePairs.add(new BasicNameValuePair("xShipZip", ""));
46
nameValuePairs.add(new BasicNameValuePair("xShipCountry", ""));
47
nameValuePairs.add(new BasicNameValuePair("xShipPhone", ""));
48
nameValuePairs.add(new BasicNameValuePair("xShipMobile", ""));
49
nameValuePairs.add(new BasicNameValuePair("xRefNum", ""));
50
nameValuePairs.add(new BasicNameValuePair("xAuthCode", ""));
51
nameValuePairs.add(new BasicNameValuePair("xIP", ""));
52
nameValuePairs.add(new BasicNameValuePair("xRouting", ""));
53
nameValuePairs.add(new BasicNameValuePair("xCardpresent", ""));
54
nameValuePairs.add(new BasicNameValuePair("xDUKPT", ""));
55
nameValuePairs.add(new BasicNameValuePair("xTax", ""));
56
nameValuePairs.add(new BasicNameValuePair("xTip", ""));
57
nameValuePairs.add(new BasicNameValuePair("xInvoice", ""));
58
nameValuePairs.add(new BasicNameValuePair("xPONum", ""));
59
nameValuePairs.add(new BasicNameValuePair("xComments", ""));
60
nameValuePairs.add(new BasicNameValuePair("xDescription", ""));
61
nameValuePairs.add(new BasicNameValuePair("xEmail", ""));
62
nameValuePairs.add(new BasicNameValuePair("xFax", ""));
63
nameValuePairs.add(new BasicNameValuePair("xBillState", ""));
64
nameValuePairs.add(new BasicNameValuePair("xAllowPartialAuth", ""));
65
nameValuePairs.add(new BasicNameValuePair("xRxAmount", ""));
66
nameValuePairs.add(new BasicNameValuePair("xDentalAmount", ""));
67
nameValuePairs.add(new BasicNameValuePair("xVisionAmount", ""));
68
nameValuePairs.add(new BasicNameValuePair("xTransitAmount", ""));
69
nameValuePairs.add(new BasicNameValuePair("xCopayAmount", ""));
70
nameValuePairs.add(new BasicNameValuePair("xClinicalAmount", ""));
71
nameValuePairs.add(new BasicNameValuePair("xOrderID", ""));
72
nameValuePairs.add(new BasicNameValuePair("xExistingCustomer", ""));
73
nameValuePairs.add(new BasicNameValuePair("xAllowDuplicate", ""));
74
nameValuePairs.add(new BasicNameValuePair("xMICR", ""));
75
nameValuePairs.add(new BasicNameValuePair("xCheckNum", ""));
76
nameValuePairs.add(new BasicNameValuePair("xCheckImageFront", ""));
77
nameValuePairs.add(new BasicNameValuePair("xCheckImageBack", ""));
78
nameValuePairs.add(new BasicNameValuePair("xVoucherApproval", ""));
79
nameValuePairs.add(new BasicNameValuePair("xVoucherSerial", ""));
80
nameValuePairs.add(new BasicNameValuePair("xGatewayRefNum", ""));
81
nameValuePairs.add(new BasicNameValuePair("xGatewayResult", ""));
82
nameValuePairs.add(new BasicNameValuePair("xGatewayError", ""));
83
nameValuePairs.add(new BasicNameValuePair("xGatewayCVV", ""));
84
nameValuePairs.add(new BasicNameValuePair("xGatewayAVS", ""));
85
nameValuePairs.add(new BasicNameValuePair("xOrderItems", ""));
86
nameValuePairs.add(new BasicNameValuePair("xOrderType", ""));
87
nameValuePairs.add(new BasicNameValuePair("xCustomerComments", ""));
88
nameValuePairs.add(new BasicNameValuePair("xShipMethod", ""));
89
nameValuePairs.add(new BasicNameValuePair("xShipAmount", ""));
90
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
91
// Execute HTTP Post Request
92
HttpResponse response = httpclient.execute(httppost);
93
System.out.println("response = " + EntityUtils.toString(response.getEntity()));
94
}
95
catch (ClientProtocolException e)
96
{
97
// TODO Auto-generated catch block
98
}
99
catch (IOException e)
100
{
101
// TODO Auto-generated catch block
102
}
103
}

Node.js

1
// Node.Js
2
var request = require("request");
3
var querystring = require('querystring');
4
request.post({
5
url: 'https://x1.cardknox.com/gateway',
6
form: {
7
xKey: '', // Credential
8
xVersion: '', // API Version
9
xSoftwareName: '', // Name of your software
10
xSoftwareVersion: '', // Version of your software
11
xCommand: '',
12
xCardNum: '',
13
xExp: '',
14
xAmount: '',
15
xAccount:'',
16
xMagstripe:'',
17
xToken:'',
18
xCustom01:'',
19
xCVV:'',
20
xStreet:'',
21
xZip:'',
22
xBillFirstName:'',
23
xBillMiddleName:'',
24
xBillLastName:'',
25
xBillCompany:'',
26
xBillStreet:'',
27
xBillStreet2:'',
28
xBillCity:'',
29
xBillCountry:'',
30
xBillPhone:'',
31
xShipFirstName:'',
32
xShipMiddleName:'',
33
xShipCompany:'',
34
xShipStreet:'',
35
xShipStreet2:'',
36
xShipCity:'',
37
xShipState:'',
38
xShipZip:'',
39
xShipCountry:'',
40
xShipPhone:'',
41
xShipMobile:'',
42
xRefNum:'',
43
xAuthCode:'',
44
xRouting:'',
45
xCardpresent:'',
46
xDUKPT:'',
47
xTax:'',
48
xTip:'',
49
xInvoice:'',
50
xPONum:'',
51
xComments:'',
52
xDescription:'',
53
xEmail:'',
54
xFax:'',
55
xBillState:'',
56
xAllowPartialAuth:'',
57
xRxAmount:'',
58
xDentalAmount:'',
59
xVisionAmount:'',
60
xTransitAmount:'',
61
xCopayAmount:'',
62
xClinicalAmount:'',
63
xOrderID:'',
64
xExistingCustomer:'',
65
xAllowDuplicate:'',
66
xMICR:'',
67
xCheckNum:'',
68
xCheckImageFront:'',
69
xCheckImageBack:'',
70
xVoucherApproval:'',
71
xVoucherSerial:'',
72
xGatewayRefNum:'',
73
xGatewayResult:'',
74
xGatewayError:'',
75
xGatewayCVV:'',
76
xGatewayAVS:'',
77
xOrderItems:'',
78
xOrderType:'',
79
xCustomerComments:'',
80
xShipMethod:'',
81
xShipAmount:'',
82
}
83
},
84
function (error, response, body) {
85
if (error) throw new Error(error);
86
console.log(querystring.parse(body));
87
});

PHP

1
<?php
2
// Request
3
$data = array();
4
$data["xKey"] = ""; // Credential
5
$data["xVersion"] = ""; // API Version
6
$data["xSoftwareName"] = ""; // Name of your software
7
$data["xSoftwareVersion"] = ""; // Version of your software
8
$data["xCommand"] = "";
9
$data["xCardNum"] = "";
10
$data["xExp"] = "";
11
$data["xName"] = "";
12
$data["xAmount"] = "";
13
$data["xAccount"] = "";
14
$data["xMagstripe"] = "";
15
$data["xToken"] = "";
16
$data["xCustom01"] = "";
17
$data["xCVV"] = "";
18
$data["xStreet"] = "";
19
$data["xZip"] = "";
20
$data["xBillFirstName"] = "";
21
$data["xBillMiddleName"] = "";
22
$data["xBillLastName"] = "";
23
$data["xBillCompany"] = "";
24
$data["xBillStreet"] = "";
25
$data["xBillStreet2"] = "";
26
$data["xBillState"] = "";
27
$data["xBillCity"] = "";
28
$data["xBillZip"] = "";
29
$data["xBillCountry"] = "";
30
$data["xBillPhone"] = "";
31
$data["xBillMobile"] = "";
32
$data["xShipFirstName"] = "";
33
$data["xShipMiddleName"] = "";
34
$data["xShipLastName"] = "";
35
$data["xShipCompany"] = "";
36
$data["xShipStreet"] = "";
37
$data["xShipStreet2"] = "";
38
$data["xShipCity"] = "";
39
$data["xShipState"] = "";
40
$data["xShipZip"] = "";
41
$data["xShipCountry"] = "";
42
$data["xShipPhone"] = "";
43
$data["xShipMobile"] = "";
44
$data["xRefNum"] = "";
45
$data["xAuthCode"] = "";
46
$data["xIP"] = "";
47
$data["xRouting"] = "";
48
$data["xCardpresent"] = "";
49
$data["xDUKPT"] = "";
50
$data["xTax"] = "";
51
$data["xTip"] = "";
52
$data["xInvoice"] = "";
53
$data["xPONum"] = "";
54
$data["xComments"] = "";
55
$data["xDescription"] = "";
56
$data["xEmail"] = "";
57
$data["xFax"] = "";
58
$data["xBillState"] = "";
59
$data["xAllowPartialAuth"] = "";
60
$data["xRxAmount"] = "";
61
$data["xDentalAmount"] = "";
62
$data["xVisionAmount"] = "";
63
$data["xTransitAmount"] = "";
64
$data["xCopayAmount"] = "";
65
$data["xClinicalAmount"] = "";
66
$data["xOrderID"] = "";
67
$data["xExistingCustomer"] = "";
68
$data["xAllowDuplicate"] = "";
69
$data["xMICR"] = "";
70
$data["xCheckNum"] = "";
71
$data["xCheckImageFront"] = "";
72
$data["xCheckImageBack"] = "";
73
$data["xVoucherApproval"] = "";
74
$data["xVoucherSerial"] = "";
75
$data["xGatewayRefNum"] = "";
76
$data["xGatewayResult"] = "";
77
$data["xGatewayError"] = "";
78
$data["xGatewayCVV"] = "";
79
$data["xGatewayAVS"] = "";
80
$data["xOrderItems"] = "";
81
$data["xOrderType"] = "";
82
$data["xCustomerComments"] = "";
83
$data["xShipMethod"] = "";
84
$data["xShipAmount"] = "";
85
86
function buildQuery($data)
87
{
88
if(function_exists('http_build_query') && ini_get('arg_separator.output')=='&') return http_build_query($data);
89
$tmp = array();
90
foreach($data as $key=>$val) $tmp[] = rawurlencode($key) . '=' . rawurlencode($val);
91
return implode('&', $tmp);
92
}
93
$data = buildQuery($data);
94
$ch = curl_init("https://x1.cardknox.com/gateway");
95
if(!is_resource($ch))
96
{
97
echo "Error: Unable to initialize CURL ($ch)";
98
exit;
99
}
100
curl_setopt($ch, CURLOPT_HEADER, 1);
101
curl_setopt($ch, CURLOPT_POST,1);
102
curl_setopt($ch, CURLOPT_TIMEOUT, 45);
103
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
104
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
105
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
106
$raw_result = curl_exec($ch);
107
if(curl_error($ch) != "")
108
{
109
echo curl_error($ch);
110
}
111
elseif(!strlen($raw_result))
112
{
113
echo "Error reading from card processing gateway. Please contact the merchant to verify whether transaction has been processed.";
114
curl_close($ch);
115
exit;
116
}
117
elseif($raw_result == false)
118
{
119
echo "Blank response from card processing gateway.";
120
curl_close($ch);
121
exit;
122
}
123
else
124
{
125
// SUCCESS
126
curl_close($ch);
127
// result will be on the last line of the return
128
$tmp = explode("\n",$raw_result);
129
$result_string = $tmp[count($tmp)-1];
130
parse_str($result_string, $result_array);
131
print_r($result_array);
132
}
133
?>

Python 2

1
# Python 2
2
import urllib2, urllib
3
from urlparse import parse_qs
4
data = {}
5
data["xKey"] = "" # Credential
6
data["xVersion"] = "" # API Version
7
data["xSoftwareName"] = "" # Name of your software
8
data["xSoftwareVersion"] = "" # Version of your software
9
data["xCommand"] = ""
10
data["xCardNum"] = ""
11
data["xExp"] = ""
12
data["xName"] = ""
13
data["xAmount"] = ""
14
data["xAccount"] = ""
15
data["xMagstripe"] = ""
16
data["xToken"] = ""
17
data["xCustom01"] = ""
18
data["xCVV"] = ""
19
data["xStreet"] = ""
20
data["xZip"] = ""
21
data["xBillFirstName"] = ""
22
data["xBillMiddleName"] = ""
23
data["xBillLastName"] = ""
24
data["xBillCompany"] = ""
25
data["xBillStreet"] = ""
26
data["xBillStreet2"] = ""
27
data["xBillCity"] = ""
28
data["xBillCountry"] = ""
29
data["xBillPhone"] = ""
30
data["xBillMobile"] = ""
31
data["xShipFirstName"] = ""
32
data["xShipMiddleName"] = ""
33
data["xShipCompany"] = ""
34
data["xShipStreet"] = ""
35
data["xShipStreet2"] = ""
36
data["xShipCity"] = ""
37
data["xShipState"] = ""
38
data["xShipZip"] = ""
39
data["xShipCountry"] = ""
40
data["xShipPhone"] = ""
41
data["xShipMobile"] = ""
42
data["xRefNum"] = ""
43
data["xAuthCode"] = ""
44
data["xIP"] = ""
45
data["xRouting"] = ""
46
data["xCardpresent"] = ""
47
data["xDUKPT"] = ""
48
data["xTax"] = ""
49
data["xTip"] = ""
50
data["xInvoice"] = ""
51
data["xPONum"] = ""
52
data["xComments"] = ""
53
data["xDescription"] = ""
54
data["xEmail"] = ""
55
data["xFax"] = ""
56
data["xBillState"] = ""
57
data["xAllowPartialAuth"] = ""
58
data["xRxAmount"] = ""
59
data["xDentalAmount"] = ""
60
data["xVisionAmount"] = ""
61
data["xTransitAmount"] = ""
62
data["xCopayAmount"] = ""
63
data["xClinicalAmount"] = ""
64
data["xOrderID"] = ""
65
data["xExistingCustomer"] = ""
66
data["xAllowDuplicate"] = ""
67
data["xMICR"] = ""
68
data["xCheckNum"] = ""
69
data["xCheckImageFront"] = ""
70
data["xCheckImageBack"] = ""
71
data["xVoucherApproval"] = ""
72
data["xVoucherSerial"] = ""
73
data["xGatewayRefNum"] = ""
74
data["xGatewayResult"] = ""
75
data["xGatewayError"] = ""
76
data["xGatewayCVV"] = ""
77
data["xGatewayAVS"] = ""
78
data["xOrderItems"] = ""
79
data["xOrderType"] = ""
80
data["xCustomerComments"] = ""
81
data["xShipMethod"] = ""
82
data["xShipAmount"] = ""
83
84
request = urllib2.Request("https://x1.cardknox.com/gateway", urllib.urlencode(data).encode('utf-8'))
85
rawResponse = urllib2.urlopen(request).read().decode('utf-8')
86
response = parse_qs(rawResponse, keep_blank_values=True)
87
print("xRefNum: " + "".join(response.get("xRefNum","")));
88
print("xResult: " + "".join(response.get("xResult","")));
89
print("xStatus: " + "".join(response.get("xStatus","")));
90
print("xError: " + "".join(response.get("xError","")));

Python 3

1
# Python 3
2
import urllib.request
3
from urllib.parse import parse_qs
4
data = {}
5
data["xKey"] = "" # Credential
6
data["xVersion"] = "" # API Version
7
data["xSoftwareName"] = "" # Name of your software
8
data["xSoftwareVersion"] = "" # Version of your software
9
data["xCommand"] = ""
10
data["xCardNum"] = ""
11<