1 25 package org.ofbiz.pos.jpos.service; 26 27 import jpos.JposException; 28 import jpos.MSRConst; 29 import jpos.JposConst; 30 import jpos.events.DataEvent; 31 import jpos.events.ErrorEvent; 32 33 import org.ofbiz.pos.adaptor.KeyboardAdaptor; 34 import org.ofbiz.pos.adaptor.KeyboardReceiver; 35 36 42 public class MsrKybService extends BaseService implements jpos.services.MSRService17, KeyboardReceiver { 43 44 public static final String module = MsrKybService.class.getName(); 45 public static final int JPOS_MSR_ACCT_ERR = 100; 46 public static final int JPOS_MSR_EXPD_ERR = 101; 47 48 protected String title = new String (); 49 protected String firstname = new String (); 50 protected String middle = new String (); 51 protected String surname = new String (); 52 protected String suffix = new String (); 53 54 protected String [] accountNumber = new String [2]; 55 protected String [] expireDate = new String [2]; 56 protected String serviceCode = new String (); 57 58 protected byte[] track1DiscretionaryData = new byte[0]; 59 protected byte[] track2DiscretionaryData = new byte[0]; 60 protected byte[] track1Data = new byte[0]; 61 protected byte[] track2Data = new byte[0]; 62 protected byte[] track3Data = new byte[0]; 63 protected int[] sentinels = new int[0]; 64 protected int[] lrc = new int[0]; 65 66 protected boolean parseDecodeData = true; 67 protected boolean decodeData = true; 68 protected boolean autoDisable = false; 69 protected boolean sendSentinels = true; 70 71 protected int tracksToRead = MSRConst.MSR_TR_1_2_3; 72 protected int errorType = MSRConst.MSR_ERT_CARD; 73 74 public MsrKybService() { 75 KeyboardAdaptor.getInstance(this, KeyboardAdaptor.MSR_DATA); 76 } 77 78 public boolean getCapISO() throws JposException { 80 return true; 82 } 83 84 public boolean getCapJISOne() throws JposException { 85 return false; 87 } 88 89 public boolean getCapJISTwo() throws JposException { 90 return false; 92 } 93 94 public String getAccountNumber() throws JposException { 95 return this.accountNumber[1]; 96 } 97 98 public boolean getAutoDisable() throws JposException { 99 return this.autoDisable; 100 } 101 102 public void setAutoDisable(boolean b) throws JposException { 103 this.autoDisable = b; 104 } 105 106 public boolean getDecodeData() throws JposException { 107 return this.decodeData; 108 } 109 110 public void setDecodeData(boolean b) throws JposException { 111 this.decodeData = b; 112 if (!b) { 113 this.parseDecodeData = false; 114 } 115 } 116 117 public int getErrorReportingType() throws JposException { 118 return this.errorType; 119 } 120 121 public void setErrorReportingType(int i) throws JposException { 122 this.errorType = i; 123 } 124 125 public String getExpirationDate() throws JposException { 126 return this.expireDate[1]; 127 } 128 129 public String getFirstName() throws JposException { 130 return this.firstname; 131 } 132 133 public String getMiddleInitial() throws JposException { 134 return this.middle; 135 } 136 137 public boolean getParseDecodeData() throws JposException { 138 return this.parseDecodeData; 139 } 140 141 public void setParseDecodeData(boolean b) throws JposException { 142 this.parseDecodeData = b; 143 } 144 145 public String getServiceCode() throws JposException { 146 return this.serviceCode; 147 } 148 149 public String getSuffix() throws JposException { 150 return this.suffix; 151 } 152 153 public String getSurname() throws JposException { 154 return this.surname; 155 } 156 157 public String getTitle() throws JposException { 158 return this.title; 159 } 160 161 public byte[] getTrack1Data() throws JposException { 162 return this.track1Data; 163 } 164 165 public byte[] getTrack1DiscretionaryData() throws JposException { 166 return this.track1DiscretionaryData; 167 } 168 169 public byte[] getTrack2Data() throws JposException { 170 return this.track2Data; 171 } 172 173 public byte[] getTrack2DiscretionaryData() throws JposException { 174 return this.track2DiscretionaryData; 175 } 176 177 public byte[] getTrack3Data() throws JposException { 178 return this.track3Data; 179 } 180 181 public int getTracksToRead() throws JposException { 182 return this.tracksToRead; 183 } 184 185 public void setTracksToRead(int i) throws JposException { 186 this.tracksToRead = i; 187 } 188 189 public void clearInput() throws JposException { 190 this.title = null; 191 this.firstname = new String (); 192 this.middle = new String (); 193 this.surname = new String (); 194 this.suffix = new String (); 195 this.serviceCode = new String (); 196 this.accountNumber = new String [2]; 197 this.expireDate = new String [2]; 198 this.track1Data = new byte[0]; 199 this.track2Data = new byte[0]; 200 this.track3Data = new byte[0]; 201 this.track1DiscretionaryData = new byte[0]; 202 this.track2DiscretionaryData = new byte[0]; 203 } 204 205 public int getCapPowerReporting() throws JposException { 207 return 0; } 209 210 public int getPowerNotify() throws JposException { 211 return 0; } 213 214 public void setPowerNotify(int i) throws JposException { 215 } 217 218 public int getPowerState() throws JposException { 219 return 0; } 221 222 public boolean getCapTransmitSentinels() throws JposException { 224 return true; 225 } 226 227 public byte[] getTrack4Data() throws JposException { 228 return new byte[0]; } 230 231 public boolean getTransmitSentinels() throws JposException { 232 return this.sendSentinels; 233 } 234 235 public void setTransmitSentinels(boolean b) throws JposException { 236 this.sendSentinels = b; 237 } 238 239 public synchronized void receiveData(int[] codes, char[] chars) { 241 String data = new String (chars); 242 this.parseMsrString(data); 243 244 DataEvent event = new DataEvent(this, 0); 245 this.fireEvent(event); 246 } 247 248 private void parseMsrString(String str) { 249 if (str.indexOf(";") == -1 || str.indexOf("^") == -1) { 250 ErrorEvent error = new ErrorEvent(this, JposConst.JPOS_E_FAILURE, -1, 251 JposConst.JPOS_EL_INPUT, JposConst.JPOS_ER_CLEAR); 252 this.fireEvent(error); 253 return; 254 } 255 256 try { 257 String track1 = str.substring(0, str.indexOf(";")); 259 String track2 = str.substring(str.indexOf(";"), str.length() - 1); 260 261 int firstCarrot = track1.indexOf("^", 2); 263 int nextCarrot = track1.indexOf("^", firstCarrot + 1); 264 265 String tr1BegChar = track1.substring(0, 1); 266 String formatCode = track1.substring(1, 2); 267 String tr1AcctNum = track1.substring(2, firstCarrot); 268 String cardHolder = track1.substring(firstCarrot + 1, nextCarrot); 269 String tr1ExpDate = track1.substring(nextCarrot + 1, nextCarrot + 5); 270 String tr1OptData = track1.substring(nextCarrot + 4, track1.length() - 2); 271 String tr1EndChar = track1.substring(track1.length() - 2, track1.length() - 1); 272 String tr1LrcCode = track1.substring(track1.length() - 1, track1.length()); 273 274 String tr2BegChar = track2.substring(0, 1); 276 String tr2AcctNum = track2.substring(1, track2.indexOf("=")); 277 String tr2ExpDate = track2.substring((track2.indexOf("=") + 1), track2.indexOf("=") + 5); 278 String tr2OptData = track2.substring(track2.indexOf("=") + 5, track2.length() - 2); 279 String tr2EndChar = track2.substring(track2.length() - 2, track2.length() - 1); 280 String tr2LrcCode = track2.substring(track2.length() - 1, track2.length()); 281 282 if (this.sendSentinels) { 284 track1 = track1.substring(0, track1.length() - 1); 285 track2 = track2.substring(0, track2.length() - 1); 286 } else { 287 track1 = track1.substring(1, track1.length() - 2); 288 track2 = track2.substring(0, track2.length() - 2); 289 } 290 291 this.track1Data = track1.getBytes(); 293 this.track2Data = track2.getBytes(); 294 295 if (this.parseDecodeData) { 297 this.sentinels = new int[4]; 299 this.sentinels[0] = (int) tr1BegChar.charAt(0); 300 this.sentinels[1] = (int) tr1EndChar.charAt(0); 301 this.sentinels[2] = (int) tr2BegChar.charAt(0); 302 this.sentinels[3] = (int) tr2EndChar.charAt(0); 303 304 this.lrc = new int[2]; 306 this.lrc[0] = (int) tr1LrcCode.charAt(0); 307 this.lrc[1] = (int) tr2LrcCode.charAt(0); 308 309 this.accountNumber = new String [2]; 311 this.accountNumber[0] = tr1AcctNum.trim(); 312 this.accountNumber[1] = tr2AcctNum.trim(); 313 314 this.expireDate = new String [2]; 316 this.expireDate[0] = tr1ExpDate.trim(); 317 this.expireDate[1] = tr2ExpDate.trim(); 318 319 this.track1DiscretionaryData = tr1OptData.getBytes(); 321 this.track2DiscretionaryData = tr2OptData.getBytes(); 322 this.track1Data = track1.getBytes(); 323 this.track2Data = track2.getBytes(); 324 325 this.serviceCode = formatCode.trim(); 327 this.surname = (cardHolder.substring(0, cardHolder.indexOf("/"))).trim(); 328 this.firstname = (cardHolder.substring((cardHolder.indexOf("/") + 1))).trim(); 329 } 331 } catch (Exception e) { 332 ErrorEvent error = new ErrorEvent(this, JposConst.JPOS_E_FAILURE, -1, 333 JposConst.JPOS_EL_INPUT, JposConst.JPOS_ER_CLEAR); 334 this.fireEvent(error); 335 return; 336 } 337 } 338 } 339 | Popular Tags |