home
/
u529748449
/
domains
/
borabilhete.com
/
public_html
/
public
➕ New
📤 Upload
✎ Editing:
sucesso.php
← Back
<?php // public/sucesso.php declare(strict_types=1); ini_set('display_errors','1'); error_reporting(E_ALL); require __DIR__ . '/../admin/conexao.php'; require __DIR__ . '/../vendor/autoload.php'; use MercadoPago\SDK; use MercadoPago\Payment; SDK::setAccessToken('APP_USR-3015882569703700-071711-383174b1d312d3019b1612810d746d03-213132560'); function mpStatusToLocal(?string $s): string { $s=strtolower((string)$s); if ($s==='approved') return 'pago'; if (in_array($s,['cancelled','rejected','refunded','charged_back'],true)) return 'cancelado'; return 'pendente'; } function detectarForma($p): string { $type=strtolower((string)($p->payment_type_id??'')); $method=strtolower((string)($p->payment_method_id??'')); $poi=strtolower((string)($p->point_of_interaction->type??'')); $fi=strtolower((string)($p->transaction_details->financial_institution??'')); $qrA=isset($p->point_of_interaction->transaction_data->qr_code)||isset($p->point_of_interaction->transaction_data->qr_code_base64); $qrB=isset($p->transaction_details->qr_code)||isset($p->transaction_details->qr_code_base64); $descr=strtolower((string)($p->statement_descriptor??'')); if ($method==='pix' || $poi==='pix' || $fi==='pix' || $qrA || $qrB || strpos($descr,'pix')!==false) return 'Pix'; if ($type==='bank_transfer') return 'Pix'; if ($type==='credit_card') return 'Crédito'; if ($type==='debit_card') return 'Débito'; if ($type==='ticket') return 'Boleto'; if ($type==='account_money') return 'Saldo MP'; return 'mercadopago'; } $token = $_GET['token'] ?? ''; $pid = $_GET['payment_id'] ?? ($_GET['collection_id'] ?? ''); if (!$token || strlen($token)<16) exit('Token inválido.'); $st=$conn->prepare("SELECT id,nome_cliente,forma_pagamento,criado_em,status_pagamento FROM pedidos WHERE token_seguro=? LIMIT 1"); $st->bind_param("s",$token); $st->execute(); $pedido=$st->get_result()->fetch_assoc(); $st->close(); if(!$pedido) exit('Pedido não encontrado.'); $idPedido=(int)$pedido['id']; $forma = (string)$pedido['forma_pagamento']; $status = (string)$pedido['status_pagamento']; try{ if ($pid){ $p = Payment::find_by_id($pid); if ($p){ $novaForma = detectarForma($p); $novoStatus = mpStatusToLocal($p->status ?? null); $u = $conn->prepare("UPDATE pedidos SET status_pagamento = ?, forma_pagamento = ? WHERE id = ?"); $u->bind_param("ssi", $novoStatus, $novaForma, $idPedido); $u->execute(); $u->close(); $forma = $novaForma; $status = $novoStatus; } } }catch(Throwable $e){ /* segue com o que tiver no BD */ } $isPago = ($status==='pago'); ?> <!doctype html> <html lang="pt-br"> <head> <meta charset="utf-8"> <title><?= $isPago?'Pedido Realizado com Sucesso':'Aguardando Confirmação' ?></title> <meta name="viewport" content="width=device-width, initial-scale=1"/> <style> body{font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:#f7f7f8;margin:0} .wrap{max-width:640px;margin:40px auto;background:#fff;border-radius:12px;box-shadow:0 6px 18px rgba(0,0,0,.06);padding:28px} h1{font-size:22px;margin:0 0 10px} p{color:#444;margin:6px 0 14px} a.btn{display:inline-block;padding:10px 16px;border-radius:8px;background:#111;color:#fff;text-decoration:none} .actions{margin-top:16px;display:flex;gap:12px;flex-wrap:wrap} .spinner{width:38px;height:38px;border:4px solid #eee;border-top-color:#555;border-radius:50%;animation:spin 1s linear infinite;margin:18px auto} @keyframes spin{to{transform:rotate(360deg)}} .badge{display:inline-block;background:#eee;border-radius:6px;padding:2px 8px;font-size:12px} </style> </head> <body> <div class="wrap"> <?php if ($isPago): ?> <h1>✅ Pedido Realizado com Sucesso!</h1> <p><strong>Nome:</strong> <?= htmlspecialchars($pedido['nome_cliente']) ?></p> <p><strong>Forma de Pagamento:</strong> <span class="badge"><?= htmlspecialchars($forma ?: 'Pix') ?></span></p> <p><strong>Data:</strong> <?= date('d/m/Y H:i', strtotime($pedido['criado_em'])) ?></p> <div class="actions"> <a class="btn" href="gerar_ingressos.php?token=<?= urlencode($token) ?>" target="_blank">📥 Baixar Ingressos</a> <a class="btn" href="../index.php" style="background:#444">← Voltar aos eventos</a> </div> <?php else: ?> <h1>⏳ Aguardando confirmação do pagamento…</h1> <div class="spinner"></div> <p>Assim que o Mercado Pago confirmar, vamos redirecionar automaticamente.</p> <div class="actions"> <a class="btn" href="../index.php" style="background:#444">← Voltar aos eventos</a> </div> <?php endif; ?> </div> <?php if (!$isPago): ?> <script> const token = <?= json_encode($token) ?>; const pid = <?= json_encode($pid) ?>; async function loop(){ try{ const r = await fetch('/public/api/refresh_mp.php?token='+encodeURIComponent(token) + (pid ? '&payment_id='+encodeURIComponent(pid) : '') + '&t='+Date.now(), {cache:'no-store'}); if (r.ok){ const j = await r.json(); if (j.ok && j.status === 'pago'){ location.reload(); return; } } }catch(e){} setTimeout(loop, 3000); } loop(); </script> <?php endif; ?> </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