| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Helper class from config form. |
| 5 |
* |
| 6 |
* @package woocommerce-sequra |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* SequraConfigFormFields class |
| 11 |
*/ |
| 12 |
class SequraConfigFormFields { |
| 13 |
|
| 14 |
/** |
| 15 |
* SequraPaymentGateway variable |
| 16 |
* |
| 17 |
* @var SequraPaymentGateway |
| 18 |
*/ |
| 19 |
protected $pm; |
| 20 |
|
| 21 |
/** |
| 22 |
* Initialize Gateway Settings Form Fields |
| 23 |
* |
| 24 |
* @param SequraPaymentGateway $pm the gateway. |
| 25 |
*/ |
| 26 |
public function __construct( &$pm ) { |
| 27 |
$this->pm = $pm; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Add form fields |
| 32 |
* |
| 33 |
* @return void |
| 34 |
*/ |
| 35 |
public function add_form_fields() { |
| 36 |
$this->pm->form_fields = array( |
| 37 |
'enabled' => array( |
| 38 |
'title' => __( 'Enable/Disable', 'sequra' ), |
| 39 |
'type' => 'checkbox', |
| 40 |
'description' => __( 'Enable SeQura payments', 'sequra' ), |
| 41 |
'default' => 'no', |
| 42 |
), |
| 43 |
'title' => array( |
| 44 |
'title' => __( 'Title', 'sequra' ), |
| 45 |
'type' => 'text', |
| 46 |
'description' => __( 'This controls the title which the user sees during checkout.', 'sequra' ), |
| 47 |
'default' => __( 'Paga a tu rítmo con SeQura', 'sequra' ), |
| 48 |
), |
| 49 |
'merchantref' => array( |
| 50 |
'title' => __( 'SeQura Merchant Reference', 'sequra' ), |
| 51 |
'type' => 'text', |
| 52 |
'description' => __( 'Id de comerciante proporcionado por SeQura.', 'sequra' ), |
| 53 |
'default' => '', |
| 54 |
), |
| 55 |
'user' => array( |
| 56 |
'title' => __( 'SeQura Username', 'sequra' ), |
| 57 |
'type' => 'text', |
| 58 |
'description' => __( 'Usuario proporcionado por SeQura.', 'sequra' ), |
| 59 |
'default' => '', |
| 60 |
'css' => 'color:' . $this->pm->is_valid_auth ? 'green' : 'red' . ';width: 450px;', |
| 61 |
), |
| 62 |
'password' => array( |
| 63 |
'title' => __( 'Password', 'sequra' ), |
| 64 |
'type' => 'text', |
| 65 |
'description' => __( 'Password proporcionada por SeQura.', 'sequra' ), |
| 66 |
'default' => '', |
| 67 |
), |
| 68 |
'assets_secret' => array( |
| 69 |
'title' => __( 'Assets secret', 'sequra' ), |
| 70 |
'type' => 'text', |
| 71 |
'description' => __( 'Código proporcionada por SeQura.', 'sequra' ), |
| 72 |
'default' => '', |
| 73 |
), |
| 74 |
'enable_for_virtual' => array( |
| 75 |
'title' => __( 'Enable for virtual orders', 'sequra' ), |
| 76 |
'label' => __( 'Enable SeQura for services', 'sequra' ), |
| 77 |
'type' => 'checkbox', |
| 78 |
'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' ), |
| 79 |
'default' => 'no', |
| 80 |
), |
| 81 |
'default_service_end_date' => array( |
| 82 |
'title' => __( 'Default service end date', 'sequra' ), |
| 83 |
'desc_tip' => true, |
| 84 |
'type' => 'text', |
| 85 |
'description' => __( 'Fecha como 2017-08-31, plazo como P3M15D (3 meses y 15 días). Se aplicará por defecto a todos los productos si no se especifica algo diferente en la ficha de producto.', 'sequra' ), |
| 86 |
'default' => 'P1Y', |
| 87 |
'placeholder' => __( 'ISO8601 format', 'sequra' ), |
| 88 |
'custom_attributes' => array( |
| 89 |
'pattern' => SequraHelper::ISO8601_PATTERN, |
| 90 |
'dependson' => 'enable_for_virtual', |
| 91 |
), |
| 92 |
), |
| 93 |
'allow_payment_delay' => array( |
| 94 |
'title' => __( 'Allow first payment delay', 'sequra' ), |
| 95 |
'desc_tip' => true, |
| 96 |
'type' => 'checkbox', |
| 97 |
'description' => __( 'Pago primera cuota diferido. No habilitar si no está indicado por SeQura', 'sequra' ), |
| 98 |
'default' => 'no', |
| 99 |
'custom_attributes' => array( |
| 100 |
'dependson' => 'enable_for_virtual', |
| 101 |
), |
| 102 |
), |
| 103 |
'allow_registration_items' => array( |
| 104 |
'title' => __( 'Allow registration items', 'sequra' ), |
| 105 |
'desc_tip' => true, |
| 106 |
'type' => 'checkbox', |
| 107 |
'description' => __( 'Permitir configurar parte del pago por adelantado. No habilitar si no está indicado por SeQura', 'sequra' ), |
| 108 |
'default' => 'no', |
| 109 |
'custom_attributes' => array( |
| 110 |
'dependson' => 'enable_for_virtual', |
| 111 |
), |
| 112 |
), |
| 113 |
'env' => array( |
| 114 |
'title' => __( 'Environment', 'sequra' ), |
| 115 |
'type' => 'select', |
| 116 |
'description' => __( 'While working in Sandbox the methods will only show to the following IP addresses.', 'sequra' ), |
| 117 |
'default' => '1', |
| 118 |
'desc_tip' => true, |
| 119 |
'options' => array( |
| 120 |
'1' => __( 'Sandbox', 'sequra' ), |
| 121 |
'0' => __( 'Live', 'sequra' ), |
| 122 |
), |
| 123 |
), |
| 124 |
// phpcs:disable WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders, WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__REMOTE_ADDR__ |
| 125 |
'test_ips' => array( |
| 126 |
'title' => __( 'IPs for testing', 'sequra' ), |
| 127 |
'label' => '', |
| 128 |
'type' => 'test', |
| 129 |
'description' => sprintf( |
| 130 |
__( 'When working is sandbox mode only these ips addresses will see the plugin. Current IP: %s', 'sequra' ), |
| 131 |
isset( $_SERVER['REMOTE_ADDR'] ) ? |
| 132 |
esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) : |
| 133 |
'' |
| 134 |
), |
| 135 |
'desc_tip' => false, |
| 136 |
'default' => gethostbyname( 'proxy-es.dev.sequra.es' ) . |
| 137 |
( isset( $_SERVER['REMOTE_ADDR'] ) ? |
| 138 |
',' . sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : |
| 139 |
'' |
| 140 |
), |
| 141 |
), |
| 142 |
// phpcs:enable WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders, WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__REMOTE_ADDR__ |
| 143 |
'debug' => array( |
| 144 |
'title' => __( 'Debugging', 'sequra' ), |
| 145 |
'label' => __( 'Modo debug', 'sequra' ), |
| 146 |
'type' => 'checkbox', |
| 147 |
'description' => __( 'Sólo para desarrolladores.', 'sequra' ), |
| 148 |
'default' => 'no', |
| 149 |
), |
| 150 |
); |
| 151 |
$this->add_active_methods_info(); |
| 152 |
$this->init_communication_form_fields(); |
| 153 |
$this->pm->form_fields = apply_filters( 'woocommerce_sequra_init_form_fields', $this->pm->form_fields, $this ); |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Initialize Gateway Settings Form Fields |
| 158 |
*/ |
| 159 |
private function add_active_methods_info() { |
| 160 |
$this->pm->form_fields['active_methods_info'] = array( |
| 161 |
'title' => __( 'Active payent methods', 'sequra' ), |
| 162 |
'type' => 'title', |
| 163 |
/* translators: %s: URL */ |
| 164 |
'description' => __( 'Information will be available once the credentials are set and correct', 'sequra' ), |
| 165 |
); |
| 166 |
if ( $this->pm->is_valid_auth ) { |
| 167 |
$this->pm->form_fields['active_methods_info']['description'] = |
| 168 |
'<ul><li>' . implode( |
| 169 |
'</li><li>', |
| 170 |
$this->pm->get_remote_config()->get_merchant_active_payment_products( 'title' ) |
| 171 |
) . '</li></ul>'; |
| 172 |
} |
| 173 |
} |
| 174 |
/** |
| 175 |
* Initialize Gateway Settings Form Fields |
| 176 |
*/ |
| 177 |
private function init_communication_form_fields() { |
| 178 |
$this->pm->form_fields['communication_fields'] = array( |
| 179 |
'title' => __( 'Comunication configuration', 'sequra' ), |
| 180 |
'type' => 'title', |
| 181 |
/* translators: %s: URL */ |
| 182 |
'description' => '', |
| 183 |
); |
| 184 |
$this->pm->form_fields['price_css_sel'] = array( |
| 185 |
'title' => __( 'CSS price selector', 'sequra' ), |
| 186 |
'type' => 'text', |
| 187 |
'description' => __( 'CSS selector to get the price for widgets in products', 'sequra' ), |
| 188 |
'default' => '.summary .price>.amount,.summary .price ins .amount', |
| 189 |
); |
| 190 |
$methods = $this->pm->get_remote_config()->get_merchant_payment_methods(); |
| 191 |
array_walk( |
| 192 |
$methods, |
| 193 |
array( $this, 'init_communication_form_fields_for_method' ) |
| 194 |
); |
| 195 |
} |
| 196 |
|
| 197 |
/** |
| 198 |
* Initialize Gateway Settings Form Fields for each method |
| 199 |
* |
| 200 |
* @param array $method payment method. |
| 201 |
*/ |
| 202 |
private function init_communication_form_fields_for_method( $method ) { |
| 203 |
switch ( SequraRemoteConfig::get_family_for( $method ) ) { |
| 204 |
case 'INVOICE': |
| 205 |
$this->fields_for_invoice( $method ); |
| 206 |
break; |
| 207 |
case 'PARTPAYMENT': |
| 208 |
$this->fields_for_partpayment( $method ); |
| 209 |
break; |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Initialize Gateway Settings Form Fields for each method |
| 215 |
* |
| 216 |
* @param array $method payment method. |
| 217 |
*/ |
| 218 |
private function fields_for_partpayment( $method ) { |
| 219 |
$product = $this->pm->get_remote_config()->build_unique_product_code( $method ); |
| 220 |
$this->pm->form_fields[ 'partpayment_config_' . $product ] = array( |
| 221 |
'title' => sprintf( |
| 222 |
__( 'Simulator config for %s', 'sequra' ), |
| 223 |
$method['title'] |
| 224 |
), |
| 225 |
'type' => 'title', |
| 226 |
); |
| 227 |
$this->pm->form_fields[ 'enabled_in_product_' . $product ] = array( |
| 228 |
'title' => __( 'Show in product page', 'sequra' ), |
| 229 |
'type' => 'checkbox', |
| 230 |
'description' => __( 'Mostrar widget en la página del producto', 'sequra' ), |
| 231 |
'default' => 'yes', |
| 232 |
); |
| 233 |
$this->pm->form_fields[ 'dest_css_sel_' . $product ] = array( |
| 234 |
'title' => __( 'CSS selector for widget in product page', 'sequra' ), |
| 235 |
'type' => 'text', |
| 236 |
'description' => __( |
| 237 |
'CSS after which the simulator will be drawn.', |
| 238 |
'sequra' |
| 239 |
), |
| 240 |
'default' => '.summary .price', |
| 241 |
'custom_attributes' => array( |
| 242 |
'dependson' => 'enabled_in_product_' . $product, |
| 243 |
), |
| 244 |
); |
| 245 |
$this->pm->form_fields[ 'widget_theme_' . $product ] = array( |
| 246 |
'title' => __( 'Simulator params', 'sequra' ), |
| 247 |
'type' => 'text', |
| 248 |
'description' => __( 'Widget visualization params', 'sequra' ), |
| 249 |
'default' => 'L', |
| 250 |
); |
| 251 |
} |
| 252 |
/** |
| 253 |
* Initialize Gateway Settings Form Fields for each method |
| 254 |
* |
| 255 |
* @param array $method payment method. |
| 256 |
*/ |
| 257 |
private function fields_for_invoice( $method ) { |
| 258 |
$product = $this->pm->get_remote_config()->build_unique_product_code( $method ); |
| 259 |
|
| 260 |
$this->pm->form_fields[ 'invoice_config_' . $product ] = array( |
| 261 |
'title' => sprintf( |
| 262 |
__( 'Teaser config for %s', 'sequra' ), |
| 263 |
$method['title'] |
| 264 |
), |
| 265 |
'type' => 'title', |
| 266 |
); |
| 267 |
$this->pm->form_fields[ 'enabled_in_product_' . $product ] = array( |
| 268 |
'title' => __( 'Show in product page', 'sequra' ), |
| 269 |
'type' => 'checkbox', |
| 270 |
'description' => __( 'Mostrar widget en la página del producto', 'sequra' ), |
| 271 |
'default' => 'yes', |
| 272 |
); |
| 273 |
$this->pm->form_fields[ 'dest_css_sel_' . $product ] = array( |
| 274 |
'title' => __( 'CSS selector for widget in product page', 'sequra' ), |
| 275 |
'type' => 'text', |
| 276 |
'description' => __( |
| 277 |
'CSS after which the simulator will be drawn.', |
| 278 |
'sequra' |
| 279 |
), |
| 280 |
'default' => '.single_add_to_cart_button, .woocommerce-variation-add-to-cart', |
| 281 |
'custom_attributes' => array( |
| 282 |
'dependson' => 'enabled_in_product_' . $product, |
| 283 |
), |
| 284 |
); |
| 285 |
$this->pm->form_fields[ 'widget_theme_' . $product ] = array( |
| 286 |
'title' => __( 'Teaser params', 'sequra' ), |
| 287 |
'type' => 'text', |
| 288 |
'description' => __( 'Teaser visualization params', 'sequra' ), |
| 289 |
'default' => 'L', |
| 290 |
); |
| 291 |
} |
| 292 |
} |
| 293 |
|