PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.3.2
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.3.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 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.3.2, at includes/Abstracts/AbstractPaymentGateway.php

128 lines 3.5 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 // Hook into the payment method form display
19 add_action('easy_invoice_payment_method_form', [$this, 'maybeRenderForm'], 10, 2);
20 }
21
22 /**
23 * Initialize the payment gateway
24 */
25 public function init(): void {
26 $this->settings = $this->getSettings();
27 }
28
29 /**
30 * Get payment gateway settings
31 *
32 * @return array
33 */
34 public function getSettings(): array {
35 $settings = [];
36
37 switch ($this->getName()) {
38 case 'paypal':
39 $settings['email'] = get_option('easy_invoice_paypal_email', '');
40 $settings['mode'] = get_option('easy_invoice_paypal_mode', 'live');
41 break;
42
43 // Stripe, Bank Transfer, Cheque, and Cash settings moved to Pro plugin
44 }
45
46 return $settings;
47 }
48
49 /**
50 * Save payment gateway settings
51 *
52 * @param array $settings
53 * @return bool
54 */
55 protected function saveSettings(array $settings): bool {
56 switch ($this->getName()) {
57 case 'paypal':
58 return update_option('easy_invoice_paypal_email', $settings['email'] ?? '');
59
60 // Stripe, Bank Transfer, Cheque, and Cash settings moved to Pro plugin
61
62 default:
63 return false;
64 }
65 }
66
67 /**
68 * Check if payment gateway is enabled
69 *
70 * @return bool
71 */
72 public function isEnabled(): bool {
73 $payment_methods = get_option('easy_invoice_payment_methods', []);
74 $is_enabled = in_array($this->getName(), $payment_methods);
75 return $is_enabled;
76 }
77
78 /**
79 * Log a message
80 *
81 * @param string $message The message to log
82 * @param string $level The log level (info, warning, error)
83 * @return void
84 */
85 protected function log($message, $level = 'info') {
86 // Allow plugins to handle logging
87 do_action('easy_invoice_payment_gateway_log', $message, $level, $this->getName());
88 }
89
90 /**
91 * Get gateway settings configuration for the settings page
92 *
93 * @return array The settings configuration array
94 */
95 public function getSettingsConfig(): array {
96 // Base implementation returns an empty array
97 // Gateway classes should override this method to provide their specific settings
98 return [
99 'show_header' => false,
100 'header_text' => '',
101 'header_class' => '',
102 'fields' => []
103 ];
104 }
105
106 /**
107 * Render the payment form for this gateway
108 *
109 * @param object $invoice The invoice object
110 * @return void
111 */
112 public function renderPaymentForm($invoice): void {
113 // Base implementation does nothing
114 // Gateway classes should override this method to provide their specific payment form
115 }
116
117 /**
118 * Check if this is the gateway being requested and render its form if so
119 *
120 * @param string $gateway_id The gateway ID from the hook
121 * @param object $invoice The invoice object
122 */
123 public function maybeRenderForm($gateway_id, $invoice): void {
124 if ($gateway_id === $this->getName()) {
125 $this->renderPaymentForm($invoice);
126 }
127 }
128 }