prepare($sql); $stmt->execute(); $data = $stmt->fetchAll(PDO::FETCH_ASSOC); $results = []; $no = 1; foreach ($data as $row) { // Decode JSON transaction_data $data2 = json_decode($row['transaction_data'], true); // Cek jika JSON tidak valid atau kosong if (json_last_error() !== JSON_ERROR_NONE || empty($data2)) { $results[] = [ 'nomor' => $no, 'id' => $row['id'], 'transaction_id' => $row['transaction_id'], 'title' => '(invalid JSON)', 'error' => 'transaction_data tidak valid' ]; $no++; continue; } $flip = new FlipPaymentGateway($row['apikey_payment_gateway'], $row['url_payment_gateway']); $delete = $flip->editBill( $data2['link_id'], 'INACTIVE', $data2['title'] ?? '', $data2['amount'] ?? 0 ); if ($delete) { $update = $pdo->prepare("UPDATE tagihan SET transaction_status = 'INACTIVE' WHERE id = :id"); $update->execute([':id' => $row['id']]); } // Tambahkan ke hasil $results[] = [ 'nomor' => $no, 'id' => $row['id'], 'transaction_id' => $row['transaction_id'], 'title' => $delete['title'] ?? '(tidak ada title)', // 'flip_response' => $response // bisa diaktifkan nanti jika perlu request ke Flip API ]; $no++; } // Output hasil header('Content-Type: application/json'); echo json_encode($results, JSON_PRETTY_PRINT); } catch (PDOException $e) { echo json_encode([ 'status' => 'error', 'message' => 'Database Error: ' . $e->getMessage() ]); } catch (Exception $e) { echo json_encode([ 'status' => 'error', 'message' => 'General Error: ' . $e->getMessage() ]); }