PluginProbe
MONEI Payments for WooCommerce / 7.3.0
MONEI Payments for WooCommerce v7.3.0
7.3.3 7.3.2 7.3.1 7.3.0 7.2.4 7.2.3 7.2.2 7.2.0 7.2.1 7.1.3 2.1.0 3.0.0 3.1.0 3.1.1 4.0.0 4.1.0 4.1.1 4.2.0 4.2.1 5.0 5.1.0 5.1.1 5.1.2 5.2.2 5.2.3 All 87 releases
monei / src / Settings / MoneiSettings.php

MoneiSettings.php in MONEI Payments for WooCommerce 7.3.0, at src/Settings/MoneiSettings.php

178 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Monei\Settings;
4
5 use Monei\Services\ApiKeyService;
6 use Psr\Container\ContainerInterface;
7 use WC_Admin_Settings;
8 use WC_Settings_Page;
9
10 class MoneiSettings extends WC_Settings_Page {
11
12 protected ContainerInterface $container;
13 /** @var ApiKeyService */
14 private $apiKeyService;
15
16 public function __construct( ContainerInterface $container ) {
17 $this->id = 'monei_settings';
18 $this->label = __( 'MONEI Settings', 'monei' );
19 $this->container = $container;
20 $this->apiKeyService = $container->get( ApiKeyService::class );
21 parent::__construct();
22 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
23 }
24
25 public function get_settings() {
26 $settings = array(
27 array(
28 'title' => __( 'MONEI Settings', 'monei' ),
29 'type' => 'title',
30 'id' => 'monei_settings_title',
31 ),
32 array(
33 'title' => __( 'API Key Mode', 'monei' ),
34 'type' => 'select',
35 'desc' => __( 'Set to Live to use the production environment.', 'monei' ),
36 'id' => 'monei_apikey_mode',
37 'default' => 'test',
38 'options' => array(
39 'test' => __( 'Test', 'monei' ),
40 'live' => __( 'Live', 'monei' ),
41 ),
42 ),
43 array(
44 'title' => __( 'Test Account ID *', 'monei' ),
45 'type' => 'text',
46 'desc' => __( 'Your MONEI Test Account ID. Available at your MONEI dashboard.', 'monei' ),
47 'id' => 'monei_test_accountid',
48 'default' => '',
49 'class' => 'monei-account-id-field monei-test-account-id-field',
50 'placeholder' => '9b1deb4d-3b7d-4bad-9bdd-2b0c11b3dcb6d',
51 ),
52 array(
53 'title' => __( 'Live Account ID *', 'monei' ),
54 'type' => 'text',
55 'desc' => __( 'Your MONEI Account ID. Available at your MONEI dashboard.', 'monei' ),
56 'id' => 'monei_live_accountid',
57 'default' => '',
58 'class' => 'monei-account-id-field monei-live-account-id-field',
59 'placeholder' => 'f47ac10b-58cc-4372-a567-0e02b2c3d479',
60 ),
61 array(
62 'title' => __( 'Test API Key *', 'monei' ),
63 'type' => 'password',
64 'desc' => __( 'Your MONEI Test API Key. Available at your MONEI dashboard.', 'monei' ),
65 'id' => 'monei_test_apikey',
66 'default' => '',
67 'class' => 'monei-api-key-field monei-test-api-key-field',
68 'placeholder' => 'pk_test_d3m0t3stk3yf0rd3v3l0pm3ntus4g3',
69 ),
70 array(
71 'title' => __( 'Live API Key *', 'monei' ),
72 'type' => 'password',
73 'desc' => __( 'Your MONEI API Key. Available at your MONEI dashboard.', 'monei' ),
74 'id' => 'monei_live_apikey',
75 'default' => '',
76 'class' => 'monei-api-key-field monei-live-api-key-field',
77 'placeholder' => 'pk_live_7h3m4n1f3st0k3yf0r3x4mpl3purp0s3',
78 ),
79 array(
80 'title' => __( 'What to do after payment?', 'monei' ),
81 'type' => 'select',
82 'desc' => __( 'Choose what to do after the customer pays the order. This setting applies to all MONEI payment methods.', 'monei' ),
83 'default' => 'processing',
84 'id' => 'monei_orderdo',
85 'options' => array(
86 'processing' => __( 'Mark as Processing (Recommended)', 'monei' ),
87 'completed' => __( 'Mark as Complete', 'monei' ),
88 ),
89 ),
90 array(
91 'title' => __( 'Payment Action', 'monei' ),
92 'type' => 'select',
93 'desc' => __( 'Choose payment flow: Immediate charge or Pre-authorization.<br>Pre-authorization is supported for: Card, Apple Pay, Google Pay, PayPal.<br>Not supported for: MBWay, Multibanco.', 'monei' ),
94 'default' => 'no',
95 'id' => 'monei_pre_authorize',
96 'options' => array(
97 'no' => __( 'Sale (Immediate charge)', 'monei' ),
98 'yes' => __( 'Authorization (Pre-authorization)', 'monei' ),
99 ),
100 ),
101 array(
102 'title' => __( 'Log Level', 'monei' ),
103 'type' => 'select',
104 'desc' => __( 'Set minimum log level. Only messages at or above this level will be logged.<br>Logs are available in WooCommerce > Status > Logs > Select MONEI Logs.<br>WARNING: INFO level may impact performance.', 'monei' ),
105 'id' => 'monei_log_level',
106 'default' => '3',
107 'options' => array(
108 '1' => __( 'INFO - All messages (Debug mode)', 'monei' ),
109 '2' => __( 'WARNING - Warnings and errors only', 'monei' ),
110 '3' => __( 'ERROR - Errors only (Recommended)', 'monei' ),
111 '4' => __( 'NONE - Disable logging', 'monei' ),
112 ),
113 ),
114 array(
115 'type' => 'sectionend',
116 'id' => 'monei_settings_sectionend',
117 ),
118 );
119
120 return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
121 }
122
123 public function output() {
124 $data = array(
125 'moneiIconUrl' => WC_Monei()->image_url( 'monei-logo.svg' ),
126 'welcomeString' => __( 'Welcome to MONEI! Enhance your payment processing experience with our seamless integration', 'monei' ),
127 'dashboardString' => __( 'Go to Dashboard', 'monei' ),
128 'supportString' => __( 'Support', 'monei' ),
129 'reviewString' => __( 'Leave a review', 'monei' ),
130 );
131
132 $templateManager = $this->container->get( 'Monei\Templates\TemplateManager' );
133 $template = $templateManager->getTemplate( 'monei-settings-header' );
134 if ( $template ) {
135 $template->render( $data );
136 }
137 $settings = $this->get_settings();
138 WC_Admin_Settings::output_fields( $settings );
139 }
140
141 public function save() {
142 $settings = $this->get_settings();
143 WC_Admin_Settings::save_fields( $settings );
144 $this->apiKeyService->update_keys();
145 }
146
147 public function enqueue_admin_scripts( $hook ) {
148 if ( ! function_exists( 'get_current_screen' ) ) {
149 return;
150 }
151
152 $screen = get_current_screen();
153
154 // Ensure we're on the WooCommerce settings page
155 if ( $screen->id !== 'woocommerce_page_wc-settings' ) {
156 return;
157 }
158
159 $plugin_url = plugin_dir_url( dirname( __DIR__ ) );
160 wp_enqueue_style(
161 'monei-admin-css',
162 $plugin_url . 'public/css/monei-admin.css',
163 array(),
164 MONEI_VERSION
165 );
166 wp_register_script(
167 'monei-admin-script',
168 $plugin_url . 'public/js/monei-settings.min.js',
169 array( 'jquery' ),
170 WC_Monei()->version,
171 true
172 );
173 wp_enqueue_script(
174 'monei-admin-script'
175 );
176 }
177 }
178