001/*
002 * jPOS Project [http://jpos.org]
003 * Copyright (C) 2000-2026 jPOS Software SRL
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jpos.iso;
020
021import java.util.Objects;
022
023/**
024 * Implements a parser for card's service code as per ISO/IEC 7813:2006(E).
025 * 
026 * @version $Revision$ $Date$
027 */
028public class ServiceCode {
029
030    final private char[] value;
031   
032    /**
033     * Creates a ServiceCode instance.
034     * 
035     * @param value Three-digit service code value.
036     */
037    public ServiceCode(String value) {
038
039        Objects.requireNonNull(value);
040
041        if (!value.matches("^\\d{3}$")) {
042            throw new IllegalArgumentException("Invalid service code.");
043        }
044
045        this.value = value.toCharArray();
046    }
047
048    public boolean isPrivate() {
049        return value[0] == '7';
050    }
051
052    public boolean isTest() {
053        return value[0] == '9';
054    }
055
056    public boolean isICC() {
057        return value[0] == '2' || value[0] == '6';
058    }
059
060    public boolean isInternational() {
061        return value[0] == '1' || value[0] == '2';
062    }
063
064    public boolean isNational() {
065        return value[0] == '5' || value[0] == '6';
066    }
067
068    public boolean hasNoRestrictions() {
069        return value[2] == '0' || value[2] == '1' || value[2] == '6';
070    }
071
072    public boolean isGoodsAndServicesOnly() {
073        return value[2] == '2' || value[2] == '5' || value[2] == '7';
074    }
075
076    public boolean isATMOnly() {
077        return value[2] == '3';
078    }
079
080    public boolean isCashOnly() {
081        return value[2] == '4';
082    }
083    
084    public boolean isPINRequired() {
085        return value[2] == '0' || value[2] == '3' || value[2] == '5';
086    }
087    
088    public boolean mustPromptForPINIfPEDPresent() {
089        return value[2] == '6' || value[2] == '7';
090    }
091    
092    public boolean isNormalAuthorization() {
093        return value[1] == '0';
094    }
095
096    public boolean isIssuerAuthorization() {
097        return value[1] == '2';
098    }
099}