PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.2
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.2
2.4.3 2.4.4 2.4.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 All 60 releases
easy-invoice / templates / admin / manual-payment-verification.php

manual-payment-verification.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.4.2, at templates/admin/manual-payment-verification.php

283 lines 13.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin template for verifying manual payments
4 *
5 * @package Easy_Invoice
6 */
7
8 // Prevent direct access
9 if (!defined('ABSPATH')) {
10 exit;
11 }
12
13 // Get invoice ID
14 $invoice_id = isset($_GET['invoice_id']) ? intval($_GET['invoice_id']) : 0;
15 if (!$invoice_id) {
16 wp_die(esc_html__('Invoice ID is required', 'easy-invoice'));
17 }
18
19 // Get invoice
20 $invoice = new \EasyInvoice\Models\Invoice(get_post($invoice_id));
21 if (!$invoice->getPost()) {
22 wp_die(esc_html__('Invalid invoice', 'easy-invoice'));
23 }
24
25 // Get payment details
26 $payment_method = get_post_meta($invoice_id, '_payment_method', true);
27 $payment_status = get_post_meta($invoice_id, '_payment_status', true);
28
29 // If not a manual payment or not pending, redirect to invoice view
30 if (!in_array($payment_method, ['bank', 'cheque']) || $payment_status !== 'pending') {
31 // `easy-invoice-invoices` is not a registered admin page, so this redirect
32 // landed the admin on a 403. The invoice list is `easy-invoice-all`.
33 wp_safe_redirect(admin_url('admin.php?page=easy-invoice-all'));
34 exit;
35 }
36
37 // Get payment proof details
38 $transaction_id = '';
39 $payment_date = '';
40 $notes = '';
41 $proof_url = '';
42 $submission_date = '';
43
44 if ($payment_method === 'bank') {
45 $transaction_id = get_post_meta($invoice_id, '_bank_transaction_id', true);
46 $notes = get_post_meta($invoice_id, '_bank_payment_notes', true);
47 $proof_url = get_post_meta($invoice_id, '_bank_payment_proof', true);
48 $submission_date = get_post_meta($invoice_id, '_bank_payment_date', true);
49 } elseif ($payment_method === 'cheque') {
50 $transaction_id = get_post_meta($invoice_id, '_cheque_number', true);
51 $bank_name = get_post_meta($invoice_id, '_cheque_bank_name', true);
52 $payment_date = get_post_meta($invoice_id, '_cheque_date', true);
53 $notes = get_post_meta($invoice_id, '_cheque_notes', true);
54 $proof_url = get_post_meta($invoice_id, '_cheque_image', true);
55 $submission_date = get_post_meta($invoice_id, '_cheque_submission_date', true);
56 }
57
58 // Format payment method label
59 $payment_method_label = $payment_method === 'bank' ? __('Bank Transfer', 'easy-invoice') : __('Cheque', 'easy-invoice');
60
61 // Format dates
62 $formatted_submission_date = $submission_date ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($submission_date)) : '';
63 $formatted_payment_date = $payment_date ? date_i18n(get_option('date_format'), strtotime($payment_date)) : '';
64 ?>
65
66 <div class="wrap">
67 <h1><?php /* translators: %s: payment method. */ printf(esc_html__('Verify %s Payment', 'easy-invoice'), esc_html($payment_method_label)); ?></h1>
68
69 <div class="notice notice-info">
70 <p><?php esc_html_e('Please review the payment details submitted by the customer and verify the payment.', 'easy-invoice'); ?></p>
71 </div>
72
73 <div class="metabox-holder">
74 <div class="postbox">
75 <h2 class="hndle"><span><?php esc_html_e('Invoice Details', 'easy-invoice'); ?></span></h2>
76 <div class="inside">
77 <table class="form-table">
78 <tr>
79 <th><?php esc_html_e('Invoice Number', 'easy-invoice'); ?></th>
80 <td><?php echo esc_html($invoice->getNumber()); ?></td>
81 </tr>
82 <tr>
83 <th><?php esc_html_e('Customer', 'easy-invoice'); ?></th>
84 <td><?php echo esc_html($invoice->getCustomerName()); ?></td>
85 </tr>
86 <tr>
87 <th><?php esc_html_e('Amount', 'easy-invoice'); ?></th>
88 <td><?php
89 $formatter = new \EasyInvoice\Helpers\InvoiceFormatter($invoice);
90 echo esc_html($formatter->format($invoice->getTotal()));
91 ?></td>
92 </tr>
93 <tr>
94 <th><?php esc_html_e('Due Date', 'easy-invoice'); ?></th>
95 <td><?php echo esc_html($invoice->getDueDate()); ?></td>
96 </tr>
97 </table>
98 </div>
99 </div>
100
101 <div class="postbox">
102 <h2 class="hndle"><span><?php /* translators: %s: payment method. */ printf(esc_html__('%s Payment Details', 'easy-invoice'), esc_html($payment_method_label)); ?></span></h2>
103 <div class="inside">
104 <table class="form-table">
105 <?php if ($payment_method === 'bank'): ?>
106 <tr>
107 <th><?php esc_html_e('Transaction ID', 'easy-invoice'); ?></th>
108 <td><?php echo esc_html($transaction_id); ?></td>
109 </tr>
110 <?php elseif ($payment_method === 'cheque'): ?>
111 <tr>
112 <th><?php esc_html_e('Cheque Number', 'easy-invoice'); ?></th>
113 <td><?php echo esc_html($transaction_id); ?></td>
114 </tr>
115 <?php if ($bank_name): ?>
116 <tr>
117 <th><?php esc_html_e('Bank Name', 'easy-invoice'); ?></th>
118 <td><?php echo esc_html($bank_name); ?></td>
119 </tr>
120 <?php endif; ?>
121 <?php if ($payment_date): ?>
122 <tr>
123 <th><?php esc_html_e('Cheque Date', 'easy-invoice'); ?></th>
124 <td><?php echo esc_html($formatted_payment_date); ?></td>
125 </tr>
126 <?php endif; ?>
127 <?php endif; ?>
128
129 <?php if ($submission_date): ?>
130 <tr>
131 <th><?php esc_html_e('Submission Date', 'easy-invoice'); ?></th>
132 <td><?php echo esc_html($formatted_submission_date); ?></td>
133 </tr>
134 <?php endif; ?>
135
136 <?php if ($notes): ?>
137 <tr>
138 <th><?php esc_html_e('Customer Notes', 'easy-invoice'); ?></th>
139 <td><?php echo wp_kses_post(wpautop(esc_html($notes))); ?></td>
140 </tr>
141 <?php endif; ?>
142
143 <?php if ($proof_url): ?>
144 <tr>
145 <th><?php esc_html_e('Payment Proof', 'easy-invoice'); ?></th>
146 <td>
147 <?php if (wp_check_filetype(basename($proof_url), null)['ext'] === 'pdf'): ?>
148 <a href="<?php echo esc_url($proof_url); ?>" target="_blank" class="button"><?php esc_html_e('View PDF', 'easy-invoice'); ?></a>
149 <?php else: ?>
150 <a href="<?php echo esc_url($proof_url); ?>" target="_blank">
151 <img src="<?php echo esc_url($proof_url); ?>" alt="<?php echo esc_js(__('Payment Proof', 'easy-invoice')); ?>" style="max-width: 300px; max-height: 200px;">
152 </a>
153 <?php endif; ?>
154 </td>
155 </tr>
156 <?php endif; ?>
157 </table>
158 </div>
159 </div>
160
161 <div class="postbox">
162 <h2 class="hndle"><span><?php esc_html_e('Payment Verification', 'easy-invoice'); ?></span></h2>
163 <div class="inside">
164 <form id="payment-verification-form" method="post">
165 <input type="hidden" name="action" value="easy_invoice_verify_manual_payment">
166 <input type="hidden" name="invoice_id" value="<?php echo esc_attr($invoice_id); ?>">
167 <input type="hidden" name="payment_method" value="<?php echo esc_attr($payment_method); ?>">
168 <?php wp_nonce_field('easy_invoice_admin', 'nonce'); ?>
169
170 <table class="form-table">
171 <tr>
172 <th><?php esc_html_e('Transaction ID', 'easy-invoice'); ?></th>
173 <td>
174 <input type="text" name="transaction_id" value="<?php echo esc_attr($transaction_id); ?>" class="regular-text">
175 <p class="description"><?php esc_html_e('Enter the transaction ID for this payment.', 'easy-invoice'); ?></p>
176 </td>
177 </tr>
178 <tr>
179 <th><?php esc_html_e('Admin Notes', 'easy-invoice'); ?></th>
180 <td>
181 <textarea name="notes" rows="3" class="large-text"></textarea>
182 <p class="description"><?php esc_html_e('Add any notes about this payment (optional).', 'easy-invoice'); ?></p>
183 </td>
184 </tr>
185 </table>
186
187 <div class="verification-actions">
188 <button type="submit" class="button button-primary verify-payment-btn"><?php esc_html_e('Verify Payment', 'easy-invoice'); ?></button>
189 <button type="button" class="button reject-payment-btn"><?php esc_html_e('Reject Payment', 'easy-invoice'); ?></button>
190 </div>
191 </form>
192
193 <div id="reject-payment-form" style="display: none; margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
194 <h3><?php esc_html_e('Reject Payment', 'easy-invoice'); ?></h3>
195 <p><?php esc_html_e('Please provide a reason for rejecting this payment:', 'easy-invoice'); ?></p>
196
197 <form method="post">
198 <input type="hidden" name="action" value="easy_invoice_reject_manual_payment">
199 <input type="hidden" name="invoice_id" value="<?php echo esc_attr($invoice_id); ?>">
200 <?php wp_nonce_field('easy_invoice_admin', 'nonce'); ?>
201
202 <textarea name="reason" rows="3" class="large-text" required></textarea>
203 <p class="description"><?php esc_html_e('This reason will be included in the email sent to the customer.', 'easy-invoice'); ?></p>
204
205 <div class="verification-actions" style="margin-top: 10px;">
206 <button type="submit" class="button button-secondary"><?php esc_html_e('Confirm Rejection', 'easy-invoice'); ?></button>
207 <button type="button" class="button cancel-rejection-btn"><?php esc_html_e('Cancel', 'easy-invoice'); ?></button>
208 </div>
209 </form>
210 </div>
211 </div>
212 </div>
213 </div>
214 </div>
215
216 <style>
217 .verification-actions {
218 margin-top: 20px;
219 padding-top: 15px;
220 border-top: 1px solid #eee;
221 }
222 .reject-payment-btn {
223 margin-left: 10px;
224 }
225 </style>
226
227 <script>
228 jQuery(document).ready(function($) {
229 // Show/hide rejection form
230 $('.reject-payment-btn').on('click', function() {
231 $('#reject-payment-form').show();
232 });
233
234 $('.cancel-rejection-btn').on('click', function() {
235 $('#reject-payment-form').hide();
236 });
237
238 // Handle verify payment form submission
239 $('#payment-verification-form').on('submit', function(e) {
240 e.preventDefault();
241
242 var formData = $(this).serialize();
243
244 // Show loading
245 $('.verify-payment-btn').prop('disabled', true).text('<?php echo esc_js(__('Processing...', 'easy-invoice')); ?>');
246
247 $.ajax({
248 url: ajaxurl,
249 type: 'POST',
250 data: formData,
251 success: function(response) {
252 if (response.success) {
253 // Use toast system if available, otherwise fallback to alert
254 if (typeof EasyInvoiceToast !== 'undefined') {
255 EasyInvoiceToast.success(response.data.message);
256 } else {
257 alert(response.data.message);
258 }
259 // See note above: `easy-invoice-invoices` 403s; the list page is `easy-invoice-all`.
260 window.location.href = '<?php echo esc_js(admin_url('admin.php?page=easy-invoice-all')); ?>';
261 } else {
262 // Use toast system if available, otherwise fallback to alert
263 if (typeof EasyInvoiceToast !== 'undefined') {
264 EasyInvoiceToast.error(response.data.message);
265 } else {
266 alert(response.data.message);
267 }
268 $('.verify-payment-btn').prop('disabled', false).text('<?php echo esc_js(__('Verify Payment', 'easy-invoice')); ?>');
269 }
270 },
271 error: function() {
272 // Use toast system if available, otherwise fallback to alert
273 if (typeof EasyInvoiceToast !== 'undefined') {
274 EasyInvoiceToast.error('<?php echo esc_js(__('An error occurred. Please try again.', 'easy-invoice')); ?>');
275 } else {
276 alert('<?php echo esc_js(__('An error occurred. Please try again.', 'easy-invoice')); ?>');
277 }
278 $('.verify-payment-btn').prop('disabled', false).text('<?php echo esc_js(__('Verify Payment', 'easy-invoice')); ?>');
279 }
280 });
281 });
282 });
283 </script>