PluginProbe
MultiSafepay plugin for WooCommerce / trunk
MultiSafepay plugin for WooCommerce vtrunk
6.11.1 6.12.0 6.13.0 6.2.0 6.2.1 6.3.0 6.3.1 6.4.0 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.6.0 6.6.1 6.6.2 6.7.0 6.7.1 6.7.2 6.7.3 6.8.0 6.8.1 6.8.2 6.8.3 6.9.0 All 84 releases
multisafepay / src / Settings / SettingsFields.php

SettingsFields.php in MultiSafepay plugin for WooCommerce trunk, at src/Settings/SettingsFields.php

377 lines 18.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace MultiSafepay\WooCommerce\Settings;
4
5 use MultiSafepay\WooCommerce\Services\PaymentMethodService;
6
7 /**
8 * Defines the settings fields properties
9 *
10 * Class SettingsFields
11 *
12 * @package MultiSafepay\WooCommerce\Settings
13 */
14 class SettingsFields {
15
16 /**
17 * Return the settings fields
18 *
19 * @return array
20 */
21 public function get_settings(): array {
22 $settings = array();
23 $settings['general'] = $this->get_settings_general();
24 $settings['options'] = $this->get_settings_options();
25 $settings['order_status'] = $this->get_settings_order_status();
26 $settings = apply_filters( 'multisafepay_common_settings_fields', $settings );
27 return $settings;
28 }
29
30 /**
31 * Return the settings fields for general section
32 *
33 * @return array
34 */
35 private function get_settings_general(): array {
36 return array(
37 'title' => '',
38 'intro' => '',
39 'fields' => array(
40 array(
41 'id' => 'multisafepay_testmode',
42 'label' => __( 'Test Mode', 'multisafepay' ),
43 'description' => '',
44 'type' => 'checkbox',
45 'default' => false,
46 'placeholder' => __( 'Test Mode', 'multisafepay' ),
47 'tooltip' => __( 'Check this option if you want to enable MultiSafepay in test mode.', 'multisafepay' ),
48 'callback' => '',
49 'setting_type' => 'boolean',
50 'sort_order' => 1,
51 ),
52 array(
53 'id' => 'multisafepay_test_api_key',
54 'label' => __( 'Test API Key', 'multisafepay' ),
55 'description' => '',
56 'type' => 'password',
57 'default' => '',
58 'placeholder' => __( 'Test API Key ', 'multisafepay' ),
59 'tooltip' => __( 'Test API Key', 'multisafepay' ),
60 'callback' => '',
61 'setting_type' => 'string',
62 'sort_order' => 2,
63 ),
64 array(
65 'id' => 'multisafepay_api_key',
66 'label' => __( 'Live API Key', 'multisafepay' ),
67 'description' => '',
68 'type' => 'password',
69 'default' => '',
70 'placeholder' => __( 'Live API Key ', 'multisafepay' ),
71 'tooltip' => __( 'Live API Key', 'multisafepay' ),
72 'callback' => '',
73 'setting_type' => 'string',
74 'sort_order' => 3,
75 ),
76 ),
77 );
78 }
79
80 /**
81 * Return the settings fields for options section
82 *
83 * @return array
84 */
85 private function get_settings_options(): array {
86 return array(
87 'title' => '',
88 'intro' => '',
89 'fields' => array(
90 array(
91 'id' => 'multisafepay_debugmode',
92 'label' => __( 'Debug Mode', 'multisafepay' ),
93 'description' => 'Is recommended to keep debug mode disabled in live environment',
94 'type' => 'checkbox',
95 'default' => false,
96 'placeholder' => __( 'Debug Mode', 'multisafepay' ),
97 'tooltip' => __( 'Logs additional information to the system log', 'multisafepay' ),
98 'callback' => '',
99 'setting_type' => 'boolean',
100 'sort_order' => 1,
101 ),
102 array(
103 'id' => 'multisafepay_group_credit_cards',
104 'label' => __( 'Group debit and credit cards', 'multisafepay' ),
105 'description' => __( 'If is enabled, payment methods classified as debit and credit cards (Amex, Maestro, Mastercard, and Visa) will be shown grouped as a single payment method', 'multisafepay' ),
106 'type' => 'checkbox',
107 'default' => (bool) get_option(
108 'multisafepay_group_credit_cards',
109 PaymentMethodService::is_multisafepay_credit_card_woocommerce_payment_gateway_enabled()
110 ),
111 'placeholder' => __( 'Group debit and credit cards', 'multisafepay' ),
112 'tooltip' => '',
113 'callback' => '',
114 'setting_type' => 'boolean',
115 'sort_order' => 3,
116 ),
117 array(
118 'id' => 'multisafepay_order_request_description',
119 'label' => __( 'Order Description', 'multisafepay' ),
120 'description' => __( 'A text which will be shown with the order in MultiSafepay Control. If the customer’s bank supports it this description will also be shown on the customer’s bank statement', 'multisafepay' ),
121 'type' => 'text',
122 'default' => 'Payment for order: {order_number}',
123 'placeholder' => __( 'Order Description.', 'multisafepay' ),
124 'tooltip' => __( 'You can include the order number using {order_number}', 'multisafepay' ),
125 'callback' => '',
126 'setting_type' => 'string',
127 'sort_order' => 10,
128 ),
129 array(
130 'id' => 'multisafepay_trigger_transaction_to_invoiced',
131 'label' => __( 'Set transaction as invoiced', 'multisafepay' ),
132 'description' => __( 'When the order reaches this status, we send the invoice id to MultiSafepay', 'multisafepay' ),
133 'type' => 'select',
134 'options' => array(
135 'wc-processing' => __( 'Processing', 'multisafepay' ),
136 'wc-completed' => __( 'Completed', 'multisafepay' ),
137 ),
138 'default' => 'wc-completed',
139 'placeholder' => __( 'Set transaction as invoiced', 'multisafepay' ),
140 'tooltip' => 'The invoice id will be added to financial reports and exports generated within MultiSafepay Control',
141 'callback' => '',
142 'setting_type' => 'string',
143 'sort_order' => 20,
144 ),
145 array(
146 'id' => 'multisafepay_trigger_transaction_to_shipped',
147 'label' => __( 'Set transaction as shipped', 'multisafepay' ),
148 'description' => __( 'When the order reaches this status, a notification will be sent to MultiSafepay to set the transaction status as shipped', 'multisafepay' ),
149 'type' => 'select',
150 'options' => array(
151 'wc-processing' => __( 'Processing', 'multisafepay' ),
152 'wc-completed' => __( 'Completed', 'multisafepay' ),
153 ),
154 'default' => 'wc-completed',
155 'placeholder' => __( 'Set transaction as shipped', 'multisafepay' ),
156 'tooltip' => '',
157 'callback' => '',
158 'setting_type' => 'string',
159 'sort_order' => 25,
160 ),
161 array(
162 'id' => 'multisafepay_redirect_after_cancel',
163 'label' => __( 'After cancel redirect the customer to', 'multisafepay' ),
164 'description' => __( 'When the order is cancelled by the customer, redirect the customer to the selected page', 'multisafepay' ),
165 'type' => 'select',
166 'options' => array(
167 'cart' => __( 'Cart Page', 'multisafepay' ),
168 'checkout' => __( 'Checkout Page', 'multisafepay' ),
169 ),
170 'default' => 'cart',
171 'placeholder' => __( 'After cancel redirect the customer to', 'multisafepay' ),
172 'tooltip' => '',
173 'callback' => '',
174 'setting_type' => 'string',
175 'sort_order' => 30,
176 ),
177 array(
178 'id' => 'multisafepay_final_order_status',
179 'label' => __( 'Is completed the final order status?', 'multisafepay' ),
180 'description' => __( 'When the order reaches the completed status, the notification callback from MultiSafepay will not alter it.', 'multisafepay' ),
181 'type' => 'checkbox',
182 'default' => false,
183 'placeholder' => __( 'Is completed the final order status?', 'multisafepay' ),
184 'tooltip' => '',
185 'callback' => '',
186 'setting_type' => 'boolean',
187 'sort_order' => 35,
188 ),
189 array(
190 'id' => 'multisafepay_time_active',
191 'label' => __( 'Value lifetime of payment link', 'multisafepay' ),
192 'description' => '',
193 'type' => 'text',
194 'default' => '30',
195 'placeholder' => __( 'Value lifetime of payment link', 'multisafepay' ),
196 'tooltip' => '',
197 'callback' => '',
198 'setting_type' => 'int',
199 'sort_order' => 40,
200 ),
201 array(
202 'id' => 'multisafepay_time_unit',
203 'label' => __( 'Unit lifetime of payment link', 'multisafepay' ),
204 'description' => __( 'The lifetime of a payment link by default is 30 days. This means that the customer has 30 days to complete the transaction using the payment link', 'multisafepay' ),
205 'type' => 'select',
206 'options' => array(
207 'days' => __( 'Days', 'multisafepay' ),
208 'hours' => __( 'Hours', 'multisafepay' ),
209 'seconds' => __( 'Seconds', 'multisafepay' ),
210 ),
211 'default' => 'days',
212 'placeholder' => __( 'Unit lifetime of payment link', 'multisafepay' ),
213 'tooltip' => '',
214 'callback' => '',
215 'setting_type' => 'string',
216 'sort_order' => 45,
217 ),
218 array(
219 'id' => 'multisafepay_second_chance',
220 'label' => __( 'Second Chance', 'multisafepay' ),
221 'description' => __( 'More information about Second Chance on <a href="https://docs.multisafepay.com/docs/second-chance" target="_blank">MultiSafepay\'s Documentation Center</a>.', 'multisafepay' ),
222 'type' => 'checkbox',
223 'default' => false,
224 'placeholder' => __( 'Second Chance', 'multisafepay' ),
225 'tooltip' => __( 'MultiSafepay will send two Second Chance reminder emails. In the emails, MultiSafepay will include a link to allow the consumer to finalize the payment. The first Second Chance email is sent 1 hour after the transaction was initiated and the second after 24 hours. To receive second chance emails, this option must also be activated within your MultiSafepay account, otherwise it will not work.', 'multisafepay' ),
226 'callback' => '',
227 'setting_type' => 'boolean',
228 'sort_order' => 50,
229 ),
230 array(
231 'id' => 'multisafepay_payment_component_template_id',
232 'label' => __( 'Payment Component Template ID', 'multisafepay' ),
233 'description' => __( 'If empty, the default one will be used', 'multisafepay' ),
234 'type' => 'text',
235 'default' => '',
236 'placeholder' => __( 'Payment Component Template ID', 'multisafepay' ),
237 'tooltip' => '',
238 'callback' => '',
239 'setting_type' => 'string',
240 'sort_order' => 55,
241 ),
242 array(
243 'id' => 'multisafepay_checkout_block_payment_icons',
244 'label' => __( 'Show Payment Icons in WooCommerce Checkout Block', 'multisafepay' ),
245 'description' => __( 'Enable this option to show payment icons on the Checkout Block', 'multisafepay' ),
246 'type' => 'checkbox',
247 'default' => false,
248 'placeholder' => __( 'Show Payment Icons in WooCommerce Checkout Block', 'multisafepay' ),
249 'tooltip' => '',
250 'callback' => '',
251 'setting_type' => 'boolean',
252 'sort_order' => 60,
253 ),
254 array(
255 'id' => 'multisafepay_disable_shopping_cart',
256 'label' => __( 'Disable Shopping Cart on the MultiSafepay payment page', 'multisafepay' ),
257 'description' => __( 'Enable this option to hide the cart items on the MultiSafepay payment page, leaving only the total order amount. Note: This behavior won\'t be adopted by the the payment methods which require shopping cart like Riverty, E-Invoicing, in3, Klarna and Pay After Delivery.', 'multisafepay' ),
258 'type' => 'checkbox',
259 'default' => false,
260 'placeholder' => __( 'Disable Shopping Cart', 'multisafepay' ),
261 'tooltip' => '',
262 'callback' => '',
263 'setting_type' => 'boolean',
264 'sort_order' => 80,
265 ),
266 ),
267 );
268 }
269
270 /**
271 * Return the settings fields for order status section
272 *
273 * @return array
274 */
275 private function get_settings_order_status(): array {
276 $wc_order_statuses = $this->get_wc_get_order_statuses();
277
278 // Complete status is manage by $order->complete_payment() in the notification;
279 // but still is important get a default value for this in case is required somewhere else as a fallback.
280 $multisafepay_order_statuses = $this->get_multisafepay_order_statuses();
281 unset( $multisafepay_order_statuses['completed_status'] );
282
283 $order_status_fields = array();
284 $sort_order = 1;
285 foreach ( $multisafepay_order_statuses as $key => $multisafepay_order_status ) {
286 $order_status_fields[] = array(
287 'id' => 'multisafepay_' . $key,
288 'label' => $multisafepay_order_status['label'],
289 'description' => '',
290 'type' => 'select',
291 'options' => $wc_order_statuses,
292 'default' => $multisafepay_order_status['default'],
293 'placeholder' => __( 'Select order status', 'multisafepay' ),
294 'tooltip' => '',
295 'callback' => '',
296 'setting_type' => 'string',
297 'sort_order' => $sort_order,
298 );
299 $sort_order++;
300 }
301
302 return array(
303 'title' => '',
304 'intro' => '',
305 'fields' => $order_status_fields,
306 );
307 }
308
309
310 /**
311 * Returns the WooCommerce registered order statuses
312 *
313 * @see http://hookr.io/functions/wc_get_order_statuses/
314 *
315 * @return array
316 */
317 private function get_wc_get_order_statuses(): array {
318 $order_statuses = wc_get_order_statuses();
319 return $order_statuses;
320 }
321
322 /**
323 * Returns the MultiSafepay order statuses to create settings fields
324 * and match them with WooCommerce order statuses
325 *
326 * @return array
327 */
328 public static function get_multisafepay_order_statuses(): array {
329 return array(
330 'initialized_status' => array(
331 'label' => __( 'Initialized', 'multisafepay' ),
332 'default' => 'wc-pending',
333 ),
334 'completed_status' => array(
335 'label' => __( 'Completed', 'multisafepay' ),
336 'default' => 'wc-processing',
337 ),
338 'uncleared_status' => array(
339 'label' => __( 'Uncleared', 'multisafepay' ),
340 'default' => 'wc-on-hold',
341 ),
342 'reserved_status' => array(
343 'label' => __( 'Reserved', 'multisafepay' ),
344 'default' => 'wc-on-hold',
345 ),
346 'void_status' => array(
347 'label' => __( 'Void', 'multisafepay' ),
348 'default' => 'wc-cancelled',
349 ),
350 'declined_status' => array(
351 'label' => __( 'Declined', 'multisafepay' ),
352 'default' => 'wc-failed',
353 ),
354 'expired_status' => array(
355 'label' => __( 'Expired', 'multisafepay' ),
356 'default' => 'wc-cancelled',
357 ),
358 'shipped_status' => array(
359 'label' => __( 'Shipped', 'multisafepay' ),
360 'default' => 'wc-completed',
361 ),
362 'refunded_status' => array(
363 'label' => __( 'Refunded', 'multisafepay' ),
364 'default' => 'wc-refunded',
365 ),
366 'cancelled_status' => array(
367 'label' => __( 'Cancelled', 'multisafepay' ),
368 'default' => 'wc-cancelled',
369 ),
370 'chargedback_status' => array(
371 'label' => __( 'Chargedback', 'multisafepay' ),
372 'default' => 'wc-on-hold',
373 ),
374 );
375 }
376 }
377