Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit b550214

Browse files
committed
fixing email order confirmations
1 parent 6826028 commit b550214

6 files changed

Lines changed: 60 additions & 22 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.zenfulcode.commercify.commercify.config;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.mail.javamail.JavaMailSender;
7+
import org.springframework.mail.javamail.JavaMailSenderImpl;
8+
9+
import java.util.Properties;
10+
11+
@Configuration
12+
public class MailConfig {
13+
@Value("${spring.mail.username}")
14+
private String username;
15+
@Value("${spring.mail.password}")
16+
private String password;
17+
@Value("${spring.mail.host}")
18+
private String host;
19+
@Value("${spring.mail.port}")
20+
private int port;
21+
22+
@Value("${spring.mail.properties.mail.smtp.starttls.enable}")
23+
private boolean tls = true;
24+
@Value("${spring.mail.properties.mail.smtp.auth}")
25+
private boolean auth = true;
26+
27+
@Bean
28+
public JavaMailSender getJavaMailSender() {
29+
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
30+
mailSender.setHost(host);
31+
mailSender.setPort(port);
32+
33+
mailSender.setUsername(username);
34+
mailSender.setPassword(password);
35+
36+
Properties props = mailSender.getJavaMailProperties();
37+
props.put("mail.transport.protocol", "smtp");
38+
props.put("mail.smtp.auth", auth);
39+
props.put("mail.smtp.starttls.enable", tls);
40+
props.put("mail.debug", "true");
41+
42+
return mailSender;
43+
}
44+
}

src/main/java/com/zenfulcode/commercify/commercify/integration/mobilepay/MobilePayController.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ public ResponseEntity<String> handleCallback(
3838
String contentSha256 = request.getHeader("x-ms-content-sha256");
3939
String authorization = request.getHeader("Authorization");
4040

41-
log.info("payload: {}", body);
42-
4341
try {
4442
// First authenticate the request with the raw string payload
4543
mobilePayService.authenticateRequest(date, contentSha256, authorization, body, request);
46-
log.info("Request authenticated");
44+
log.info("MP Webhook authenticated");
4745

4846
// Convert the string payload to WebhookPayload object
4947
ObjectMapper objectMapper = new ObjectMapper();

src/main/java/com/zenfulcode/commercify/commercify/integration/mobilepay/MobilePayService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ public void authenticateRequest(String date, String contentSha256, String author
283283
throw new SecurityException("Hash mismatch");
284284
}
285285

286-
log.info("Hash verified");
287-
288286
URI uri = new URI(request.getRequestURL().toString());
289287
String path = uri.getPath() + (uri.getQuery() != null ? "?" + uri.getQuery() : "");
290288

src/main/java/com/zenfulcode/commercify/commercify/service/email/EmailService.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,8 @@ public void sendNewOrderNotification(OrderDetailsDTO orderDetails) throws Messag
7676
OrderDTO order = orderDetails.getOrder();
7777

7878
Context context = new Context();
79-
Map<String, Object> orderContext = createOrderContext(orderDetails);
80-
orderContext.put("dashboardUrl", frontendUrl + "/admin/orders/" + order.getId());
81-
orderContext.put("customerEmail", orderDetails.getCustomerDetails().getEmail());
82-
orderContext.put("customerPhone", orderDetails.getCustomerDetails().getPhone());
83-
84-
context.setVariables(orderContext);
79+
context.setVariable("order", createOrderContext(orderDetails));
80+
context.setVariable("dashboardUrl", frontendUrl + "/admin/orders/" + order.getId());
8581

8682
String template = "new-order-notification-email";
8783
String subject = String.format("New Order Received - #%d", order.getId());
@@ -129,6 +125,8 @@ private Map<String, Object> createOrderContext(OrderDetailsDTO orderDetails) {
129125
orderContext.put("currency", order.getCurrency());
130126
orderContext.put("totalAmount", order.getTotalAmount());
131127
orderContext.put("customerName", orderDetails.getCustomerDetails().getFullName());
128+
orderContext.put("customerEmail", orderDetails.getCustomerDetails().getEmail());
129+
orderContext.put("customerPhone", orderDetails.getCustomerDetails().getPhone());
132130

133131
// Add shipping and billing addresses
134132
orderContext.put("shippingAddress", orderDetails.getShippingAddress());

src/main/resources/application-docker.properties

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ security.jwt.secret-key=${JWT_SECRET_KEY}
1717
logging.level.org.springframework=INFO
1818
stripe.secret-test-key=${STRIPE_SECRET_TEST_KEY}
1919
stripe.webhook-secret=${STRIPE_WEBHOOK_SECRET}
20-
admin.email=${ADMIN_EMAIL}
21-
admin.password=${ADMIN_PASSWORD}
2220
mobilepay.client-id=${MOBILEPAY_CLIENT_ID}
2321
mobilepay.merchant-id=${MOBILEPAY_MERCHANT_ID}
2422
mobilepay.client-secret=${MOBILEPAY_CLIENT_SECRET}
2523
mobilepay.subscription-key=${MOBILEPAY_SUBSCRIPTION_KEY}
2624
mobilepay.api-url=${MOBILEPAY_API_URL:https://api.vipps.no}
2725
mobilepay.system-name=${MOBILEPAY_SYSTEM_NAME:commercify}
2826
# Email Configuration
29-
spring.mail.host=smtp.gmail.com
30-
spring.mail.port=587
27+
spring.mail.host=${MAIL_HOST:smtp.gmail.com}
28+
spring.mail.port=${MAIL_PORT:587}
3129
spring.mail.username=${MAIL_USERNAME}
3230
spring.mail.password=${MAIL_PASSWORD}
33-
admin.order-email=${ORDER_EMAIL_RECEIVER}
3431
spring.mail.properties.mail.smtp.auth=true
3532
spring.mail.properties.mail.smtp.starttls.enable=true
33+
admin.order-email=${ORDER_EMAIL_RECEIVER}
3634
# Application Configuration
37-
app.frontend-url=${FRONTEND_URL:http://localhost:3000}
35+
app.frontend-url=${FRONTEND_URL:http://localhost:3000}
36+
admin.email=${ADMIN_EMAIL}
37+
admin.password=${ADMIN_PASSWORD}

src/main/resources/application.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ security.jwt.secret-key=${JWT_SECRET_KEY}
1414
security.jwt.expiration-time=3600000
1515
stripe.secret-test-key=${STRIPE_SECRET_TEST_KEY:undefined}
1616
stripe.webhook-secret=${STRIPE_WEBHOOK_SECRET:undefined}
17-
admin.email=admin@commercify.app
18-
admin.password=commercifyadmin123!
1917
mobilepay.client-id=${MOBILEPAY_CLIENT_ID}
2018
mobilepay.merchant-id=${MOBILEPAY_MERCHANT_ID}
2119
mobilepay.client-secret=${MOBILEPAY_CLIENT_SECRET}
2220
mobilepay.subscription-key=${MOBILEPAY_SUBSCRIPTION_KEY}
2321
mobilepay.api-url=${MOBILEPAY_API_URL:https://apitest.vipps.no}
2422
mobilepay.system-name=${MOBILEPAY_SYSTEM_NAME:commercify}
2523
# Email Configuration
26-
spring.mail.host=${MAIL_HOST:smtp.ethereal.email}
24+
spring.mail.host=${MAIL_HOST:smtp.gmail.com}
2725
spring.mail.port=${MAIL_PORT:587}
2826
spring.mail.username=${MAIL_USERNAME}
2927
spring.mail.password=${MAIL_PASSWORD}
30-
admin.order-email=${ORDER_EMAIL_RECEIVER}
3128
spring.mail.properties.mail.smtp.auth=true
3229
spring.mail.properties.mail.smtp.starttls.enable=true
30+
admin.order-email=${ORDER_EMAIL_RECEIVER}
3331
# Application Configuration
34-
app.frontend-url=${FRONTEND_URL:http://localhost:3000}
32+
app.frontend-url=${FRONTEND_URL:http://localhost:3000}
33+
admin.email=admin@commercify.app
34+
admin.password=commercifyadmin123!

0 commit comments

Comments
 (0)