PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.1.2
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.1.2
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / Admin / AdminController.php

AdminController.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.1.2, at includes/Admin/AdminController.php

135 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 admin email
41 $admin_email = get_option('admin_email');
42
43 // Get invoice details
44 $invoice = new \EasyInvoice\Models\Invoice(get_post($invoice_id));
45
46 // Get customer details
47 $customer_name = $invoice->getCustomerName();
48 $customer_email = $invoice->getCustomerEmail();
49
50 // Format amount
51 $formatter = new \EasyInvoice\Helpers\InvoiceFormatter($invoice);
52 $amount = $formatter->format($invoice->getTotal());
53
54 // Format payment method
55 $payment_method_label = $payment_method === 'bank' ? 'Bank Transfer' : 'Cheque';
56
57 // Email subject
58 $subject = sprintf(
59 __('New %s Payment Received - Invoice #%s', 'easy-invoice'),
60 $payment_method_label,
61 $invoice->getNumber()
62 );
63
64 // Email message
65 $message = sprintf(
66 __('A new %s payment has been submitted for invoice #%s.
67
68 Invoice Details:
69 - Amount: %s
70 - Customer: %s
71 - Email: %s
72
73 Please review and verify this payment in the admin dashboard:
74 %s
75
76 This is an automated message from Easy Invoice.', 'easy-invoice'),
77 $payment_method_label,
78 $invoice->getNumber(),
79 $amount,
80 $customer_name,
81 $customer_email,
82 admin_url('admin.php?page=easy-invoice-payments&action=verify&invoice_id=' . $invoice_id)
83 );
84
85 // Send email
86 wp_mail($admin_email, $subject, $message);
87 }
88
89 /**
90 * Initialize the controller
91 */
92 public function init() {
93 // Add menu pages
94 add_action('admin_menu', [$this, 'addMenuPages']);
95
96 // Add settings
97 add_action('admin_init', [$this, 'registerSettings']);
98
99 // Add custom columns
100 add_filter('manage_easy-invoice_posts_columns', [$this, 'addCustomColumns']);
101 add_action('manage_easy-invoice_posts_custom_column', [$this, 'renderCustomColumns'], 10, 2);
102
103 // Add payment status filter
104 add_action('restrict_manage_posts', [$this, 'addPaymentStatusFilter']);
105 add_filter('parse_query', [$this, 'filterByPaymentStatus']);
106
107 // Add manual payment notification
108 add_action('easy_invoice_manual_payment_submitted', [$this, 'sendManualPaymentNotification'], 10, 2);
109 }
110
111 public function registerSettings() {
112 // Payment settings
113 register_setting('easy_invoice_payment_settings', 'easy_invoice_payment_methods', [
114 'type' => 'array',
115 'default' => ['paypal'],
116 'sanitize_callback' => function($value) {
117 return is_array($value) ? array_map('sanitize_text_field', $value) : [];
118 }
119 ]);
120
121 register_setting('easy_invoice_payment_settings', 'easy_invoice_paypal_email', [
122 'type' => 'string',
123 'sanitize_callback' => 'sanitize_email',
124 ]);
125
126 register_setting('easy_invoice_payment_settings', 'easy_invoice_payment_reminder_days', [
127 'type' => 'integer',
128 'default' => 3,
129 'sanitize_callback' => 'absint',
130 ]);
131
132 // Additional hook to register Pro gateway settings
133 do_action('easy_invoice_register_payment_gateway_settings');
134 }
135 }