Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
payment methods shown
Browse files Browse the repository at this point in the history
  • Loading branch information
L23de committed Apr 5, 2022
1 parent bf1ba3c commit 7846adb
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 6 deletions.
76 changes: 76 additions & 0 deletions numa/src/main/java/numa/Portals/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,80 @@ public void addVenmo() throws IOException, ExitException, SQLException {
add.execute();
}
}
}

class Venmo {
String handle;

public Venmo(String handle) {
this.handle = handle;
}

public String toString() {
String out = String.format(
"Handle: %s\n",
handle
);
return out;
}
}

class ACH {
String acct_num;
String rout_num;
String bank_name;

public ACH(String acct_num, String rout_num, String bank_name) {
this.acct_num = acct_num;
this.rout_num = rout_num;
this.bank_name = bank_name;
}

public String toString() {
String out = String.format(
"Bank Name: %s\n" +
"Account Number: %s\n" +
"Routing Number: %s\n",
bank_name, acct_num, rout_num
);
return out;
}
}

class Card {
String first_name;
String last_name;
String card_num;
String exp_date;
String cvv;
String pin;
Boolean isCredit;

public Card(String first_name, String last_name, String card_num, String exp_date, String cvv, String pin) {
this.first_name = first_name;
this.last_name = last_name;
this.card_num = card_num;
this.exp_date = exp_date;
this.cvv = cvv;
this.pin = pin;

isCredit = pin == null ? true : false;
}

public String toString() {
String type = isCredit ? "Credit" : "Debit";
String out = "";
out += String.format(
"Type: %s\n" +
"Cardholder First Name: %s\n" +
"Cardholder Last Name: %s\n" +
"Card Number: %s\n" +
"Expiration Date (MM/YYYY): %s\n" +
"CVV: %s\n",
type, first_name, last_name, card_num, exp_date, cvv
);

if (!isCredit) out += String.format("PIN: %s", pin);
return out;
}
}
70 changes: 64 additions & 6 deletions numa/src/main/java/numa/Portals/ResidentPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.naming.spi.DirStateFactory.Result;

import numa.Reader;
import numa.Exceptions.*;

public class ResidentPortal extends Portal {
final String BOLD_ON = "\033[1m";
final String BOLD_OFF = "\033[0m";

Reader input;
Connection conn;
int resId = -1;
Expand Down Expand Up @@ -73,7 +79,10 @@ public int residentLogin(Reader input) throws IOException, ExitException, MenuEx
public void resInfo() throws SQLException, NumberFormatException, IOException, ExitException, MenuException {
try (
Statement getInfo = conn.createStatement();
Statement getPay = conn.createStatement();
PreparedStatement getVenmo = conn.prepareStatement("select payment_method.id, handle from payment_method join venmo on venmo_id = venmo.id where person_id = ?");
PreparedStatement getACH = conn.prepareStatement("select payment_method.id, bank_name, acct_num, routing_num from payment_method join ach on ach_id = ach.id where person_id = ?");
PreparedStatement getCard = conn.prepareStatement("select payment_method.id, first_name, last_name, card_num, exp_date, cvv, pin from payment_method join pay_card on card_id = pay_card.id where person_id = ?");

) {
// resInfo should only have one entry, because of PK constraints and residentLogin() already checks that resId exists in the renter_info table
ResultSet resInfo = getInfo.executeQuery(
Expand Down Expand Up @@ -104,14 +113,63 @@ public void resInfo() throws SQLException, NumberFormatException, IOException, E
);

// Also show payment info
// ResultSet payInfo = getPay.executeQuery(
// "select "
// );
getVenmo.setInt(1, resId);
getACH.setInt(1, resId);
getCard.setInt(1, resId);

ResultSet venmoInfo = getVenmo.executeQuery();
ResultSet achInfo = getACH.executeQuery();
ResultSet cardInfo = getCard.executeQuery();

String venmoOut = "";
String achOut = "";
String cardOut = "";

while (venmoInfo.next()) {
String handle = venmoInfo.getString("handle");
Venmo acc = new Venmo(handle);
venmoOut += acc.toString();
}

while (achInfo.next()) {
String bank = achInfo.getString("bank_name");
String acct = achInfo.getString("acct_num");
String rout = achInfo.getString("routing_num");
ACH acc = new ACH(acct, rout, bank);
achOut += acc.toString();
}

while (cardInfo.next()) {
String first = cardInfo.getString("first_name");
String last = cardInfo.getString("last_name");
String card_num = cardInfo.getString("card_num");
String exp = cardInfo.getString("exp_date");
String cvv = cardInfo.getString("cvv");
String pin = cardInfo.getString("pin");

String payOut = String.format("");
Card acc = new Card(first, last, card_num, exp, cvv, pin);
cardOut += acc.toString();
}

System.out.println(infoOut);
System.out.println(payOut);

if (venmoOut != "") {
System.out.println(BOLD_ON + "Venmo" + BOLD_OFF);
System.out.println();
System.out.println(venmoOut);
}

if (achOut != "") {
System.out.println(BOLD_ON + "Bank ACH Transfers" + BOLD_OFF);
System.out.println();
System.out.println(achOut);
}

if (cardOut != "") {
System.out.println(BOLD_ON + "Payment Cards" + BOLD_OFF);
System.out.println();
System.out.println(cardOut);
}

System.out.print("Do you need to add a new payment? [Y/N]: ");
String yn = input.getPrompt();
Expand Down

0 comments on commit 7846adb

Please sign in to comment.