PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.1
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.1
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 / Abstracts / AbstractPaymentGateway.php

AbstractPaymentGateway.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.4.1, at includes/Abstracts/AbstractPaymentGateway.php

115 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace EasyInvoice\Abstracts;
3
4 use EasyInvoice\Interfaces\PaymentGatewayInterface;
5
6 abstract class AbstractPaymentGateway implements PaymentGatewayInterface {
7 /**
8 * Gateway settings
9 *
10 * @var array
11 */
12 protected $settings = [];
13
14 /**
15 * Constructor
16 */
17 public function __construct() {
18 }
19
20 /**
21 * Initialize the payment gateway
22 */
23 public function init(): void {
24 $this->settings = $this->getSettings();
25 }
26
27 /**
28 * Get payment gateway settings
29 *
30 * @return array
31 */
32 public function getSettings(): array {
33 $settings = [];
34
35 switch ($this->getName()) {
36 case 'paypal':
37 $settings['email'] = get_option('easy_invoice_paypal_email', '');
38 $settings['mode'] = get_option('easy_invoice_paypal_mode', 'live');
39 break;
40
41 // Stripe, Bank Transfer, Cheque, and Cash settings moved to Pro plugin
42 }
43
44 return $settings;
45 }
46
47 /**
48 * Save payment gateway settings
49 *
50 * @param array $settings
51 * @return bool
52 */
53 protected function saveSettings(array $settings): bool {
54 switch ($this->getName()) {
55 case 'paypal':
56 return update_option('easy_invoice_paypal_email', $settings['email'] ?? '');
57
58 // Stripe, Bank Transfer, Cheque, and Cash settings moved to Pro plugin
59
60 default:
61 return false;
62 }
63 }
64
65 /**
66 * Check if payment gateway is enabled
67 *
68 * @return bool
69 */
70 public function isEnabled(): bool {
71 $payment_methods = get_option('easy_invoice_payment_methods', []);
72 $is_enabled = in_array($this->getName(), $payment_methods);
73 return $is_enabled;
74 }
75
76 /**
77 * Log a message
78 *
79 * @param string $message The message to log
80 * @param string $level The log level (info, warning, error)
81 * @return void
82 */
83 protected function log($message, $level = 'info') {
84 // Allow plugins to handle logging
85 do_action('easy_invoice_payment_gateway_log', $message, $level, $this->getName());
86 }
87
88 /**
89 * Get gateway settings configuration for the settings page
90 *
91 * @return array The settings configuration array
92 */
93 public function getSettingsConfig(): array {
94 // Base implementation returns an empty array
95 // Gateway classes should override this method to provide their specific settings
96 return [
97 'show_header' => false,
98 'header_text' => '',
99 'header_class' => '',
100 'fields' => []
101 ];
102 }
103
104 /**
105 * Render the payment form for this gateway
106 *
107 * @param object $invoice The invoice object
108 * @return void
109 */
110 public function renderPaymentForm($invoice): void {
111 // Base implementation does nothing
112 // Gateway classes should override this method to provide their specific payment form
113 }
114
115 }