PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.3.4
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.3.4
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 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / Gateways / ManualGateway.php

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

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