PluginProbe
seQura / 2.0.7
seQura v2.0.7
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.7, at class-sequraconfigformfields.php

308 lines 10.8 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 SEQURA_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' => 'test',
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' ),
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 * Initialize Gateway Settings Form Fields
168 */
169 private function add_active_methods_info() {
170 $this->pm->form_fields['active_methods_info'] = array(
171 'title' => __( 'Active payent methods', 'sequra' ),
172 'type' => 'title',
173 /* translators: %s: URL */
174 'description' => __( 'Information will be available once the credentials are set and correct', 'sequra' ),
175 );
176 if ( $this->pm->is_valid_auth ) {
177 $this->pm->form_fields['active_methods_info']['description'] =
178 '<ul><li>' . implode(
179 '</li><li>',
180 $this->pm->get_remote_config()->get_merchant_active_payment_products( 'title' )
181 ) . '</li></ul>';
182 }
183 }
184 /**
185 * Initialize Gateway Settings Form Fields
186 */
187 private function init_communication_form_fields() {
188 $this->pm->form_fields['communication_fields'] = array(
189 'title' => __( 'Comunication configuration', 'sequra' ),
190 'type' => 'title',
191 /* translators: %s: URL */
192 'description' => '',
193 );
194 $this->pm->form_fields['price_css_sel'] = array(
195 'title' => __( 'CSS price selector', 'sequra' ),
196 'type' => 'text',
197 'description' => __( 'CSS selector to get the price for widgets in products', 'sequra' ),
198 'default' => '.summary .price>.amount,.summary .price ins .amount',
199 );
200 $methods = $this->pm->get_remote_config()->get_merchant_payment_methods();
201 array_walk(
202 $methods,
203 array( $this, 'init_communication_form_fields_for_method' )
204 );
205 }
206
207 /**
208 * Initialize Gateway Settings Form Fields for each method
209 *
210 * @param array $method payment method.
211 */
212 private function init_communication_form_fields_for_method( $method ) {
213 switch ( SequraRemoteConfig::get_family_for( $method ) ) {
214 case 'INVOICE':
215 $this->fields_for_invoice( $method );
216 break;
217 case 'PARTPAYMENT':
218 $this->fields_for_partpayment( $method );
219 break;
220 }
221 }
222
223 /**
224 * Initialize Gateway Settings Form Fields for each method
225 *
226 * @param array $method payment method.
227 */
228 private function fields_for_partpayment( $method ) {
229 $product = $this->pm->get_remote_config()->build_unique_product_code( $method );
230 $this->pm->form_fields[ 'partpayment_config_' . $product ] = array(
231 'title' => sprintf(
232 // translators: %s: payment method title.
233 __( 'Simulator config for %s', 'sequra' ),
234 $method['title']
235 ),
236 'type' => 'title',
237 );
238 $this->pm->form_fields[ 'enabled_in_product_' . $product ] = array(
239 'title' => __( 'Show in product page', 'sequra' ),
240 'type' => 'checkbox',
241 'description' => __( 'Mostrar widget en la página del producto', 'sequra' ),
242 'default' => 'yes',
243 );
244 $this->pm->form_fields[ 'dest_css_sel_' . $product ] = array(
245 'title' => __( 'CSS selector for widget in product page', 'sequra' ),
246 'type' => 'text',
247 'description' => __(
248 'CSS after which the simulator will be drawn.',
249 'sequra'
250 ),
251 'default' => '.summary .price',
252 'custom_attributes' => array(
253 'dependson' => 'enabled_in_product_' . $product,
254 ),
255 );
256 $this->pm->form_fields[ 'widget_theme_' . $product ] = array(
257 'title' => __( 'Simulator params', 'sequra' ),
258 'type' => 'text',
259 'description' => __( 'Widget visualization params', 'sequra' ),
260 'default' => 'L',
261 'custom_attributes' => array(
262 'dependson' => 'enabled_in_product_' . $product,
263 ),
264 );
265 }
266 /**
267 * Initialize Gateway Settings Form Fields for each method
268 *
269 * @param array $method payment method.
270 */
271 private function fields_for_invoice( $method ) {
272 $product = $this->pm->get_remote_config()->build_unique_product_code( $method );
273
274 $this->pm->form_fields[ 'invoice_config_' . $product ] = array(
275 'title' => sprintf(
276 // translators: %s: payment method title.
277 __( 'Teaser config for %s', 'sequra' ),
278 $method['title']
279 ),
280 'type' => 'title',
281 );
282 $this->pm->form_fields[ 'enabled_in_product_' . $product ] = array(
283 'title' => __( 'Show in product page', 'sequra' ),
284 'type' => 'checkbox',
285 'description' => __( 'Mostrar widget en la página del producto', 'sequra' ),
286 'default' => 'yes',
287 );
288 $this->pm->form_fields[ 'dest_css_sel_' . $product ] = array(
289 'title' => __( 'CSS selector for widget in product page', 'sequra' ),
290 'type' => 'text',
291 'description' => __(
292 'CSS after which the simulator will be drawn.',
293 'sequra'
294 ),
295 'default' => '.single_add_to_cart_button, .woocommerce-variation-add-to-cart',
296 'custom_attributes' => array(
297 'dependson' => 'enabled_in_product_' . $product,
298 ),
299 );
300 $this->pm->form_fields[ 'widget_theme_' . $product ] = array(
301 'title' => __( 'Teaser params', 'sequra' ),
302 'type' => 'text',
303 'description' => __( 'Teaser visualization params', 'sequra' ),
304 'default' => 'L',
305 );
306 }
307 }
308