Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add walletpasses to email #448

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,17 @@ public byte[] getApplePass(Ticket ticket) throws TicketPassFailedException {


Map<String, String> 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();
Expand Down
Loading