| @@ -6,13 +6,17 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace EasyInvoice\Templates\Payments; |
| 9 | 9 | |
| 10 | + | |
| 11 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | + exit; | |
| 13 | +} | |
| 10 | 14 | use EasyInvoice\Models\Invoice; |
| 11 | 15 | use EasyInvoice\Models\Payment; |
| 12 | 16 | |
| 13 | 17 | if (!isset($payment) || !($payment instanceof Payment)) { |
| 14 | - wp_die(__('Invalid payment', 'easy-invoice')); | |
| 18 | + wp_die(esc_html__('Invalid payment', 'easy-invoice')); | |
| 15 | 19 | } |
| 16 | 20 | ?> |
| 17 | 21 | |
| 18 | 22 | <div class="p-8"> |
| @@ -17,13 +21,13 @@ | ||
| 17 | 21 | |
| 18 | 22 | <div class="p-8"> |
| 19 | 23 | <div class="flex justify-between items-center mb-6"> |
| 20 | 24 | <h1 class="text-2xl font-bold text-gray-900"> |
| 21 | - <?php _e('Edit Payment', 'easy-invoice'); ?> | |
| 25 | + <?php esc_html_e('Edit Payment', 'easy-invoice'); ?> | |
| 22 | 26 | </h1> |
| 23 | - <a href="<?php echo admin_url('admin.php?page=easy-invoice-payments'); ?>" | |
| 27 | + <a href="<?php echo esc_url(admin_url('admin.php?page=easy-invoice-payments')); ?>" | |
| 24 | 28 | class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"> |
| 25 | - <?php _e('Back to Payments', 'easy-invoice'); ?> | |
| 29 | + <?php esc_html_e('Back to Payments', 'easy-invoice'); ?> | |
| 26 | 30 | </a> |
| 27 | 31 | </div> |
| 28 | 32 | |
| 29 | 33 | |
| @@ -28,22 +32,21 @@ | ||
| 28 | 32 | |
| 29 | 33 | |
| 30 | 34 | |
| 31 | 35 | <div class="bg-white shadow overflow-hidden sm:rounded-lg"> |
| 32 | - <form method="post" action="<?php echo admin_url('admin-ajax.php'); ?>" id="edit-payment-form" class="space-y-6 p-6"> | |
| 36 | + <form method="post" action="<?php echo esc_url(admin_url('admin-ajax.php')); ?>" id="edit-payment-form" class="space-y-6 p-6"> | |
| 33 | 37 | <?php wp_nonce_field('easy_invoice_payment', 'payment_nonce'); ?> |
| 34 | 38 | <input type="hidden" name="action" value="easy_invoice_update_payment"> |
| 35 | 39 | <input type="hidden" name="payment_id" value="<?php echo esc_attr($payment->getId()); ?>"> |
| 36 | 40 | |
| 37 | 41 | <div class="grid grid-cols-1 gap-6 sm:grid-cols-2"> |
| 38 | - <!-- Invoice Selection --> | |
| 39 | 42 | <div> |
| 40 | 43 | <label for="invoice_id" class="block text-sm font-medium text-gray-700"> |
| 41 | - <?php _e('Invoice', 'easy-invoice'); ?> <span class="text-red-500">*</span> | |
| 44 | + <?php esc_html_e('Invoice', 'easy-invoice'); ?> <span class="text-red-500">*</span> | |
| 42 | 45 | </label> |
| 43 | 46 | <select name="invoice_id" id="invoice_id" required |
| 44 | 47 | class="mt-1 block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md"> |
| 45 | - <option value=""><?php _e('Select Invoice', 'easy-invoice'); ?></option> | |
| 48 | + <option value=""><?php esc_html_e('Select Invoice', 'easy-invoice'); ?></option> | |
| 46 | 49 | <?php |
| 47 | 50 | // Get current payment's invoice ID |
| 48 | 51 | $current_invoice_id = $payment->getInvoiceId(); |
| 49 | 52 | |
| @@ -114,10 +117,10 @@ | ||
| 114 | 117 | } |
| 115 | 118 | |
| 116 | 119 | printf( |
| 117 | 120 | '<option value="%d" %s>%s - %s</option>', |
| 118 | - $invoice->getId(), | |
| 119 | - $is_selected ? 'selected="selected"' : '', | |
| 121 | + (int) $invoice->getId(), | |
| 122 | + $is_selected ? 'selected="selected"' : '', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- literal attribute. | |
| 120 | 123 | esc_html($invoice_number), |
| 121 | 124 | esc_html($currency_symbol . number_format($total, 2)) |
| 122 | 125 | ); |
| 123 | 126 | } |
| @@ -124,16 +127,15 @@ | ||
| 124 | 127 | ?> |
| 125 | 128 | </select> |
| 126 | 129 | </div> |
| 127 | 130 | |
| 128 | - <!-- Payment Method --> | |
| 129 | 131 | <div> |
| 130 | 132 | <label for="payment_method" class="block text-sm font-medium text-gray-700"> |
| 131 | - <?php _e('Payment Method', 'easy-invoice'); ?> <span class="text-red-500">*</span> | |
| 133 | + <?php esc_html_e('Payment Method', 'easy-invoice'); ?> <span class="text-red-500">*</span> | |
| 132 | 134 | </label> |
| 133 | 135 | <select name="payment_method" id="payment_method" required |
| 134 | 136 | class="mt-1 block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md"> |
| 135 | - <option value=""><?php _e('Select Payment Method', 'easy-invoice'); ?></option> | |
| 137 | + <option value=""><?php esc_html_e('Select Payment Method', 'easy-invoice'); ?></option> | |
| 136 | 138 | <?php |
| 137 | 139 | $current_payment_method = $payment->getPaymentMethod(); |
| 138 | 140 | if (empty($current_payment_method)) { |
| 139 | 141 | $current_payment_method = get_post_meta($payment->getId(), '_payment_method', true); |
| @@ -165,16 +167,15 @@ | ||
| 165 | 167 | ?> |
| 166 | 168 | </select> |
| 167 | 169 | </div> |
| 168 | 170 | |
| 169 | - <!-- Amount --> | |
| 170 | 171 | <div> |
| 171 | 172 | <label for="amount" class="block text-sm font-medium text-gray-700"> |
| 172 | - <?php _e('Amount', 'easy-invoice'); ?> <span class="text-red-500">*</span> | |
| 173 | + <?php esc_html_e('Amount', 'easy-invoice'); ?> <span class="text-red-500">*</span> | |
| 173 | 174 | </label> |
| 174 | 175 | <div class="mt-1 relative rounded-md shadow-sm"> |
| 175 | 176 | <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none"> |
| 176 | - <span class="text-gray-500 sm:text-sm"><?php echo get_option('easy_invoice_currency_symbol', '$'); ?></span> | |
| 177 | + <span class="text-gray-500 sm:text-sm"><?php echo esc_html(get_option('easy_invoice_currency_symbol', '$')); ?></span> | |
| 177 | 178 | </div> |
| 178 | 179 | <input type="number" name="amount" id="amount" step="0.01" required |
| 179 | 180 | value="<?php echo esc_attr($payment->getAmount()); ?>" |
| 180 | 181 | class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 pl-7 pr-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" |
| @@ -181,12 +182,11 @@ | ||
| 181 | 182 | placeholder="0.00"> |
| 182 | 183 | </div> |
| 183 | 184 | </div> |
| 184 | 185 | |
| 185 | - <!-- Payment Date --> | |
| 186 | 186 | <div> |
| 187 | 187 | <label for="payment_date" class="block text-sm font-medium text-gray-700"> |
| 188 | - <?php _e('Payment Date', 'easy-invoice'); ?> <span class="text-red-500">*</span> | |
| 188 | + <?php esc_html_e('Payment Date', 'easy-invoice'); ?> <span class="text-red-500">*</span> | |
| 189 | 189 | </label> |
| 190 | 190 | <input type="date" name="payment_date" id="payment_date" |
| 191 | 191 | value="<?php |
| 192 | 192 | $payment_date = $payment->getPaymentDate(); |
| @@ -193,9 +193,9 @@ | ||
| 193 | 193 | if (empty($payment_date)) { |
| 194 | 194 | $payment_date = get_post_meta($payment->getId(), '_payment_date', true); |
| 195 | 195 | } |
| 196 | 196 | if (empty($payment_date)) { |
| 197 | - $payment_date = date('Y-m-d'); | |
| 197 | + $payment_date = current_time('Y-m-d'); | |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Ensure date is in YYYY-MM-DD format for HTML date input |
| 201 | 201 | if (!empty($payment_date)) { |
| @@ -200,11 +200,11 @@ | ||
| 200 | 200 | // Ensure date is in YYYY-MM-DD format for HTML date input |
| 201 | 201 | if (!empty($payment_date)) { |
| 202 | 202 | $timestamp = strtotime($payment_date); |
| 203 | 203 | if ($timestamp) { |
| 204 | - $payment_date = date('Y-m-d', $timestamp); | |
| 204 | + $payment_date = gmdate('Y-m-d', $timestamp); | |
| 205 | 205 | } else { |
| 206 | - $payment_date = date('Y-m-d'); | |
| 206 | + $payment_date = current_time('Y-m-d'); | |
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | echo esc_attr($payment_date); |
| @@ -211,31 +211,29 @@ | ||
| 211 | 211 | ?>" required |
| 212 | 212 | class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"> |
| 213 | 213 | </div> |
| 214 | 214 | |
| 215 | - <!-- Status --> | |
| 216 | 215 | <div> |
| 217 | 216 | <label for="status" class="block text-sm font-medium text-gray-700"> |
| 218 | - <?php _e('Status', 'easy-invoice'); ?> <span class="text-red-500">*</span> | |
| 217 | + <?php esc_html_e('Status', 'easy-invoice'); ?> <span class="text-red-500">*</span> | |
| 219 | 218 | </label> |
| 220 | 219 | <select name="status" id="status" required |
| 221 | 220 | class="mt-1 block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md"> |
| 222 | - <option value="pending" <?php selected($payment->getStatus(), 'pending'); ?>><?php _e('Pending', 'easy-invoice'); ?></option> | |
| 223 | - <option value="completed" <?php selected($payment->getStatus(), 'completed'); ?>><?php _e('Completed', 'easy-invoice'); ?></option> | |
| 224 | - <option value="failed" <?php selected($payment->getStatus(), 'failed'); ?>><?php _e('Failed', 'easy-invoice'); ?></option> | |
| 225 | - <option value="refunded" <?php selected($payment->getStatus(), 'refunded'); ?>><?php _e('Refunded', 'easy-invoice'); ?></option> | |
| 221 | + <option value="pending" <?php selected($payment->getStatus(), 'pending'); ?>><?php esc_html_e('Pending', 'easy-invoice'); ?></option> | |
| 222 | + <option value="completed" <?php selected($payment->getStatus(), 'completed'); ?>><?php esc_html_e('Completed', 'easy-invoice'); ?></option> | |
| 223 | + <option value="failed" <?php selected($payment->getStatus(), 'failed'); ?>><?php esc_html_e('Failed', 'easy-invoice'); ?></option> | |
| 224 | + <option value="refunded" <?php selected($payment->getStatus(), 'refunded'); ?>><?php esc_html_e('Refunded', 'easy-invoice'); ?></option> | |
| 226 | 225 | </select> |
| 227 | 226 | </div> |
| 228 | 227 | |
| 229 | - <!-- Notes --> | |
| 230 | 228 | <div class="sm:col-span-2"> |
| 231 | 229 | <label for="notes" class="block text-sm font-medium text-gray-700"> |
| 232 | - <?php _e('Notes', 'easy-invoice'); ?> | |
| 230 | + <?php esc_html_e('Notes', 'easy-invoice'); ?> | |
| 233 | 231 | </label> |
| 234 | 232 | <div class="mt-1"> |
| 235 | 233 | <textarea name="notes" id="notes" rows="3" |
| 236 | 234 | class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" |
| 237 | - placeholder="<?php _e('Add any additional notes about this payment...', 'easy-invoice'); ?>"><?php echo wp_kses_post($payment->getNotes()); ?></textarea> | |
| 235 | + placeholder="<?php echo esc_js(__('Add any additional notes about this payment...', 'easy-invoice')); ?>"><?php echo wp_kses_post($payment->getNotes()); ?></textarea> | |
| 238 | 236 | </div> |
| 239 | 237 | </div> |
| 240 | 238 | </div> |
| 241 | 239 | |
| @@ -242,9 +240,9 @@ | ||
| 242 | 240 | <div class="pt-5"> |
| 243 | 241 | <div class="flex justify-end"> |
| 244 | 242 | <button type="submit" |
| 245 | 243 | class="ml-3 inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"> |
| 246 | - <?php _e('Update Payment', 'easy-invoice'); ?> | |
| 244 | + <?php esc_html_e('Update Payment', 'easy-invoice'); ?> | |
| 247 | 245 | </button> |
| 248 | 246 | </div> |
| 249 | 247 | </div> |
| 250 | 248 | </form> |
| @@ -266,16 +264,16 @@ | ||
| 266 | 264 | processData: false, |
| 267 | 265 | contentType: false, |
| 268 | 266 | success: function(response) { |
| 269 | 267 | if (response.success) { |
| 270 | - window.location.href = '<?php echo admin_url('admin.php?page=easy-invoice-payments'); ?>'; | |
| 268 | + EasyInvoiceToast.success(response.data.message || '<?php echo esc_js(__('Payment updated successfully', 'easy-invoice')); ?>'); | |
| 271 | 269 | } else { |
| 272 | - EasyInvoiceToast.error(response.data.message || '<?php _e('An error occurred', 'easy-invoice'); ?>'); | |
| 270 | + EasyInvoiceToast.error(response.data.message || '<?php echo esc_js(__('An error occurred', 'easy-invoice')); ?>'); | |
| 273 | 271 | } |
| 274 | 272 | }, |
| 275 | 273 | error: function() { |
| 276 | - EasyInvoiceToast.error('<?php _e('An error occurred', 'easy-invoice'); ?>'); | |
| 274 | + EasyInvoiceToast.error('<?php echo esc_js(__('An error occurred', 'easy-invoice')); ?>'); | |
| 277 | 275 | } |
| 278 | 276 | }); |
| 279 | 277 | }); |
| 280 | 278 | }); |
| 281 | 279 | </script> |