PluginProbe
MONEI Payments for WooCommerce / trunk
MONEI Payments for WooCommerce vtrunk
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 trunk, at src/Settings/MoneiSettings.php

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