feat(back-end and front-end) email
Some checks failed
Build and Deploy / test-backend (push) Successful in 25s
Build and Deploy / test-frontend (push) Successful in 1m0s
Build and Deploy / build-and-push (push) Successful in 44s
Build and Deploy / deploy (push) Successful in 9s
PR Checks / prettier-autofix (pull_request) Failing after 10s
PR Checks / security-sast (pull_request) Successful in 31s
PR Checks / test-backend (pull_request) Successful in 25s
PR Checks / test-frontend (pull_request) Successful in 1m7s
Some checks failed
Build and Deploy / test-backend (push) Successful in 25s
Build and Deploy / test-frontend (push) Successful in 1m0s
Build and Deploy / build-and-push (push) Successful in 44s
Build and Deploy / deploy (push) Successful in 9s
PR Checks / prettier-autofix (pull_request) Failing after 10s
PR Checks / security-sast (pull_request) Successful in 31s
PR Checks / test-backend (pull_request) Successful in 25s
PR Checks / test-frontend (pull_request) Successful in 1m7s
This commit is contained in:
@@ -101,13 +101,16 @@ public class AdminOrderController {
|
||||
|
||||
@PostMapping("/{orderId}/payments/confirm")
|
||||
@Transactional
|
||||
public ResponseEntity<OrderDto> confirmPayment(
|
||||
public ResponseEntity<OrderDto> updatePaymentMethod(
|
||||
@PathVariable UUID orderId,
|
||||
@RequestBody(required = false) Map<String, String> payload
|
||||
) {
|
||||
getOrderOrThrow(orderId);
|
||||
String method = payload != null ? payload.get("method") : null;
|
||||
paymentService.confirmPayment(orderId, method);
|
||||
if (method == null || method.isBlank()) {
|
||||
throw new ResponseStatusException(BAD_REQUEST, "Payment method is required");
|
||||
}
|
||||
paymentService.updatePaymentMethod(orderId, method);
|
||||
return ResponseEntity.ok(toOrderDto(getOrderOrThrow(orderId)));
|
||||
}
|
||||
|
||||
|
||||
@@ -98,4 +98,20 @@ public class PaymentService {
|
||||
|
||||
return payment;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Payment updatePaymentMethod(UUID orderId, String method) {
|
||||
if (method == null || method.isBlank()) {
|
||||
throw new IllegalArgumentException("Payment method is required");
|
||||
}
|
||||
|
||||
Order order = orderRepo.findById(orderId)
|
||||
.orElseThrow(() -> new RuntimeException("Order not found with id " + orderId));
|
||||
|
||||
Payment payment = paymentRepo.findByOrder_Id(orderId)
|
||||
.orElseGet(() -> getOrCreatePaymentForOrder(order, "OTHER"));
|
||||
|
||||
payment.setMethod(method.trim().toUpperCase());
|
||||
return paymentRepo.save(payment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,12 +163,10 @@
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
(click)="confirmPayment()"
|
||||
[disabled]="
|
||||
confirmingPayment || selectedOrder.paymentStatus === 'COMPLETED'
|
||||
"
|
||||
(click)="updatePaymentMethod()"
|
||||
[disabled]="confirmingPayment"
|
||||
>
|
||||
{{ confirmingPayment ? "Invio..." : "Conferma pagamento" }}
|
||||
{{ confirmingPayment ? "Salvataggio..." : "Cambia metodo pagamento" }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -132,14 +132,14 @@ export class AdminDashboardComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
confirmPayment(): void {
|
||||
updatePaymentMethod(): void {
|
||||
if (!this.selectedOrder || this.confirmingPayment) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.confirmingPayment = true;
|
||||
this.adminOrdersService
|
||||
.confirmPayment(this.selectedOrder.id, this.selectedPaymentMethod)
|
||||
.updatePaymentMethod(this.selectedOrder.id, this.selectedPaymentMethod)
|
||||
.subscribe({
|
||||
next: (updatedOrder) => {
|
||||
this.confirmingPayment = false;
|
||||
@@ -147,7 +147,7 @@ export class AdminDashboardComponent implements OnInit {
|
||||
},
|
||||
error: () => {
|
||||
this.confirmingPayment = false;
|
||||
this.errorMessage = 'Conferma pagamento non riuscita.';
|
||||
this.errorMessage = 'Aggiornamento metodo pagamento non riuscito.';
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export class AdminOrdersService {
|
||||
});
|
||||
}
|
||||
|
||||
confirmPayment(orderId: string, method: string): Observable<AdminOrder> {
|
||||
updatePaymentMethod(orderId: string, method: string): Observable<AdminOrder> {
|
||||
return this.http.post<AdminOrder>(
|
||||
`${this.baseUrl}/${orderId}/payments/confirm`,
|
||||
{ method },
|
||||
|
||||
Reference in New Issue
Block a user