diff --git a/app/Controllers/PembelianController.php b/app/Controllers/PembelianController.php
index 6778c9dcf6875fa0fa4aa4959edc121d419e9415..f548d1fe94e4f4791c78adb9310048d13a035c83 100644
--- a/app/Controllers/PembelianController.php
+++ b/app/Controllers/PembelianController.php
@@ -6,7 +6,8 @@ require_once(__DIR__ . '/../Models/Pembelian.php');
 
 class PembelianController {
     private $pembelianModel;
-
+    
+    
     public function __construct() {
         $this->pembelianModel = new PembelianModel();
     }
@@ -31,15 +32,43 @@ class PembelianController {
         return $this->pembelianModel->getAllPembelian();
     }
 
-    // public function paginateHistory($page=1,$pagesize=10,$pembelian) {
-    //     $maxpage = ceil(count($pembelian)/$pagesize);
-    //     if ($page > $maxpage) {
-    //         $page = $maxpage;
-    //     }
-    //     $offset = $pagesize * ($page-1);
-    //     $selectedHistory = array_slice($pembelian, $offset, $pagesize);
+    public function paginateHistory($pembelian,$page=1,$pagesize=10) {
+        $maxpage = ceil(count($pembelian)/$pagesize);
+        if ($page > $maxpage) {
+            $page = $maxpage;
+        }
+        $offset = $pagesize * ($page-1);
+        $selectedHistory = array_slice($pembelian, $offset, $pagesize);
+
+        return $selectedHistory;
+    }
+
+    // Returns true if purchase succeeds
+    public function purchaseTicket($ticketId,$userId) {
+        // $purchases = $this->getAllPembelian();
+        // foreach ($purchases as $purchase) :
+        //     echo $purchase['pembelian_id'] . ': ' . $purchase['user_id'] . ', ' . $purchase['ticket_id'] . ', ' . $purchase['pembelian_created_time']."\n";
+        // endforeach;
 
-    //     return $selectedHistory;
-    // }
+        $createdTime = date("Y-m-d H:i:s");
+        $this->createPembelian($ticketId,$userId,$createdTime);
+        // $purchases = $this->getAllPembelian();
+        // foreach ($purchases as $purchase) :
+        //     echo $purchase['pembelian_id'] . ': ' . $purchase['user_id'] . ', ' . $purchase['ticket_id'] . ', ' . $purchase['pembelian_created_time']."\n";
+        // endforeach;
+    }
+
+    public function handleRequest() {
+        if (isset($_GET['action'])) {
+            if ($_GET['action'] === 'purchaseTicket') {
+                $ticketId = $_POST['ticketId'];
+                $userId = $_POST['userId'];
+                $this->purchaseTicket($ticketId,$userId);
+            } else {
+                // Handle other actions here, if needed
+            }
+        }
+    }
+    
 }
 ?>
diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php
index b8e4e799195ffb6c596d7b42e446bd43d0e5fe82..8e65e817bfb130e8bd408dc525a7a78751b78a96 100644
--- a/app/Controllers/TicketController.php
+++ b/app/Controllers/TicketController.php
@@ -26,5 +26,11 @@ class TicketController {
     public function deleteTicket($ticketId) {
         return $this->ticketModel->deleteTicket($ticketId);
     }
+
+    public function previewTicket($ticketId) {
+        $ticket = $this->getTicket($ticketId);
+        
+        include(__DIR__ . '/../Views/pembelian/pembelian.php');
+    }
 }
 ?>
diff --git a/app/Views/pembelian/pembelian.php b/app/Views/pembelian/pembelian.php
new file mode 100644
index 0000000000000000000000000000000000000000..35ad2ab8f6c235f6fed13f06b6bff5bc2bc0254f
--- /dev/null
+++ b/app/Views/pembelian/pembelian.php
@@ -0,0 +1,46 @@
+<<!-- app/Views/purchase.php -->
+
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Purchase Ticket</title>
+    <!-- Include any CSS styles or external libraries here -->
+</head>
+<body>
+    <h1>Purchase Ticket</h1>
+    
+    <!-- Display the ticket details -->
+    <h2>Ticket Details</h2>
+    <p>Ticket ID: <?php echo $ticket['ticket_id']; ?></p>
+    <p>Ticket Name: <?php echo $ticket['ticket_name']; ?></p>
+    <p>Price: <?php echo $ticket['ticket_price']; ?></p>
+    
+    <!-- Purchase Form -->
+    <form id="purchaseForm" method="post" action="home.php?action=purchaseTicket">
+        <input type="hidden" name="ticketId" value="<?php echo $ticket['ticket_id']; ?>">
+        <input type="hidden" name="userId" value="<?php echo $_SESSION['user_id']; ?>">
+        
+        <!-- Additional form fields or options can be added here -->
+        
+        <button type="button" id="confirmPurchaseBtn">Confirm Purchase</button>
+    </form>
+
+    <!-- JavaScript code for the confirmation dialog -->
+    <script>
+        // Function to show the confirmation dialog
+        function showConfirmationDialog() {
+            if (confirm("Are you sure you want to purchase this ticket?")) {
+                // If the user confirms, submit the form
+                document.getElementById("purchaseForm").submit();
+            }
+        }
+
+        // Attach the confirmation dialog to the button click event
+        document.getElementById("confirmPurchaseBtn").addEventListener("click", showConfirmationDialog);
+    </script>
+    
+    <!-- Include any additional content or messages here -->
+</body>
+</html>