From f09762c10022cff3a96ffb315ad2f165d9743ee5 Mon Sep 17 00:00:00 2001 From: joethei Date: Wed, 5 Jun 2019 14:57:54 +0200 Subject: [PATCH] + payment pages + selection pages --- src/main/java/de/hsel/itech/db/AddressDB.java | 6 +- src/main/java/de/hsel/itech/db/PaymentDB.java | 16 ++++-- .../hsel/itech/db/pojo/CreditCardPayment.java | 8 +++ .../de/hsel/itech/db/pojo/PayPalPayment.java | 6 ++ .../java/de/hsel/itech/jsf/AddressBean.java | 14 ++++- .../de/hsel/itech/jsf/CreditCardBean.java | 55 ++++++++++++++++++ .../java/de/hsel/itech/jsf/PayPalBean.java | 43 ++++++++++++++ .../java/de/hsel/itech/jsf/PaymentBean.java | 10 ++++ src/main/webapp/address-add.xhtml | 15 +++-- src/main/webapp/addressSelection.xhtml | 34 +++++++++++ src/main/webapp/payment-add-credit.xhtml | 42 ++++++++++++++ src/main/webapp/payment-add-paypal.xhtml | 34 +++++++++++ src/main/webapp/paymentSelection.xhtml | 57 +++++++++++++++++++ src/main/webapp/payments.xhtml | 17 ++++-- src/main/webapp/version.jsp | 2 +- 15 files changed, 338 insertions(+), 21 deletions(-) create mode 100644 src/main/java/de/hsel/itech/jsf/CreditCardBean.java create mode 100644 src/main/java/de/hsel/itech/jsf/PayPalBean.java create mode 100644 src/main/webapp/addressSelection.xhtml create mode 100644 src/main/webapp/payment-add-credit.xhtml create mode 100644 src/main/webapp/payment-add-paypal.xhtml create mode 100644 src/main/webapp/paymentSelection.xhtml diff --git a/src/main/java/de/hsel/itech/db/AddressDB.java b/src/main/java/de/hsel/itech/db/AddressDB.java index e6654ad..d15b22f 100644 --- a/src/main/java/de/hsel/itech/db/AddressDB.java +++ b/src/main/java/de/hsel/itech/db/AddressDB.java @@ -66,7 +66,11 @@ public class AddressDB { try { ResultSet rs = entry.getKey(); - Address address = new Address(user, id, rs.getString("name"), rs.getString("street"), rs.getString("number"), rs.getInt("zipCode"), rs.getString("city")); + rs.beforeFirst(); + Address address = null; + while(rs.next()) { + address = new Address(user, id, rs.getString("name"), rs.getString("street"), rs.getString("number"), rs.getInt("zipCode"), rs.getString("city")); + } entry.getValue().close(); return address; diff --git a/src/main/java/de/hsel/itech/db/PaymentDB.java b/src/main/java/de/hsel/itech/db/PaymentDB.java index 5c4dadb..425baa7 100644 --- a/src/main/java/de/hsel/itech/db/PaymentDB.java +++ b/src/main/java/de/hsel/itech/db/PaymentDB.java @@ -32,8 +32,8 @@ public class PaymentDB { try { ResultSet rs = entry.getKey(); - rs.beforeFirst(); PaymentType type = null; + rs.beforeFirst(); while(rs.next()) { type = new PaymentType(id, rs.getString("name")); } @@ -92,8 +92,8 @@ public class PaymentDB { try { ResultSet rs = entry.getKey(); - rs.beforeFirst(); PayPalPayment payment = null; + rs.beforeFirst(); while(rs.next()) { payment = new PayPalPayment(id, user, rs.getString("mail"), rs.getString("auth")); } @@ -114,8 +114,8 @@ public class PaymentDB { try { ResultSet rs = entry.getKey(); - rs.beforeFirst(); CreditCardPayment payment = null; + rs.beforeFirst(); while(rs.next()) { payment = new CreditCardPayment(id, user, rs.getInt("number"), rs.getString("owner"), rs.getDate("expiration"), rs.getInt("checksum")); } @@ -137,8 +137,8 @@ public class PaymentDB { try { ResultSet rs = entry.getKey(); - rs.beforeFirst(); DebitCardPayment payment = null; + rs.beforeFirst(); while(rs.next()) { payment = new DebitCardPayment(id, user, rs.getString("iban"), rs.getString("bic"), rs.getString("owner")); } @@ -266,6 +266,7 @@ public class PaymentDB { return insertCount; } + @Nullable private long insertType(@NotNull Payment payment) { Connection connection = database.getConnection(); assert connection != null; @@ -277,7 +278,12 @@ public class PaymentDB { statement.executeUpdate(); - long id = statement.getGeneratedKeys().getLong("id"); + ResultSet rs = statement.getGeneratedKeys(); + Long id = null; + + while(rs.next()) { + id = rs.getLong("id"); + } connection.close(); diff --git a/src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java b/src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java index 694ec88..0bb509f 100644 --- a/src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java +++ b/src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java @@ -23,6 +23,14 @@ public class CreditCardPayment extends Payment{ @NonNull private Date expiration; @NonNull private int checksum; + public CreditCardPayment(User user, int number, String owner, Date expiration, int checksum) { + super(0, new PaymentType(1, "CreditCard"), user); + this.number = number; + this.owner = owner; + this.expiration = expiration; + this.checksum = checksum; + } + public CreditCardPayment(long id, User user, int number, String owner, Date expiration, int checksum) { super(id, new PaymentType(1, "CreditCard"), user); this.number = number; diff --git a/src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java b/src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java index 1d6f65c..150dca9 100644 --- a/src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java +++ b/src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java @@ -19,6 +19,12 @@ public class PayPalPayment extends Payment{ @NonNull private String email; @NonNull private String authCode; + public PayPalPayment(User user, String email, String authCode) { + super(0, new PaymentType(4, "PayPal"), user); + this.email = email; + this.authCode = authCode; + } + public PayPalPayment(long id, User user, String email, String authCode) { super(id, new PaymentType(4, "PayPal"), user); this.email = email; diff --git a/src/main/java/de/hsel/itech/jsf/AddressBean.java b/src/main/java/de/hsel/itech/jsf/AddressBean.java index ef25d6c..98a41a8 100644 --- a/src/main/java/de/hsel/itech/jsf/AddressBean.java +++ b/src/main/java/de/hsel/itech/jsf/AddressBean.java @@ -41,7 +41,7 @@ public class AddressBean implements Serializable { @Getter @Setter - private int zipCode = -1; + private Integer zipCode; @Getter @Setter @@ -50,6 +50,14 @@ public class AddressBean implements Serializable { @Getter private boolean valid = true; + @Getter + private Address selected; + + public String select(Address address) { + selected = address; + return "paymentSelection.jsf"; + } + public List
getAddressList() { List
list = Database.getInstance().address().getAll(getUser()); @@ -58,11 +66,11 @@ public class AddressBean implements Serializable { } public String add() { - if(getUser() != null && name != null && street != null && number != null && zipCode != -1 && city != null) { + if(getUser() != null && name != null && street != null && number != null && zipCode != null && city != null) { Database.getInstance().address().insert(new Address(getUser(), name, street, number, zipCode, city)); name = null; number = null; - zipCode = -1; + zipCode = null; city = null; valid = true; return "address.xhtml"; diff --git a/src/main/java/de/hsel/itech/jsf/CreditCardBean.java b/src/main/java/de/hsel/itech/jsf/CreditCardBean.java new file mode 100644 index 0000000..582e2dc --- /dev/null +++ b/src/main/java/de/hsel/itech/jsf/CreditCardBean.java @@ -0,0 +1,55 @@ +package de.hsel.itech.jsf; + + +import de.hsel.itech.db.Database; +import de.hsel.itech.db.pojo.CreditCardPayment; +import de.hsel.itech.db.pojo.User; +import lombok.Getter; +import lombok.Setter; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.RequestScoped; +import javax.faces.context.FacesContext; +import java.io.Serializable; +import java.util.Date; + +/** + * + * @author Johannes Theiner + * @version 0.1 + */ + +@ManagedBean +@RequestScoped +public class CreditCardBean implements Serializable { + + public User getUser() { + FacesContext context = FacesContext.getCurrentInstance(); + return (User) context.getApplication().evaluateExpressionGet(context,"#{userBean.user}", User.class); + } + + @Getter + @Setter + private String owner; + + @Getter + @Setter + private int number; + + @Getter + @Setter + private Date expiration; + + @Getter + @Setter + private int checksum; + + public String add() { + java.sql.Date date = new java.sql.Date(expiration.getTime()); + CreditCardPayment payment = new CreditCardPayment(getUser(), number, owner, date, checksum); + + Database.getInstance().payment().insert(payment); + + return "payments.jsf"; + } +} \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/jsf/PayPalBean.java b/src/main/java/de/hsel/itech/jsf/PayPalBean.java new file mode 100644 index 0000000..022037e --- /dev/null +++ b/src/main/java/de/hsel/itech/jsf/PayPalBean.java @@ -0,0 +1,43 @@ +package de.hsel.itech.jsf; + +import de.hsel.itech.db.Database; +import de.hsel.itech.db.pojo.PayPalPayment; +import de.hsel.itech.db.pojo.User; +import lombok.Getter; +import lombok.Setter; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.RequestScoped; +import javax.faces.context.FacesContext; +import java.io.Serializable; + +/** + * @author Johannes Theiner + * @version 0.1 + */ + +@ManagedBean +@RequestScoped +public class PayPalBean implements Serializable { + + public User getUser() { + FacesContext context = FacesContext.getCurrentInstance(); + return (User) context.getApplication().evaluateExpressionGet(context,"#{userBean.user}", User.class); + } + + @Getter + @Setter + private String mail; + + @Getter + @Setter + private String auth; + + + public String add() { + PayPalPayment payment = new PayPalPayment(getUser(), mail, auth); + Database.getInstance().payment().insert(payment); + + return "payments.jsf"; + } +} diff --git a/src/main/java/de/hsel/itech/jsf/PaymentBean.java b/src/main/java/de/hsel/itech/jsf/PaymentBean.java index 265e6ed..9f297ab 100644 --- a/src/main/java/de/hsel/itech/jsf/PaymentBean.java +++ b/src/main/java/de/hsel/itech/jsf/PaymentBean.java @@ -2,6 +2,7 @@ package de.hsel.itech.jsf; import de.hsel.itech.db.Database; import de.hsel.itech.db.pojo.*; +import lombok.Getter; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @@ -18,6 +19,15 @@ public class PaymentBean { return (User) context.getApplication().evaluateExpressionGet(context,"#{userBean.user}", User.class); } + @Getter + private Payment selected; + + public String select(Payment payment) { + selected = payment; + + return "confirmation.jsf"; + } + public List getCreditCard() { List list = new ArrayList<>(); for(Payment payment : Database.getInstance().payment().get(getUser())) { diff --git a/src/main/webapp/address-add.xhtml b/src/main/webapp/address-add.xhtml index d6d31f3..5541abe 100644 --- a/src/main/webapp/address-add.xhtml +++ b/src/main/webapp/address-add.xhtml @@ -12,15 +12,20 @@
- Name + Name +
- Straße + Straße +
- Hausnummer + Hausnummer +
- Postleitzahl + Postleitzahl +
- Ort + Ort +
diff --git a/src/main/webapp/addressSelection.xhtml b/src/main/webapp/addressSelection.xhtml new file mode 100644 index 0000000..a176760 --- /dev/null +++ b/src/main/webapp/addressSelection.xhtml @@ -0,0 +1,34 @@ + + + + + + + + +

Adresse auswählen

+ + + + + + +
+ #{address.name}
+ #{address.street} #{address.number}
+ #{address.zipCode} #{address.city} +
+
+
+
+
+ +
+ +
+
+ diff --git a/src/main/webapp/payment-add-credit.xhtml b/src/main/webapp/payment-add-credit.xhtml new file mode 100644 index 0000000..018f4c0 --- /dev/null +++ b/src/main/webapp/payment-add-credit.xhtml @@ -0,0 +1,42 @@ + + + + + + + + +
+
+ + Besitzer + +
+ Kartennummer + +
+ Ablaufdaten + + + +
+ Prüfsumme + + + +
+ +
+
+
+ + +
+ +
+
+ diff --git a/src/main/webapp/payment-add-paypal.xhtml b/src/main/webapp/payment-add-paypal.xhtml new file mode 100644 index 0000000..a376b08 --- /dev/null +++ b/src/main/webapp/payment-add-paypal.xhtml @@ -0,0 +1,34 @@ + + + + + + + + + +
+
+ + Mail + +
+ Kartennummer + +
+ +
+
+
+ + +
+ +
+ +
+ diff --git a/src/main/webapp/paymentSelection.xhtml b/src/main/webapp/paymentSelection.xhtml new file mode 100644 index 0000000..0905b7e --- /dev/null +++ b/src/main/webapp/paymentSelection.xhtml @@ -0,0 +1,57 @@ + + + + + + + +

Zahlungsmöglichkeit auswählen

+ + + + +

Kreditkarte

+ + + +
+
+ #{payment.owner}
+ #{payment.number} / + #{payment.checksum}
+ Ablaufdatum: + + +
+
+
+
+ +
+ + +

PayPal

+ + + +
+
+ #{payment.email} +
+
+
+
+ +
+ + +
+ +
+
+
+ diff --git a/src/main/webapp/payments.xhtml b/src/main/webapp/payments.xhtml index 40e2fe3..953b670 100644 --- a/src/main/webapp/payments.xhtml +++ b/src/main/webapp/payments.xhtml @@ -14,20 +14,23 @@ -

Kreditkarte

+

Kreditkarte

#{payment.owner}
- #{payment.number}
+ #{payment.number} / #{payment.checksum}
- #{payment.expiration} + Ablaufdatum: + + +
- +
@@ -36,7 +39,9 @@ -

PayPal

+ + +

PayPal

@@ -46,7 +51,7 @@
- +
diff --git a/src/main/webapp/version.jsp b/src/main/webapp/version.jsp index 25247f2..f84e6e4 100644 --- a/src/main/webapp/version.jsp +++ b/src/main/webapp/version.jsp @@ -2,5 +2,5 @@ Server info: <%= application.getServerInfo() %>
Servlet version: <%= application.getMajorVersion() %>.<%= application.getMinorVersion() %>
JSP version: <%= JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion() %>
-JSF version: <%= FacesContext.class.getPackage().getImplementationVersion()%> +JSF version: <%= FacesContext.class.getPackage().getImplementationVersion()%>
Java version: <%= System.getProperty("java.version") %>