Compare commits
10 Commits
3b9b0769d1
...
MailSender
| Author | SHA1 | Date | |
|---|---|---|---|
| 62a5ad1bc6 | |||
| 8ea5d84779 | |||
| a09603f8cb | |||
| 45c607060a | |||
| 0b85fed4b8 | |||
| d2163e1601 | |||
| f4c8177270 | |||
|
|
9b64dc8da8 | ||
|
|
12cb37127b | ||
|
|
281cc627de |
5
pom.xml
5
pom.xml
@@ -77,6 +77,11 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-mail</artifactId>
|
||||||
|
<version>3.3.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package _11.asktpk.artisanconnectbackend.controller;
|
||||||
|
import _11.asktpk.artisanconnectbackend.dto.EmailDTO;
|
||||||
|
import _11.asktpk.artisanconnectbackend.service.EmailService;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/email")
|
||||||
|
public class EmailController {
|
||||||
|
private final EmailService emailService;
|
||||||
|
|
||||||
|
public EmailController(EmailService emailService) {
|
||||||
|
this.emailService = emailService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/send")
|
||||||
|
public ResponseEntity<String> sendEmail(@RequestBody EmailDTO email) {
|
||||||
|
try {
|
||||||
|
emailService.sendEmail(email);
|
||||||
|
return ResponseEntity.ok("Email wysłany pomyślnie");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.status(500).body("Błąd podczas wysyłania emaila");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,9 +43,11 @@ public class OrderController {
|
|||||||
paymentDescription += order.getNotice().getTitle();
|
paymentDescription += order.getNotice().getTitle();
|
||||||
TransactionPaymentRequestDTO request = new TransactionPaymentRequestDTO(
|
TransactionPaymentRequestDTO request = new TransactionPaymentRequestDTO(
|
||||||
order.getAmount(), paymentDescription, payer);
|
order.getAmount(), paymentDescription, payer);
|
||||||
|
|
||||||
String response = paymentService.createTransaction(order,authPaymentDTO.getAccess_token(), request);
|
String response = paymentService.createTransaction(order,authPaymentDTO.getAccess_token(), request);
|
||||||
System.out.println(response);
|
System.out.println(response);
|
||||||
|
System.out.println(request);
|
||||||
|
|
||||||
return ResponseEntity.ok(authPaymentDTO.getAccess_token());
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package _11.asktpk.artisanconnectbackend.controller;
|
||||||
|
|
||||||
|
import _11.asktpk.artisanconnectbackend.entities.Notice;
|
||||||
|
import _11.asktpk.artisanconnectbackend.entities.Order;
|
||||||
|
import _11.asktpk.artisanconnectbackend.entities.Payment;
|
||||||
|
import _11.asktpk.artisanconnectbackend.repository.PaymentRepository;
|
||||||
|
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.util.DigestUtils;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/payments")
|
||||||
|
public class PaymentController {
|
||||||
|
|
||||||
|
@Value("${tpay.securityCode}")
|
||||||
|
private String sellerSecurityCode;
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(PaymentController.class);
|
||||||
|
|
||||||
|
private final PaymentRepository paymentRepository;
|
||||||
|
|
||||||
|
public PaymentController(PaymentRepository paymentRepository) {
|
||||||
|
this.paymentRepository = paymentRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/notification", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||||
|
public ResponseEntity<String> handleTpayNotification(@RequestParam Map<String, String> params) {
|
||||||
|
log.info("=== ODEBRANO NOTYFIKACJĘ Tpay ===");
|
||||||
|
log.info("Parametry:\n{}", paramsToLogString(params));
|
||||||
|
|
||||||
|
String id = params.get("id");
|
||||||
|
String trId = params.get("tr_id");
|
||||||
|
String trAmount = params.get("tr_amount");
|
||||||
|
String trCrc = params.get("tr_crc");
|
||||||
|
String md5sum = params.get("md5sum");
|
||||||
|
String trStatus = params.get("tr_status");
|
||||||
|
|
||||||
|
String expectedMd5 = DigestUtils.md5DigestAsHex(
|
||||||
|
(id + trId + trAmount + trCrc + sellerSecurityCode).getBytes()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!expectedMd5.equals(md5sum)) {
|
||||||
|
log.warn("❌ Błędna suma kontrolna! Otrzymano: {}, Oczekiwano: {}", md5sum, expectedMd5);
|
||||||
|
return ResponseEntity.status(400).body("INVALID CHECKSUM");
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Payment> optionalPayment = paymentRepository.findByTransactionId(trId);
|
||||||
|
if (optionalPayment.isPresent()) {
|
||||||
|
Payment payment = optionalPayment.get();
|
||||||
|
|
||||||
|
if ("true".equalsIgnoreCase(trStatus) || "PAID".equalsIgnoreCase(trStatus)) {
|
||||||
|
log.info("✅ Transakcja opłacona: tr_id={}, kwota={}", trId, params.get("tr_paid"));
|
||||||
|
payment.setStatus(Enums.PaymentStatus.CORRECT);
|
||||||
|
|
||||||
|
if (payment.getOrder() != null) {
|
||||||
|
Order order = payment.getOrder();
|
||||||
|
order.setStatus(Enums.OrderStatus.COMPLETED);
|
||||||
|
Notice notice = order.getNotice();
|
||||||
|
if (order.getOrderType() == Enums.OrderType.ACTIVATION) {
|
||||||
|
notice.setStatus(Enums.Status.ACTIVE);
|
||||||
|
} else if (order.getOrderType() == Enums.OrderType.BOOST) {
|
||||||
|
notice.setPublishDate(LocalDateTime.now());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if ("false".equalsIgnoreCase(trStatus)) {
|
||||||
|
log.warn("❌ Transakcja nieudana: {}", trId);
|
||||||
|
payment.setStatus(Enums.PaymentStatus.INCORRECT);
|
||||||
|
|
||||||
|
if (payment.getOrder() != null) {
|
||||||
|
payment.getOrder().setStatus(Enums.OrderStatus.CANCELLED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
paymentRepository.save(payment);
|
||||||
|
} else {
|
||||||
|
log.warn("⚠️ Brak płatności o tr_id={}", trId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.ok("TRUE");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String paramsToLogString(Map<String, String> params) {
|
||||||
|
return params.entrySet().stream()
|
||||||
|
.map(e -> e.getKey() + " = " + e.getValue())
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,10 +24,10 @@ public class WishlistController {
|
|||||||
this.noticeService = noticeService;
|
this.noticeService = noticeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/toggle")
|
@PostMapping("/toggle/{noticeId}")
|
||||||
public ResponseEntity<RequestResponseDTO> toggleWishlist(@RequestBody WishlistDTO wishlistDTO) {
|
public ResponseEntity<RequestResponseDTO> toggleWishlist(@PathVariable Long noticeId) {
|
||||||
Long noticeId = wishlistDTO.getNoticeId();
|
|
||||||
Long clientId = wishlistDTO.getClientId();
|
Long clientId = 1L;
|
||||||
NoticeDTO noticeDTO = noticeService.getNoticeById(noticeId);
|
NoticeDTO noticeDTO = noticeService.getNoticeById(noticeId);
|
||||||
if (noticeDTO == null) {
|
if (noticeDTO == null) {
|
||||||
return ResponseEntity.badRequest().body(new RequestResponseDTO("Notice not found"));
|
return ResponseEntity.badRequest().body(new RequestResponseDTO("Notice not found"));
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package _11.asktpk.artisanconnectbackend.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import jakarta.validation.constraints.Email;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class EmailDTO {
|
||||||
|
@Email(message = "Podaj poprawny adres email")
|
||||||
|
@NotBlank(message = "Adres email nie może być pusty")
|
||||||
|
private String to;
|
||||||
|
|
||||||
|
@NotBlank(message = "Temat nie może być pusty")
|
||||||
|
private String subject;
|
||||||
|
|
||||||
|
@NotBlank(message = "Treść nie może być pusta")
|
||||||
|
private String body;
|
||||||
|
}
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.dto;
|
package _11.asktpk.artisanconnectbackend.dto;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ToString
|
||||||
public class TransactionPaymentRequestDTO {
|
public class TransactionPaymentRequestDTO {
|
||||||
private double amount;
|
private double amount;
|
||||||
private String description;
|
private String description;
|
||||||
|
|||||||
@@ -54,6 +54,27 @@ import lombok.Setter;
|
|||||||
private double amountPaid;
|
private double amountPaid;
|
||||||
private DateInfo date;
|
private DateInfo date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "YourClassName{" +
|
||||||
|
"result='" + result + '\'' +
|
||||||
|
", requestId='" + requestId + '\'' +
|
||||||
|
", transactionId='" + transactionId + '\'' +
|
||||||
|
", title='" + title + '\'' +
|
||||||
|
", posId='" + posId + '\'' +
|
||||||
|
", status='" + status + '\'' +
|
||||||
|
", date=" + date +
|
||||||
|
", amount=" + amount +
|
||||||
|
", currency='" + currency + '\'' +
|
||||||
|
", description='" + description + '\'' +
|
||||||
|
", hiddenDescription='" + hiddenDescription + '\'' +
|
||||||
|
", payer=" + payer +
|
||||||
|
", payments=" + payments +
|
||||||
|
", transactionPaymentUrl='" + transactionPaymentUrl + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import _11.asktpk.artisanconnectbackend.entities.Payment;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
||||||
|
Optional<Payment> findByTransactionId(String transactionId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package _11.asktpk.artisanconnectbackend.service;
|
||||||
|
|
||||||
|
import _11.asktpk.artisanconnectbackend.dto.EmailDTO;
|
||||||
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EmailService {
|
||||||
|
private final JavaMailSender mailSender;
|
||||||
|
|
||||||
|
public EmailService(JavaMailSender mailSender) {
|
||||||
|
this.mailSender = mailSender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEmail(EmailDTO email) {
|
||||||
|
SimpleMailMessage message = new SimpleMailMessage();
|
||||||
|
message.setTo(email.getTo());
|
||||||
|
message.setSubject(email.getSubject());
|
||||||
|
message.setText(email.getBody());
|
||||||
|
message.setFrom("patryk.kania001@gmail.com");
|
||||||
|
mailSender.send(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,10 +69,12 @@ public class PaymentService {
|
|||||||
|
|
||||||
payment.setStatus(Enums.PaymentStatus.PENDING);
|
payment.setStatus(Enums.PaymentStatus.PENDING);
|
||||||
|
|
||||||
payment.setTransactionId(response.getTransactionId());
|
payment.setTransactionId(response.getTitle());
|
||||||
payment.setTransactionPaymentUrl(response.getTransactionPaymentUrl());
|
payment.setTransactionPaymentUrl(response.getTransactionPaymentUrl());
|
||||||
paymentRepository.save(payment);
|
paymentRepository.save(payment);
|
||||||
|
|
||||||
|
System.out.println(response);
|
||||||
|
|
||||||
return response.getTransactionPaymentUrl();
|
return response.getTransactionPaymentUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,18 @@ file.upload-dir=/Users/andsol/Desktop/uploads
|
|||||||
spring.servlet.multipart.max-file-size=10MB
|
spring.servlet.multipart.max-file-size=10MB
|
||||||
spring.servlet.multipart.max-request-size=10MB
|
spring.servlet.multipart.max-request-size=10MB
|
||||||
|
|
||||||
|
spring.mail.host=smtp.gmail.com
|
||||||
|
spring.mail.port=587
|
||||||
|
spring.mail.username=patryk.kania001@gmail.com
|
||||||
|
spring.mail.password=pmyd ylwg mbsn hcpp
|
||||||
|
spring.mail.properties.mail.smtp.auth=true
|
||||||
|
spring.mail.properties.mail.smtp.starttls.enable=true
|
||||||
|
|
||||||
tpay.clientId = 01JQKC048X62ST9V59HNRSXD92-01JQKC2CQHPYXQFSFX8BKC24BX
|
tpay.clientId = 01JQKC048X62ST9V59HNRSXD92-01JQKC2CQHPYXQFSFX8BKC24BX
|
||||||
tpay.clientSecret = 44898642be53381cdcc47f3e44bf5a15e592f5d270fc3a6cf6fb81a8b8ebffb9
|
tpay.clientSecret = 44898642be53381cdcc47f3e44bf5a15e592f5d270fc3a6cf6fb81a8b8ebffb9
|
||||||
tpay.authUrl = https://openapi.sandbox.tpay.com/oauth/auth
|
tpay.authUrl = https://openapi.sandbox.tpay.com/oauth/auth
|
||||||
tpay.transactionUrl = https://openapi.sandbox.tpay.com/transactions
|
tpay.transactionUrl = https://openapi.sandbox.tpay.com/transactions
|
||||||
|
tpay.securityCode = )IY7E)YSM!A)Q6O-GN#U7U_33s9qObk8
|
||||||
|
|
||||||
|
logging.file.name=logs/payment-notifications.log
|
||||||
|
logging.level.TpayLogger=INFO
|
||||||
|
|||||||
Reference in New Issue
Block a user