load->model('paystack_model'); } /** * Display settings page */ public function settings() { if (!has_permission('settings', '', 'view')) { access_denied('settings'); } if ($this->input->post()) { if (!has_permission('settings', '', 'edit')) { access_denied('settings'); } $data = $this->input->post(); $success = $this->paystack_model->update_settings($data); if ($success) { set_alert('success', _l('settings_updated')); } } $data['title'] = _l('paystack_settings'); $data['tab'] = 'settings'; $this->load->view('admin/settings', $data); } /** * Display transaction logs */ public function transactions() { if (!has_permission('payments', '', 'view')) { access_denied('payments'); } $data['title'] = _l('paystack_transactions'); $data['tab'] = 'transactions'; // Get filters $filter = [ 'start_date' => $this->input->get('start_date'), 'end_date' => $this->input->get('end_date'), 'status' => $this->input->get('status') ]; $data['transactions'] = $this->paystack_model->get_transactions($filter); $this->load->view('admin/transactions', $data); } /** * Display test mode interface */ public function test_mode() { if (!has_permission('settings', '', 'view')) { access_denied('settings'); } $data['title'] = _l('paystack_test_mode'); $data['tab'] = 'test_mode'; $data['test_keys'] = $this->paystack_model->get_test_keys(); $this->load->view('admin/test_mode', $data); } /** * Display payment status dashboard */ public function dashboard() { if (!has_permission('payments', '', 'view')) { access_denied('payments'); } $data['title'] = _l('paystack_dashboard'); $data['tab'] = 'dashboard'; // Get statistics $data['stats'] = $this->paystack_model->get_payment_stats(); $data['recent_transactions'] = $this->paystack_model->get_recent_transactions(); $data['monthly_chart'] = $this->paystack_model->get_monthly_chart_data(); $this->load->view('admin/dashboard', $data); } /** * Get transaction details (AJAX) */ public function get_transaction_details($reference) { if (!has_permission('payments', '', 'view')) { ajax_access_denied(); } $transaction = $this->paystack_model->get_transaction($reference); echo json_encode($transaction); } /** * Verify test webhook */ // public function test_webhook() // { // if (!has_permission('settings', '', 'view')) { // ajax_access_denied(); // } // // $this->load->library('paystack_gateway'); // $result = $this->paystack_gateway->test_webhook(); // // echo json_encode($result); // } /** * Initiate test payment */ public function initiate_test_payment() { if (!has_permission('settings', '', 'view')) { ajax_access_denied(); } $amount = $this->input->post('amount'); $email = $this->input->post('email'); if (!$amount || !$email) { echo json_encode([ 'success' => false, 'message' => _l('invalid_input') ]); return; } $reference = 'TEST_' . time() . '_' . mt_rand(1000, 9999); echo json_encode([ 'success' => true, 'reference' => $reference ]); } /** * Test webhook connection */ public function test_webhook() { if (!has_permission('settings', '', 'view')) { ajax_access_denied(); } $this->load->library('paystack_gateway'); // Try to send a test webhook $webhook_url = site_url('paystack/webhook'); $test_data = [ 'event' => 'test', 'data' => [ 'reference' => 'TEST_' . time(), 'status' => 'success' ] ]; $ch = curl_init($webhook_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($test_data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'X-Paystack-Signature: ' . hash_hmac('sha512', json_encode($test_data), $this->paystack_gateway->get_webhook_secret()) ]); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($http_code == 200) { echo json_encode([ 'success' => true, 'message' => _l('webhook_received_response') ]); } else { echo json_encode([ 'success' => false, 'message' => _l('webhook_connection_failed') . ' (HTTP ' . $http_code . ')' ]); } } /** * Log debug message */ public function log_debug() { if (!has_permission('settings', '', 'view')) { ajax_access_denied(); } $message = $this->input->post('message'); if ($message) { $this->paystack_model->add_debug_log($message); } } /** * Get debug log */ public function get_debug_log() { if (!has_permission('settings', '', 'view')) { ajax_access_denied(); } $log = $this->paystack_model->get_debug_log(); echo $log; } /** * Clear debug log */ public function clear_debug_log() { if (!has_permission('settings', '', 'view')) { ajax_access_denied(); } $this->paystack_model->clear_debug_log(); } }