dev #20
@@ -101,13 +101,16 @@ public class AdminOrderController {
|
|||||||
|
|
||||||
@PostMapping("/{orderId}/payments/confirm")
|
@PostMapping("/{orderId}/payments/confirm")
|
||||||
@Transactional
|
@Transactional
|
||||||
public ResponseEntity<OrderDto> confirmPayment(
|
public ResponseEntity<OrderDto> updatePaymentMethod(
|
||||||
@PathVariable UUID orderId,
|
@PathVariable UUID orderId,
|
||||||
@RequestBody(required = false) Map<String, String> payload
|
@RequestBody(required = false) Map<String, String> payload
|
||||||
) {
|
) {
|
||||||
getOrderOrThrow(orderId);
|
getOrderOrThrow(orderId);
|
||||||
String method = payload != null ? payload.get("method") : null;
|
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)));
|
return ResponseEntity.ok(toOrderDto(getOrderOrThrow(orderId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,4 +98,20 @@ public class PaymentService {
|
|||||||
|
|
||||||
return payment;
|
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,12 @@
|
|||||||
</select>
|
</select>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
(click)="confirmPayment()"
|
(click)="updatePaymentMethod()"
|
||||||
[disabled]="
|
[disabled]="confirmingPayment"
|
||||||
confirmingPayment || selectedOrder.paymentStatus === 'COMPLETED'
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
{{ confirmingPayment ? "Invio..." : "Conferma pagamento" }}
|
{{
|
||||||
|
confirmingPayment ? "Salvataggio..." : "Cambia metodo pagamento"
|
||||||
|
}}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -132,14 +132,14 @@ export class AdminDashboardComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmPayment(): void {
|
updatePaymentMethod(): void {
|
||||||
if (!this.selectedOrder || this.confirmingPayment) {
|
if (!this.selectedOrder || this.confirmingPayment) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.confirmingPayment = true;
|
this.confirmingPayment = true;
|
||||||
this.adminOrdersService
|
this.adminOrdersService
|
||||||
.confirmPayment(this.selectedOrder.id, this.selectedPaymentMethod)
|
.updatePaymentMethod(this.selectedOrder.id, this.selectedPaymentMethod)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (updatedOrder) => {
|
next: (updatedOrder) => {
|
||||||
this.confirmingPayment = false;
|
this.confirmingPayment = false;
|
||||||
@@ -147,7 +147,7 @@ export class AdminDashboardComponent implements OnInit {
|
|||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.confirmingPayment = false;
|
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>(
|
return this.http.post<AdminOrder>(
|
||||||
`${this.baseUrl}/${orderId}/payments/confirm`,
|
`${this.baseUrl}/${orderId}/payments/confirm`,
|
||||||
{ method },
|
{ method },
|
||||||
|
|||||||
Reference in New Issue
Block a user