/dev/null 2>&1 // */ ini_set('max_execution_time', 60); ini_set('memory_limit', '256M'); date_default_timezone_set('Asia/Jakarta'); require "/www/wwwroot/bilspro/config/connect.php"; require "/www/wwwroot/bilspro/payment/flip/Flip/Transaction.php"; try { // Ambil maksimum 5 data agar ringan $sql = " SELECT a.id, a.transaction_id, b.apikey_payment_gateway, b.url_payment_gateway FROM tagihan a LEFT JOIN data_server b ON a.id_data_server = b.id WHERE a.status = 'lewat' AND a.transaction_id != '' AND a.transaction_status = 'ACTIVE' AND b.payment_gateway = 'flip' AND b.status_payment_gateway = 'ACTIVE' AND ( YEAR(a.limit_pembayaran) < YEAR(NOW()) OR ( YEAR(a.limit_pembayaran) = YEAR(NOW()) AND MONTH(a.limit_pembayaran) < MONTH(NOW()) ) ) ORDER BY a.limit_pembayaran ASC LIMIT 5 "; $stmt = $pdo->prepare($sql); $stmt->execute(); $data = $stmt->fetchAll(PDO::FETCH_ASSOC); if (empty($data)) { exit; // tidak ada data, langsung keluar biar hemat resource } $logFile = "/www/wwwroot/bilspro/load/cronjob/flip_auto_inactive.log"; if (!file_exists(dirname($logFile))) { mkdir(dirname($logFile), 0777, true); } $results = []; foreach ($data as $row) { try { $flip = new FlipPaymentGateway($row['apikey_payment_gateway'], $row['url_payment_gateway']); $response = $flip->getBillStatus($row['transaction_id']); if (!is_array($response) || empty($response['link_id'])) { $results[] = [ 'id' => $row['id'], 'transaction_id' => $row['transaction_id'], 'status' => 'error', 'message' => 'Invalid or missing response from Flip API' ]; continue; } $delete = $flip->editBill( $response['link_id'], 'INACTIVE', $response['title'] ?? '', $response['amount'] ?? 0 ); $results[] = [ 'id' => $row['id'], 'transaction_id' => $row['transaction_id'], 'flip_response' => $delete ]; if ($delete) { $update = $pdo->prepare("UPDATE tagihan SET transaction_status = 'INACTIVE' WHERE id = :id"); $update->execute([':id' => $row['id']]); } // Delay 1 detik antar request agar tidak membanjiri Flip API sleep(1); } catch (Exception $e) { $results[] = [ 'id' => $row['id'], 'transaction_id' => $row['transaction_id'], 'status' => 'error', 'message' => $e->getMessage() ]; } } // Simpan hasil ke log file, bukan echo ke output file_put_contents( $logFile, "[" . date('Y-m-d H:i:s') . "] " . json_encode($results, JSON_UNESCAPED_SLASHES) . PHP_EOL, FILE_APPEND ); } catch (Throwable $e) { // Tangkap semua error (PDO/Exception) file_put_contents( "/www/wwwroot/bilspro/load/cronjob/flip_auto_inactive_error.log", "[" . date('Y-m-d H:i:s') . "] ERROR: " . $e->getMessage() . PHP_EOL, FILE_APPEND ); }