+ payment pages

+ selection pages
This commit is contained in:
Johannes Theiner 2019-06-05 14:57:54 +02:00
parent d205e62419
commit f09762c100
15 changed files with 338 additions and 21 deletions

View File

@ -66,7 +66,11 @@ public class AddressDB {
try { try {
ResultSet rs = entry.getKey(); 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(); entry.getValue().close();
return address; return address;

View File

@ -32,8 +32,8 @@ public class PaymentDB {
try { try {
ResultSet rs = entry.getKey(); ResultSet rs = entry.getKey();
rs.beforeFirst();
PaymentType type = null; PaymentType type = null;
rs.beforeFirst();
while(rs.next()) { while(rs.next()) {
type = new PaymentType(id, rs.getString("name")); type = new PaymentType(id, rs.getString("name"));
} }
@ -92,8 +92,8 @@ public class PaymentDB {
try { try {
ResultSet rs = entry.getKey(); ResultSet rs = entry.getKey();
rs.beforeFirst();
PayPalPayment payment = null; PayPalPayment payment = null;
rs.beforeFirst();
while(rs.next()) { while(rs.next()) {
payment = new PayPalPayment(id, user, rs.getString("mail"), rs.getString("auth")); payment = new PayPalPayment(id, user, rs.getString("mail"), rs.getString("auth"));
} }
@ -114,8 +114,8 @@ public class PaymentDB {
try { try {
ResultSet rs = entry.getKey(); ResultSet rs = entry.getKey();
rs.beforeFirst();
CreditCardPayment payment = null; CreditCardPayment payment = null;
rs.beforeFirst();
while(rs.next()) { while(rs.next()) {
payment = new CreditCardPayment(id, user, rs.getInt("number"), rs.getString("owner"), rs.getDate("expiration"), rs.getInt("checksum")); 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 { try {
ResultSet rs = entry.getKey(); ResultSet rs = entry.getKey();
rs.beforeFirst();
DebitCardPayment payment = null; DebitCardPayment payment = null;
rs.beforeFirst();
while(rs.next()) { while(rs.next()) {
payment = new DebitCardPayment(id, user, rs.getString("iban"), rs.getString("bic"), rs.getString("owner")); payment = new DebitCardPayment(id, user, rs.getString("iban"), rs.getString("bic"), rs.getString("owner"));
} }
@ -266,6 +266,7 @@ public class PaymentDB {
return insertCount; return insertCount;
} }
@Nullable
private long insertType(@NotNull Payment payment) { private long insertType(@NotNull Payment payment) {
Connection connection = database.getConnection(); Connection connection = database.getConnection();
assert connection != null; assert connection != null;
@ -277,7 +278,12 @@ public class PaymentDB {
statement.executeUpdate(); statement.executeUpdate();
long id = statement.getGeneratedKeys().getLong("id"); ResultSet rs = statement.getGeneratedKeys();
Long id = null;
while(rs.next()) {
id = rs.getLong("id");
}
connection.close(); connection.close();

View File

@ -23,6 +23,14 @@ public class CreditCardPayment extends Payment{
@NonNull private Date expiration; @NonNull private Date expiration;
@NonNull private int checksum; @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) { public CreditCardPayment(long id, User user, int number, String owner, Date expiration, int checksum) {
super(id, new PaymentType(1, "CreditCard"), user); super(id, new PaymentType(1, "CreditCard"), user);
this.number = number; this.number = number;

View File

@ -19,6 +19,12 @@ public class PayPalPayment extends Payment{
@NonNull private String email; @NonNull private String email;
@NonNull private String authCode; @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) { public PayPalPayment(long id, User user, String email, String authCode) {
super(id, new PaymentType(4, "PayPal"), user); super(id, new PaymentType(4, "PayPal"), user);
this.email = email; this.email = email;

View File

@ -41,7 +41,7 @@ public class AddressBean implements Serializable {
@Getter @Getter
@Setter @Setter
private int zipCode = -1; private Integer zipCode;
@Getter @Getter
@Setter @Setter
@ -50,6 +50,14 @@ public class AddressBean implements Serializable {
@Getter @Getter
private boolean valid = true; private boolean valid = true;
@Getter
private Address selected;
public String select(Address address) {
selected = address;
return "paymentSelection.jsf";
}
public List<Address> getAddressList() { public List<Address> getAddressList() {
List<Address> list = Database.getInstance().address().getAll(getUser()); List<Address> list = Database.getInstance().address().getAll(getUser());
@ -58,11 +66,11 @@ public class AddressBean implements Serializable {
} }
public String add() { 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)); Database.getInstance().address().insert(new Address(getUser(), name, street, number, zipCode, city));
name = null; name = null;
number = null; number = null;
zipCode = -1; zipCode = null;
city = null; city = null;
valid = true; valid = true;
return "address.xhtml"; return "address.xhtml";

View File

@ -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";
}
}

View File

@ -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";
}
}

View File

@ -2,6 +2,7 @@ package de.hsel.itech.jsf;
import de.hsel.itech.db.Database; import de.hsel.itech.db.Database;
import de.hsel.itech.db.pojo.*; import de.hsel.itech.db.pojo.*;
import lombok.Getter;
import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped; import javax.faces.bean.SessionScoped;
@ -18,6 +19,15 @@ public class PaymentBean {
return (User) context.getApplication().evaluateExpressionGet(context,"#{userBean.user}", User.class); 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<CreditCardPayment> getCreditCard() { public List<CreditCardPayment> getCreditCard() {
List<CreditCardPayment> list = new ArrayList<>(); List<CreditCardPayment> list = new ArrayList<>();
for(Payment payment : Database.getInstance().payment().get(getUser())) { for(Payment payment : Database.getInstance().payment().get(getUser())) {

View File

@ -12,15 +12,20 @@
<div class="m-row"> <div class="m-row">
<div class="m-col-s-4 m-push-s-4"> <div class="m-col-s-4 m-push-s-4">
<h:form> <h:form>
<h:inputText id="name" value="#{addressBean.name}">Name</h:inputText> <h:inputText id="name" value="#{addressBean.name}" required="true">Name</h:inputText>
<h:message for="name"/>
<br/> <br/>
<h:inputText id="street" value="#{addressBean.street}">Straße</h:inputText> <h:inputText id="street" value="#{addressBean.street}" required="true">Straße</h:inputText>
<h:message for="street"/>
<br/> <br/>
<h:inputText id="number" value="#{addressBean.number}">Hausnummer</h:inputText> <h:inputText id="number" value="#{addressBean.number}" required="true">Hausnummer</h:inputText>
<h:message for="number"/>
<br/> <br/>
<h:inputText id="zipCode" value="#{addressBean.zipCode}">Postleitzahl</h:inputText> <h:inputText id="zipCode" value="#{addressBean.zipCode}" required="true">Postleitzahl</h:inputText>
<h:message for="zipCode"/>
<br/> <br/>
<h:inputText id="city" value="#{addressBean.city}">Ort</h:inputText> <h:inputText id="city" value="#{addressBean.city}" required="true">Ort</h:inputText>
<h:message for="city"/>
<br/> <br/>
<h:commandButton action="#{addressBean.add}" value="hinzufügen"/> <h:commandButton action="#{addressBean.add}" value="hinzufügen"/>
</h:form> </h:form>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<ui:composition template="template.xhtml">
<ui:define name="content">
<h1 class="m-text-center">Adresse auswählen</h1>
<h:panelGroup layout="block" styleClass="m-row" rendered="#{userBean.loggedIn}">
<ui:repeat value="#{addressBean.addressList}" var="address">
<h:panelGroup layout="block" styleClass="m-col-t-3">
<h:commandLink action="#{addressBean.select(address)}">
<div class="m-block m-primary">
#{address.name}<br/>
#{address.street} #{address.number}<br/>
#{address.zipCode} #{address.city}
</div>
</h:commandLink>
</h:panelGroup>
</ui:repeat>
</h:panelGroup>
</ui:define>
</ui:composition>
</f:view>
</html>

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<ui:composition template="template.xhtml">
<ui:define name="content">
<div class="m-row">
<div class="m-col-s-4 m-push-s-4">
<h:form>
<h:inputText id="owner" value="#{creditCardBean.owner}">Besitzer</h:inputText>
<h:message for="owner"/>
<br/>
<h:inputText id="number" value="#{creditCardBean.number}">Kartennummer</h:inputText>
<h:message for="number"/>
<br/>
<h:inputText id="expiration" value="#{creditCardBean.expiration}">Ablaufdaten
<f:convertDateTime pattern="dd.MM.yyyy"/>
</h:inputText>
<h:message for="expiration"/>
<br/>
<h:inputText id="checksum" value="#{creditCardBean.checksum}">Prüfsumme</h:inputText>
<h:message for="checksum"/>
<br/>
<h:commandButton action="#{creditCardBean.add}" value="hinzufügen"/>
</h:form>
</div>
</div>
</ui:define>
</ui:composition>
</f:view>
</html>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<ui:composition template="template.xhtml">
<ui:define name="content">
<div class="m-row">
<div class="m-col-s-4 m-push-s-4">
<h:form>
<h:inputText id="mail" value="#{payPalBean.mail}">Mail</h:inputText>
<h:message for="mail"/>
<br/>
<h:inputText id="number" value="#{creditCardBean.number}">Kartennummer</h:inputText>
<h:message for="number"/>
<br/>
<h:commandButton action="#{payPalBean.add}" value="hinzufügen"/>
</h:form>
</div>
</div>
</ui:define>
</ui:composition>
</f:view>
</html>

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<ui:composition template="template.xhtml">
<ui:define name="content">
<h1 class="m-text-center">Zahlungsmöglichkeit auswählen</h1>
<h:panelGroup layout="block" rendered="#{userBean.loggedIn}">
<h3 class="m-text-center m-text m-small">Kreditkarte</h3>
<h:panelGroup layout="block" styleClass="m-row">
<ui:repeat value="#{paymentBean.creditCard}" var="payment">
<h:commandLink action="#{paymentBean.select(payment)}">
<div class="m-col-t-3">
<div class="m-block m-primary">
#{payment.owner}<br/>
#{payment.number} /
#{payment.checksum}<br/>
Ablaufdatum:<h:outputText value="#{payment.expiration}">
<f:convertDateTime pattern="dd.MM.yyyy"/>
</h:outputText>
</div>
</div>
</h:commandLink>
</ui:repeat>
</h:panelGroup>
<h3 class="m-text-center m-text m-small">PayPal</h3>
<h:panelGroup layout="block" styleClass="m-row">
<ui:repeat value="#{paymentBean.payPal}" var="payment">
<h:commandLink action="#{paymentBean.select(payment)}">
<div class="m-col-t-3">
<div class="m-block m-primary">
#{payment.email}
</div>
</div>
</h:commandLink>
</ui:repeat>
</h:panelGroup>
</h:panelGroup>
</ui:define>
</ui:composition>
</f:view>
</html>

View File

@ -14,20 +14,23 @@
<h:panelGroup layout="block" rendered="#{userBean.loggedIn}"> <h:panelGroup layout="block" rendered="#{userBean.loggedIn}">
<h3 class="m-text-center">Kreditkarte</h3> <h3 class="m-text-center m-text m-small">Kreditkarte</h3>
<h:panelGroup layout="block" styleClass="m-row"> <h:panelGroup layout="block" styleClass="m-row">
<ui:repeat value="#{paymentBean.creditCard}" var="payment"> <ui:repeat value="#{paymentBean.creditCard}" var="payment">
<div class="m-col-t-3"> <div class="m-col-t-3">
<div class="m-block m-primary"> <div class="m-block m-primary">
#{payment.owner}<br/> #{payment.owner}<br/>
#{payment.number}<br/> #{payment.number} /
#{payment.checksum}<br/> #{payment.checksum}<br/>
#{payment.expiration} Ablaufdatum:
<h:outputText value="#{payment.expiration}" >
<f:convertDateTime pattern="dd.MM.yyyy" />
</h:outputText>
</div> </div>
</div> </div>
</ui:repeat> </ui:repeat>
<div class="m-col-t-3"> <div class="m-col-t-3">
<h:outputLink value="payment-add.jsf"> <h:outputLink value="payment-add-credit.jsf">
<div class="m-block m-text-center"> <div class="m-block m-text-center">
<i class="fas fa-plus fa-4x"/> <i class="fas fa-plus fa-4x"/>
</div> </div>
@ -36,7 +39,9 @@
</h:panelGroup> </h:panelGroup>
<h3 class="m-text-center">PayPal</h3>
<h3 class="m-text-center m-text m-small">PayPal</h3>
<h:panelGroup layout="block" styleClass="m-row"> <h:panelGroup layout="block" styleClass="m-row">
<ui:repeat value="#{paymentBean.payPal}" var="payment"> <ui:repeat value="#{paymentBean.payPal}" var="payment">
<div class="m-col-t-3"> <div class="m-col-t-3">
@ -46,7 +51,7 @@
</div> </div>
</ui:repeat> </ui:repeat>
<div class="m-col-t-3"> <div class="m-col-t-3">
<h:outputLink value="payment-add.jsf"> <h:outputLink value="payment-add-paypal.jsf">
<div class="m-block m-text-center"> <div class="m-block m-text-center">
<i class="fas fa-plus fa-4x"/> <i class="fas fa-plus fa-4x"/>
</div> </div>

View File

@ -2,5 +2,5 @@
Server info: <%= application.getServerInfo() %><br> Server info: <%= application.getServerInfo() %><br>
Servlet version: <%= application.getMajorVersion() %>.<%= application.getMinorVersion() %><br> Servlet version: <%= application.getMajorVersion() %>.<%= application.getMinorVersion() %><br>
JSP version: <%= JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion() %><br> JSP version: <%= JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion() %><br>
JSF version: <%= FacesContext.class.getPackage().getImplementationVersion()%> JSF version: <%= FacesContext.class.getPackage().getImplementationVersion()%><br>
Java version: <%= System.getProperty("java.version") %><br> Java version: <%= System.getProperty("java.version") %><br>