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