-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement admin manage payments (#218)
* implement admin manage payments * add css * fix updating individual payments
- Loading branch information
Showing
8 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/main/java/net/novucs/esd/controllers/admin/AdminEditPaymentServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.novucs.esd.controllers.admin; | ||
|
||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.inject.Inject; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import net.novucs.esd.controllers.BaseServlet; | ||
import net.novucs.esd.model.Payment; | ||
import net.novucs.esd.orm.Dao; | ||
|
||
/** | ||
* The type Member edit claim servlet. | ||
*/ | ||
public class AdminEditPaymentServlet extends BaseServlet { | ||
|
||
private static final long serialVersionUID = 1426082847044519303L; | ||
|
||
@Inject | ||
private Dao<Payment> paymentDao; | ||
|
||
@Override | ||
public void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws IOException { | ||
int paymentId = Integer.parseInt(request.getParameter("paymentId")); | ||
try { | ||
Payment payment = paymentDao.selectById(paymentId); | ||
|
||
boolean verifyPayment = Boolean.parseBoolean(request.getParameter("verify-payment")); | ||
boolean declinePayment = Boolean.parseBoolean(request.getParameter("decline-payment")); | ||
boolean pendingPayment = Boolean.parseBoolean(request.getParameter("pending-payment")); | ||
if (verifyPayment) { | ||
payment.setApprovalStatus("VERIFIED"); | ||
} else if (declinePayment) { | ||
payment.setApprovalStatus("DECLINED"); | ||
} else if (pendingPayment) { | ||
payment.setApprovalStatus("PENDING"); | ||
} | ||
paymentDao.update(payment); | ||
response.sendRedirect("payments"); | ||
} catch (SQLException e) { | ||
Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.getMessage(), e); | ||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
@Override | ||
public String getServletInfo() { | ||
return "MemberEditClaimServlet"; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/net/novucs/esd/controllers/admin/AdminManagePaymentsServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package net.novucs.esd.controllers.admin; | ||
|
||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
import javax.inject.Inject; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import net.novucs.esd.controllers.BaseServlet; | ||
import net.novucs.esd.lifecycle.Session; | ||
import net.novucs.esd.model.Payment; | ||
import net.novucs.esd.orm.Dao; | ||
import net.novucs.esd.util.PaginationUtil; | ||
|
||
public class AdminManagePaymentsServlet extends BaseServlet { | ||
|
||
private static final long serialVersionUID = 1426082847044519303L; | ||
|
||
private static final String PAGE_SIZE_FILTER = "userPageSizeFilter"; | ||
|
||
private static final String PAYMENT_SEARCH_QUERY = "userSearchQuery"; | ||
|
||
@Inject | ||
private Dao<Payment> paymentDao; | ||
|
||
@Override | ||
public void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws IOException, ServletException { | ||
|
||
try { | ||
Session session = Session.fromRequest(request); | ||
String searchQuery = (String) session.getFilter(PAYMENT_SEARCH_QUERY); | ||
int pageSize = PaginationUtil.getPageSize(request, PAGE_SIZE_FILTER); | ||
double pageNumber = PaginationUtil.getPageNumber(request); | ||
|
||
List<Payment> payments; | ||
if (searchQuery == null) { | ||
payments = PaginationUtil | ||
.paginate(paymentDao, pageSize, pageNumber); | ||
} else { | ||
String[] columns = {"reference", "approval_status"}; | ||
payments = PaginationUtil.paginateWithSearch(paymentDao, pageSize, pageNumber, | ||
searchQuery, columns); | ||
} | ||
|
||
int max = PaginationUtil.getMaxPages(paymentDao, pageSize); | ||
PaginationUtil.setRequestAttributes(request, max, pageNumber, pageSize); | ||
request.setAttribute("payments", payments); | ||
session.removeFilter(PAYMENT_SEARCH_QUERY); | ||
|
||
super.forward(request, response, "Manage Payments", "admin.payments.manage"); | ||
} catch (SQLException e) { | ||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
@Override | ||
public void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws IOException { | ||
// Here we will set the filters in the users session. | ||
String searchQuery = request.getParameter("search-payment-query"); | ||
PaginationUtil.postPaginationWithSearch(request, PAGE_SIZE_FILTER, PAYMENT_SEARCH_QUERY, | ||
searchQuery); | ||
|
||
response.sendRedirect("payments"); | ||
} | ||
|
||
@Override | ||
public String getServletInfo() { | ||
return "ManagePaymentsServlet"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %> | ||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | ||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> | ||
<%@ taglib prefix="p" tagdir="/WEB-INF/tags/pagination" %> | ||
<script src="${pageContext.request.contextPath}/js/editpayment.js"></script> | ||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> | ||
|
||
<div> | ||
<div class="row no-bottom-margin"> | ||
<div class="col s3 input-field"> | ||
<label for="search-payment-query">Filter</label> | ||
<input type="text" id="search-payment-query" placeholder="Search payments..." | ||
name="search-payment-query" form="search-form"/> | ||
</div> | ||
<div class="col s2 input-field"> | ||
<form method="post" id="search-form"> | ||
<button type="submit" class="waves-effect btn waves-light xyz-button"> | ||
Search | ||
</button> | ||
</form> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col s12"> | ||
<div id="users-table"> | ||
<table class="highlight"> | ||
<tr> | ||
<th>Payment ID</th> | ||
<th>User ID</th> | ||
<th>Amount</th> | ||
<th>Reference</th> | ||
<th>Status</th> | ||
<th>Manage Status</th> | ||
</tr> | ||
<c:forEach var="payment" items="${payments}"> | ||
<tr> | ||
<td>${payment.id}</td> | ||
<td>${payment.userId}</td> | ||
<td>£ <fmt:formatNumber type="number" maxFractionDigits="2" value="${payment.getAmount()}"/></td> | ||
<td>${payment.stripeId != null ? "Card Payment" : payment.reference}</td> | ||
<td class="managed-icon"> | ||
<c:choose> | ||
<c:when test="${payment.approvalStatus == 'VERIFIED'}"> | ||
<i class="material-icons small"> | ||
check | ||
</i> | ||
</c:when> | ||
<c:when test="${payment.approvalStatus == 'PENDING'}"> | ||
<i class="material-icons small"> | ||
av_timer | ||
</i> | ||
</c:when> | ||
<c:when test="${payment.approvalStatus == 'DECLINED'}"> | ||
<i class="material-icons small"> | ||
pan_tool | ||
</i> | ||
</c:when> | ||
</c:choose> | ||
</td> | ||
<td> | ||
<div id="managePayment"> | ||
<form id="verifyPayment_${payment.id}" name="verifyPayment" method="post" action="editpayment"> | ||
<input | ||
type="hidden" | ||
id="verify-payment" | ||
name="verify-payment" | ||
value="${true}"/> | ||
<input | ||
type="hidden" | ||
id="payment-id" | ||
name="paymentId" | ||
value="${payment.id}"/> | ||
<a class="managed-icon" href="javascript: verifyPayment(${payment.id})"> | ||
<i class="material-icons small"> | ||
check | ||
</i> | ||
</a> | ||
</form> | ||
<form id="declinePayment_${payment.id}" name="declinePayment" method="post" action="editpayment"> | ||
<input | ||
type="hidden" | ||
id="decline-payment" | ||
name="decline-payment" | ||
value="${true}"/> | ||
<input | ||
type="hidden" | ||
id="payment-id" | ||
name="paymentId" | ||
value="${payment.id}"/> | ||
<a class="managed-icon" href="javascript: declinePayment(${payment.id})"> | ||
<i class="material-icons small"> | ||
pan_tool | ||
</i> | ||
</a> | ||
</form> | ||
<form id="pendingPayment_${payment.id}" name="pendingPayment" method="post" action="editpayment"> | ||
<input | ||
type="hidden" | ||
id="pending-payment" | ||
name="pending-payment" | ||
value="${true}"/> | ||
<input | ||
type="hidden" | ||
id="payment-id" | ||
name="paymentId" | ||
value="${payment.id}"/> | ||
<a href="javascript: pendingPayment(${payment.id})"> | ||
<i class="material-icons small"> | ||
av_timer | ||
</i> | ||
</a> | ||
</form> | ||
</div> | ||
</td> | ||
</tr> | ||
</c:forEach> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="row no-bottom-margin"> | ||
<div class="col s2 input-field"> | ||
<p:pagesize formName="filter-form" /> | ||
</div> | ||
<div class="col s1 input-field"> | ||
<form method="post" id="filter-form"> | ||
<button type="submit" class="waves-effect waves-light btn xyz-button" | ||
name="change-page-size"> | ||
Update | ||
</button> | ||
</form> | ||
</div> | ||
</div> | ||
<div class="row" class="pagination-control"> | ||
<div class="col s12 center-align"> | ||
<ul class="pagination"> | ||
<p:pagination /> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="${pageContext.request.contextPath}/js/pagination.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#managePayment{max-width:150px;display:flex;justify-content:space-evenly} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function verifyPayment(paymentId) { | ||
document.getElementById('verifyPayment_' + paymentId.toString()).submit(); | ||
} | ||
function declinePayment(paymentId) { | ||
document.getElementById('declinePayment_' + paymentId.toString()).submit(); | ||
} | ||
function pendingPayment(paymentId) { | ||
document.getElementById('pendingPayment_' + paymentId.toString()).submit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#managePayment{ | ||
max-width: 150px; | ||
display:flex; | ||
justify-content: space-evenly; | ||
} |