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.
publicabstractclassBaseActivityextendsAppCompatActivityimplementsCardServiceListener {protectedCardServiceBinding cardServiceBinding; @OverrideprotectedvoidonCreate(@NullableBundle savedInstanceState) { super.onCreate(savedInstanceState); cardServiceBinding =newCardServiceBinding(this,this); } @OverrideprotectedvoidonDestroy() {//Make sure to call unBind() method when activity is finishingcardServiceBinding.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.
*/ @OverridepublicvoidonCardServiceConnected() { } /** * 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 */publicvoidonCardDataReceived(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 */publicvoidonPinReceived(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.
*/publicvoidonICCTakeOut() {}}
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 usevoidgetCard(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 dataintsetEMVConfiguration(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 SecvoidgetOnlinePIN(int amount,String pan,int keySet,int keyIndex,int minLen,int maxLen,int timeout);//ret: device SN as StringStringgetDeviceSN();// timeout:// duration as seconds that will present take out Chip CardvoidtakeOutICC(int timeout);//ret: EMV completion datas as JSON dataStringgetEMVCompletionData();//info will be addedvoidshowQR(String header,String total,String QRData);voidshowSuccess(boolean isSuccess,String header);voidshowBlackScreen();// config:// emv settings xml dataintsetEMVCLConfiguration(String config);// config:// config pin entrypublicvoidgetOnlinePINEx(String config)}
getCard(...) API Details
It is used to get card (ICC, MSR, CL) according to config of the API.
emvProcessType: It is used if txn is ICC. The types of the EMV process are below.
publicenumemvProcessType { 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.
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?"}