private void putCard (Context ctx, ISOMsg m, boolean mandatory, Set<String> validFields, Result rc) { boolean hasCard = m.hasAny("2", "14", "35", "45"); if (!mandatory && !hasCard) return; // nothing to do, card is optional try { Card.Builder cb = Card.builder().isomsg(m); if (ignoreCardValidation) cb.validator(null); Card card = cb.build(); ctx.put (ContextConstants.CARD.toString(), card); if (card.hasTrack1()) validFields.add("45"); if (card.hasTrack2()) validFields.add("35"); if (card.getPan() != null && m.hasField(2)) validFields.add("2"); if (card.getExp() != null && m.hasField(14)) validFields.add("14"); } catch (InvalidCardException e) { validFields.addAll(Arrays.asList("2", "14", "35", "45")); if (hasCard) { rc.fail(CMF.INVALID_CARD_NUMBER, Caller.info(), e.getMessage()); } else if (mandatory) { rc.fail(CMF.MISSING_FIELD, Caller.info(), e.getMessage()); } } }
public Builder isomsg (ISOMsg m) throws InvalidCardException { if (m.hasField(2)) pan(m.getString(2)); if (m.hasField(14)) exp(m.getString(14)); if (m.hasField(35)) track2(Track2.builder().track(m.getString(35)).build()); if (m.hasField(45)) track1(Track1.builder().track(m.getString(45)).build()); if (pan == null && track2 != null) pan (track2.getPan()); if (pan == null && track1 != null) pan (track1.getPan()); if (exp == null && track2 != null) exp (track2.getExp()); if (exp == null && track1 != null) exp (track1.getExp()); if (track2 != null) { if (pan == null) pan (track2.getPan()); if (exp == null) exp (track2.getExp()); if (serviceCode == null) serviceCode(track2.getServiceCode()); pan (track1.getPan()); if (exp == null) exp (track1.getExp()); if (serviceCode == null) serviceCode(track1.getServiceCode());
@Override public int prepare(long id, Serializable context) { Context ctx = (Context) context; ISOMsg m = (ISOMsg) ctx.get(requestName); boolean destinationSet = false; if (m != null && (m.hasField(2) || m.hasField(35))) { try { Card card = Card.builder().validator(validator).isomsg(m).build(); String destination = getDestination(card); if (destination != null) { ctx.put(destinationName, destination); destinationSet = true; } } catch (InvalidCardException ex) { return ctx.getResult().fail( CMF.INVALID_CARD_OR_CARDHOLDER_NUMBER, Caller.info(), ex.getMessage() ).FAIL(); } } if (!destinationSet && ctx.get(destinationName) == null) ctx.put(destinationName, defaultDestination); if (failOnNoRoute && ctx.get(destinationName) == null) return ctx.getResult().fail(CMF.ROUTING_ERROR, Caller.info(), "No routing info").FAIL(); return PREPARED | NO_JOIN | READONLY; }
@Test public void testISOMsg() throws Throwable { ISOMsg m = new ISOMsg("0800"); m.set(45, "%B4111111111111111^FAT ALBERT ^201112345671234567890?"); m.set(35, "4111111111111111=201112345612345678901"); m.set(2, "4111111111111111"); m.set(14, "2011"); Card c = Card.builder() .isomsg(m) .cvv2("123") .serviceCode("123") .build(); assertEquals("not expired", false, c.isExpired(new Date())); assertEquals("pan", "4111111111111111", c.getPan()); assertEquals("exp", "2011", c.getExp()); assertEquals("serviceCode", "123", c.getServiceCode()); assertEquals("t1.serviceCode", "123", c.getTrack1().getServiceCode()); assertEquals("t2.serviceCode", "123", c.getTrack2().getServiceCode()); assertEquals("cvv2", "123", c.getCvv2()); assertEquals("t1.cvv", "4567", c.getTrack1().getCvv()); assertEquals("t2.cvv", "4561", c.getTrack2().getCvv()); assertEquals("discretionaryData", "1234567890", c.getTrack1().getDiscretionaryData()); assertEquals("discretionaryData", "2345678901", c.getTrack2().getDiscretionaryData()); } }
@Test public void testInvalidPAN() throws Throwable { try { Track1 t1 = Track1.builder() .track("%B4111111111111112^FAT ALBERT ^201112345671234567890?").build(); Track2 t2 = Track2.builder() .track("4111111111111112=201112345612345678901").build(); Card c = Card.builder() .pan("4111111111111112") .exp("2011") .cvv("123") .cvv2("4567") .serviceCode("201") .track1(t1) .track2(t2) .build(); fail ("InvalidCardException was not raised"); } catch (InvalidCardException ignored) { } }
public static Builder builder() { return new Builder(); }
@Test public void testCard() throws Throwable { Track1 t1 = Track1.builder() .track("%B4111111111111111^FAT ALBERT ^201112345671234567890?").build(); Track2 t2 = Track2.builder() .track("4111111111111111=201112345612345678901").build(); Card c = Card.builder() .pan("4111111111111111") .exp("2011") .cvv("123") .cvv2("4567") .serviceCode("123") .track1(t1) .track2(t2) .build(); assertEquals("not expired", false, c.isExpired(new Date())); }