Skip to content

Commit

Permalink
feat: allow passes on anonymous checkouts
Browse files Browse the repository at this point in the history
  • Loading branch information
dsluijk committed Jul 28, 2024
1 parent 46b60aa commit eac2ea1
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public String getPass(Ticket ticket) throws TicketPassFailedException {
}

Product product = ticket.getProduct();
EventTicketClass newClass = this.createClass(product);
EventTicketObject newObject = this.createObject(ticket);
EventTicketClass ticketClass = this.createClass(product);
EventTicketObject ticketObject = this.createObject(ticket);

HashMap<String, Object> claims = new HashMap<String, Object>();
claims.put("iss", credentials.getClientEmail());
Expand All @@ -79,8 +79,8 @@ public String getPass(Ticket ticket) throws TicketPassFailedException {
claims.put("iat", Instant.now().getEpochSecond());

HashMap<String, Object> payload = new HashMap<String, Object>();
payload.put("eventTicketClasses", List.of(newClass));
payload.put("eventTicketObjects", List.of(newObject));
payload.put("eventTicketClasses", List.of(ticketClass));
payload.put("eventTicketObjects", List.of(ticketObject));
claims.put("payload", payload);

Algorithm algorithm = Algorithm.RSA256(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package ch.wisv.events.webshop.controller;

import ch.wisv.events.core.exception.normal.TicketNotFoundException;
import ch.wisv.events.core.exception.normal.TicketPassFailedException;
import ch.wisv.events.core.model.customer.Customer;
import ch.wisv.events.core.model.ticket.Ticket;
import ch.wisv.events.core.service.auth.AuthenticationService;
import ch.wisv.events.core.service.order.OrderService;
import ch.wisv.events.core.service.ticket.TicketService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("/passes")
public class WebshopPassesController extends WebshopController {
/** TicketService. */
private final TicketService ticketService;

/**
* @param authenticationService of type AuthenticationService
* @param orderService of type OrderService
* @param ticketService of type TicketService
*/
public WebshopPassesController(
AuthenticationService authenticationService,
OrderService orderService,
TicketService ticketService
) {
super(orderService, authenticationService);
this.ticketService = ticketService;
}

/**
* Get wallet pass of ticket.
*/
@GetMapping("/apple/{key}/wallet.pkpass")
public void getApplePass(HttpServletResponse response, @PathVariable String key) throws IOException {
Customer customer = authenticationService.getCurrentCustomer();

try {
Ticket ticket = ticketService.getByKey(key);

if (!ticket.owner.equals(customer) && ticket.owner.isVerifiedChMember()) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}

byte[] bytes = ticketService.getApplePass(ticket);

response.setContentType("application/vnd.apple.pkpass");
response.setContentLength(bytes.length);
response.getOutputStream().write(bytes);
response.getOutputStream().close();
}
catch (TicketNotFoundException e) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
catch (TicketPassFailedException | IOException e) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}

/**
* Redirect the user to the Google Pass URL.
*/
@GetMapping("/google/{key}")
public void getGooglePass(HttpServletResponse response, @PathVariable String key) throws IOException {
Customer customer = authenticationService.getCurrentCustomer();

try {
Ticket ticket = ticketService.getByKey(key);

if (!ticket.owner.equals(customer) && ticket.owner.isVerifiedChMember()) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}

String link = ticketService.getGooglePass(ticket);
response.sendRedirect(link);
}
catch (TicketNotFoundException e) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
catch (TicketPassFailedException | IOException e) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ch.wisv.events.core.exception.normal.CustomerNotFoundException;
import ch.wisv.events.core.exception.normal.TicketNotFoundException;
import ch.wisv.events.core.exception.normal.TicketNotTransferableException;
import ch.wisv.events.core.exception.normal.TicketPassFailedException;
import ch.wisv.events.core.model.customer.Customer;
import ch.wisv.events.core.model.ticket.Ticket;
import ch.wisv.events.core.service.auth.AuthenticationService;
Expand Down Expand Up @@ -169,58 +168,4 @@ public void getQrCode(HttpServletResponse response, @PathVariable String key) th
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}

/**
* Get wallet pass of ticket.
*/
@GetMapping("/{key}/wallet.pkpass")
public void getApplePass(HttpServletResponse response, @PathVariable String key) throws IOException {
Customer customer = authenticationService.getCurrentCustomer();
try {
Ticket ticket = ticketService.getByKey(key);

if (!ticket.owner.equals(customer)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}

byte[] bytes = ticketService.getApplePass(ticket);

response.setContentType("application/vnd.apple.pkpass");
response.setContentLength(bytes.length);
response.getOutputStream().write(bytes);
response.getOutputStream().close();
}
catch (TicketNotFoundException e) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
catch (TicketPassFailedException | IOException e) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}

/**
* Redirect the user to the Google Pass URL.
*/
@GetMapping("/{key}/googlewallet")
public void getGooglePass(HttpServletResponse response, @PathVariable String key) throws IOException {
Customer customer = authenticationService.getCurrentCustomer();
try {
Ticket ticket = ticketService.getByKey(key);

if (!ticket.owner.equals(customer)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}

String link = ticketService.getGooglePass(ticket);
response.sendRedirect(link);
}
catch (TicketNotFoundException e) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
catch (TicketPassFailedException | IOException e) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
}
4 changes: 2 additions & 2 deletions src/main/resources/templates/mail/order.html
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,14 @@ <h3>Ticket overview</h3>
style="font-family: Arial, sans-serif;color: #5e5e5e;font-size: 16px;text-align: left;border-collapse: collapse;background-color: #f3f3f3;padding: 5px; text-align: center;"
>
<a
th:href="${origin + '/tickets/' + ticket.getKey() + '/wallet.pkpass'}"
th:href="${origin + '/passes/apple/' + ticket.getKey() + '/wallet.pkpass'}"
target="_blank"
style="display: block; padding: 0 20px;"
>
<img src="cid:apple-wallet.svg" class="apple-wallet" alt="Add to Apple Wallet" style="height: 40px;">
</a>
<a
th:href="${origin + '/tickets/'+ ticket.getKey() + '/googlewallet'}"
th:href="${origin + '/passes/google/'+ ticket.getKey()}"
target="_blank"
style="display: block; padding: 0 20px;"
>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/templates/webshop/overview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ <h6 class="card-header">Open tickets</h6>
<div th:if="${ticket.getUniqueCode().length() != 6}" class="modal-body text-center">
<img class="img-fluid" th:src="@{'/tickets/'+ ${ticket.getKey()}+'/qrcode.png'}">
<div class="col">
<a th:href="@{'/tickets/'+ ${ticket.getKey()}+'/wallet.pkpass'}"
<a th:href="@{'/passes/apple/'+ ${ticket.getKey()}+'/wallet.pkpass'}"
target="_blank">
<img th:src="@{/images/apple-wallet.svg}" class="apple-wallet" alt="Add to Apple Wallet" style="height: 40px;">
</a>
<a th:href="@{'/tickets/'+ ${ticket.getKey()}+'/googlewallet'}"
<a th:href="@{'/passes/google/' + ${ticket.getKey()}}"
target="_blank">
<img th:src="@{/images/google-wallet.svg}" class="google-wallet" alt="Add to Google Wallet" style="height: 40px;">
</a>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/templates/webshop/return/success.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ <h4 class="display-4">Thanks for ordering!</h4>
style="vertical-align: middle;"
></td>
<td style="text-align: center;">
<a th:href="@{'/tickets/'+ ${ticket.getKey()}+'/wallet.pkpass'}" target="_blank">
<a th:href="@{'/passes/apple/'+ ${ticket.getKey()}+'/wallet.pkpass'}" target="_blank">
<img th:src="@{/images/apple-wallet.svg}" class="apple-wallet" alt="Add to Apple Wallet" style="height: 35px; max-width: 20vw;">
</a>
</td>
<td style="text-align: center;">
<a th:href="@{'/tickets/'+ ${ticket.getKey()}+'/googlewallet'}" target="_blank">
<a th:href="@{'/passes/google/'+ ${ticket.getKey()}}" target="_blank">
<img th:src="@{/images/google-wallet.svg}" class="google-wallet" alt="Add to Google Wallet" style="height: 35px; max-width: 25vw;">
</a>
</td>
Expand Down

0 comments on commit eac2ea1

Please sign in to comment.