prepare($sql); $stmt->execute(); $data = $stmt->fetchAll(PDO::FETCH_ASSOC); $results = []; foreach ($data as $row) { // Pastikan class FlipPaymentGateway ada di Transaction.php $flip = new FlipPaymentGateway($row['apikey_payment_gateway'], $row['url_payment_gateway']); // Ambil status bill $response = $flip->getBillStatus($row['transaction_id']); // Cek apakah respon valid dan mengandung link_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; } // Tampilkan respon dari Flip (opsional) // print_r($response); // Edit bill menjadi INACTIVE // $delete = $flip->editBill( // $response['link_id'], // 'INACTIVE', // $response['title'] ?? '', // $response['amount'] ?? 0 // ); $results[] = [ 'id' => $row['id'], 'transaction_id' => $row['transaction_id'], 'flip_response' => $response ]; // // Jika berhasil, update status di database // if ($delete) { // $update = $pdo->prepare("UPDATE tagihan SET transaction_status = :status WHERE id = :id"); // $update->execute([ // ':status' => 'INACTIVE', // ':id' => $row['id'] // ]); // } } // Tampilkan hasil dari Flip (bukan data dari DB) header('Content-Type: application/json'); echo json_encode($results, JSON_PRETTY_PRINT); } catch (PDOException $e) { echo json_encode([ 'status' => 'error', 'message' => $e->getMessage() ]); } catch (Exception $e) { echo json_encode([ 'status' => 'error', 'message' => $e->getMessage() ]); }