One Hat Cyber Team
Your IP :
216.73.216.36
Server IP :
162.240.179.46
Server :
Linux vps-14493116.nutrivittasaude.com.br 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
Server Software :
Apache
PHP Version :
8.2.31
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
lifeprimeti
/
meta.lifeprimeti.com.br
/
api
/
View File Name :
hubpay_charge.php
<?php require_once __DIR__ . '/../config/database.php'; require_once __DIR__ . '/../includes/hubpay.php'; requireAuth(); header('Content-Type: application/json; charset=utf-8'); $empresaId = getEmpresaId(); $agendamentoId = (int)($_POST['agendamento_id'] ?? 0); if (!$agendamentoId) { echo json_encode(['error' => 'ID do agendamento obrigatorio']); exit; } $config = HubpayClient::getConfig($pdo, $empresaId); if (!HubpayClient::isConfigured($config)) { echo json_encode(['error' => 'Hubpay nao configurado']); exit; } $apiKey = $config['hubpay_api_key']; $ambiente = $config['hubpay_ambiente'] ?? 'test'; if ($ambiente === 'test' && strpos($apiKey, 'hpx_test_') !== 0) { echo json_encode(['error' => 'Chave informada nao e de ambiente test. Configure corretamente o ambiente.']); exit; } if ($ambiente === 'live' && strpos($apiKey, 'hpx_live_') !== 0) { echo json_encode(['error' => 'Chave informada nao e de ambiente live. Configure corretamente o ambiente.']); exit; } $stmt = $pdo->prepare("SELECT a.id, a.cliente_id, u.nome as cliente_nome, u.email as cliente_email, u.cpf as cliente_cpf, s.preco, s.nome as servico_nome FROM agendamentos a JOIN usuarios u ON a.cliente_id = u.id JOIN servicos s ON a.servico_id = s.id WHERE a.id=? AND a.empresa_id=? AND a.status NOT IN ('concluido','cancelado')"); $stmt->execute([$agendamentoId, $empresaId]); $agendamento = $stmt->fetch(); if (!$agendamento) { echo json_encode(['error' => 'Agendamento nao encontrado ou ja concluido']); exit; } $amount = round((float)$agendamento['preco'] * 100); if ($amount <= 0) { echo json_encode(['error' => 'Valor invalido para cobranca']); exit; } $payer = ['name' => $agendamento['cliente_nome']]; if (!empty($agendamento['cliente_email'])) $payer['email'] = $agendamento['cliente_email']; if (!empty($agendamento['cliente_cpf'])) $payer['document'] = preg_replace('/\D/', '', $agendamento['cliente_cpf']); $description = $agendamento['servico_nome'] . ' - ' . $agendamento['cliente_nome']; $hubpay = new HubpayClient($apiKey); try { $charge = $hubpay->createCharge( $amount, 'asaas', $description, $payer, ['agendamento_id' => $agendamentoId, 'empresa_id' => $empresaId], 3600, uniqid('ag_', true) ); $pdo->prepare("UPDATE agendamentos SET hubpay_charge_id=?, hubpay_pix_copy_paste=?, hubpay_pix_qrcode=?, pagamento_status='pendente', pagamento_tipo='hubpay' WHERE id=?") ->execute([$charge['id'], $charge['pix']['copy_paste'] ?? null, $charge['pix']['qr_code_base64'] ?? null, $agendamentoId]); echo json_encode([ 'success' => true, 'charge_id' => $charge['id'], 'copy_paste' => $charge['pix']['copy_paste'] ?? null, 'qr_code_base64' => $charge['pix']['qr_code_base64'] ?? null, 'status' => $charge['status'], ]); } catch (Exception $e) { echo json_encode(['error' => 'Erro ao gerar cobranca: ' . $e->getMessage()]); }