PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.12
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.12
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | stripe/controllers/FrmStrpLiteActionsController.php +78 -158 6.29 → 6.12 View file →
@@ -10,31 +10,8 @@
10 10 */
11 11 private static $customer;
12 12
13 13 /**
14 - * @since 6.22
15 - *
16 - * @param string $callback
17 - * @param array|false|object $field
18 - *
19 - * @return string
20 - */
21 - public static function maybe_show_card( $callback, $field = false ) {
22 - if ( false === $field ) {
23 - // Pro isn't up to date.
24 - // Fallback to Stripe Lite if we do not know the form.
25 - // This way we do not display the default credit card field
26 - // when Pro is not up to version 6.21.
27 - return self::class . '::show_card';
28 - }
29 -
30 - $form_id = is_object( $field ) ? $field->form_id : $field['form_id'];
31 - $actions = self::get_actions_before_submit( $form_id );
32 -
33 - return $actions ? self::class . '::show_card' : $callback;
34 - }
35 -
36 - /**
37 14 * Override the credit card field HTML if there is a Stripe action.
38 15 *
39 16 * @since 6.5, introduced in v2.0 of the Stripe add on.
40 17 *
@@ -40,9 +17,8 @@
40 17 *
41 18 * @param array $field
42 19 * @param string $field_name
43 20 * @param array $atts
44 - *
45 21 * @return void
46 22 */
47 23 public static function show_card( $field, $field_name, $atts ) {
48 24 $actions = self::get_actions_before_submit( $field['form_id'] );
@@ -62,23 +38,19 @@
62 38 *
63 39 * @since 6.5, introduced in v2.0 of the Stripe add on.
64 40 *
65 41 * @param int|string $form_id
66 - *
67 42 * @return array
68 43 */
69 44 public static function get_actions_before_submit( $form_id ) {
70 45 $payment_actions = self::get_actions_for_form( $form_id );
71 -
72 46 foreach ( $payment_actions as $k => $payment_action ) {
73 47 $gateway = $payment_action->post_content['gateway'];
74 48 $is_stripe = $gateway === 'stripe' || ( is_array( $gateway ) && in_array( 'stripe', $gateway, true ) );
75 -
76 49 if ( ! $is_stripe || empty( $payment_action->post_content['amount'] ) ) {
77 50 unset( $payment_actions[ $k ] );
78 51 }
79 52 }
80 -
81 53 return $payment_actions;
82 54 }
83 55
84 56 /**
@@ -88,9 +60,8 @@
88 60 *
89 61 * @since 6.5, introduced in v3.0 of the Stripe add on.
90 62 *
91 63 * @param int|string $form_id
92 - *
93 64 * @return false|WP_Post
94 65 */
95 66 public static function get_stripe_link_action( $form_id ) {
96 67 $actions = self::get_actions_before_submit( $form_id );
@@ -103,10 +74,9 @@
103 74 * It is also called when Stripe link is active but the Stripe payment is triggered instead with JavaScript.
104 75 *
105 76 * @param WP_Post $action
106 77 * @param stdClass $entry
107 - * @param mixed $form
108 - *
78 + * @param stdClass $form
109 79 * @return array
110 80 */
111 81 public static function trigger_gateway( $action, $entry, $form ) {
112 82 $response = array(
@@ -114,12 +84,11 @@
114 84 'run_triggers' => false,
115 85 'show_errors' => true,
116 86 );
117 87 $atts = compact( 'action', 'entry', 'form' );
118 - $amount = self::prepare_amount( $action->post_content['amount'], $atts );
119 88
120 - // phpcs:ignore Universal.Operators.StrictComparisons
121 - if ( ! $amount || $amount == 000 ) {
89 + $amount = self::prepare_amount( $action->post_content['amount'], $atts );
90 + if ( empty( $amount ) || $amount == 000 ) {
122 91 $response['error'] = __( 'Please specify an amount for the payment', 'formidable' );
123 92 return $response;
124 93 }
125 94
@@ -128,9 +97,8 @@
128 97 return $response;
129 98 }
130 99
131 100 $customer = self::set_customer_with_token( $atts );
132 -
133 101 if ( ! is_object( $customer ) ) {
134 102 $response['error'] = $customer;
135 103 return $response;
136 104 }
@@ -136,13 +104,9 @@
136 104 }
137 105
138 106 $one_time_payment_args = compact( 'customer', 'form', 'entry', 'action', 'amount' );
139 107
140 - if ( ! FrmStrpLiteLinkController::create_pending_stripe_link_payment( $one_time_payment_args ) ) {
141 - $response['error'] = __( 'There was something wrong with the payment data.', 'formidable' );
142 - return $response;
143 - }
144 -
108 + FrmStrpLiteLinkController::create_pending_stripe_link_payment( $one_time_payment_args );
145 109 $response['show_errors'] = false;
146 110 return $response;
147 111 }
148 112
@@ -158,9 +122,8 @@
158 122 /**
159 123 * Set a customer object to $_POST['customer'] to use later.
160 124 *
161 125 * @param array $atts
162 - *
163 126 * @return object|string
164 127 */
165 128 private static function set_customer_with_token( $atts ) {
166 129 if ( isset( self::$customer ) ) {
@@ -189,13 +152,12 @@
189 152 /**
190 153 * Replace an [email] shortcode with the current user email.
191 154 *
192 155 * @param string $email
193 - *
194 156 * @return string
195 157 */
196 158 private static function replace_email_shortcode( $email ) {
197 - if ( ! str_contains( $email, '[email]' ) ) {
159 + if ( false === strpos( $email, '[email]' ) ) {
198 160 return $email;
199 161 }
200 162
201 163 global $current_user;
@@ -212,9 +174,8 @@
212 174 * @since 6.5, introduced in v2.02 of the Stripe add on.
213 175 *
214 176 * @param array $atts
215 177 * @param array $payment_info
216 - *
217 178 * @return void
218 179 */
219 180 private static function add_customer_name( $atts, &$payment_info ) {
220 181 if ( empty( $atts['action']->post_content['billing_first_name'] ) ) {
@@ -221,9 +182,8 @@
221 182 return;
222 183 }
223 184
224 185 $name = '[' . $atts['action']->post_content['billing_first_name'] . ' show="first"]';
225 -
226 186 if ( ! empty( $atts['action']->post_content['billing_last_name'] ) ) {
227 187 $name .= ' [' . $atts['action']->post_content['billing_last_name'] . ' show="last"]';
228 188 }
229 189
@@ -235,20 +195,17 @@
235 195 *
236 196 * @since 6.5, introduced in v1.16 of the Stripe add on.
237 197 *
238 198 * @param array $atts Includes 'customer', 'entry', 'action', 'amount'.
239 - *
240 199 * @return int The timestamp when the trial should end. 0 for no trial
241 200 */
242 201 public static function get_trial_end_time( $atts ) {
243 202 $settings = $atts['action']->post_content;
244 -
245 203 if ( empty( $settings['trial_interval_count'] ) ) {
246 204 return 0;
247 205 }
248 206
249 207 $trial = $settings['trial_interval_count'];
250 -
251 208 if ( ! is_numeric( $trial ) ) {
252 209 $trial = FrmTransLiteAppHelper::process_shortcodes(
253 210 array(
254 211 'value' => $trial,
@@ -268,9 +225,8 @@
268 225 * Convert the amount from 10.00 to 1000.
269 226 *
270 227 * @param mixed $amount
271 228 * @param array $atts
272 - *
273 229 * @return string
274 230 */
275 231 public static function prepare_amount( $amount, $atts = array() ) {
276 232 $amount = parent::prepare_amount( $amount, $atts );
@@ -281,9 +237,8 @@
281 237 /**
282 238 * Add defaults for additional Stripe action options.
283 239 *
284 240 * @param array $defaults
285 - *
286 241 * @return array
287 242 */
288 243 public static function add_action_defaults( $defaults ) {
289 244 $defaults['plan_id'] = '';
@@ -295,9 +250,8 @@
295 250 /**
296 251 * Print additional options for Stripe action settings.
297 252 *
298 253 * @param array $atts
299 - *
300 254 * @return void
301 255 */
302 256 public static function add_action_options( $atts ) {
303 257 $form_action = $atts['form_action'];
@@ -309,35 +263,86 @@
309 263 * Filter Stripe action on save.
310 264 *
311 265 * @param array $settings
312 266 * @param array $action
313 - *
314 267 * @return array
315 268 */
316 269 public static function before_save_settings( $settings, $action ) {
317 270 $settings['currency'] = strtolower( $settings['currency'] );
318 271
319 - // Gateway is a radio button but it should always be an array in the database for
320 - // compatibility with the payments submodule where it is a checkbox.
321 - $settings['gateway'] = ! empty( $settings['gateway'] ) ? (array) $settings['gateway'] : array( 'stripe' );
272 + // In Lite Stripe link is always used.
273 + $settings['stripe_link'] = 1;
274 + $settings = self::create_plans( $settings );
275 + $form_id = absint( $action['menu_order'] );
322 276
323 - $is_stripe = in_array( 'stripe', $settings['gateway'], true );
277 + if ( empty( $settings['credit_card'] ) ) {
278 + $credit_card_field_id = FrmDb::get_var(
279 + 'frm_fields',
280 + array(
281 + 'type' => 'credit_card',
282 + 'form_id' => $form_id,
283 + )
284 + );
285 + if ( ! $credit_card_field_id ) {
286 + $credit_card_field_id = self::add_a_credit_card_field( $form_id );
287 + }
288 + if ( $credit_card_field_id ) {
289 + $settings['credit_card'] = $credit_card_field_id;
290 + }
291 + }
324 292
325 - if ( ! $is_stripe ) {
326 - return $settings;
293 + $gateway_field_id = FrmDb::get_var(
294 + 'frm_fields',
295 + array(
296 + 'type' => 'gateway',
297 + 'form_id' => $form_id,
298 + )
299 + );
300 + if ( ! $gateway_field_id ) {
301 + self::add_a_gateway_field( $form_id );
327 302 }
328 303
329 - // In Lite Stripe link is always used.
330 - $settings['stripe_link'] = 1;
304 + return $settings;
305 + }
331 306
332 - return self::create_plans( $settings );
307 + /**
308 + * @param int $form_id
309 + * @param string $field_type
310 + * @param string $field_name
311 + * @return false|int
312 + */
313 + private static function add_a_field( $form_id, $field_type, $field_name ) {
314 + $new_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
315 + $new_values['name'] = $field_name;
316 + $field_id = FrmField::create( $new_values );
317 + return $field_id;
333 318 }
334 319
335 320 /**
321 + * A credit card field is added automatically if missing before a Stripe action is updated.
322 + *
323 + * @param int $form_id
324 + * @return false|int
325 + */
326 + private static function add_a_credit_card_field( $form_id ) {
327 + return self::add_a_field( $form_id, 'credit_card', __( 'Payment', 'formidable' ) );
328 + }
329 +
330 + /**
331 + * A gateway field is added automatically for compatibility with the Stripe add on.
332 + * The gateway field is not important for the Stripe Lite implementation.
333 + *
334 + * @param int $form_id
335 + * @return false|int
336 + */
337 + private static function add_a_gateway_field( $form_id ) {
338 + return self::add_a_field( $form_id, 'gateway', __( 'Payment Method', 'formidable' ) );
339 + }
340 +
341 + /**
336 342 * Create any required Stripe plans, used for subscriptions.
337 343 *
338 344 * @param array $settings
339 - *
340 345 * @return array
341 346 */
342 347 public static function create_plans( $settings ) {
343 348 if ( $settings['type'] !== 'recurring' || strpos( $settings['amount'], ']' ) ) {
@@ -346,10 +351,8 @@
346 351 return $settings;
347 352 }
348 353
349 354 $plan_opts = FrmStrpLiteSubscriptionHelper::prepare_plan_options( $settings );
350 -
351 - // phpcs:ignore Universal.Operators.StrictComparisons
352 355 if ( $plan_opts['id'] != $settings['plan_id'] ) {
353 356 $settings['plan_id'] = FrmStrpLiteSubscriptionHelper::maybe_create_plan( $plan_opts );
354 357 }
355 358
@@ -359,14 +362,14 @@
359 362 /**
360 363 * Include settings in the plan description in order to make sure the correct plan is used.
361 364 *
362 365 * @param array $settings
363 - *
364 366 * @return string
365 367 */
366 368 public static function create_plan_id( $settings ) {
367 369 $amount = self::prepare_amount( $settings['amount'], $settings );
368 - return sanitize_title_with_dashes( $settings['description'] ) . '_' . $amount . '_' . $settings['interval_count'] . $settings['interval'] . '_' . $settings['currency'];
370 + $id = sanitize_title_with_dashes( $settings['description'] ) . '_' . $amount . '_' . $settings['interval_count'] . $settings['interval'] . '_' . $settings['currency'];
371 + return $id;
369 372 }
370 373
371 374 /**
372 375 * If this form submits with ajax, load the scripts on the first page.
@@ -371,13 +374,11 @@
371 374 /**
372 375 * If this form submits with ajax, load the scripts on the first page.
373 376 *
374 377 * @param array $params
375 - *
376 378 * @return void
377 379 */
378 380 public static function maybe_load_scripts( $params ) {
379 - // phpcs:ignore Universal.Operators.StrictComparisons
380 381 if ( $params['form_id'] == $params['posted_form_id'] ) {
381 382 // This form has already been posted, so we aren't on the first page.
382 383 return;
383 384 }
@@ -382,9 +383,8 @@
382 383 return;
383 384 }
384 385
385 386 $form = FrmForm::getOne( $params['form_id'] );
386 -
387 387 if ( ! $form ) {
388 388 return;
389 389 }
390 390
@@ -393,9 +393,8 @@
393 393 'fi.form_id' => $form->id,
394 394 'type' => 'credit_card',
395 395 )
396 396 );
397 -
398 397 if ( ! $credit_card_field ) {
399 398 return;
400 399 }
401 400
@@ -405,9 +404,8 @@
405 404 /**
406 405 * Load front end JavaScript for a Stripe form.
407 406 *
408 407 * @param int $form_id
409 - *
410 408 * @return void
411 409 */
412 410 public static function load_scripts( $form_id ) {
413 411 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
@@ -418,9 +416,8 @@
418 416 return;
419 417 }
420 418
421 419 $stripe_connect_is_setup = FrmStrpLiteConnectHelper::stripe_connect_is_setup();
422 -
423 420 if ( ! $stripe_connect_is_setup ) {
424 421 return;
425 422 }
426 423
@@ -450,9 +447,8 @@
450 447 if ( ! $suffix && ! is_readable( FrmStrpLiteAppHelper::plugin_path() . 'js/frmstrp.js' ) ) {
451 448 // The unminified file is not included in releases so force the minified script.
452 449 $suffix = '.min';
453 450 }
454 -
455 451 $script_url = FrmStrpLiteAppHelper::plugin_url() . 'js/frmstrp' . $suffix . '.js';
456 452 }
457 453
458 454 if ( class_exists( 'FrmProStrpLiteController' ) && ( ! $suffix || ! FrmProAppController::has_combo_js_file() ) ) {
@@ -458,24 +454,8 @@
458 454 if ( class_exists( 'FrmProStrpLiteController' ) && ( ! $suffix || ! FrmProAppController::has_combo_js_file() ) ) {
459 455 $dependencies[] = 'formidablepro';
460 456 }
461 457
462 - $action_settings = self::prepare_settings_for_js( $form_id );
463 - $found_gateway = false;
464 -
465 - foreach ( $action_settings as $action ) {
466 - $gateways = $action['gateways'];
467 -
468 - if ( ! $gateways || in_array( 'stripe', (array) $gateways, true ) ) {
469 - $found_gateway = true;
470 - break;
471 - }
472 - }
473 -
474 - if ( ! $found_gateway ) {
475 - return;
476 - }
477 -
478 458 wp_enqueue_script(
479 459 'formidable-stripe',
480 460 $script_url,
481 461 $dependencies,
@@ -482,10 +462,11 @@
482 462 FrmAppHelper::plugin_version(),
483 463 false
484 464 );
485 465
486 - $style_settings = self::get_style_settings_for_form( $form_id );
487 - $stripe_vars = array(
466 + $action_settings = self::prepare_settings_for_js( $form_id );
467 + $style_settings = self::get_style_settings_for_form( $form_id );
468 + $stripe_vars = array(
488 469 'publishable_key' => $publishable,
489 470 'form_id' => $form_id,
490 471 'nonce' => wp_create_nonce( 'frm_strp_ajax' ),
491 472 'ajax' => esc_url_raw( FrmAppHelper::get_ajax_url() ),
@@ -504,9 +485,8 @@
504 485 *
505 486 * @since 6.5, introduced in v3.0 of the Stripe add on.
506 487 *
507 488 * @param mixed $form_id
508 - *
509 489 * @return array
510 490 */
511 491 private static function get_style_settings_for_form( $form_id ) {
512 492 if ( ! $form_id ) {
@@ -513,9 +493,8 @@
513 493 return array();
514 494 }
515 495
516 496 $style = FrmStylesController::get_form_style( $form_id );
517 -
518 497 if ( ! $style ) {
519 498 return array();
520 499 }
521 500
@@ -520,9 +499,8 @@
520 499 }
521 500
522 501 $settings = FrmStylesHelper::get_settings_for_output( $style );
523 502 $disallowed = array( ';', ':', '!important' );
524 -
525 503 foreach ( $settings as $k => $s ) {
526 504 if ( is_string( $s ) ) {
527 505 $settings[ $k ] = str_replace( $disallowed, '', $s );
528 506 }
@@ -539,24 +517,20 @@
539 517 *
540 518 * @since 6.5, introduced in v3.0 of the Stripe add on.
541 519 *
542 520 * @param array $settings
543 - *
544 521 * @return array
545 522 */
546 523 private static function get_appearance_rules( $settings ) {
547 - $rules = array(
524 + return array(
548 525 '.Input' => array(
549 - 'fontFamily' => $settings['font'],
550 526 'color' => $settings['text_color'],
551 527 'backgroundColor' => $settings['bg_color'],
552 528 'padding' => $settings['field_pad'],
553 529 'lineHeight' => 1.3,
554 530 'borderColor' => $settings['border_color'],
555 - 'borderWidth' => self::get_border_width( $settings ),
531 + 'borderWidth' => $settings['field_border_width'],
556 532 'borderStyle' => $settings['field_border_style'],
557 - 'borderRadius' => self::get_border_radius( $settings ),
558 - 'fontWeight' => $settings['field_weight'],
559 533 ),
560 534 '.Input::placeholder' => array(
561 535 'color' => $settings['text_color_disabled'],
562 536 ),
@@ -563,73 +537,22 @@
563 537 '.Input:focus' => array(
564 538 'backgroundColor' => $settings['bg_color_active'],
565 539 ),
566 540 '.Label' => array(
567 - 'color' => $settings['label_color'],
568 - 'fontSize' => $settings['font_size'],
569 - 'fontWeight' => $settings['weight'],
570 - 'padding' => $settings['label_padding'],
571 - 'marginBottom' => 0,
541 + 'color' => $settings['label_color'],
542 + 'fontSize' => $settings['font_size'],
543 + 'fontWeight' => $settings['weight'],
572 544 ),
573 545 '.Error' => array(
574 546 'color' => $settings['border_color_error'],
575 547 ),
576 548 );
577 -
578 - /*
579 - * Filters the appearance rules for Stripe elements.
580 - *
581 - * @since 6.21
582 - *
583 - * @param array $rules
584 - * @param array $settings
585 - */
586 - return apply_filters( 'frm_stripe_appearance_rules', $rules, $settings );
587 549 }
588 550
589 551 /**
590 - * Get the border width for Stripe elements.
591 - *
592 - * @since 6.21
593 - *
594 - * @param array $settings
595 - *
596 - * @return string
597 - */
598 - private static function get_border_width( $settings ) {
599 - if ( ! empty( $settings['field_shape_type'] ) && 'underline' === $settings['field_shape_type'] ) {
600 - return '0 0 ' . $settings['field_border_width'] . ' 0';
601 - }
602 - return $settings['field_border_width'];
603 - }
604 -
605 - /**
606 - * Get the border radius for Stripe elements.
607 - *
608 - * @since 6.21
609 - *
610 - * @param array $settings
611 - *
612 - * @return string
613 - */
614 - private static function get_border_radius( $settings ) {
615 - if ( ! empty( $settings['field_shape_type'] ) ) {
616 - switch ( $settings['field_shape_type'] ) {
617 - case 'underline':
618 - case 'regular':
619 - return '0px';
620 - case 'circle':
621 - return '30px';
622 - }
623 - }
624 - return $settings['border_radius'];
625 - }
626 -
627 - /**
628 552 * Get the language to use for Stripe elements.
629 553 *
630 554 * @since 6.5, introduced in v2.0 of the Stripe add on.
631 - *
632 555 * @return string
633 556 */
634 557 private static function get_locale() {
635 558 $allowed = array( 'ar', 'da', 'de', 'en', 'es', 'fi', 'fr', 'he', 'it', 'ja', 'nl', 'no', 'pl', 'ru', 'sv', 'zh' );
@@ -647,24 +570,21 @@
647 570 *
648 571 * @param array $errors
649 572 * @param stdClass $field
650 573 * @param array $values
651 - *
652 574 * @return array
653 575 */
654 576 public static function remove_cc_validation( $errors, $field, $values ) {
655 577 $has_processed = isset( $_POST[ 'frmintent' . $field->form_id ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
656 -
657 578 if ( ! $has_processed ) {
658 579 return $errors;
659 580 }
660 581
661 - $field_id = $field->temp_id ?? $field->id;
582 + $field_id = isset( $field->temp_id ) ? $field->temp_id : $field->id;
662 583
663 584 if ( isset( $errors[ 'field' . $field_id . '-cc' ] ) ) {
664 585 unset( $errors[ 'field' . $field_id . '-cc' ] );
665 586 }
666 -
667 587 if ( isset( $errors[ 'field' . $field_id ] ) ) {
668 588 unset( $errors[ 'field' . $field_id ] );
669 589 }
670 590