<?php if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } function verifyEtransfer(int $orderId, string $refCode): array { $order = Database::fetchOne( "SELECT id, order_ref, subtotal, status_code, etransfer_ref FROM orders WHERE id = :id AND payment_method = 'etransfer'", [':id' => $orderId] ); if (!$order) return ['ok' => false, 'error' => 'Order not found or not e-transfer']; if ((int)$order['status_code'] !== StatusCode::ORDER_PENDING) return ['ok' => false, 'error' => 'Order not pending']; $adminId = (int)($_SESSION['admin_id'] ?? 0); $storedRef = $order['etransfer_ref'] ?? ''; $match = ($refCode !== '' && strtoupper(trim($refCode)) === strtoupper(trim($storedRef))); Database::execute("UPDATE orders SET status_code = :sc, updated_at = NOW() WHERE id = :id", [':sc' => StatusCode::ORDER_PAID, ':id' => $orderId]); Events::record(Events::CAT_VERIFY, 'payment.etransfer_confirmed', 'order', $orderId, ['ref_provided' => $refCode, 'ref_stored' => $storedRef, 'auto_match' => $match, 'admin_id' => $adminId]); return ['ok' => true, 'ref_match' => $match]; } function renderEtransferVerify(int $orderId): string { $order = Database::fetchOne( "SELECT id, order_ref, subtotal, status_code, status_label, etransfer_ref, email, shipping_name, created_at          FROM orders WHERE id = :id AND payment_method = 'etransfer'", [":id" => $orderId] ); if (!$order) return ""; $order = Encryption::decryptFields($order, ['email', 'shipping_name']); $ref = $order['etransfer_ref'] ?? ''; $html = '<div class="etransfer-verify">'; $html .= '<span class="section-label">E-Transfer: #' . UI::e($order['order_ref']) . '</span>'; $html .= '<div class="detail-grid">'; $html .= '<div><span>Customer:</span> ' . UI::e($order['shipping_name'] ?? '') . '</div>'; $html .= '<div><span>Email:</span> ' . UI::e($order['email'] ?? '') . '</div>'; $html .= '<div><span>Expected:</span> $' . number_format((float)$order['subtotal'], 2) . '</div>'; $html .= '<div><span>Status:</span> ' . UI::e($order['status_label'] ?? '') . '</div>'; $html .= '<div><span>Reference:</span> ' . ($ref ? UI::e($ref) : '<em>Not set</em>') . '</div>'; $html .= '<div><span>Placed:</span> ' . UI::e($order['created_at']) . '</div>'; $html .= '</div>'; if ((int)$order['status_code'] === StatusCode::ORDER_PENDING) { $html .= '<div class="verify-action" style="margin-top:12px">'; $html .= '<input type="text" class="form-group input" id="etref-' . $orderId . '" placeholder="Reference code from transfer" style="width:100%;margin-bottom:8px">'; $html .= '<a class="btn btn-primary" href="javascript:void(0)" data-action="bridge-etransfer" data-id="' . $orderId . '"><span>Confirm Received</span></a>'; $html .= '</div>'; } $html .= '</div>'; return $html; } 