PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.3
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.3
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 / includes / Gateways / ManualGateway.php

ManualGateway.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.4.3, at includes/Gateways/ManualGateway.php

427 lines 14.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Manual Payment Gateway
4 *
5 * @package EasyInvoice
6 * @since 1.0.0
7 */
8
9 namespace EasyInvoice\Gateways;
10
11 use EasyInvoice\Abstracts\AbstractPaymentGateway;
12 use EasyInvoice\Interfaces\PaymentGatewayInterface;
13
14 /**
15 * Manual Payment Gateway Class
16 *
17 * Handles manual payment processing for cash, check, and bank transfer payments
18 *
19 * @since 1.0.0
20 */
21 /**
22 * @deprecated 2.4.2 No longer registered. Bank transfer, cheque and cash are
23 * separate OfflineGateway instances (see Services\OfflinePayments);
24 * the class stays so code that type-checks against it keeps loading.
25 */
26 class ManualGateway extends AbstractPaymentGateway implements PaymentGatewayInterface {
27
28 /**
29 * Gateway name
30 *
31 * @since 1.0.0
32 * @var string
33 */
34 protected $name = 'manual';
35
36 /**
37 * Gateway title
38 *
39 * @since 1.0.0
40 * @var string
41 */
42 protected $title = 'Manual Payment';
43
44 /**
45 * Gateway description
46 *
47 * @since 1.0.0
48 * @var string
49 */
50 protected $description = 'Pay manually via cash, check, or bank transfer';
51
52 /**
53 * Gateway icon
54 *
55 * @since 1.0.0
56 * @var string
57 */
58 protected $icon = 'fas fa-money-bill-wave';
59
60 /**
61 * Constructor
62 *
63 * @since 1.0.0
64 */
65 public function __construct() {
66 $this->init();
67 }
68
69 /**
70 * Initialize the gateway
71 *
72 * @since 1.0.0
73 * @return void
74 */
75 public function init(): void {
76 // Add any initialization logic here
77 }
78
79 /**
80 * Get gateway name
81 *
82 * @since 1.0.0
83 * @return string
84 */
85 public function getName(): string {
86 return $this->name;
87 }
88
89 /**
90 * Get gateway title
91 *
92 * @since 1.0.0
93 * @return string
94 */
95 public function getTitle(): string {
96 return $this->title;
97 }
98
99 /**
100 * Get gateway description
101 *
102 * @since 1.0.0
103 * @return string
104 */
105 public function getDescription(): string {
106 return $this->description;
107 }
108
109 /**
110 * Get gateway icon
111 *
112 * @since 1.0.0
113 * @return string
114 */
115 public function getIcon(): string {
116 return $this->icon;
117 }
118
119 /**
120 * Check if gateway is available
121 *
122 * @since 1.0.0
123 * @return bool
124 */
125 public function isAvailable(): bool {
126 return true; // Manual payment is always available
127 }
128
129 /**
130 * Process payment
131 *
132 * @since 1.0.0
133 * @param float $amount Payment amount
134 * @param array $data Additional payment data
135 * @return array
136 */
137 public function processPayment(float $amount, array $data = []): array {
138 // Manual payments are processed by admin
139 return [
140 'success' => true,
141 'message' => __('Manual payment submitted for verification', 'easy-invoice'),
142 'data' => [
143 'status' => 'pending',
144 'requires_verification' => true
145 ]
146 ];
147 }
148
149 /**
150 * Handle callback
151 *
152 * @since 1.0.0
153 * @param array $data Callback data
154 * @return array
155 */
156 public function handleCallback(array $data): array {
157 // Manual payments don't have callbacks
158 return [
159 'success' => true,
160 'message' => __('Manual payment processed', 'easy-invoice')
161 ];
162 }
163
164 /**
165 * Get payment form fields
166 *
167 * @since 1.0.0
168 * @param int $invoice_id Invoice ID
169 * @return string
170 */
171 public function getPaymentForm(int $invoice_id): string {
172 ob_start();
173 $this->renderPaymentForm((object)['id' => $invoice_id]);
174 return ob_get_clean();
175 }
176
177 /**
178 * Render payment form
179 *
180 * @since 1.0.0
181 * @param object $invoice Invoice object
182 * @return void
183 */
184 public function renderPaymentForm($invoice): void {
185 // Get invoice ID from invoice object
186 $invoice_id = is_object($invoice) && method_exists($invoice, 'getId') ? $invoice->getId() : 0;
187 ?>
188 <div class="manual-payment-form">
189 <div class="payment-methods">
190 <div class="payment-method-option">
191 <input type="radio" id="payment-cash" name="payment_type" value="cash" checked>
192 <label for="payment-cash">
193 <i class="fas fa-money-bill-wave"></i>
194 <span><?php esc_html_e('Cash', 'easy-invoice'); ?></span>
195 </label>
196 </div>
197 <div class="payment-method-option">
198 <input type="radio" id="payment-bank" name="payment_type" value="bank">
199 <label for="payment-bank">
200 <i class="fas fa-university"></i>
201 <span><?php esc_html_e('Bank Transfer', 'easy-invoice'); ?></span>
202 </label>
203 </div>
204 <div class="payment-method-option">
205 <input type="radio" id="payment-cheque" name="payment_type" value="cheque">
206 <label for="payment-cheque">
207 <i class="fas fa-money-check"></i>
208 <span><?php esc_html_e('Cheque', 'easy-invoice'); ?></span>
209 </label>
210 </div>
211 </div>
212
213 <div class="payment-details">
214 <div class="cash-details" id="cash-details">
215 <p><?php esc_html_e('Please pay in cash and notify the administrator.', 'easy-invoice'); ?></p>
216 </div>
217
218 <div class="bank-details" id="bank-details" style="display: none;">
219 <?php $this->renderBankDetails(); ?>
220 </div>
221
222 <div class="cheque-details" id="cheque-details" style="display: none;">
223 <?php $this->renderChequeDetails(); ?>
224 </div>
225 </div>
226
227 <div class="payment-proof-section">
228 <h4><?php esc_html_e('Upload Payment Proof', 'easy-invoice'); ?></h4>
229 <div class="form-group">
230 <label for="payment_proof"><?php esc_html_e('Upload receipt or proof of payment:', 'easy-invoice'); ?></label>
231 <input type="file" id="payment_proof" name="payment_proof" accept="image/*,.pdf">
232 </div>
233 <div class="form-group">
234 <label for="payment_notes"><?php esc_html_e('Additional notes:', 'easy-invoice'); ?></label>
235 <textarea id="payment_notes" name="payment_notes" rows="3"></textarea>
236 </div>
237 </div>
238
239 <div class="form-actions">
240 <button type="button" class="manual-payment-submit" data-invoice-id="<?php echo esc_attr($invoice_id); ?>">
241 <?php esc_html_e('Submit Manual Payment', 'easy-invoice'); ?>
242 </button>
243 </div>
244 </div>
245 <?php
246 }
247
248 /**
249 * Render bank details
250 *
251 * @since 1.0.0
252 * @return void
253 */
254 private function renderBankDetails(): void {
255 $bank_name = get_option('easy_invoice_manual_bank_name', '');
256 $account_name = get_option('easy_invoice_manual_account_name', '');
257 $account_number = get_option('easy_invoice_manual_account_number', '');
258 $routing_number = get_option('easy_invoice_manual_routing_number', '');
259 $swift_code = get_option('easy_invoice_manual_swift_code', '');
260 $bank_address = get_option('easy_invoice_manual_bank_address', '');
261
262 if (empty($bank_name)) {
263 echo '<p>' . esc_html__('Bank transfer details will be provided by the administrator.', 'easy-invoice') . '</p>';
264 return;
265 }
266
267 echo '<table class="bank-details-table">';
268 if ($bank_name) {
269 echo '<tr><th>' . esc_html__('Bank Name', 'easy-invoice') . '</th><td>' . esc_html($bank_name) . '</td></tr>';
270 }
271 if ($account_name) {
272 echo '<tr><th>' . esc_html__('Account Name', 'easy-invoice') . '</th><td>' . esc_html($account_name) . '</td></tr>';
273 }
274 if ($account_number) {
275 echo '<tr><th>' . esc_html__('Account Number', 'easy-invoice') . '</th><td>' . esc_html($account_number) . '</td></tr>';
276 }
277 if ($routing_number) {
278 echo '<tr><th>' . esc_html__('Routing Number', 'easy-invoice') . '</th><td>' . esc_html($routing_number) . '</td></tr>';
279 }
280 if ($swift_code) {
281 echo '<tr><th>' . esc_html__('SWIFT Code', 'easy-invoice') . '</th><td>' . esc_html($swift_code) . '</td></tr>';
282 }
283 if ($bank_address) {
284 echo '<tr><th>' . esc_html__('Bank Address', 'easy-invoice') . '</th><td>' . esc_html($bank_address) . '</td></tr>';
285 }
286 echo '</table>';
287 }
288
289 /**
290 * Render cheque details
291 *
292 * @since 1.0.0
293 * @return void
294 */
295 private function renderChequeDetails(): void {
296 $payee_name = get_option('easy_invoice_manual_payee_name', '');
297 $payee_address = get_option('easy_invoice_manual_payee_address', '');
298
299 if (empty($payee_name)) {
300 echo '<p>' . esc_html__('Cheque payment details will be provided by the administrator.', 'easy-invoice') . '</p>';
301 return;
302 }
303
304 echo '<div class="cheque-info">';
305 if ($payee_name) {
306 echo '<p><strong>' . esc_html__('Make cheque payable to:', 'easy-invoice') . '</strong> ' . esc_html($payee_name) . '</p>';
307 }
308 if ($payee_address) {
309 echo '<p><strong>' . esc_html__('Mail cheque to:', 'easy-invoice') . '</strong> ' . esc_html($payee_address) . '</p>';
310 }
311 echo '</div>';
312 }
313
314 /**
315 * Get gateway settings
316 *
317 * @since 1.0.0
318 * @return array
319 */
320 public function getSettings(): array {
321 return [
322 'enabled' => [
323 'title' => __('Enable Manual Payment', 'easy-invoice'),
324 'type' => 'checkbox',
325 'description' => __('Enable manual payment option', 'easy-invoice'),
326 'default' => 'yes'
327 ],
328 'title' => [
329 'title' => __('Title', 'easy-invoice'),
330 'type' => 'text',
331 'description' => __('Payment method title that will be shown to customers', 'easy-invoice'),
332 'default' => __('Manual Payment', 'easy-invoice')
333 ],
334 'description' => [
335 'title' => __('Description', 'easy-invoice'),
336 'type' => 'textarea',
337 'description' => __('Payment method description that will be shown to customers', 'easy-invoice'),
338 'default' => __('Pay manually via cash, check, or bank transfer', 'easy-invoice')
339 ],
340 'bank_name' => [
341 'title' => __('Bank Name', 'easy-invoice'),
342 'type' => 'text',
343 'description' => __('Bank name for bank transfer payments', 'easy-invoice'),
344 'default' => ''
345 ],
346 'account_name' => [
347 'title' => __('Account Name', 'easy-invoice'),
348 'type' => 'text',
349 'description' => __('Account holder name', 'easy-invoice'),
350 'default' => ''
351 ],
352 'account_number' => [
353 'title' => __('Account Number', 'easy-invoice'),
354 'type' => 'text',
355 'description' => __('Bank account number', 'easy-invoice'),
356 'default' => ''
357 ],
358 'routing_number' => [
359 'title' => __('Routing Number', 'easy-invoice'),
360 'type' => 'text',
361 'description' => __('Bank routing number', 'easy-invoice'),
362 'default' => ''
363 ],
364 'swift_code' => [
365 'title' => __('SWIFT Code', 'easy-invoice'),
366 'type' => 'text',
367 'description' => __('Bank SWIFT code for international transfers', 'easy-invoice'),
368 'default' => ''
369 ],
370 'bank_address' => [
371 'title' => __('Bank Address', 'easy-invoice'),
372 'type' => 'textarea',
373 'description' => __('Bank address for payments', 'easy-invoice'),
374 'default' => ''
375 ],
376 'payee_name' => [
377 'title' => __('Payee Name', 'easy-invoice'),
378 'type' => 'text',
379 'description' => __('Name to make cheques payable to', 'easy-invoice'),
380 'default' => ''
381 ],
382 'payee_address' => [
383 'title' => __('Payee Address', 'easy-invoice'),
384 'type' => 'textarea',
385 'description' => __('Address to mail cheques to', 'easy-invoice'),
386 'default' => ''
387 ]
388 ];
389 }
390
391 /**
392 * Save gateway settings
393 *
394 * @since 1.0.0
395 * @param array $settings Settings to save
396 * @return bool
397 */
398 public function saveSettings(array $settings): bool {
399 foreach ($settings as $key => $value) {
400 update_option('easy_invoice_manual_' . $key, $value);
401 }
402 return true;
403 }
404
405 /**
406 * Get gateway settings values
407 *
408 * @since 1.0.0
409 * @return array
410 */
411 public function getSettingsValues(): array {
412 return [
413 'enabled' => get_option('easy_invoice_manual_enabled', 'yes'),
414 'title' => get_option('easy_invoice_manual_title', __('Manual Payment', 'easy-invoice')),
415 'description' => get_option('easy_invoice_manual_description', __('Pay manually via cash, check, or bank transfer', 'easy-invoice')),
416 'bank_name' => get_option('easy_invoice_manual_bank_name', ''),
417 'account_name' => get_option('easy_invoice_manual_account_name', ''),
418 'account_number' => get_option('easy_invoice_manual_account_number', ''),
419 'routing_number' => get_option('easy_invoice_manual_routing_number', ''),
420 'swift_code' => get_option('easy_invoice_manual_swift_code', ''),
421 'bank_address' => get_option('easy_invoice_manual_bank_address', ''),
422 'payee_name' => get_option('easy_invoice_manual_payee_name', ''),
423 'payee_address' => get_option('easy_invoice_manual_payee_address', '')
424 ];
425 }
426 }
427