PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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/models/FrmStrpLiteAuth.php +128 -76 6.25 → trunk View file →
@@ -18,12 +18,14 @@
18 18 *
19 19 * @since 6.5, introduced in v2.0 of the Stripe add on.
20 20 *
21 21 * @param string $html Form HTML that gets filtered through frm_filter_final_form.
22 + *
22 23 * @return string
23 24 */
24 25 public static function maybe_show_message( $html ) {
25 26 $link_error = FrmAppHelper::simple_get( 'frm_link_error' );
27 +
26 28 if ( $link_error ) {
27 29 $message = '<div class="frm_error_style">' . self::get_message_for_stripe_link_code( $link_error ) . '</div>';
28 30 self::insert_error_message( $message, $html );
29 31 return $html;
@@ -29,13 +31,15 @@
29 31 return $html;
30 32 }
31 33
32 34 $form_id = self::check_html_for_form_id_match( $html );
35 +
33 36 if ( false === $form_id ) {
34 37 return $html;
35 38 }
36 39
37 40 $details = FrmStrpLiteUrlParamHelper::get_details_for_form( $form_id );
41 +
38 42 if ( ! is_array( $details ) ) {
39 43 return $html;
40 44 }
41 45
@@ -44,10 +48,9 @@
44 48 'entry' => $details['entry'],
45 49 );
46 50 self::prepare_success_atts( $atts );
47 51
48 - $intent = $details['intent'];
49 - $payment = $details['payment'];
52 + $intent = $details['intent'];
50 53
51 54 if ( self::intent_has_failed_status( $intent ) ) {
52 55 $message = '<div class="frm_error_style">' . $intent->last_payment_error->message . '</div>';
53 56 self::insert_error_message( $message, $html );
@@ -54,14 +57,14 @@
54 57 return $html;
55 58 }
56 59
57 60 $intent_is_processing = 'processing' === $intent->status;
61 +
58 62 if ( $intent_is_processing ) {
59 63 // Append an additional processing message to the end of the success message.
60 64 $filter = function ( $message ) {
61 65 $stripe_settings = FrmStrpLiteAppHelper::get_settings();
62 - $message .= '<p>' . esc_html( $stripe_settings->settings->processing_message ) . '</p>';
63 - return $message;
66 + return $message . ( '<p>' . esc_html( $stripe_settings->settings->processing_message ) . '</p>' );
64 67 };
65 68 add_filter( 'frm_content', $filter );
66 69 }
67 70
@@ -66,10 +69,9 @@
66 69 }
67 70
68 71 ob_start();
69 72 FrmFormsController::run_on_submit_actions( $atts );
70 - $message = ob_get_contents();
71 - ob_end_clean();
73 + $message = ob_get_clean();
72 74
73 75 // Clean up the filter we added above so no other success messages get altered if there are multiple forms.
74 76 if ( $intent_is_processing ) {
75 77 remove_filter( 'frm_content', $filter );
@@ -79,8 +81,9 @@
79 81 }
80 82
81 83 /**
82 84 * @param int|string $form_id
85 + *
83 86 * @return array|false
84 87 */
85 88 private static function check_request_params( $form_id ) {
86 89 if ( ! FrmStrpLiteAppHelper::stripe_is_configured() ) {
@@ -87,8 +90,9 @@
87 90 return false;
88 91 }
89 92
90 93 $details = FrmStrpLiteUrlParamHelper::get_details_for_form( $form_id );
94 +
91 95 if ( ! is_array( $details ) ) {
92 96 return false;
93 97 }
94 98
@@ -104,14 +108,16 @@
104 108 *
105 109 * @since 6.5
106 110 *
107 111 * @param string $html
112 + *
108 113 * @return false|int Matching form id or false if there is no match.
109 114 */
110 115 private static function check_html_for_form_id_match( $html ) {
111 116 foreach ( self::$form_ids as $form_id ) {
112 117 $substring = '<input type="hidden" name="form_id" value="' . $form_id . '"';
113 - if ( strpos( $html, $substring ) ) {
118 +
119 + if ( str_contains( $html, $substring ) ) {
114 120 return $form_id;
115 121 }
116 122 }
117 123
@@ -124,8 +130,9 @@
124 130 *
125 131 * @since 6.5, introduced in v3.0 of the Stripe add on.
126 132 *
127 133 * @param string $code
134 + *
128 135 * @return string
129 136 */
130 137 private static function get_message_for_stripe_link_code( $code ) {
131 138 switch ( $code ) {
@@ -144,8 +151,10 @@
144 151 case 'create_subscription_failed':
145 152 return __( 'Something went wrong when trying to create a subscription.', 'formidable' );
146 153 case 'payment_failed':
147 154 return __( 'Payment was not successfully processed.', 'formidable' );
155 + case 'amount_mismatch':
156 + return __( 'The payment amount does not match the expected amount.', 'formidable' );
148 157 }
149 158 return '';
150 159 }
151 160
@@ -154,8 +163,9 @@
154 163 *
155 164 * @since 6.5, introduced in v2.0 of the Stripe add on.
156 165 *
157 166 * @param array $atts
167 + *
158 168 * @return void
159 169 */
160 170 private static function prepare_success_atts( &$atts ) {
161 171 $atts['form'] = FrmForm::getOne( $atts['entry']->form_id );
@@ -163,14 +173,18 @@
163 173 $opt = 'success_action';
164 174 $atts['conf_method'] = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message';
165 175
166 176 $actions = FrmFormsController::get_met_on_submit_actions( $atts, 'create' );
167 - if ( $actions ) {
168 - $action = reset( $actions );
169 - if ( ! empty( $action->post_content['success_action'] ) && 'message' === $action->post_content['success_action'] ) {
170 - $atts['conf_method'] = $action->post_content['success_action'];
171 - }
177 +
178 + if ( ! $actions ) {
179 + return;
172 180 }
181 +
182 + $action = reset( $actions );
183 +
184 + if ( ! empty( $action->post_content['success_action'] ) && 'message' === $action->post_content['success_action'] ) {
185 + $atts['conf_method'] = $action->post_content['success_action'];
186 + }
173 187 }
174 188
175 189 /**
176 190 * Insert a message/error where the form styling will be applied.
@@ -175,12 +189,18 @@
175 189 /**
176 190 * Insert a message/error where the form styling will be applied.
177 191 *
178 192 * @since 6.5, introduced in v2.0 of the Stripe add on.
193 + *
194 + * @param string $message Message.
195 + * @param string $form Form.
196 + *
197 + * @return void
179 198 */
180 199 private static function insert_error_message( $message, &$form ) {
181 200 $add_after = '<fieldset>';
182 201 $pos = strpos( $form, $add_after );
202 +
183 203 if ( $pos !== false ) {
184 204 $form = substr_replace( $form, $add_after . $message, $pos, strlen( $add_after ) );
185 205 }
186 206 }
@@ -188,13 +208,15 @@
188 208 /**
189 209 * Include the token if going between pages.
190 210 *
191 211 * @param object $form The form being submitted.
212 + *
192 213 * @return void
193 214 */
194 215 public static function add_hidden_token_field( $form ) {
195 216 $posted_form = FrmAppHelper::get_param( 'form_id', 0, 'post', 'absint' );
196 - if ( $posted_form != $form->id || FrmFormsController::just_created_entry( $form->id ) ) {
217 +
218 + if ( $posted_form !== (int) $form->id || FrmFormsController::just_created_entry( $form->id ) ) {
197 219 // Check to make sure the correct form was submitted.
198 220 // Was an entry already created and the form should be loaded fresh?
199 221
200 222 $intents = self::maybe_create_intents( $form->id );
@@ -203,10 +225,11 @@
203 225 return;
204 226 }
205 227
206 228 $intents = self::get_payment_intents( 'frmintent' . $form->id );
207 - if ( ! empty( $intents ) ) {
208 - self::update_intent_pricing( $form->id, $intents );
229 +
230 + if ( $intents ) {
231 + self::update_intent_pricing( $form->id, $intents, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
209 232 } else {
210 233 $intents = self::maybe_create_intents( $form->id );
211 234 }
212 235
@@ -219,8 +242,9 @@
219 242 * @since 6.5, introduced in v2.02 of the Stripe add on.
220 243 *
221 244 * @param array $intents
222 245 * @param stdClass $form
246 + *
223 247 * @return void
224 248 */
225 249 private static function include_intents_in_form( $intents, $form ) {
226 250 foreach ( $intents as $intent ) {
@@ -241,8 +265,9 @@
241 265 *
242 266 * @since 6.5, introduced in v2.0 of the Stripe add on.
243 267 *
244 268 * @param string $name
269 + *
245 270 * @return mixed
246 271 */
247 272 public static function get_payment_intents( $name ) {
248 273 // phpcs:ignore WordPress.Security.NonceVerification.Missing
@@ -248,9 +273,11 @@
248 273 // phpcs:ignore WordPress.Security.NonceVerification.Missing
249 274 if ( ! isset( $_POST[ $name ] ) ) {
250 275 return array();
251 276 }
252 - $intents = $_POST[ $name ]; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
277 +
278 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
279 + $intents = $_POST[ $name ];
253 280 FrmAppHelper::sanitize_value( 'sanitize_text_field', $intents );
254 281 return $intents;
255 282 }
256 283
@@ -267,9 +294,11 @@
267 294 if ( empty( $_POST['form'] ) ) {
268 295 wp_die();
269 296 }
270 297
271 - $form = json_decode( stripslashes( $_POST['form'] ), true ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
298 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
299 + $form = json_decode( stripslashes( $_POST['form'] ), true );
300 +
272 301 if ( ! is_array( $form ) ) {
273 302 wp_die();
274 303 }
275 304
@@ -277,24 +306,23 @@
277 306
278 307 $form_id = absint( $form['form_id'] );
279 308 $intents = $form[ 'frmintent' . $form_id ] ?? array();
280 309
281 - if ( empty( $intents ) ) {
310 + if ( ! $intents ) {
282 311 wp_die();
283 312 }
284 313
285 - if ( ! is_array( $intents ) ) {
286 - $intents = array( $intents );
287 - } else {
314 + if ( is_array( $intents ) ) {
288 315 foreach ( $intents as $k => $intent ) {
289 316 if ( is_array( $intent ) && isset( $intent[ $k ] ) ) {
290 317 $intents[ $k ] = $intent[ $k ];
291 318 }
292 319 }
320 + } else {
321 + $intents = array( $intents );
293 322 }
294 323
295 - $_POST = $form;
296 - self::update_intent_pricing( $form_id, $intents );
324 + self::update_intent_pricing( $form_id, $intents, $form );
297 325
298 326 wp_die();
299 327 }
300 328
@@ -301,20 +329,23 @@
301 329 /**
302 330 * Update pricing on page turn and non-ajax validation.
303 331 *
304 332 * @since 6.5, introduced in v2.0 of the Stripe add on.
305 - * @param int $form_id
306 - * @param array $intents
333 + *
334 + * @param int|string $form_id
335 + * @param array $intents
336 + * @param array $form_data
337 + *
307 338 * @return void
308 339 */
309 - private static function update_intent_pricing( $form_id, &$intents ) {
310 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
311 - if ( ! isset( $_POST['form_id'] ) || absint( $_POST['form_id'] ) != $form_id ) {
340 + private static function update_intent_pricing( $form_id, &$intents, $form_data ) {
341 + if ( ! isset( $form_data['form_id'] ) || absint( $form_data['form_id'] ) !== (int) $form_id ) {
312 342 return;
313 343 }
314 344
315 345 $actions = FrmStrpLiteActionsController::get_actions_before_submit( $form_id );
316 - if ( empty( $actions ) || empty( $intents ) ) {
346 +
347 + if ( ! $actions || ! $intents ) {
317 348 return;
318 349 }
319 350
320 351 $form = FrmForm::getOne( $form_id );
@@ -329,22 +360,26 @@
329 360 }
330 361
331 362 foreach ( $intents as $k => $intent ) {
332 363 $intent_id = explode( '_secret_', $intent )[0];
333 - $is_setup_intent = 0 === strpos( $intent_id, 'seti_' );
364 + $is_setup_intent = str_starts_with( $intent_id, 'seti_' );
365 +
334 366 if ( $is_setup_intent ) {
335 367 continue;
336 368 }
337 369
338 370 $saved = FrmStrpLiteAppHelper::call_stripe_helper_class( 'get_intent', $intent_id );
371 +
339 372 if ( empty( $saved->metadata->action ) ) {
340 373 continue;
341 374 }
342 375
343 376 foreach ( $actions as $action ) {
377 + // phpcs:ignore Universal.Operators.StrictComparisons
344 378 if ( $saved->metadata->action != $action->ID ) {
345 379 continue;
346 380 }
381 +
347 382 $intents[ $k ] = array(
348 383 'id' => $intent,
349 384 'action' => $action->ID,
350 385 );
@@ -349,16 +384,19 @@
349 384 'action' => $action->ID,
350 385 );
351 386
352 387 $amount = $action->post_content['amount'];
353 - if ( strpos( $amount, '[' ) === false ) {
388 +
389 + if ( ! str_contains( $amount, '[' ) ) {
354 390 // The amount is static, so it doesn't need an update.
355 391 continue;
356 392 }
357 393
358 394 // Update amount based on field shortcodes.
359 - $entry = self::generate_false_entry();
395 + $entry = self::generate_false_entry( $form_data );
360 396 $amount = FrmStrpLiteActionsController::prepare_amount( $amount, compact( 'form', 'entry', 'action' ) );
397 +
398 + // phpcs:ignore Universal.Operators.StrictComparisons
361 399 if ( $saved->amount == $amount || $amount == '000' ) {
362 400 continue;
363 401 }
364 402
@@ -370,11 +408,14 @@
370 408 /**
371 409 * Create an entry object with posted values.
372 410 *
373 411 * @since 6.5, introduced in v2.0 of the Stripe add on.
412 + *
413 + * @param array $form_data
414 + *
374 415 * @return stdClass
375 416 */
376 - private static function generate_false_entry() {
417 + private static function generate_false_entry( $form_data ) {
377 418 $entry = new stdClass();
378 419 $entry->post_id = 0;
379 420 $entry->id = 0;
380 421 $entry->item_key = '';
@@ -379,22 +420,22 @@
379 420 $entry->id = 0;
380 421 $entry->item_key = '';
381 422 $entry->metas = array();
382 423
383 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
384 - foreach ( $_POST as $k => $v ) {
424 + foreach ( $form_data as $k => $v ) {
385 425 $k = sanitize_text_field( stripslashes( $k ) );
386 426 $v = wp_unslash( $v );
387 427
388 - if ( $k === 'item_meta' ) {
389 - foreach ( $v as $f => $value ) {
390 - FrmAppHelper::sanitize_value( 'wp_kses_post', $value );
391 - $entry->metas[ absint( $f ) ] = $value;
392 - }
393 - } else {
428 + if ( $k !== 'item_meta' ) {
394 429 FrmAppHelper::sanitize_value( 'wp_kses_post', $v );
395 430 $entry->{$k} = $v;
431 + continue;
396 432 }
433 +
434 + foreach ( $v as $f => $value ) {
435 + FrmAppHelper::sanitize_value( 'wp_kses_post', $value );
436 + $entry->metas[ absint( $f ) ] = $value;
437 + }
397 438 }
398 439
399 440 return $entry;
400 441 }
@@ -404,8 +445,9 @@
404 445 *
405 446 * @since 6.5, introduced in v2.0 of the Stripe add on.
406 447 *
407 448 * @param array $form
449 + *
408 450 * @return void
409 451 */
410 452 private static function format_form_data( &$form ) {
411 453 $formatted = array();
@@ -411,16 +453,18 @@
411 453 $formatted = array();
412 454
413 455 foreach ( $form as $input ) {
414 456 $key = $input['name'];
415 - if ( isset( $formatted[ $key ] ) ) {
416 - if ( is_array( $formatted[ $key ] ) ) {
417 - $formatted[ $key ][] = $input['value'];
418 - } else {
419 - $formatted[ $key ] = array( $formatted[ $key ], $input['value'] );
420 - }
457 +
458 + if ( ! isset( $formatted[ $key ] ) ) {
459 + $formatted[ $key ] = $input['value'];
460 + continue;
461 + }
462 +
463 + if ( is_array( $formatted[ $key ] ) ) {
464 + $formatted[ $key ][] = $input['value'];
421 465 } else {
422 - $formatted[ $key ] = $input['value'];
466 + $formatted[ $key ] = array( $formatted[ $key ], $input['value'] );
423 467 }
424 468 }
425 469
426 470 parse_str( http_build_query( $formatted ), $form );
@@ -432,14 +476,15 @@
432 476 *
433 477 * @since 6.5, introduced in v2.0 of the Stripe add on.
434 478 *
435 479 * @param int|string $form_id
480 + *
436 481 * @return array
437 482 */
438 483 private static function maybe_create_intents( $form_id ) {
439 484 $intents = array();
485 + $details = self::check_request_params( $form_id );
440 486
441 - $details = self::check_request_params( $form_id );
442 487 if ( is_array( $details ) ) {
443 488 $payment = $details['payment'];
444 489 $intent = $details['intent'];
445 490 $payment_failed = self::payment_failed( $payment, $intent );
@@ -468,8 +513,9 @@
468 513 continue;
469 514 }
470 515
471 516 $intent = self::create_intent( $action );
517 +
472 518 if ( ! is_object( $intent ) ) {
473 519 // A non-object is a string error message.
474 520 // The error gets logged to results.log so we can just skip it.
475 521 // Reasons it could fail is because a payment method type was specified that will not work.
@@ -494,8 +540,9 @@
494 540 *
495 541 * @since 3.0 This code was moved out of self::maybe_create_intents into a new function.
496 542 *
497 543 * @param WP_Post $action
544 + *
498 545 * @return mixed
499 546 */
500 547 private static function create_intent( $action ) {
501 548 $amount = $action->post_content['amount'];
@@ -500,8 +547,9 @@
500 547 private static function create_intent( $action ) {
501 548 $amount = $action->post_content['amount'];
502 549 $currency = $action->post_content['currency'];
503 550
551 + // phpcs:ignore Universal.Operators.StrictComparisons
504 552 if ( $amount == '000' ) {
505 553 // Create the intent when the form loads.
506 554 $amount = in_array( strtolower( $currency ), array( 'aud', 'cad', 'eur', 'gbp', 'usd' ), true ) ? 100 : 1000;
507 555 }
@@ -532,12 +580,14 @@
532 580 /**
533 581 * Add the statement descriptor to the intent data, if it is valid.
534 582 *
535 583 * @param array $intent_data
584 + *
536 585 * @return array
537 586 */
538 587 private static function maybe_add_statement_descriptor( $intent_data ) {
539 588 $statement_descriptor = self::get_statement_descriptor();
589 +
540 590 if ( false !== $statement_descriptor ) {
541 591 $intent_data['statement_descriptor'] = $statement_descriptor;
542 592 }
543 593
@@ -569,13 +619,9 @@
569 619 }
570 620
571 621 $name = self::strip_special_characters_from_statement_descriptor( $name );
572 622
573 - if ( ! self::statement_descriptor_is_valid( $name ) ) {
574 - return false;
575 - }
576 -
577 - return $name;
623 + return self::statement_descriptor_is_valid( $name ) ? $name : false;
578 624 }
579 625
580 626 /**
581 627 * Remove the special characters that Stripe doesn't allow in statement descriptors, in case any exist.
@@ -582,8 +628,9 @@
582 628 *
583 629 * @since 6.23
584 630 *
585 631 * @param string $name The name of the site.
632 + *
586 633 * @return string The name with special characters removed.
587 634 */
588 635 private static function strip_special_characters_from_statement_descriptor( $name ) {
589 636 $special_characters = array(
@@ -603,8 +650,9 @@
603 650 *
604 651 * @since 6.23
605 652 *
606 653 * @param string $name Passed by reference, as this is updated if it is too long.
654 + *
607 655 * @return bool
608 656 */
609 657 private static function statement_descriptor_is_valid( &$name ) {
610 658 if ( strlen( $name ) < 5 ) {
@@ -614,13 +662,9 @@
614 662 if ( strlen( $name ) > 22 ) {
615 663 $name = substr( $name, 0, 22 );
616 664 }
617 665
618 - if ( ! preg_match( '/^[a-zA-Z0-9\s\p{P}]+$/', $name ) ) {
619 - return false;
620 - }
621 -
622 - return true;
666 + return (bool) preg_match( '/^[a-zA-Z0-9\s\p{P}]+$/', $name );
623 667 }
624 668
625 669 /**
626 670 * Create a customer and an associated setup intent for a recurring Stripe link payment.
@@ -627,8 +671,9 @@
627 671 *
628 672 * @since 6.5, introduced in v3.0 of the Stripe add on.
629 673 *
630 674 * @param array $payment_method_types
675 + *
631 676 * @return false|object
632 677 */
633 678 private static function create_setup_intent( $payment_method_types ) {
634 679 $payment_info = array(
@@ -636,8 +681,9 @@
636 681 );
637 682
638 683 // We need to add a customer to support subscriptions with link.
639 684 $customer = FrmStrpLiteAppHelper::call_stripe_helper_class( 'get_customer', $payment_info );
685 +
640 686 if ( ! is_object( $customer ) ) {
641 687 return false;
642 688 }
643 689
@@ -648,14 +694,16 @@
648 694 * @since 6.5, introduced in v2.0 of the Stripe add on.
649 695 *
650 696 * @param int|string $form_id
651 697 * @param array $actions
698 + *
652 699 * @return void
653 700 */
654 701 private static function add_amount_to_actions( $form_id, &$actions ) {
655 - if ( empty( $actions ) ) {
702 + if ( ! $actions ) {
656 703 return;
657 704 }
705 +
658 706 $form = FrmForm::getOne( $form_id );
659 707
660 708 foreach ( $actions as $k => $action ) {
661 709 $amount = self::get_amount_before_submit( compact( 'action', 'form' ) );
@@ -666,12 +714,12 @@
666 714 /**
667 715 * @since 6.5, introduced in v2.0 of the Stripe add on.
668 716 *
669 717 * @param array $atts
718 + *
670 719 * @return string
671 720 */
672 721 private static function get_amount_before_submit( $atts ) {
673 - $amount = $atts['action']->post_content['amount'];
674 722 return FrmStrpLiteActionsController::prepare_amount( $atts['action']->post_content['amount'], $atts );
675 723 }
676 724
677 725 /**
@@ -681,8 +729,9 @@
681 729 *
682 730 * @since 6.5, introduced in v2.0 of the Stripe add on.
683 731 *
684 732 * @param array $atts
733 + *
685 734 * @return string
686 735 */
687 736 public static function return_url( $atts ) {
688 737 $atts = array(
@@ -689,15 +738,9 @@
689 738 'entry' => $atts['entry'],
690 739 );
691 740 self::prepare_success_atts( $atts );
692 741
693 - if ( $atts['conf_method'] === 'redirect' ) {
694 - $redirect = self::get_redirect_url( $atts );
695 - } else {
696 - $redirect = self::get_message_url( $atts );
697 - }
698 -
699 - return $redirect;
742 + return $atts['conf_method'] === 'redirect' ? self::get_redirect_url( $atts ) : self::get_message_url( $atts );
700 743 }
701 744
702 745 /**
703 746 * If the form should redirect, get the url to redirect to.
@@ -709,12 +752,14 @@
709 752 *
710 753 * @type stdClass $form
711 754 * @type stdClass $entry
712 755 * }
756 + *
713 757 * @return string
714 758 */
715 759 private static function get_redirect_url( $atts ) {
716 760 $actions = FrmFormsController::get_met_on_submit_actions( $atts );
761 +
717 762 if ( $actions ) {
718 763 $success_url = reset( $actions )->post_content['success_url'];
719 764 }
720 765
@@ -721,9 +766,9 @@
721 766 if ( empty( $success_url ) ) {
722 767 $success_url = $atts['form']->options['success_url'];
723 768 }
724 769
725 - $success_url = trim( $atts['form']->options['success_url'] );
770 + $success_url = trim( $success_url );
726 771 $success_url = apply_filters( 'frm_content', $success_url, $atts['form'], $atts['entry'] );
727 772 $success_url = do_shortcode( $success_url );
728 773 $atts['id'] = $atts['entry']->id;
729 774
@@ -736,14 +781,18 @@
736 781 *
737 782 * @since 6.5, introduced in v2.0 of the Stripe add on.
738 783 *
739 784 * @param array $atts
785 + *
786 + * @return string
740 787 */
741 788 private static function get_message_url( $atts ) {
742 789 $url = self::get_referer_url( $atts['entry_id'], false );
790 +
743 791 if ( false === $url ) {
744 792 $url = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
745 793 }
794 +
746 795 return add_query_arg( array( 'frmstrp' => $atts['entry_id'] ), $url );
747 796 }
748 797
749 798 /**
@@ -750,8 +799,9 @@
750 799 * @since 6.5
751 800 *
752 801 * @param int|string $entry_id
753 802 * @param bool $delete_meta
803 + *
754 804 * @return false|string
755 805 */
756 806 public static function get_referer_url( $entry_id, $delete_meta = true ) {
757 807 $row = FrmDb::get_row(
@@ -762,8 +812,9 @@
762 812 'meta_value LIKE' => '{"referer":',
763 813 ),
764 814 'id, meta_value'
765 815 );
816 +
766 817 if ( ! $row ) {
767 818 return false;
768 819 }
769 820
@@ -773,9 +824,12 @@
773 824 if ( ! is_array( $meta ) || empty( $meta['referer'] ) ) {
774 825 return false;
775 826 }
776 827
777 - self::delete_temporary_referer_meta( (int) $row->id );
828 + if ( $delete_meta ) {
829 + self::delete_temporary_referer_meta( (int) $row->id );
830 + }
831 +
778 832 return $meta['referer'];
779 833 }
780 834
781 835 /**
@@ -781,8 +835,9 @@
781 835 /**
782 836 * Delete the referer meta as we'll no longer need it.
783 837 *
784 838 * @param int $row_id
839 + *
785 840 * @return void
786 841 */
787 842 private static function delete_temporary_referer_meta( $row_id ) {
788 843 global $wpdb;
@@ -794,8 +849,9 @@
794 849 *
795 850 * @since 6.5.1
796 851 *
797 852 * @param object $intent
853 + *
798 854 * @return bool
799 855 */
800 856 private static function intent_has_failed_status( $intent ) {
801 857 return in_array( $intent->status, array( 'requires_source', 'requires_payment_method', 'canceled' ), true );
@@ -807,8 +863,9 @@
807 863 * @since 6.8
808 864 *
809 865 * @param object $payment
810 866 * @param object $intent
867 + *
811 868 * @return bool
812 869 */
813 870 public static function payment_failed( $payment, $intent ) {
814 871 if ( self::intent_has_failed_status( $intent ) ) {
@@ -813,13 +870,8 @@
813 870 public static function payment_failed( $payment, $intent ) {
814 871 if ( self::intent_has_failed_status( $intent ) ) {
815 872 return true;
816 873 }
817 -
818 874 // The $intent will be "succeeded" with a failed payment when testing with the 4000000000000341 credit card.
819 - if ( 'payment_failed' === FrmAppHelper::simple_get( 'frm_link_error' ) && 'failed' === $payment->status ) {
820 - return true;
821 - }
822 -
823 - return false;
875 + return 'payment_failed' === FrmAppHelper::simple_get( 'frm_link_error' ) && 'failed' === $payment->status;
824 876 }
825 877 }