TCardService provides basic card reading and pinpad functionality via providing AIDL interface. It is a BoundedService, which is only active when another application is bounded.
Integration
Download the zip file below and extract it.
Place the cardservicebinding-release.aar library file into your project's "libs" folder and add it as dependency inside your app level build.gradle file like below and build your project in order to create build classes of library.
public abstract class BaseActivity extends AppCompatActivity implements CardServiceListener {
protected CardServiceBinding cardServiceBinding;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
cardServiceBinding = new CardServiceBinding(this, this);
}
@Override
protected void onDestroy() {
//Make sure to call unBind() method when activity is finishing
cardServiceBinding.unBind();
super.onDestroy();
}
/**
* Callback for Card Service connected method. You will not need to check whether card service is connected or not in most cases.
* When you make an asynchronous method call on CardServiceBinding,it will be executed automatically as soon as CardService is connected.
*/
@Override
public void onCardServiceConnected() {
}
/**
* Callback for TCardService getCard method.
* As getCard is an asynchronous service operation, you will get the response after operation is done in this callback.
* @apiNote Override this method in your activity in order to get card data after calling #getData() method of Card Service.
* @param cardData: Card data json string
*/
public void onCardDataReceived(String cardData) { }
/**
* Callback for TCardService getOnlinePin method.
* As getOnlinePin is an asynchronous real time operation, you will get the response after operation is done in this callback.
* @apiNote Override this method in your activity in order to get pin data after calling #getOnlinePin() method of Card Service.
* @param pin: Pin string
*/
public void onPinReceived(String pin) {}
/**
* Callback for TCardService iccTakeOut method.
* This callback will be triggered when user takes out card from pos device after you inform the user with takeOutICC() method.
* @apiNote Override this method in your activity in order to get icc take out callback after calling #iccTakeOut() method of Card Service.
*/
public void onICCTakeOut() {}
}
CardServiceBinding api methods
// amount:
// please provide it as 100 x Float amount.
// example -> For 1 = provide 100, for 0.05 = provide 5
//
// timeout:
// duration as seconds that will present card view and
// detects any card types
//
// config:
// reserved for future use
void getCard(int amount, int timeout, String config);
// action:
// Online approval 1
// Online decline 2
// Unable go online 3
// Issuer referral approval 4
// Issuer referral decline 5
// Unable go online with specific ARC 6
//
// authRespCode:
// Response Code from the host. 2 bytes.
//
// issuerAuthData:
// Issuer Authentication Data from the issuer host
//
// issuerAuthDataLen:
// Length of the Issuer Authentication Data
//
// issuerScript:
// Issuer Script from the issuer host
//
// issuerScriptLen:
// Length of the Issuer Script
int completeEmvTxn(byte action, in byte[] authRespCode, in byte[] issuerAuthData, int issuerAuthDataLen, in byte[] issuerScript, int issuerScriptLen);
// config:
// emv settings xml data
int setEMVConfiguration(String config);
// amount:
// please provide it as 100 x Float amount.
// example -> For 1 = provide 100, for 0.05 = provide 5
//
// pan:
// PAN of the Card
//
// keySet:
// The keySet that assigned for Bank
//
// keyIndex:
// The index of the key in keySet
//
// minLen:
// min PIN entry len
//
// maxLen:
// max PIN entry len
//
// timeout:
// PIN entry timeout as Sec
void getOnlinePIN(int amount, String pan, int keySet, int keyIndex, int minLen, int maxLen, int timeout);
//ret: device SN as String
String getDeviceSN();
// timeout:
// duration as seconds that will present take out Chip Card
void takeOutICC(int timeout);
//ret: EMV completion datas as JSON data
String getEMVCompletionData();
//info will be added
void showQR(String header, String total, String QRData);
void showSuccess(boolean isSuccess, String header);
void showBlackScreen();
// config:
// emv settings xml data
int setEMVCLConfiguration(String config);
// config:
// config pin entry
public void getOnlinePINEx(String config)
}
getCard(...) API Details
It is used to get card (ICC, MSR, CL) according to config of the API.
zeroAmount: Show the amount data on screen however send to EMV kernel amount as "0".
keyIn: Enable keyIn on getCard screen.
askCVV: Enable CVV entry on keyIn screen.
showAmount: Show the amount data on screen.
extraAmount: This amount will be added to the main amount and displayed as the total amount on the screen. It will be excluded from the EMV processing. Please provide it as 100 x Float amount.
showCardScreen: Show the Card Screen. If pre-reading has been made by the platform please set is as "0"
partialEMV: Deprecated, please use emvProcessType.
emvProcessType: It is used if txn is ICC. The types of the EMV process are below.
public enum emvProcessType {
PARTIAL_EMV(0), //After reading card data with requested Tags, requesting AAC at the 1st Generate AC to complete transaction and return requested Tag data
READ_CARD(1), //After app selection, read requested card data and return
CONTINUE_EMV(2), //Continue and complete full EMV Txn from Read Card Data process and returns requested Tag data.
FULL_EMV(3); //Actions based EMV Specification, such as Initiate App. Processing, Read App. Data, Off. Auth., Processing restrictions, Cardholder Verification, Term. Risk Man., First Gen AC and returns requested Tag data.
}
reqEMVData: Tags that requested for ICC Read Type. ICCData fields will be filled also according to requestedEMVData.
If it is not set by user, for READ_CARD it is set to "575A5F245F204F84", for other Txn Types it is set to "575A5F245F204F9B849F125F2A5F3482959A9C9F029F039F099F109F1A9F1E9F269F279F339F349F359F369F379F418E9F069F539F0D9F0E9F0F" by default.
Note 1:Please consider, it will take more time if you request more tags. Please make optimiziation on this tag to speed up the EMV Txn.
cardReadTypes:
public enum CardReadCombination {
ICC,
CL,
MSR,
ICC_CL,
ICC_MSR,
CL_MSR,
ALL
}
currencySymbol: The ISO 4217 currency numeric code to show currency symbol on cardService screens. Ex:949 for TRY, 840 for USD.
forceICCTermCurrencyCode: For ICC transactions, temporarily set currencySymbol to 5F2A.
getOnlinePIN: Enable Online PIN during the getCard operation only for ICC transactions..
kmsVersion :
1 : Deprecated: Compatible with 400TR and 1000TR Castles-based systems.
2 : new KMS library, compatible with all devices.
keySet : allocated keySet value of the bank. Only set for kmsVersion 1. Not needed for kmsVersion 2.
keyIndex : keyIndex value of the PIN key.
minLen: min length of the requested PIN.
maxLen: max length of the requested PIN.
isDukptKey: it is set to 1 if the PIN key is Dukpt.
extraAmount: This amount will be added only to the main Amount and will be showed as Total Amount on the screen. It will be excluded from EMV process.
resultCode Values
public enum CardServiceResult {
SUCCESS(0),
USER_CANCELLED(1),
ERROR(2),
}
Indicate which CVM is required
0x00 – None.
0x01 – Signature.
0x02 – Online PIN.
0x03 – CVM Fail.
0x04 – NO CVM.
0x05 – Confirmation Code Verified.
MSR Card Type Return
{
"resultCode":0,
"mCardReadType":2,
"mCardNumber":"5168881167113299",
"mTrack2Data":"1201530011?", //other than pan and exp date
"mExpireDate":"2711",
"mTranAmount1":123,
"mTrack1CustomerName":"REMZI SEPIK",
"Track1Data":"%B5168881167113299^SEPIK\/REMZI ^27111201100000000153000000?",
"Track2Data":";5168881167113299=27111201530011?"
}