diff --git a/src/main/java/ch/wisv/events/core/service/mail/MailServiceImpl.java b/src/main/java/ch/wisv/events/core/service/mail/MailServiceImpl.java index 8c137c53..4636a87c 100644 --- a/src/main/java/ch/wisv/events/core/service/mail/MailServiceImpl.java +++ b/src/main/java/ch/wisv/events/core/service/mail/MailServiceImpl.java @@ -15,6 +15,7 @@ import javax.mail.internet.MimeMessage; import javax.validation.constraints.NotNull; +import ch.wisv.events.core.service.ticket.TicketService; import ch.wisv.events.core.util.QrCode; import com.google.zxing.WriterException; import org.springframework.beans.factory.annotation.Autowired; @@ -45,6 +46,9 @@ public class MailServiceImpl implements MailService { /** SpringTemplateEngine. */ private final SpringTemplateEngine templateEngine; + /** TicketService. */ + private final TicketService ticketService; + /** Link to GTC. */ @Value("${links.gtc}") @NotNull @@ -57,9 +61,10 @@ public class MailServiceImpl implements MailService { * @param templateEngine of type templateEngine */ @Autowired - public MailServiceImpl(JavaMailSender mailSender, SpringTemplateEngine templateEngine) { + public MailServiceImpl(JavaMailSender mailSender, SpringTemplateEngine templateEngine, TicketService ticketService) { this.mailSender = mailSender; this.templateEngine = templateEngine; + this.ticketService = ticketService; } /** @@ -181,6 +186,14 @@ private void sendMailWithContent(String recipientEmail, String subject, String c BufferedImage qrCode = QrCode.generateQrCode(uniqueCode); byte[] bytes = QrCode.bufferedImageToBytes(qrCode); message.addInline("ch-" + uniqueCode + ".png", new ByteArrayResource(bytes), "image/png"); + + // Get wallet passes + try { + byte[] walletPass = ticketService.getApplePass(ticket); + message.addAttachment("ch-" + uniqueCode + ".pkpass", new ByteArrayResource(walletPass), "application/vnd.apple.pkpass"); + } catch (Exception e) { + // Do nothing + } } } } diff --git a/src/main/java/ch/wisv/events/core/service/ticket/TicketServiceImpl.java b/src/main/java/ch/wisv/events/core/service/ticket/TicketServiceImpl.java index 98e9cbf3..ea81ac2a 100644 --- a/src/main/java/ch/wisv/events/core/service/ticket/TicketServiceImpl.java +++ b/src/main/java/ch/wisv/events/core/service/ticket/TicketServiceImpl.java @@ -269,16 +269,17 @@ public byte[] getApplePass(Ticket ticket) throws TicketPassFailedException { Map params = new HashMap<>(); - params.put("name", ticket.getProduct().getTitle()); + params.put("title", ticket.getProduct().getTitle()); params.put("description", ticket.getProduct().getDescription()); - // Format date as yyyy-MM-dd params.put("date", ticket.getProduct().getEvent().getStart().format(DateTimeFormatter.ISO_LOCAL_DATE)); - params.put("time", ticket.getProduct().getEvent().getStart().format(DateTimeFormatter.ISO_LOCAL_TIME)); + params.put("time", ticket.getProduct().getEvent().getStart().format(DateTimeFormatter.ofPattern("HH:mm"))); params.put("location", ticket.getProduct().getEvent().getLocation()); + params.put("name", ticket.getOwner().getName()); params.put("code", ticket.getUniqueCode()); return restTemplate.getForObject(passesLink + - "?name={name}&description={description}&date={date}&time={time}&location={location}&code={code}" + "?title={title}&description={description}&date={date}&time={time}" + + "&location={location}&code={code}&name={name}" , byte[].class, params); } catch (Exception e) { e.printStackTrace();