<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use App\Models\Order;  
use Illuminate\Http\Request;

class PaymentController extends Controller
{
    /**
     * Tampilkan halaman QRIS untuk membayar.
     * @param int $total
     */
    public function show($order_id)
{
    // Cari order berdasarkan ID
    $order = Order::where('id', $order_id)
                ->where('user_id', auth()->id())
                ->firstOrFail();

    // Total harga ambil dari database, bukan dari URL
    $total = $order->total_harga;

    return view('user.payment.qris', compact('order', 'total'));
}


    /**
     * Konfirmasi pembayaran setelah user membayar
     */
    public function confirm($id)
    {
        $order = \App\Models\Order::findOrFail($id);
        $order->status = 'selesai';
        $order->save();

        return redirect()->route('user.orders.index')->with('success', 'Pembayaran berhasil!');
    }
}
