EMV
Sample code uses ES6 language features such as arrow functions and promises. For compatibility with IE11, code written with these features must be either transpiled using tools like Babel or refactored accordingly using callbacks.

Introduction

This container supports functionality for EMV "chip and PIN" bank cards, including:
    VISA, MasterCard, Amex, CB and UK Post Office Account contact cards
    PayWave (VISA) and PayPass (MasterCard) contactless cards

Get EMV container object

Initialise a Trust1Connector:
1
T1CSdk.initialize(config).then(res => {
2
3
}, err => {
4
console.error(error)
5
});
Copied!
Get the EMV service:
1
var emv = client.emv(reader_id);
Copied!
Call a function for the EMV container:
1
function callback(err,data) {
2
if(err){console.log("Error:",JSON.stringify(err, null, ' '));}
3
else {console.log(JSON.stringify(data, null, ' '));}
4
}
5
emv.readData(callback)
Copied!

Obtain the Reader-ID

The constructor for the EMV expect as the parameter to be a valid reader-ID. A reader-ID can be obtained from the exposed core functionality, for more information see Core Services. Core services responds with available card-readers, available card in a card-reader, etc. For example: In order to get all connected card-readers, with available cards:
1
var coreService = client.core();
2
core.readersCardAvailable(callback);
Copied!
This function call returns:
We notice that a card object is available in the response in the context of a detected reader. The reader in the example above is VASCO DIGIPASS 870, has pin-pad capabilities, and there is a card detected with given ATR and some descriptions. An ATR (Answer To Reset) identifies the type of a smart-card. The reader, has a unique ID, reader_id; this reader_id must be used in order to request functionalities for the EMV card. This must be done upon instantiation of the EMV container:
1
var emv = client.emv(reader_id);
Copied!
All methods for emv will use the selected reader - identified by the reader_id.

Reading data

Applications

List the supported applications on the EMV card
1
client.emv(reader_id).readData(callback);
Copied!
An example callback:
1
function callback(err,data) {
2
if(err){
3
console.log("Error:",JSON.stringify(err, null, ' '));
4
}
5
else {
6
console.log(JSON.stringify(data, null, ' '));
7
}
8
}
Copied!
Response:
1
{
2
"data": [
3
{
4
"aid": "A0000000048002",
5
"name": "MAESTRO",
6
"priority": 1
7
},{
8
"aid": "A0000000048008",
9
"name": "MASTERCARD",
10
"priority": 1
11
}
12
],
13
"success": true
14
}
Copied!

Application data

The application data contains information of the holder of the card, the validity, the primary account number, ...
1
client.emv(reader_id).readApplicationData(callback);
Copied!
An example callback:
1
function callback(err,data) {
2
if(err){
3
console.log("Error:",JSON.stringify(err, null, ' '));
4
}
5
else {
6
console.log(JSON.stringify(data, null, ' '));
7
}
8
}
Copied!
Response:
1
{
2
"country": "BE",
3
"countryCode": "0056",
4
"effectiveDate": "190201",
5
"expirationDate": "241231",
6
"language": "nlen",
7
"name": "",
8
"pan": "670...001"
9
}
Copied!

Issuer Public Key Certificate

On some applications there is an issuer public key certificate present. The aid parameter indicates which application you want to use, this can be fetched using the applications endpoint.
1
// Application ID can be retrieved with the Applications endpoint
2
var aid = "..."
3
4
client.emv(reader_id).issuerPublicCertificate(aid, callback);
Copied!
An example callback:
1
function callback(err,data) {
2
if(err){
3
console.log("Error:",JSON.stringify(err, null, ' '));
4
}
5
else {
6
console.log(JSON.stringify(data, null, ' '));
7
}
8
}
Copied!
Response:
1
{
2
"data": {
3
"data": "base64 encoded data",
4
"exponent": "base64 encoded data",
5
"remainder": "base64 encoded data"
6
},
7
"success": true
8
}
Copied!

ICC Public Key Certificate

On some applications there is an icc public key certificate present. The aid parameter indicates which application you want to use, this can be fetched using the applications endpoint.
1
// Application ID can be retrieved with the Applications endpoint
2
var aid = "..."
3
4
client.emv(reader_id).iccPublicCertificate(aid, callback);
Copied!
An example callback:
1
function callback(err,data) {
2
if(err){
3
console.log("Error:",JSON.stringify(err, null, ' '));
4
}
5
else {
6
console.log(JSON.stringify(data, null, ' '));
7
}
8
}
Copied!
Response:
1
{
2
"certificate": "dxL8JnkxHneX36tdQCzz...HC3Wpt/qppk008q9OMDgVp0F7NJjCC2mXg3b/qD7c09WFXUwZ+XdkmIefhoZT/kme4QEoD49+ppQiqSeCaRjn6N0OetcjleWkPej8vE0QG4mLlG/edWTVbfMGbED9Kbjf4ooauNnq+iAVwgHedsDpdDWJLhV8sDSLQgZ1B3fMQuyZIaD79+X+H9fbhmJg+j7Lr638srglWM9VlthaWjRbFH2HzNEiQ9sOE20lmj6WM6zdYas9+Z4hcwZqWbeiTeIJDwDc6w==",
3
"exponent": "AQAB",
4
"remainder": ""
5
}
Copied!

Verify PIN

Verify PIN without pin-pad

When the web or native application is responsible for showing the password input, the following request is used to verify a card holder PIN:
1
var data = {
2
"pin": "...."
3
}
4
client.emv().verifyPin(data, callback);
Copied!
Response:
1
{
2
"verified": true
3
}
Copied!

Verify PIN with pin-pad

When the pin entry is done on the pin-pad, the following request is used to verify a given PIN:
1
var data = {}
2
client.emv().verifyPin(data, callback);
Copied!
Response:
1
{
2
"verified": true
3
}
Copied!

Verify PIN - retries left

After an unsuccessful PIN verification, the error code indicates the number of retries left. For example, when executing:
1
$("#buttonValidate").on('click', function () {
2
var _body={};
3
_body.pin = $("#psw").val(); //only when no pin-pad available
4
var emv = connector.emv(reader_id);
5
emv.verifyPin(_body, validationCallback);
6
});
Copied!
The following error message will be returned when PIN is wrong:
1
{
2
"code": 301,
3
"description": "Wrong pin, 2 tries remaining",
4
"success": false
5
}
Copied!
After a second wrong PIN verification:
1
{
2
"code": 301,
3
"description": "Wrong pin, 1 try remaining",
4
"success": false
5
}
Copied!
Note that, when the user has at least one retry left, entering a correct PIN resets the PIN retry status.
Code
Description
301
Warning: the user can try twice more to verify his PIN
301
Warning: the user has only 1 retry left
301
Error: the PIN is blocked

Error Handling

Error Object

The functions specified are asynchronous and always need a callback function. The callback function will reply with a data object in case of success, or with an error object in case of an error. An example callback:
1
function callback(err,data) {
2
if(err){
3
console.log("Error:",JSON.stringify(err, null, ' '));
4
}
5
else {
6
console.log(JSON.stringify(data, null, ' '));
7
}
8
}
Copied!
The error object returned:
1
{
2
success: false,
3
description: "some error description",
4
code: "some error code"
5
}
Copied!
For the error codes and description, see Status codes.
Last modified 1yr ago