| 1 |
<?php |
| 2 |
|
| 3 |
namespace EasyInvoice\Admin; |
| 4 |
|
| 5 |
class AdminController { |
| 6 |
public function registerPages(): void { |
| 7 |
// Check if we need to display a specific page |
| 8 |
$page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
| 9 |
$action = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : ''; |
| 10 |
|
| 11 |
if ($page === 'easy-invoice-invoices' && $action === 'verify-payment') { |
| 12 |
$this->loadTemplate('manual-payment-verification'); |
| 13 |
return; |
| 14 |
} |
| 15 |
|
| 16 |
|
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Load a template file |
| 21 |
* |
| 22 |
* @param string $template_name Template name without .php extension |
| 23 |
* @return void |
| 24 |
*/ |
| 25 |
private function loadTemplate($template_name) { |
| 26 |
$template_path = EASY_INVOICE_PLUGIN_DIR . 'templates/admin/' . $template_name . '.php'; |
| 27 |
if (file_exists($template_path)) { |
| 28 |
include $template_path; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Send admin notification for manual payment |
| 34 |
* |
| 35 |
* @param int $invoice_id |
| 36 |
* @param string $payment_method |
| 37 |
* @return void |
| 38 |
*/ |
| 39 |
public function sendManualPaymentNotification($invoice_id, $payment_method) { |
| 40 |
// Get invoice details |
| 41 |
$invoice = new \EasyInvoice\Models\Invoice(get_post($invoice_id)); |
| 42 |
|
| 43 |
if (!$invoice || !$invoice->getId()) { |
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
// Use EmailManager to send admin notification |
| 48 |
$email_manager = \EasyInvoice\Services\EmailManager::getInstance(); |
| 49 |
$email_manager->sendAdminPaymentNotification($invoice, [ |
| 50 |
'payment_method' => $payment_method |
| 51 |
]); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Initialize the controller |
| 56 |
*/ |
| 57 |
public function init() { |
| 58 |
// Add menu pages |
| 59 |
add_action('admin_menu', [$this, 'addMenuPages']); |
| 60 |
|
| 61 |
// Add settings |
| 62 |
add_action('admin_init', [$this, 'registerSettings']); |
| 63 |
|
| 64 |
// Add custom columns |
| 65 |
add_filter('manage_easy-invoice_posts_columns', [$this, 'addCustomColumns']); |
| 66 |
add_action('manage_easy-invoice_posts_custom_column', [$this, 'renderCustomColumns'], 10, 2); |
| 67 |
|
| 68 |
// Add payment status filter |
| 69 |
add_action('restrict_manage_posts', [$this, 'addPaymentStatusFilter']); |
| 70 |
add_filter('parse_query', [$this, 'filterByPaymentStatus']); |
| 71 |
|
| 72 |
// Add manual payment notification |
| 73 |
add_action('easy_invoice_manual_payment_submitted', [$this, 'sendManualPaymentNotification'], 10, 2); |
| 74 |
} |
| 75 |
|
| 76 |
public function registerSettings() { |
| 77 |
// Payment settings |
| 78 |
register_setting('easy_invoice_payment_settings', 'easy_invoice_payment_methods', [ |
| 79 |
'type' => 'array', |
| 80 |
'default' => ['paypal'], |
| 81 |
'sanitize_callback' => function($value) { |
| 82 |
return is_array($value) ? array_map('sanitize_text_field', $value) : []; |
| 83 |
} |
| 84 |
]); |
| 85 |
|
| 86 |
register_setting('easy_invoice_payment_settings', 'easy_invoice_paypal_email', [ |
| 87 |
'type' => 'string', |
| 88 |
'sanitize_callback' => 'sanitize_email', |
| 89 |
]); |
| 90 |
|
| 91 |
register_setting('easy_invoice_payment_settings', 'easy_invoice_payment_reminder_days', [ |
| 92 |
'type' => 'integer', |
| 93 |
'default' => 3, |
| 94 |
'sanitize_callback' => 'absint', |
| 95 |
]); |
| 96 |
|
| 97 |
// Additional hook to register Pro gateway settings |
| 98 |
do_action('easy_invoice_register_payment_gateway_settings'); |
| 99 |
} |
| 100 |
} |