PluginProbe
seQura / 2.0.12
seQura v2.0.12
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
sequra / class-sequraconfigformfields.php

class-sequraconfigformfields.php in seQura 2.0.12, at class-sequraconfigformfields.php

321 lines 11.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Helper class from config form.
4 *
5 * @package woocommerce-sequra
6 */
7
8 /**
9 * SequraConfigFormFields class
10 */
11 class SequraConfigFormFields {
12
13 /**
14 * SequraPaymentGateway variable
15 *
16 * @var SequraPaymentGateway
17 */
18 protected $pm;
19
20 /**
21 * Initialize Gateway Settings Form Fields
22 *
23 * @param SequraPaymentGateway $pm the gateway.
24 */
25 public function __construct( &$pm ) {
26 $this->pm = $pm;
27 }
28
29 /**
30 * Add form fields
31 *
32 * @return void
33 */
34 public function add_form_fields() {
35 $this->pm->form_fields = array(
36 'enabled' => array(
37 'title' => __( 'Enable/Disable', 'sequra' ),
38 'type' => 'checkbox',
39 'description' => __( 'Enable seQura payments', 'sequra' ),
40 'default' => 'no',
41 ),
42 'title' => array(
43 'title' => __( 'Title', 'sequra' ),
44 'type' => 'text',
45 'description' => __( 'This controls the title which the user sees during checkout.', 'sequra' ),
46 'default' => __( 'Flexible payment with seQura', 'sequra' ),
47 ),
48 'sign-up-info' => array(
49 'title' => __( 'Credentials:', 'sequra' ),
50 'type' => 'title',
51 'description' => sprintf(
52 // translators: %s: URL to seQura signup page.
53 __( 'Following information should be provided by seQura, you can sign-up <a href="%s">here</a> to get it.', 'sequra' ),
54 $this->get_signup_url()
55 ),
56 ),
57 'merchantref' => array(
58 'title' => __( 'seQura Merchant Reference', 'sequra' ),
59 'type' => 'text',
60 'default' => '',
61 ),
62 'user' => array(
63 'title' => __( 'seQura Username', 'sequra' ),
64 'type' => 'text',
65 'default' => '',
66 'css' => 'color:' . ( $this->pm->is_valid_auth ? 'green' : 'red' ) . ';width: 450px;',
67 ),
68 'password' => array(
69 'title' => __( 'Password', 'sequra' ),
70 'type' => 'text',
71 'default' => '',
72 ),
73 'assets_secret' => array(
74 'title' => __( 'Assets secret', 'sequra' ),
75 'type' => 'text',
76 'default' => '',
77 ),
78 'enable_for_virtual' => array(
79 'title' => __( 'Enable for virtual orders', 'sequra' ),
80 'label' => __( 'Enable seQura for services', 'sequra' ),
81 'type' => 'checkbox',
82 'description' => __( 'Your contract must allow selling services, seQura will be enabled only for virtual products that have a "Service end date" specified. Only one product can be purchased at a time', 'sequra' ),
83 'default' => 'no',
84 ),
85 'default_service_end_date' => array(
86 'title' => __( 'Default service end date', 'sequra' ),
87 'desc_tip' => true,
88 'type' => 'text',
89 'description' => __( 'Dates as 2017-08-31, time ranges as P3M15D (3 months and 15 days). It applies by default to all product unless a different value is set at the product settings page.', 'sequra' ),
90 'default' => 'P1Y',
91 'placeholder' => __( 'ISO8601 format', 'sequra' ),
92 'custom_attributes' => array(
93 'pattern' => SequraHelper::ISO8601_PATTERN,
94 'dependson' => 'enable_for_virtual',
95 ),
96 ),
97 'allow_payment_delay' => array(
98 'title' => __( 'Allow first payment delay', 'sequra' ),
99 'desc_tip' => true,
100 'type' => 'checkbox',
101 'description' => __( 'Do not enable except by indication of seQura.', 'sequra' ),
102 'default' => 'no',
103 'custom_attributes' => array(
104 'dependson' => 'enable_for_virtual',
105 ),
106 ),
107 'allow_registration_items' => array(
108 'title' => __( 'Allow registration items', 'sequra' ),
109 'desc_tip' => true,
110 'type' => 'checkbox',
111 'description' => __( 'Allows configuring part of the product price to be paid in advance as registration', 'sequra' ) . __( 'Do not enable except by indication of seQura.', 'sequra' ),
112 'default' => 'no',
113 'custom_attributes' => array(
114 'dependson' => 'enable_for_virtual',
115 ),
116 ),
117 'env' => array(
118 'title' => __( 'Environment', 'sequra' ),
119 'type' => 'select',
120 'description' => __( 'While working in Sandbox the methods will only show to the following IP addresses.', 'sequra' ),
121 'default' => '1',
122 'desc_tip' => true,
123 'options' => array(
124 '1' => __( 'Sandbox', 'sequra' ),
125 '0' => __( 'Live', 'sequra' ),
126 ),
127 ),
128 // phpcs:disable WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders, WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__REMOTE_ADDR__
129 'test_ips' => array(
130 'title' => __( 'IPs for testing', 'sequra' ),
131 'label' => '',
132 'type' => 'text',
133 'description' => sprintf(
134 // translators: %s: IP address.
135 __( 'When working is sandbox mode only these ips addresses will see the plugin. Current IP: %s', 'sequra' ),
136 isset( $_SERVER['REMOTE_ADDR'] ) ?
137 esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) :
138 ''
139 ),
140 'desc_tip' => false,
141 'default' => gethostbyname( 'proxy-es.dev.sequra.es' ) .
142 ( isset( $_SERVER['REMOTE_ADDR'] ) ?
143 ',' . sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) :
144 ''
145 ),
146 ),
147 // phpcs:enable WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders, WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__REMOTE_ADDR__
148 'debug' => array(
149 'title' => __( 'Debugging', 'sequra' ),
150 'label' => __( 'Debug mode', 'sequra' ),
151 'type' => 'checkbox',
152 'description' => __( 'Only for developers.', 'sequra' ) . ' <a href="' . esc_url( admin_url( 'admin.php?page=sequra-logs' ) ) . '">' . __( 'View logs', 'sequra' ) . '</a>',
153 'default' => 'no',
154 ),
155 );
156 $this->add_active_methods_info();
157 $this->init_communication_form_fields();
158 /**
159 * Filter to add custom settings
160 *
161 * @since 2.0.0
162 */
163 $this->pm->form_fields = apply_filters( 'woocommerce_sequra_init_form_fields', $this->pm->form_fields, $this );
164 }
165
166 /**
167 * Get signup URL
168 *
169 * @return string
170 */
171 private function get_signup_url() {
172 $lang = substr( get_locale(), 0, 2 );
173 if ( in_array( $lang, array( 'es', 'pt', 'it', 'fr' ), true ) ) {
174 return 'https://sqra.es/signupw' . $lang;
175 }
176 return 'https://sqra.es/signupwen';
177 }
178
179 /**
180 * Initialize Gateway Settings Form Fields
181 */
182 private function add_active_methods_info() {
183 $this->pm->form_fields['active_methods_info'] = array(
184 'title' => __( 'Active payment methods', 'sequra' ),
185 'type' => 'title',
186 /* translators: %s: URL */
187 'description' => __( 'Information will be available once the credentials are set and correct', 'sequra' ),
188 );
189 if ( $this->pm->is_valid_auth ) {
190 $this->pm->form_fields['active_methods_info']['description'] =
191 '<ul><li>' . implode(
192 '</li><li>',
193 $this->pm->get_remote_config()->get_merchant_active_payment_products( 'title' )
194 ) . '</li></ul>';
195 }
196 }
197 /**
198 * Initialize Gateway Settings Form Fields
199 */
200 private function init_communication_form_fields() {
201 $this->pm->form_fields['communication_fields'] = array(
202 'title' => __( 'Communication configuration', 'sequra' ),
203 'type' => 'title',
204 /* translators: %s: URL */
205 'description' => '',
206 );
207 $this->pm->form_fields['price_css_sel'] = array(
208 'title' => __( 'CSS price selector', 'sequra' ),
209 'type' => 'text',
210 'description' => __( 'CSS selector to get the price for widgets in products', 'sequra' ),
211 'default' => '.summary .price>.amount,.summary .price ins .amount',
212 );
213 $methods = $this->pm->get_remote_config()->get_merchant_payment_methods();
214 array_walk(
215 $methods,
216 array( $this, 'init_communication_form_fields_for_method' )
217 );
218 }
219
220 /**
221 * Initialize Gateway Settings Form Fields for each method
222 *
223 * @param array $method payment method.
224 */
225 private function init_communication_form_fields_for_method( $method ) {
226 switch ( SequraRemoteConfig::get_family_for( $method ) ) {
227 case 'INVOICE':
228 $this->fields_for_invoice( $method );
229 break;
230 case 'PARTPAYMENT':
231 $this->fields_for_partpayment( $method );
232 break;
233 }
234 }
235
236 /**
237 * Initialize Gateway Settings Form Fields for each method
238 *
239 * @param array $method payment method.
240 */
241 private function fields_for_partpayment( $method ) {
242 $product = $this->pm->get_remote_config()->build_unique_product_code( $method );
243 $this->pm->form_fields[ 'partpayment_config_' . $product ] = array(
244 'title' => sprintf(
245 // translators: %s: payment method title.
246 __( 'Simulator config for %s', 'sequra' ),
247 $method['title']
248 ),
249 'type' => 'title',
250 );
251 $this->pm->form_fields[ 'enabled_in_product_' . $product ] = array(
252 'title' => __( 'Show in product page', 'sequra' ),
253 'type' => 'checkbox',
254 'description' => __( 'Show widget on product page', 'sequra' ),
255 'default' => 'yes',
256 );
257 $this->pm->form_fields[ 'dest_css_sel_' . $product ] = array(
258 'title' => __( 'CSS selector for widget in product page', 'sequra' ),
259 'type' => 'text',
260 'description' => __(
261 'CSS after which the simulator will be drawn.',
262 'sequra'
263 ),
264 'default' => '.summary .price',
265 'custom_attributes' => array(
266 'dependson' => 'enabled_in_product_' . $product,
267 ),
268 );
269 $this->pm->form_fields[ 'widget_theme_' . $product ] = array(
270 'title' => __( 'Simulator params', 'sequra' ),
271 'type' => 'text',
272 'description' => __( 'Widget visualization params', 'sequra' ),
273 'default' => 'L',
274 'custom_attributes' => array(
275 'dependson' => 'enabled_in_product_' . $product,
276 ),
277 );
278 }
279 /**
280 * Initialize Gateway Settings Form Fields for each method
281 *
282 * @param array $method payment method.
283 */
284 private function fields_for_invoice( $method ) {
285 $product = $this->pm->get_remote_config()->build_unique_product_code( $method );
286
287 $this->pm->form_fields[ 'invoice_config_' . $product ] = array(
288 'title' => sprintf(
289 // translators: %s: payment method title.
290 __( 'Teaser config for %s', 'sequra' ),
291 $method['title']
292 ),
293 'type' => 'title',
294 );
295 $this->pm->form_fields[ 'enabled_in_product_' . $product ] = array(
296 'title' => __( 'Show in product page', 'sequra' ),
297 'type' => 'checkbox',
298 'description' => __( 'Show widget on product page', 'sequra' ),
299 'default' => 'yes',
300 );
301 $this->pm->form_fields[ 'dest_css_sel_' . $product ] = array(
302 'title' => __( 'CSS selector for widget in product page', 'sequra' ),
303 'type' => 'text',
304 'description' => __(
305 'CSS after which the simulator will be drawn.',
306 'sequra'
307 ),
308 'default' => '.single_add_to_cart_button, .woocommerce-variation-add-to-cart',
309 'custom_attributes' => array(
310 'dependson' => 'enabled_in_product_' . $product,
311 ),
312 );
313 $this->pm->form_fields[ 'widget_theme_' . $product ] = array(
314 'title' => __( 'Teaser params', 'sequra' ),
315 'type' => 'text',
316 'description' => __( 'Teaser visualization params', 'sequra' ),
317 'default' => 'L',
318 );
319 }
320 }
321