Slide 56
Slide 56 text
class OrderController extends Controller
{
public function placeOrder(Request $request): JsonResponse
{
$validated = $request->validate([...]);
$command = new CreateOrderCommand(
(int) $validated['user_id'],
(float) $validated['amount'],
$validated['currency'] ?? 'JPY'
);
$order = $this->orderApplicationService->placeOrder($command);
return response()->json([
'id' => $order->id()->value(),
'user_id' => $order->userId()->getValue(),
'amount' => $order->amount(),
'currency' => $order->currency(),
'status' => $order->status()->value,
'payment_completed' => $order->isPaymentCompleted(),
'transaction_id' => $order->paymentTransactionId(),
'created_at' => $order->createdAt()->format('c'),
], 201);