PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.1.18
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.1.18
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 / assets / js / manual-payment.js

manual-payment.js in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.1.18, at assets/js/manual-payment.js

275 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Manual Payment JavaScript
3 *
4 * Handles manual payment form interactions
5 *
6 * @package EasyInvoice
7 * @since 1.0.0
8 */
9
10 // Add CSS styles for manual payment
11 jQuery('<style>')
12 .prop('type', 'text/css')
13 .html(`
14 .manual-payment-form {
15 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
16 }
17
18 .payment-methods {
19 display: flex;
20 gap: 12px;
21 margin-bottom: 20px;
22 flex-wrap: wrap;
23 }
24
25 .payment-method-option {
26 flex: 1;
27 min-width: 120px;
28 }
29
30 .payment-method-option input[type="radio"] {
31 display: none;
32 }
33
34 .payment-method-option label {
35 display: flex;
36 flex-direction: column;
37 align-items: center;
38 padding: 16px;
39 border: 2px solid #e5e7eb;
40 border-radius: 8px;
41 cursor: pointer;
42 transition: all 0.2s ease;
43 background: #ffffff;
44 }
45
46 .payment-method-option label:hover {
47 border-color: #10b981;
48 background: #f0fdf4;
49 }
50
51 .payment-method-option input[type="radio"]:checked + label {
52 border-color: #10b981;
53 background: #f0fdf4;
54 color: #059669;
55 }
56
57 .payment-method-option label i {
58 font-size: 24px;
59 margin-bottom: 8px;
60 }
61
62 .payment-method-option label span {
63 font-size: 14px;
64 font-weight: 500;
65 }
66
67 .payment-details {
68 margin-bottom: 20px;
69 padding: 16px;
70 background: #f8fafc;
71 border-radius: 8px;
72 border: 1px solid #e5e7eb;
73 }
74
75 .bank-details-table {
76 width: 100%;
77 border-collapse: collapse;
78 margin-bottom: 16px;
79 }
80
81 .bank-details-table th,
82 .bank-details-table td {
83 padding: 8px 12px;
84 border-bottom: 1px solid #e5e7eb;
85 text-align: left;
86 }
87
88 .bank-details-table th {
89 font-weight: 600;
90 color: #374151;
91 width: 40%;
92 }
93
94 .payment-proof-section {
95 padding: 20px;
96 background: #ffffff;
97 border: 1px solid #e5e7eb;
98 border-radius: 8px;
99 }
100
101 .payment-proof-section h4 {
102 margin: 0 0 16px 0;
103 font-size: 16px;
104 font-weight: 600;
105 color: #374151;
106 }
107
108 .form-group {
109 margin-bottom: 16px;
110 }
111
112 .form-group label {
113 display: block;
114 margin-bottom: 6px;
115 font-weight: 500;
116 color: #374151;
117 }
118
119 .form-group input[type="file"],
120 .form-group textarea {
121 width: 100%;
122 padding: 10px;
123 border: 1px solid #d1d5db;
124 border-radius: 6px;
125 font-size: 14px;
126 transition: border-color 0.2s ease;
127 }
128
129 .form-group input[type="file"]:focus,
130 .form-group textarea:focus {
131 outline: none;
132 border-color: #10b981;
133 box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
134 }
135
136 .form-actions {
137 margin-top: 20px;
138 text-align: right;
139 }
140
141 .manual-payment-submit {
142 background: #10b981;
143 color: white;
144 padding: 12px 24px;
145 border: none;
146 border-radius: 6px;
147 font-size: 14px;
148 font-weight: 500;
149 cursor: pointer;
150 transition: background-color 0.2s ease;
151 }
152
153 .manual-payment-submit:hover {
154 background: #059669;
155 }
156
157 .manual-payment-submit:disabled {
158 background: #9ca3af;
159 cursor: not-allowed;
160 }
161
162 #payment-proof-preview {
163 margin-top: 12px;
164 padding: 12px;
165 background: #f8fafc;
166 border: 1px solid #e5e7eb;
167 border-radius: 6px;
168 }
169
170 #payment-proof-preview img {
171 max-width: 200px;
172 max-height: 200px;
173 border-radius: 4px;
174 }
175 `)
176 .appendTo('head');
177
178 jQuery(document).ready(function($) {
179 // Handle payment method selection
180 $(document).on('change', 'input[name="payment_type"]', function() {
181 const selectedMethod = $(this).val();
182
183 // Hide all payment details
184 $('.cash-details, .bank-details, .cheque-details').hide();
185
186 // Show selected payment details
187 $('#' + selectedMethod + '-details').show();
188 });
189
190 // Handle manual payment submission
191 $(document).on('click', '.manual-payment-submit', function(e) {
192 e.preventDefault();
193
194 const form = $(this).closest('form');
195 const invoiceId = form.find('input[name="invoice_id"]').val();
196 const paymentType = form.find('input[name="payment_type"]:checked').val();
197 const paymentNotes = form.find('textarea[name="payment_notes"]').val();
198 const paymentProof = form.find('input[name="payment_proof"]')[0].files[0];
199
200 // Validate form
201 if (!paymentType) {
202 alert('Please select a payment method');
203 return;
204 }
205
206 // Create form data
207 const formData = new FormData();
208 formData.append('action', 'easy_invoice_submit_manual_payment');
209 formData.append('invoice_id', invoiceId);
210 formData.append('payment_type', paymentType);
211 formData.append('payment_notes', paymentNotes);
212 formData.append('payment_proof', paymentProof);
213 formData.append('nonce', easy_invoice_ajax.nonce);
214
215 // Show loading
216 $(this).prop('disabled', true).text('Processing...');
217
218 // Submit payment
219 $.ajax({
220 url: easy_invoice_ajax.ajax_url,
221 type: 'POST',
222 data: formData,
223 processData: false,
224 contentType: false,
225 success: function(response) {
226 if (response.success) {
227 alert('Payment submitted successfully! Your payment will be verified by the administrator.');
228 // Reload page or redirect
229 window.location.reload();
230 } else {
231 alert('Error: ' + response.data.message);
232 }
233 },
234 error: function() {
235 alert('An error occurred while processing your payment. Please try again.');
236 },
237 complete: function() {
238 // Restore button
239 $(this).prop('disabled', false).text('Submit Payment');
240 }
241 });
242 });
243
244 // Handle payment proof file upload
245 $(document).on('change', '#payment_proof', function() {
246 const file = this.files[0];
247 const fileSize = file.size / 1024 / 1024; // Convert to MB
248
249 if (fileSize > 5) {
250 alert('File size must be less than 5MB');
251 $(this).val('');
252 return;
253 }
254
255 const allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'application/pdf'];
256 if (!allowedTypes.includes(file.type)) {
257 alert('Only JPG, PNG, GIF, and PDF files are allowed');
258 $(this).val('');
259 return;
260 }
261
262 // Show file preview
263 const preview = $('#payment-proof-preview');
264 if (file.type.startsWith('image/')) {
265 const reader = new FileReader();
266 reader.onload = function(e) {
267 preview.html('<img src="' + e.target.result + '" style="max-width: 200px; max-height: 200px;" />');
268 };
269 reader.readAsDataURL(file);
270 } else {
271 preview.html('<p>' + file.name + ' (' + fileSize.toFixed(2) + ' MB)</p>');
272 }
273 });
274 });
275