Skip to content

Commit

Permalink
Minor mail and template fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
everoddandeven committed Dec 23, 2024
1 parent b0218ab commit a70bb0b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/main/java/monero/ecwid/server/GatewayController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import monero.ecwid.server.config.ServerConfigFileReader;
import monero.ecwid.server.error.PaymentRequestAlreadyExistsException;
import monero.ecwid.server.repository.PaymentRequestEntity;
import monero.ecwid.server.service.MailService;
import monero.ecwid.server.service.PaymentRequestService;

import org.springframework.ui.Model;
Expand All @@ -32,8 +33,12 @@ public class GatewayController {
@Autowired
private final PaymentRequestService paymentRequestService;

public GatewayController(PaymentRequestService paymentRequestService) {
@Autowired
private final MailService mailService;

public GatewayController(PaymentRequestService paymentRequestService, MailService mailService) {
this.paymentRequestService = paymentRequestService;
this.mailService = mailService;
}

private static ServerConfig getServerConfig() {
Expand Down Expand Up @@ -77,6 +82,13 @@ private String processPaymentRequest(EcwidPaymentData paymentData, Model model)

try {
request = paymentRequestService.newPaymentRequest(paymentData);

try {
mailService.sendInvoince(request);
}
catch (Exception e) {
logger.warn("Could not send invoice email");
}
}
catch (Exception e) {
if (e instanceof PaymentRequestAlreadyExistsException) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/monero/ecwid/server/service/MailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static abstract class Template {
""";

private static final String Invoice = """
<h4>Monero Payment Invoince</h4>
<h4>Monero Payment Invoice</h4>
<br>
<strong>Order ID:</strong> {txId}
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/templates/payment.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h4 class="card-title"><i class="bi bi-cash-coin"></i>&nbsp;Order Amount</h4>

<h4 class="card-title"><i class="bi bi-info-circle"></i>&nbsp;Payment Status</h4>
<div id="paidBody" class="alert alert-success text-center" role="alert" hidden>
<i class="bi bi-check-circle"></i> Successfully paid <span th:text="${amountDeposited}">amount</span>
<i class="bi bi-check-circle"></i> Successfully paid <span id="amountDeposited" th:text="${amountDeposited}">amount</span>
</div>
<div id="cancelledBody" class="alert alert-danger text-center" role="alert" hidden>
<i class="bi bi-exclamation-triangle"></i> Payment was cancelled
Expand Down Expand Up @@ -169,6 +169,10 @@ <h4 class="card-title"><i class="bi bi-wallet2"></i>&nbsp;Payment Instructions</
element.textContent = content;
}

function setAmountDeposited(amount) {
setElementText('amountDeposited', `${amount / 1e12} XMR`);
}

function setConfirmations(confirmations, confirmationsRequired) {
const content = `${confirmations}/${confirmationsRequired}`;
setElementText('confirmations', content);
Expand Down Expand Up @@ -241,6 +245,8 @@ <h4 class="card-title"><i class="bi bi-wallet2"></i>&nbsp;Payment Instructions</
if (payment.status === 'PAID') {
setTimeout(() => window.location.replace(getReturnUrl()), 6000);
hideElement('unpaidBody');
hideElement('waitingBody');
setAmountDeposited(payment.amountDeposited);
showElement('paidBody');
clearInterval(refreshInterval);
return;
Expand Down

0 comments on commit a70bb0b

Please sign in to comment.