update
This commit is contained in:
@@ -19,6 +19,7 @@ use App\Repositories\Api\Order\OrderRepository;
|
||||
use App\Services\ActivityLogger;
|
||||
use App\Services\Api\Order\OrderQueryService;
|
||||
use App\Services\Api\Order\OrderService;
|
||||
use App\Services\InvoicePaymentService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -29,6 +30,7 @@ class OrderControllerRefactor extends Controller
|
||||
private readonly OrderRepository $orderRepository,
|
||||
private readonly OrderQueryService $orderQueryService,
|
||||
private readonly ActivityLogger $activityLogger,
|
||||
private readonly InvoicePaymentService $invoicePaymentService,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -179,6 +181,50 @@ class OrderControllerRefactor extends Controller
|
||||
return response()->json(['success' => true, 'data' => new InvoiceDetailResource($order->invoice->setRelation('order', $order))]);
|
||||
}
|
||||
|
||||
public function getClientInvoiceDetailByNumber(Request $request, string $invoiceNumber): JsonResponse
|
||||
{
|
||||
$invoice = $this->orderQueryService->findCustomerInvoiceByNumber((int) $request->user()->id, $invoiceNumber);
|
||||
|
||||
if (! $invoice) {
|
||||
return response()->json(['success' => false, 'message' => 'Hóa đơn không tồn tại.'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => new InvoiceDetailResource($invoice),
|
||||
'payment_url' => url('/client/invoices/' . $invoice->invoice_number . '/payment'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function payClientInvoiceByNumber(Request $request, string $invoiceNumber): JsonResponse
|
||||
{
|
||||
$invoice = $this->orderQueryService->findCustomerInvoiceByNumber((int) $request->user()->id, $invoiceNumber);
|
||||
|
||||
if (! $invoice) {
|
||||
return response()->json(['success' => false, 'message' => 'Hóa đơn không tồn tại.'], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
$paidInvoice = $this->invoicePaymentService->payWithBalance($invoice, $request->user(), 'balance');
|
||||
|
||||
$this->activityLogger->log(
|
||||
event: 'payment',
|
||||
logName: 'Invoice',
|
||||
description: "Customer {$request->user()->email} thanh toán hóa đơn #{$paidInvoice->invoice_number}",
|
||||
subject: $paidInvoice,
|
||||
newValues: ['invoice_number' => $paidInvoice->invoice_number, 'total' => $paidInvoice->total],
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Thanh toán hóa đơn thành công.',
|
||||
'data' => new InvoiceDetailResource($paidInvoice),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return response()->json(['success' => false, 'message' => $e->getMessage()], 422);
|
||||
}
|
||||
}
|
||||
|
||||
public function getClientServices(Request $request): JsonResponse
|
||||
{
|
||||
$services = $this->orderQueryService->getCustomerServices((int) $request->user()->id);
|
||||
|
||||
Reference in New Issue
Block a user