| @@ -75,8 +75,10 @@ | ||
| 75 | 75 | add_action('wp_ajax_easy_invoice_test_email', [$this, 'testEmail']); |
| 76 | 76 | add_action('wp_ajax_easy_invoice_test_template_email', [$this, 'testTemplateEmail']); |
| 77 | 77 | add_action('wp_ajax_easy_invoice_test_payment_reminder_email', [$this, 'testPaymentReminderEmail']); |
| 78 | 78 | add_action('wp_ajax_regenerate_invoice_numbers', [$this, 'ajaxRegenerateInvoiceNumbers']); |
| 79 | + add_action('wp_ajax_easy_invoice_add_offline_method', [$this, 'ajaxAddOfflineMethod']); | |
| 80 | + add_action('wp_ajax_easy_invoice_remove_offline_method', [$this, 'ajaxRemoveOfflineMethod']); | |
| 79 | 81 | add_action('wp_ajax_regenerate_quote_numbers', [$this, 'ajaxRegenerateQuoteNumbers']); |
| 80 | 82 | |
| 81 | 83 | // Clear cache on admin init to ensure new fields are recognized |
| 82 | 84 | add_action('admin_init', [$this, 'clearCache']); |
| @@ -576,9 +578,9 @@ | ||
| 576 | 578 | 'col_span' => 'sm:col-span-3' |
| 577 | 579 | ], |
| 578 | 580 | |
| 579 | 581 | 'easy_invoice_invoice_numbering' => ['label' => __('Auto-increment invoice numbers', 'easy-invoice'), 'type' => 'checkbox', 'description' => __('Automatically increment invoice numbers for new invoices', 'easy-invoice'), 'default' => 'yes', 'col_span' => 'sm:col-span-6' ], |
| 580 | - 'easy_invoice_payment_reminder_days' => ['label' => __('Payment Reminder Days', 'easy-invoice'), 'type' => 'number', 'default' => 3, 'col_span' => 'sm:col-span-3'], | |
| 582 | + 'easy_invoice_payment_reminder_days' => ['label' => __('Payment reminder (days after due date)', 'easy-invoice'), 'type' => 'number', 'default' => 3, 'min' => 0, 'col_span' => 'sm:col-span-3', 'description' => __('Emails the Reminder template once to each invoice still owed this many days after its due date. Leave empty to switch reminders off. Easy Invoice Pro replaces this with its own schedule.', 'easy-invoice')], | |
| 581 | 583 | 'easy_invoice_remove_data_on_uninstall' => ['label' => __('Remove all data when the plugin is deleted', 'easy-invoice'), 'type' => 'checkbox', 'default' => 'no', 'col_span' => 'sm:col-span-6', 'description' => __('Off, deleting the plugin from the Plugins screen keeps every invoice, quote, payment, client record and setting, so reinstalling picks up where you left off. On, all of it is removed — invoices are tax records, so leave this off unless you are certain.', 'easy-invoice')], |
| 582 | 584 | ] |
| 583 | 585 | ], |
| 584 | 586 | ]; |
| @@ -813,8 +815,44 @@ | ||
| 813 | 815 | } |
| 814 | 816 | } catch (\Exception $e) { |
| 815 | 817 | throw $e; // Re-throw to be caught by the main try-catch |
| 816 | 818 | } |
| 819 | + } | |
| 820 | + | |
| 821 | + /** | |
| 822 | + * Settings → Payment Methods → "Add an offline method": registers a new | |
| 823 | + * offline payment method (ACH, wire transfer, mobile money, …) by name. | |
| 824 | + */ | |
| 825 | + public function ajaxAddOfflineMethod(): void { | |
| 826 | + check_ajax_referer('easy_invoice_settings', 'nonce'); | |
| 827 | + if (!current_user_can('manage_options')) { | |
| 828 | + wp_send_json_error(['message' => __('You do not have permission to change payment methods.', 'easy-invoice')]); | |
| 829 | + } | |
| 830 | + $title = isset($_POST['title']) ? sanitize_text_field(wp_unslash($_POST['title'])) : ''; | |
| 831 | + $id = \EasyInvoice\Services\OfflinePayments::addCustom($title); | |
| 832 | + if (is_wp_error($id)) { | |
| 833 | + wp_send_json_error(['message' => $id->get_error_message()]); | |
| 834 | + } | |
| 835 | + wp_send_json_success([ | |
| 836 | + 'id' => $id, | |
| 837 | + /* translators: %s: method name. */ | |
| 838 | + 'message' => sprintf(__('"%s" added. Fill in its instructions below and save.', 'easy-invoice'), $title), | |
| 839 | + ]); | |
| 840 | + } | |
| 841 | + | |
| 842 | + /** | |
| 843 | + * Remove a merchant-added offline method. Recorded payments keep the method name. | |
| 844 | + */ | |
| 845 | + public function ajaxRemoveOfflineMethod(): void { | |
| 846 | + check_ajax_referer('easy_invoice_settings', 'nonce'); | |
| 847 | + if (!current_user_can('manage_options')) { | |
| 848 | + wp_send_json_error(['message' => __('You do not have permission to change payment methods.', 'easy-invoice')]); | |
| 849 | + } | |
| 850 | + $id = isset($_POST['id']) ? sanitize_key(wp_unslash($_POST['id'])) : ''; | |
| 851 | + if ('' === $id || !\EasyInvoice\Services\OfflinePayments::removeCustom($id)) { | |
| 852 | + wp_send_json_error(['message' => __('That payment method cannot be removed.', 'easy-invoice')]); | |
| 853 | + } | |
| 854 | + wp_send_json_success(['message' => __('Payment method removed.', 'easy-invoice')]); | |
| 817 | 855 | } |
| 818 | 856 | |
| 819 | 857 | /** |
| 820 | 858 | * Save settings |