input('reservation_id'); $reservation = Reservation::find($reservationId); if (! $reservation || $reservation->status !== 'held') { return response()->json(['message' => 'invalid_reservation'], 422); } // Compute server-side amount: price_per_cell * area $pricePerCell = (int) config('pixel_grid.price_per_cell', 100); $amount = $reservation->w * $reservation->h * $pricePerCell; $amountCents = $amount; // assume cents already $charge = $gateway->charge($reservation->id, $amountCents, []); if ($charge['status'] !== 'succeeded') { return response()->json(['message' => 'payment_failed'], 402); } // Mark reservation confirmed and dispatch composite job $reservation->status = 'confirmed'; $reservation->save(); dispatch(new CompositeImage($reservation->id)); return response()->json(['status' => 'ok', 'charge' => $charge]); } }