Code Samples

See our code samples here to learn how to connect to Linkpay in various languages and on various platforms.

Cut-n-Pay EASY PAYMENT INTEGRATION

icon-one

Generate token for payment

icon-two

Create payment form

icon-three

See transaction status

01 Generate token for payment

Prepare the payment request with all the required data, ensuring the shopper cannot view or alter the data in any manner. This includes data such as your payment credentials, as well as fixed values such as amount and currency. The preparation call is carried out with a simple POST request from the merchant’s server to the payment server. The JSON response contains a token required in the second step where the payment form is created.

public string GenerateToken()
{
var token = string.Empty;
var data = new NameValueCollection() {
{"SECURITY.SENDER", "ff80808142b2c03c0142b7a7339603e0"},
{"USER.LOGIN", "ff80808142b2c03c0142b7a7339803e4"},
{"USER.PWD", "demo"},
{"TRANSACTION.CHANNEL", "ff80808142b2c03c0142b7a7339803e5"},
{"TRANSACTION.MODE", "INTEGRATOR_TEST"},
{"PAYMENT.TYPE", "DB"},
{"PRESENTATION.AMOUNT", "50.99"},
{"PRESENTATION.CURRENCY", "EUR"}
};
using (var wc = new WebClient())
{
var rslt = wc.UploadValues("https://test.ctpe.net/frontend/GenerateToken", data);
var s = new JavaScriptSerializer();
var json = s.Deserialize<Dictionary<string, dynamic>>(Encoding.UTF8.GetString(rslt));
if (json.ContainsKey("transaction"))
{
token = json ["transaction"]["token"];
}
}
return token;
}

curl -X POST

https://test.ctpe.net/frontend/GenerateToken

-d "SECURITY.SENDER=ff80808142b2c03c0142b7a7339603e0"
-d "TRANSACTION.CHANNEL=ff80808142b2c03c0142b7a7339803e5"
-d "TRANSACTION.MODE=INTEGRATOR_TEST"
-d "USER.LOGIN=ff80808142b2c03c0142b7a7339803e4"
-d "USER.PWD=demo"
-d "PAYMENT.TYPE=DB"
-d "PRESENTATION.AMOUNT=50.99"
-d "PRESENTATION.CURRENCY=EUR"

public class TokenGenerator {

public static String generateToken(final Double amount, final String currency) {
def url = “https://test.ctpe.net/frontend/GenerateToken”.toURL()
def connection = url.openConnection()

connection.setRequestMethod(“POST”)
connection.doOutput = true

String parameters = “SECURITY.SENDER=ff80808142b2c03c0142b7a7339603e0″ +
“&TRANSACTION.CHANNEL=ff80808142b2c03c0142b7a7339803e5″ +
“&TRANSACTION.MODE=INTEGRATOR_TEST” +
“&USER.LOGIN=ff80808142b2c03c0142b7a7339803e4″ +
“&USER.PWD=demo” +
“&PAYMENT.TYPE=DB” +
“&PRESENTATION.AMOUNT=${amount}” +
“&PRESENTATION.CURRENCY=${currency}”

connection.outputStream << parameters

def json = new JsonSlurper().parseText(connection.inputStream.text)

json.transaction.token
}

}

URL url = new URL("https://test.ctpe.net/frontend/GenerateToken");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

conn.setRequestMethod(“POST”);
conn.setDoInput(true);
conn.setDoOutput(true);

String parameters = “SECURITY.SENDER=ff80808142b2c03c0142b7a7339603e0″
+ “&TRANSACTION.CHANNEL=ff80808142b2c03c0142b7a7339803e5″
+ “&TRANSACTION.MODE=INTEGRATOR_TEST”
+ “&USER.LOGIN=ff80808142b2c03c0142b7a7339803e4″
+ “&USER.PWD=demo”
+ “&PAYMENT.TYPE=DB”
+ “&PRESENTATION.AMOUNT=50.99″
+ “&PRESENTATION.CURRENCY=EUR”;

IOUtils.write(parameters, conn.getOutputStream());

conn.connect();

String content = IOUtils.toString(conn.getInputStream());
System.out.println(content);

var http = require('https');
var querystring = require('querystring');

var postParameters = querystring.stringify( {
‘SECURITY.SENDER’ : ‘ff80808142b2c03c0142b7a7339603e0′
,’TRANSACTION.CHANNEL’ : ‘ff80808142b2c03c0142b7a7339803e5′
,’TRANSACTION.MODE’ : ‘INTEGRATOR_TEST’
,’USER.LOGIN’ : ‘ff80808142b2c03c0142b7a7339803e4′
,’USER.PWD’ : ‘demo’
,’PAYMENT.TYPE’ : ‘DB’
,’PRESENTATION.AMOUNT’ : ‘10.99’
,’PRESENTATION.CURRENCY’ : ‘EUR’
} );

var options = {
port: 443,
host: ‘test.ctpe.net’,
path: ‘/frontend/GenerateToken’,
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/x-www-form-urlencoded’,
‘Content-Length’: postParameters.length
}
};

var postRequest = http.request(options, function(res) {
console.log(‘STATUS: ‘ + res.statusCode);
res.setEncoding(‘utf8′);
res.on(‘data’, function (chunk) {
console.log(‘BODY: ‘ + chunk);
});
});

postRequest.write(postParameters);
postRequest.end();

$url = "https://test.ctpe.net/frontend/GenerateToken";
$data = "SECURITY.SENDER=ff80808142b2c03c0142b7a7339603e0" .
"&TRANSACTION.CHANNEL=ff80808142b2c03c0142b7a7339803e5" .
"&TRANSACTION.MODE=INTEGRATOR_TEST" .
"&USER.LOGIN=ff80808142b2c03c0142b7a7339803e4" .
"&USER.PWD=demo" .
"&PAYMENT.TYPE=DB" .
"&PRESENTATION.AMOUNT=50.99" .
"&PRESENTATION.CURRENCY=EUR";
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}

print $response

import urllib
import urllib2

data = {
“SECURITY.SENDER”: “ff80808142b2c03c0142b7a7339603e0″,
“TRANSACTION.CHANNEL”: “ff80808142b2c03c0142b7a7339803e5″,
“TRANSACTION.MODE”: “INTEGRATOR_TEST”,
“USER.LOGIN”: “ff80808142b2c03c0142b7a7339803e4″,
“USER.PWD”: “demo”,
“PAYMENT.TYPE”: “DB”,
“PRESENTATION.AMOUNT”: “50.99”,
“PRESENTATION.CURRENCY”: “EUR”
}
resp = urllib2.urlopen(‘https://test.ctpe.net/frontend/GenerateToken’, urllib.urlencode(data) )
print resp.read()

require 'net/http'
require 'net/https'
require 'uri'

uri = URI(‘https://test.ctpe.net/frontend/GenerateToken’)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri.path)
req.set_form_data({
‘SECURITY.SENDER’ => ‘ff80808142b2c03c0142b7a7339603e0′,
‘TRANSACTION.CHANNEL’ => ‘ff80808142b2c03c0142b7a7339803e5′,
‘TRANSACTION.MODE’ => ‘INTEGRATOR_TEST’,
‘USER.LOGIN’ => ‘ff80808142b2c03c0142b7a7339803e4′,
‘USER.PWD’ => ‘demo’,
‘PAYMENT.TYPE’ => ‘DB’,
‘PRESENTATION.AMOUNT’ => ‘50.99’,
‘PRESENTATION.CURRENCY’ => ‘EUR’
})
res = http.request(req)
puts res.body

object TokenGenerator {

val url = “https://test.ctpe.net/frontend/GenerateToken”

val parameters = (“SECURITY.SENDER=ff80808142b2c03c0142b7a7339603e0″
+ “&TRANSACTION.CHANNEL=ff80808142b2c03c0142b7a7339803e5″
+ “&TRANSACTION.MODE=INTEGRATOR_TEST”
+ “&USER.LOGIN=ff80808142b2c03c0142b7a7339803e4″
+ “&USER.PWD=demo”
+ “&PAYMENT.TYPE=DB”
+ “&PRESENTATION.AMOUNT=50.99″
+ “&PRESENTATION.CURRENCY=EUR”)

def generateToken : String = {
val conn = new URL(url).openConnection()

conn match {
case secureConn: HttpsURLConnection => secureConn.setRequestMethod(“POST”)
case _ => throw new ClassCastException
}

conn.setDoInput(true)
conn.setDoOutput(true)

IOUtils.write(parameters, conn.getOutputStream())

conn.connect()

val jsonString = IOUtils.toString(conn.getInputStream())
val json = Json.parse(jsonString)
val token = (json “transaction” “token”).as[String]
return token
}

}

Imports System.Web
Imports System.IO
Imports System.Net
Imports System.Text
Imports System

Module MainModule

Sub Main()

Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
Dim address As Uri

Dim data As StringBuilder
Dim byteData() As Byte
Dim postStream As Stream = Nothing

Create the web request
request = DirectCast(WebRequest.Create(New Uri(“https://test.ctpe.net/frontend/GenerateToken”)), HttpWebRequest)

Set type to POST
request.Method = “POST”
request.ContentType = “application/x-www-form-urlencoded”

data = New StringBuilder()

data.Append(“SECURITY.SENDER=” + HttpUtility.UrlEncode(“ff80808142b2c03c0142b7a7339603e0″))
data.Append(“TRANSACTION.CHANNEL=” + HttpUtility.UrlEncode(“ff80808142b2c03c0142b7a7339803e5″))
data.Append(“TRANSACTION.MODE=” + HttpUtility.UrlEncode(“INTEGRATOR_TEST”))
data.Append(“USER.LOGIN=” + HttpUtility.UrlEncode(“ff80808142b2c03c0142b7a7339803e4″))
data.Append(“USER.PWD=” + HttpUtility.UrlEncode(“demo”))
data.Append(“PAYMENT.TYPE=” + HttpUtility.UrlEncode(“DB”))
data.Append(“PRESENTATION.AMOUNT=” + HttpUtility.UrlEncode(“50.99″))
data.Append(“PRESENTATION.CURRENCY=” + HttpUtility.UrlEncode(“EUR”))

Create a byte array of the data we want to send
byteData = UTF8Encoding.UTF8.GetBytes(data.ToString())

Set the content length in the request headers
request.ContentLength = byteData.Length

Write data
Try
postStream = request.GetRequestStream()
postStream.Write(byteData, 0, byteData.Length)
Finally
If Not postStream Is Nothing Then postStream.Close()
End Try

Try
‘ Get response
response = DirectCast(request.GetResponse(), HttpWebResponse)

Get the response stream into a reader
reader = New StreamReader(response.GetResponseStream())

Console application output
Console.WriteLine(reader.ReadToEnd())
Console.Write(“Press Enter to close the program”)
Console.Read()

Finally
If Not response Is Nothing Then response.Close()
End Try
End Sub

End Module

02 Create Payment Form

Once the shopper enters your checkout page all that is required is for you to integrate two lines of code into your HTML page.

  • Load Javascript library with the version, language, and style parameters. Note that you can also add a compressed=false parameter on either system to view human readable form of the javascript and the css.
  • Place the following form in the area where the shopper is required to choose between brands
    MASTER VISA AMEX CHINAUNIONPAY
  • For security reasons, it is important to host your live payment form on an HTTPS page. This will assure buyers of your identity and prevent some browsers from displaying errors.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<script
src=”https://test.ctpe.net/frontend/widget/v3/widget.js?language=en&style=card” >
</script>
</head>
<body>
<form action=”{url for redirecting the shopper after the payment}” id=”{token}”>
MASTER VISA AMEX CHINAUNIONPAY
</form>
</body>
</html>

WHAT DOES “URL FOR REDIRECTING THE SHOPPER AFTER THE PAYMENT” MEAN?

After the payment is made, the shopper will be redirected to the specified URL. The content of the URL contains either a script which asks for the status of the payment in order to redirect the shopper again to an error or success page (see Step 3), or it simply contains an HTML “Thank you for paying” message. The status of the payment can be checked manually, just like any other transaction – by using the regular transaction search feature.

You don’t have a redirect URL yet? No problem, for testing purposes you can use any URL you wish (e.g., http://www.google.com)

03 See Transaction Status

After the payment is made, the shopper will be redirected to the specified URL with the token added to the URL (&token={token}). The content of the URL contains either a script which asks for the status of the payment in order to redirect the shopper again to an error or success page, or it simply contains an HTML “Thank you for paying” message. The status of the payment can be checked manually – just like any other transaction – by using the regular transaction search feature.

The following snipped code shows how to request the status after the payment is finished. Simply copy the script into your “URL for redirecting the shopper after the payment” file and you will receive the transaction status.

string token = Request.QueryString["token"];

string url = “https://test.ctpe.net/frontend/GetStatus;jsessionid=” + token;

WebClient webClient = new WebClient();
string json = webClient.DownloadString(url);

JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, dynamic> result = serializer.Deserialize<Dictionary<string, dynamic>>(json);

if (result.ContainsKey(“transaction”) &&
“ACK”.Equals(result[“transaction”][“processing”][“result”], StringComparison.InvariantCultureIgnoreCase))
{
Response.Redirect(“http://www.myshop.html?status=success”);
}
else
{
Response.Redirect(“http://www.myshop.html?status=error”);
}

string token = Request.QueryString["token"];

string url = “https://test.ctpe.net/frontend/GetStatus;jsessionid=” + token;

WebClient webClient = new WebClient();
string json = webClient.DownloadString(url);

JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, dynamic> result = serializer.Deserialize<Dictionary<string, dynamic>>(json);

if (result.ContainsKey(“transaction”) &&
“ACK”.Equals(result[“transaction”][“processing”][“result”], StringComparison.InvariantCultureIgnoreCase))
{
Response.Redirect(“http://www.myshop.html?status=success”);
}
else
{
Response.Redirect(“http://www.myshop.html?status=error”);
}

string token = Request.QueryString["token"];

string url = “https://test.ctpe.net/frontend/GetStatus;jsessionid=” + token;

WebClient webClient = new WebClient();
string json = webClient.DownloadString(url);

JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, dynamic> result = serializer.Deserialize<Dictionary<string, dynamic>>(json);

if (result.ContainsKey(“transaction”) &&
“ACK”.Equals(result[“transaction”][“processing”][“result”], StringComparison.InvariantCultureIgnoreCase))
{
Response.Redirect(“http://www.myshop.html?status=success”);
}
else
{
Response.Redirect(“http://www.myshop.html?status=error”);
}

string token = Request.QueryString["token"];

string url = “https://test.ctpe.net/frontend/GetStatus;jsessionid=” + token;

WebClient webClient = new WebClient();
string json = webClient.DownloadString(url);

JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, dynamic> result = serializer.Deserialize<Dictionary<string, dynamic>>(json);

if (result.ContainsKey(“transaction”) &&
“ACK”.Equals(result[“transaction”][“processing”][“result”], StringComparison.InvariantCultureIgnoreCase))
{
Response.Redirect(“http://www.myshop.html?status=success”);
}
else
{
Response.Redirect(“http://www.myshop.html?status=error”);
}

string token = Request.QueryString["token"];

string url = “https://test.ctpe.net/frontend/GetStatus;jsessionid=” + token;

WebClient webClient = new WebClient();
string json = webClient.DownloadString(url);

JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, dynamic> result = serializer.Deserialize<Dictionary<string, dynamic>>(json);

if (result.ContainsKey(“transaction”) &&
“ACK”.Equals(result[“transaction”][“processing”][“result”], StringComparison.InvariantCultureIgnoreCase))
{
Response.Redirect(“http://www.myshop.html?status=success”);
}
else
{
Response.Redirect(“http://www.myshop.html?status=error”);
}

string token = Request.QueryString["token"];

string url = “https://test.ctpe.net/frontend/GetStatus;jsessionid=” + token;

WebClient webClient = new WebClient();
string json = webClient.DownloadString(url);

JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, dynamic> result = serializer.Deserialize<Dictionary<string, dynamic>>(json);

if (result.ContainsKey(“transaction”) &&
“ACK”.Equals(result[“transaction”][“processing”][“result”], StringComparison.InvariantCultureIgnoreCase))
{
Response.Redirect(“http://www.myshop.html?status=success”);
}
else
{
Response.Redirect(“http://www.myshop.html?status=error”);
}

string token = Request.QueryString["token"];

string url = “https://test.ctpe.net/frontend/GetStatus;jsessionid=” + token;

WebClient webClient = new WebClient();
string json = webClient.DownloadString(url);

JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, dynamic> result = serializer.Deserialize<Dictionary<string, dynamic>>(json);

if (result.ContainsKey(“transaction”) &&
“ACK”.Equals(result[“transaction”][“processing”][“result”], StringComparison.InvariantCultureIgnoreCase))
{
Response.Redirect(“http://www.myshop.html?status=success”);
}
else
{
Response.Redirect(“http://www.myshop.html?status=error”);
}

string token = Request.QueryString["token"];

string url = “https://test.ctpe.net/frontend/GetStatus;jsessionid=” + token;

WebClient webClient = new WebClient();
string json = webClient.DownloadString(url);

JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, dynamic> result = serializer.Deserialize<Dictionary<string, dynamic>>(json);

if (result.ContainsKey(“transaction”) &&
“ACK”.Equals(result[“transaction”][“processing”][“result”], StringComparison.InvariantCultureIgnoreCase))
{
Response.Redirect(“http://www.myshop.html?status=success”);
}
else
{
Response.Redirect(“http://www.myshop.html?status=error”);
}

string token = Request.QueryString["token"];

string url = “https://test.ctpe.net/frontend/GetStatus;jsessionid=” + token;

WebClient webClient = new WebClient();
string json = webClient.DownloadString(url);

JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, dynamic> result = serializer.Deserialize<Dictionary<string, dynamic>>(json);

if (result.ContainsKey(“transaction”) &&
“ACK”.Equals(result[“transaction”][“processing”][“result”], StringComparison.InvariantCultureIgnoreCase))
{
Response.Redirect(“http://www.myshop.html?status=success”);
}
else
{
Response.Redirect(“http://www.myshop.html?status=error”);
}

string token = Request.QueryString["token"];

string url = “https://test.ctpe.net/frontend/GetStatus;jsessionid=” + token;

WebClient webClient = new WebClient();
string json = webClient.DownloadString(url);

JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, dynamic> result = serializer.Deserialize<Dictionary<string, dynamic>>(json);

if (result.ContainsKey(“transaction”) &&
“ACK”.Equals(result[“transaction”][“processing”][“result”], StringComparison.InvariantCultureIgnoreCase))
{
Response.Redirect(“http://www.myshop.html?status=success”);
}
else
{
Response.Redirect(“http://www.myshop.html?status=error”);
}

If you would like to customize the style of the widget view please contact us.