1
Verify Credit Card Info
  • public void verifyCreditCardInfo(boolean isOracle) throws AddressMismatchException,InvalidCardNumberException,ExpiredCardException,NameMismatchException,InSufficientBalanceException,Exception
    {

    CreditCardProcessor creditCardProcessor = new CreditCardProcessor("C:\\Program Files\\Apache Group\\jakarta-tomcat-4.1.27\\webapps\\cs5890project\\WEB-INF\\decryptedpaymentfile.xml");
    Creditcardpayment creditCardPayment = null;
    Connection con = null;

    try
    {
    creditCardPayment = creditCardProcessor.readCreditcardpayment(); //Un marshal the XML File to Java Objects
    CreditcardinfoType creditCardInfo = creditCardPayment.getCreditcardinfo();

    if (isOracle) // Can connect to Oracle DB or MS Access DB
    {
    System.out.println("Before loading oracle driver ");

    Class.forName("oracle.jdbc.driver.OracleDriver");

    System.out.println("After loading oracle driver ");

    con = DriverManager.getConnection("jdbc:oracle:thin:@ALHAMDULILLAH:1521:SULTHANA","scott","tiger");

    System.out.println("After creating Oracle connection ");
    }
    else
    {
    System.out.println("Before loading MSAccess driver ");

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    System.out.println("After creating MSAccess driver ");

    con = DriverManager.getConnection("jdbc:odbc:cs5890project","system","password");

    System.out.println("After creating MSAccess connection ");
    }

    PreparedStatement pstmt = con.prepareStatement("SELECT * FROM CREDIT_CARD_MASTER WHERE credit_card_number = ? ");

    String cardNumber = creditCardInfo.getCardnumber();
    System.out.println("Card Number is " + cardNumber);

    pstmt.setString(1, cardNumber);

    ResultSet rSet = pstmt.executeQuery();

    if (rSet.next())
    {
    validateNameInfo(creditCardPayment,rSet);
    validateCreditCardInfo(creditCardPayment,rSet);
    validateCreditCardExpiration(creditCardPayment,rSet);
    validateAddressInfo(creditCardPayment,rSet);
    validateAvailableFundsInfo(creditCardPayment,rSet);
    }
    else
    {
    throw new InvalidCardNumberException();
    }

    }
    catch(AddressMismatchException amme)
    {
    throw amme;
    }
    catch(InvalidCardNumberException icne)
    {
    throw icne;
    }
    catch(ExpiredCardException ece)
    {
    throw ece;
    }
    catch(NameMismatchException nmme)
    {
    throw nmme;
    }
    catch(InSufficientBalanceException ibe)
    {
    throw ibe;
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    finally
    {
    con.close();
    }
    }

     

  • // Get data from the un marshalled Java objects  and compare against Secure Pay's DB

  • public void validateNameInfo(Creditcardpayment creditCardPayment,ResultSet rSet) throws NameMismatchException,SQLException
    {
    CustomerType customer = creditCardPayment.getCustomer();

    String firstName = (customer.getFirstname().trim()).toUpperCase();
    System.out.println("fisrtName is " + firstName);

    String lastName = (customer.getLastname().trim()).toUpperCase();
    System.out.println("lastName is " + lastName);

    if (!(firstName.equalsIgnoreCase(rSet.getString("card_holder_first_name"))) ||
    !(lastName.equalsIgnoreCase(rSet.getString("card_holder_last_name")))
    )
    {
    throw new NameMismatchException();
    }
    }

    public void validateCreditCardInfo(Creditcardpayment creditCardPayment,ResultSet rSet) throws InvalidCardNumberException,SQLException
    {
    CreditcardinfoType creditCardInfo = creditCardPayment.getCreditcardinfo();
    String securityCode = creditCardInfo.getSecuritycode().trim();
    System.out.println("securityCode is " + securityCode);

    if (!(securityCode.equals(rSet.getString("credit_card_security_code"))))
    {
    throw new InvalidCardNumberException();
    }
    }

    public void validateCreditCardExpiration(Creditcardpayment creditCardPayment,ResultSet rSet) throws ExpiredCardException,SQLException
    {
    Calendar sysDate = new GregorianCalendar();
    Calendar currentDate = new GregorianCalendar(sysDate.get(Calendar.YEAR), sysDate.get(Calendar.MONTH)+1, sysDate.get(Calendar.DAY_OF_MONTH));

    String expiryDate = rSet.getString("credit_card_expiry_date");

    System.out.println("expiry date is " + expiryDate);

    int expiryDateYear = Integer.parseInt(expiryDate.substring(6));
    int expiryMonth = Integer.parseInt(expiryDate.substring(0,2));
    int expiryDay = Integer.parseInt(expiryDate.substring(3,5));

    Calendar expirationDate = new GregorianCalendar(expiryDateYear,expiryMonth, expiryDay);

    if (expirationDate.before(currentDate))
    {
    throw new ExpiredCardException();
    }
    }

    public void validateAvailableFundsInfo(Creditcardpayment creditCardPayment,ResultSet rSet) throws InSufficientBalanceException,SQLException
    {
    String paymentAmount= creditCardPayment.getPaymentamount().trim();
    int creditLimit = rSet.getInt("credit_limit");
    int creditAvailable = rSet.getInt("credit_available");

    System.out.println("cerdit limit is " + creditLimit);
    System.out.println("cerdit available is " + creditAvailable);

    if ( (creditLimit < Integer.parseInt(paymentAmount)) || (creditAvailable < Integer.parseInt(paymentAmount)) )
    {
    throw new InSufficientBalanceException();
    }
    }

    public void validateAddressInfo(Creditcardpayment creditCardPayment,ResultSet rSet) throws AddressMismatchException,SQLException
    {
    CustomerType customer = creditCardPayment.getCustomer();

    AddressType address = customer.getAddress();

    String street1 = (address.getStreet1().trim()).toUpperCase();
    System.out.println("street1 is " + street1);

    String street2 = (address.getStreet2().trim()).toUpperCase();
    System.out.println("street2 is " + street2);

    String city = (address.getCity().trim()).toUpperCase();
    System.out.println("city is " + city);

    String state = (address.getState().trim()).toUpperCase();
    System.out.println("state is " + state);

    String zip = address.getZip().trim();
    System.out.println("zip is " + zip);

    if( !(rSet.getString("card_holder_street").equalsIgnoreCase(street1)) ||
    !(rSet.getString("card_holder_apartment").equalsIgnoreCase(street2)) ||
    !(rSet.getString("card_holder_city").equalsIgnoreCase(city)) ||
    !(rSet.getString("card_holder_state").equalsIgnoreCase(state)) ||
    !(rSet.getString("card_holder_zip").equals(zip))
    )
    {
    throw new AddressMismatchException();
    }
    }