Integrate simple payment handling with WebClient and persist results
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
package _11.asktpk.artisanconnectbackend.controller;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.dto.ClientDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.OrderDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.OrderStatusDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.*;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Order;
|
||||
import _11.asktpk.artisanconnectbackend.service.ClientService;
|
||||
import _11.asktpk.artisanconnectbackend.service.OrderService;
|
||||
import _11.asktpk.artisanconnectbackend.service.PaymentService;
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -14,9 +15,11 @@ import org.springframework.web.bind.annotation.*;
|
||||
public class OrderController {
|
||||
|
||||
private final OrderService orderService;
|
||||
private final PaymentService paymentService;
|
||||
|
||||
public OrderController(OrderService orderService) {
|
||||
public OrderController(OrderService orderService, PaymentService paymentService) {
|
||||
this.orderService = orderService;
|
||||
this.paymentService = paymentService;
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
@@ -28,4 +31,21 @@ public class OrderController {
|
||||
public ResponseEntity changeStatus(@RequestBody OrderStatusDTO orderStatusDTO) {
|
||||
return new ResponseEntity<>(orderService.changeOrderStatus(orderStatusDTO.getId(),orderStatusDTO.getStatus()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/token")
|
||||
public ResponseEntity<?> fetchToken() {
|
||||
Order order = orderService.getOrderById(1L);
|
||||
OAuthPaymentResponseDTO authPaymentDTO= paymentService.getOAuthToken();
|
||||
TransactionPaymentRequestDTO.Payer payer = new TransactionPaymentRequestDTO.Payer(
|
||||
"patryk@test.pl", "Patryk Test");
|
||||
|
||||
String paymentDescription = order.getOrderType() == Enums.OrderType.ACTIVATION ? "Aktywacja ogłoszenia" : "Podbicie ogłoszenia";
|
||||
paymentDescription += order.getNotice().getTitle();
|
||||
TransactionPaymentRequestDTO request = new TransactionPaymentRequestDTO(
|
||||
order.getAmount(), paymentDescription, payer);
|
||||
String response = paymentService.createTransaction(order,authPaymentDTO.getAccess_token(), request);
|
||||
System.out.println(response);
|
||||
|
||||
return ResponseEntity.ok(authPaymentDTO.getAccess_token());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user