home
/
u529748449
/
domains
/
borabilhete.com
/
public_html
/
public
➕ New
📤 Upload
✎ Editing:
processar_pedido.php
← Back
<?php // public/processar_pedido.php declare(strict_types=1); ini_set('display_errors', '1'); error_reporting(E_ALL); session_start(); require_once __DIR__ . '/../admin/conexao.php'; header('Content-Type: text/html; charset=UTF-8'); // --------------------------------------------------------- // 1) Regras básicas // --------------------------------------------------------- if (!isset($_SESSION['cliente_id'])) { http_response_code(401); echo "Você precisa estar logado para ver esta página."; exit; } $clienteId = (int) $_SESSION['cliente_id']; $pedidoId = isset($_GET['pedido_id']) ? (int) $_GET['pedido_id'] : 0; if ($pedidoId <= 0) { http_response_code(400); echo "Acesso inválido."; exit; } // --------------------------------------------------------- // 2) Carrega o pedido e valida a posse // --------------------------------------------------------- $sql = " SELECT p.id, p.id_evento, p.id_cliente, p.nome_cliente, p.email, p.status_pagamento, p.forma_pagamento, p.codigo_pix, p.criado_em FROM pedidos p WHERE p.id = ? AND p.id_cliente = ? LIMIT 1 "; $st = $conn->prepare($sql); $st->bind_param('ii', $pedidoId, $clienteId); $st->execute(); $pedido = $st->get_result()->fetch_assoc(); $st->close(); if (!$pedido) { http_response_code(404); echo "Pedido não encontrado para este usuário."; exit; } $status = strtolower(trim((string)($pedido['status_pagamento'] ?? 'pendente'))); // pago | pendente | cancelado $forma = $pedido['forma_pagamento'] ?? ''; // Carrega itens se existirem (tabela pedidos_itens) $itens = []; if ($it = $conn->prepare(" SELECT pi.id_setor, pi.quantidade, pi.valor_unitario, pi.taxa, pi.valor_total, s.nome_setor FROM pedidos_itens pi LEFT JOIN setores s ON s.id = pi.id_setor WHERE pi.id_pedido = ? ")) { $it->bind_param('i', $pedidoId); $it->execute(); $rs = $it->get_result(); while ($row = $rs->fetch_assoc()) $itens[] = $row; $it->close(); } // --------------------------------------------------------- // 3) UI simples de resultado // --------------------------------------------------------- ?> <!DOCTYPE html> <html lang="pt-BR"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1" /> <title>Pedido #<?= htmlspecialchars((string)$pedidoId) ?></title> <link rel="stylesheet" href="css/baseingressos.css"> <link rel="stylesheet" href="css/header.css"> <link rel="stylesheet" href="css/footer.css"> <style> .wrap { max-width: 920px; margin: 24px auto; padding: 16px; } .card { background:#fff; border-radius:14px; padding:20px; box-shadow:0 8px 24px rgba(0,0,0,.06); } .status { display:inline-block; padding:6px 10px; border-radius:999px; font-size:13px; font-weight:600; } .s-pago { background:#DCFCE7; color:#166534; } .s-pendente { background:#FEF9C3; color:#854D0E; } .s-cancelado { background:#FEE2E2; color:#991B1B; } .grid { display:grid; gap:10px; } .btn { display:inline-block; background:#1f6feb; color:#fff; text-decoration:none; padding:10px 16px; border-radius:10px; } .btn-outline { background:#fff; color:#1f2937; border:1px solid #e5e7eb; } table { width:100%; border-collapse: collapse; margin-top:12px; } th, td { padding:10px 8px; border-bottom:1px solid #eee; font-size:14px; } .muted { color:#6b7280; font-size:12px; } </style> </head> <body> <?php include __DIR__ . '/includes/header.php'; ?> <main class="wrap"> <div class="card"> <h2>Pedido #<?= htmlspecialchars((string)$pedidoId) ?></h2> <p> Status: <?php if ($status === 'pago'): ?> <span class="status s-pago">Pago</span> <?php elseif ($status === 'cancelado'): ?> <span class="status s-cancelado">Cancelado</span> <?php else: ?> <span class="status s-pendente">Pendente</span> <?php endif; ?> </p> <p class="muted">Forma de pagamento: <?= htmlspecialchars($forma ?: '—') ?></p> <?php if (!empty($itens)): ?> <h3>Itens do pedido</h3> <table> <thead> <tr><th>Setor</th><th>Qtd</th><th>Vlr unit.</th><th>Taxa</th><th>Subtotal</th></tr> </thead> <tbody> <?php $total = 0.0; foreach ($itens as $i): $total += (float)$i['valor_total']; ?> <tr> <td><?= htmlspecialchars($i['nome_setor'] ?? ('Setor #'.$i['id_setor'])) ?></td> <td><?= (int)$i['quantidade'] ?></td> <td>R$ <?= number_format((float)$i['valor_unitario'], 2, ',', '.') ?></td> <td>R$ <?= number_format((float)$i['taxa'], 2, ',', '.') ?></td> <td>R$ <?= number_format((float)$i['valor_total'], 2, ',', '.') ?></td> </tr> <?php endforeach; ?> </tbody> <tfoot> <tr> <th colspan="4" style="text-align:right;">Total</th> <th>R$ <?= number_format($total, 2, ',', '.') ?></th> </tr> </tfoot> </table> <?php endif; ?> <div class="grid" style="margin-top:18px;"> <?php if ($status === 'pago'): ?> <div> <p>Pagamento confirmado! 🎉</p> <!-- Aqui você pode emitir ingressos, enviar e-mail, etc. --> <a class="btn" href="meus_ingressos.php">Ver meus ingressos</a> <a class="btn btn-outline" href="eventos.php" style="margin-left:8px;">Voltar aos eventos</a> </div> <?php elseif ($status === 'pendente'): ?> <div> <p>Estamos aguardando a confirmação do pagamento.</p> <p class="muted">Assim que o Mercado Pago confirmar, esta página atualizará automaticamente.</p> <a class="btn btn-outline" href="comprar.php">Voltar</a> </div> <script> // auto refresh suave a cada 6s enquanto pendente setTimeout(() => location.reload(), 6000); </script> <?php else: ?> <div> <p>Este pedido foi cancelado ou não foi aprovado.</p> <a class="btn" href="comprar.php">Tentar novamente</a> </div> <?php endif; ?> </div> <?php if ($status !== 'pago' && !empty($pedido['codigo_pix'])): ?> <p class="muted" style="margin-top:16px;"> Código PIX (copia-e-cola): <?= htmlspecialchars($pedido['codigo_pix']) ?> </p> <?php endif; ?> </div> </main> <?php include __DIR__ . '/footer.php'; ?> </body> </html>
💾 Save Changes
Cancel
📤 Upload File
×
Select File
Upload
Cancel
➕ Create New
×
Type
📄 File
📁 Folder
Name
Create
Cancel
✎ Rename Item
×
Current Name
New Name
Rename
Cancel
🔐 Change Permissions
×
Target File
Permission (e.g., 0755, 0644)
0755
0644
0777
Apply
Cancel