Mpos Development Guidelines

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 10

Mpos Development guidelines

Directory
Initialization TTLHandler................................................................................................................. 3
Activity Implement the listen interface........................................................................................... 3
Read Card....................................................................................................................................... 4
Read M1 card data.................................................................................................................. 4
Read Quick Pass and Visa pay Wave card data........................................................................5
Mpos Settings and configuration information................................................................................. 6
Mpos Print test............................................................................................................................... 7
Attentions....................................................................................................................................... 9
Initialization TTLHandler

TTLHandler handler;
Settings settings;
//com.imagpay.ttl.TTLHandler.TTLHandler(Context context)
handler = new TTLHandler(getApplicationContext());
// void com.imagpay.ttl.TTLHandler.setParameters(String devName, int baudrate)
handler.setParameters("/dev/ttyHSL1", 115200);
//com.imagpay.Settings.Settings(SwipeHandler handler)
settings = new Settings(handler);
handler.setShowLog(true);//Set the display print log
handler.addSwipeListener(this);//Add the monitor

Activity Implement the listen interface

implements SwipeListener

SwipeListener:
@Override
public void onCardDetect(CardDetected card) {
}
public void onConnected(SwipeEvent arg0) {
Log.i("xtztt","Connect ok...");
String ver = settings.readVersion();
ver = hexToSting(ver);
Log.i("xtztt","The version number:" + ver);
}
private String hexToSting(String ver) {
if (ver == null)
return "";
String[] tmps = ver.trim().replaceAll("..", "$0 ").split(" ");
StringBuffer sbf = new StringBuffer();
for (String str : tmps) {
sbf.append((char) Integer.parseInt(str, 16));
}
ver = sbf.toString();
return ver;
}
@Override
public void onDisconnected(SwipeEvent arg0) {
}
@Override
public void onParseData(SwipeEvent arg0) {
}
@Override
public void onPermission(SwipeEvent event) {
}
@Override
public void onReadData(SwipeEvent arg0) {
}
@Override
public void onStarted(SwipeEvent arg0) {
}
@Override
public void onStopped(SwipeEvent arg0) {
}
@Override
public void onEmvStatus(EmvStatus arg0) {
}

Read Card

Non-contact card read operation

Read M1 card data

(Using the button in the Demo trigger)


private void m1Test() {
Log.i("xtztt","Start to read M1 card......");
new Thread(new Runnable() {
@Override
public void run() {
handler.setShowLog(true);
Log.i("xtztt",settings.m1Request());
Log.i("xtztt",settings.m1Auth(Settings.M1_KEY_A, "00",
"FFFFFFFFFFFF") + "");
//The default password is "FFFFFFFFFFFF"
Log.i("xtztt",settings.m1ReadBlock("00"));//0 Block
Log.i("xtztt",settings.m1ReadBlock("01"));//1 Block
Log.i("xtztt",settings.m1ReadBlock("02"));//2 Block
Log.i("xtztt",settings.m1ReadBlock("03"));//3 Block
}
}).start();
}

Read Quick Pass and Visa pay Wave card data

(Using the button in the Demo trigger)


private void nfctest() {
EmvCoreJNI dds=new EmvCoreJNI();
final String path=dds.exists();
//Callback method
dds.addTransMethod(new TransAPDU() {
@Override
public byte[] onTransmitApdu(byte[] arg0) {
String dataWithAPDU =
settings.getDataWithAPDUForStr(Settings.SLOT_NFC,
StringUtils.convertBytesToHex(arg0));
if (dataWithAPDU == null) {
return null;
}
byte[] arg1 = new byte[dataWithAPDU.substring(4).length() /
2];

System.arraycopy(Base16EnDecoder.Decode(dataWithAPDU.substring(4)), 0,
arg1, 0, dataWithAPDU.substring(4).length() / 2);
return arg1;
}
@Override
public String onGetDataPath() {
return path;
}
});
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
//Search card
String reset = settings.reset(Settings.SLOT_NFC);
if (reset != null) {
sendMessage("card near field");
}else{
sendMessage("no card near field");
return;
}
//Set the amount .The unit of the amount is a cent, 100 means 1
yuan
dds.EmvQTransParamInit(ISOUtil.zeropad("100",12));
byte[] bTransResult = new byte[1];
byte[] bCVMType = new byte[1];
byte[] bBalance = new byte[6];
int resp=dds.EmvQTrans(bBalance,bTransResult,bCVMType);
if(resp==0){
Toast.makeText(mctx, "quick pass read successful...........",
Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(mctx, "quick pass read failed.....<"+resp+">",
Toast.LENGTH_SHORT).show();
return;
}
if(bTransResult[0] == (byte)EmvCoreJNI.ONLINE_M){
}
else if(bTransResult[0] == (byte)EmvCoreJNI.APPROVE_M){
}
else if(bTransResult[0] == (byte)EmvCoreJNI.DECLINE_M){
}

}
Mpos Settings and configuration information

//Read Mpos SN number


Log.i("xtztt","SN:"+settings.setReadSN());
SN is null return:"ffffffffffffffffffffffffffffffff"
SN is not null return the SN number
//Write SN number, sn The maximum length of the string 32
settings.mposWriteSN(sn);
//Read Mpos Firmware version number
settings.readVersion()The result is a hexadecimal ASCII version number
When Activity destroy close the MposHandler
_handler.close();

Mpos Print test

Initialization MposHandler
MposHandler _handler;
Settings _setting;
_handler = new MposHandler(this);
_setting = new Settings(_handler);
_handler.setParameters("/dev/ttyS2", 115200);
_handler.addSwipeListener(this);

Implement SwipeListener

Power on (_setting.mPosPowerOn())
Then Connect the serial port
try {
if (!_handler.isConnected()) {
sendMessage("Connect Res:" + _handler.connect());
} else {
_handler.close();
sendMessage("ReConnect Res:" + _handler.connect());
}
} catch (Exception e) {
sendMessage(e.getMessage());
}
Print
new Thread(new Runnable() {
public void run() {
settings.mPosPrintAlign(Settings.MPOS_PRINT_ALIGN_CENTER);

settings.mPosPrintTextSize(Settings.MPOS_PRINT_TEXT_DOUBLE_HEIGHT);
settings.mPosPrnStr("POS Signed Order");
settings.mPosPrintLn();

settings.mPosPrintTextSize(Settings.MPOS_PRINT_TEXT_NORMAL);
settings.mPosPrintAlign(Settings.MPOS_PRINT_ALIGN_LEFT);
settings.mPosPrnStr("The cardholder stub \nPlease
properly keep");
settings.mPosPrnStr("--------------------------");
settings.mPosPrnStr("Merchant Name:ABCDEFG");
settings.mPosPrnStr("Merchant No.:846584000103052");
settings.mPosPrnStr("Terminal no.:12345678");
settings.mPosPrnStr("categories: visa card");
settings.mPosPrnStr("Period of Validity:2016/07");
settings.mPosPrnStr("Batch no.:000101");
settings.mPosPrnStr("Card Number:");
settings.mPosPrnStr("622202400******0269");
settings.mPosPrnStr("Trade Type:consumption");
settings.mPosPrnStr("Serial No.:000024
\nAuthenticode:096706");
settings.mPosPrnStr("Date/Time:2016/09/01 11:27:12");
settings.mPosPrnStr("Ref.No.:123456789012345");
settings.mPosPrnStr("Amount:$ 100.00");
settings.mPosPrnStr("--------------------------");

settings.mPosPrintAlign(Settings.MPOS_PRINT_ALIGN_CENTER);
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
InputStream is =
getResources().openRawResource(R.drawable.ic_launcher);
Bitmap bitmap = BitmapFactory.decodeStream(is, null,
opt);
settings.mPosPrnImg(bitmap);
settings.mPosPrnStr("\n\n\n");
if (!bitmap.isRecycled()) {
bitmap.recycle();// Recycle image assets
}
bitmap = null;
}
}).start();

Enter the print mode


Settings.mPosEnterPrint()

Set the font:The default font: Settings.MPOS_PRINT_FONT_DEFAULT,


New font: Settings.MPOS_PRINT_FONT_NEW
Settings.mPosPrintFontSwitch(String choice)

Sets the print alignment:Left


justified
:Settings.MPOS_PRINT_ALIGN_LEFT,Centered
:Settings.MPOS_PRINT_ALIGN_CENTER,Right
justified:Settings.MPOS_PRINT_ALIGN_RIGHT
Settings.mPosPrintAlign(String align)

Print and wrap


Settings.mPosPrintLn()

Sets the print font size:


Normal font printing:Settings.MPOS_PRINT_TEXT_NORMAL,
The font prints at twice the
height:Settings.MPOS_PRINT_TEXT_DOUBLE_HEIGHT,
The font prints at twice the width
:Settings.MPOS_PRINT_TEXT_DOUBLE_WIDTH,
The font prints at Double width Double height
Print:Settings.MPOS_PRINT_TEXT_DOUBLE_SIZE
Settings.mPosPrintTextSize(String size)

Print the string


Settings.mPosPrnStr(String str)

Print a picture
Settings.mPosPrnImg(Bitmap bit)
Attentions

Print and card reader module communicates with Android via serial port, this need for serial port
permissions. Serial port permissions are system-level, you need to refer to the following
documents.
Android Studio Automatic generation of APK with system signature.docx
apk_signature.doc

You might also like