Skip to content

Commit

Permalink
Merge pull request #7 from 7SOATSquad30/fix/payments-integration
Browse files Browse the repository at this point in the history
fix: payments integration
  • Loading branch information
MuriloKakazu authored Dec 4, 2024
2 parents 8af60d3 + 7153356 commit 7096444
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package br.com.fiap.grupo30.fastfood.order_api.domain;

public enum PaymentStatus {
NOT_SUBMITTED,
PROCESSING,
PENDING,
REJECTED,
COLLECTED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Payment {
private Double amount;

public static Payment create() {
return new Payment(PaymentStatus.NOT_SUBMITTED, 0.0);
return new Payment(PaymentStatus.PENDING, 0.0);
}

public static Payment create(PaymentStatus status, Double amount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PaymentUseCase {
private String paymentsApiEndpoint;

public Payment findPaymentStateByOrderId(Long orderId) {
String uri = this.paymentsApiEndpoint + "/paytments/" + orderId;
String uri = this.paymentsApiEndpoint + "/payments/" + orderId;
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<PaymentDTO> response = restTemplate.getForEntity(uri, PaymentDTO.class);
PaymentDTO result = response.getBody();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import br.com.fiap.grupo30.fastfood.order_api.presentation.presenters.exceptions.DatabaseException;
import br.com.fiap.grupo30.fastfood.order_api.presentation.presenters.exceptions.InvalidCpfException;
import br.com.fiap.grupo30.fastfood.order_api.presentation.presenters.exceptions.InvalidOrderStatusException;
import br.com.fiap.grupo30.fastfood.order_api.presentation.presenters.exceptions.OrderPaymentIsStillPendingException;
import br.com.fiap.grupo30.fastfood.order_api.presentation.presenters.exceptions.ResourceNotFoundException;
import jakarta.servlet.http.HttpServletRequest;
import java.time.Instant;
Expand Down Expand Up @@ -155,4 +156,17 @@ public ResponseEntity<StandardError> invalidCpf(
err.setPath(request.getRequestURI());
return ResponseEntity.status(status).body(err);
}

@ExceptionHandler(OrderPaymentIsStillPendingException.class)
public ResponseEntity<StandardError> invalidCpf(
OrderPaymentIsStillPendingException e, HttpServletRequest request) {
HttpStatus status = HttpStatus.BAD_REQUEST;
StandardError err = new StandardError();
err.setTimestamp(Instant.now());
err.setStatus(status.value());
err.setError("Order payment is still pending");
err.setMessage(e.getMessage());
err.setPath(request.getRequestURI());
return ResponseEntity.status(status).body(err);
}
}

0 comments on commit 7096444

Please sign in to comment.