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/FrmStrpLiteLinkController.php +17 -95 6.296.12 View file →
@@ -49,16 +49,15 @@
49 49 * @since 6.5, introduced in v3.0 of the Stripe add on.
50 50 *
51 51 * @param string $intent_id
52 52 * @param string $client_secret
53 - *
54 53 * @return void
55 54 */
56 55 private static function handle_one_time_stripe_link_return_url( $intent_id, $client_secret ) {
57 56 $redirect_helper = new FrmStrpLiteLinkRedirectHelper( $intent_id, $client_secret );
58 57 $frm_payment = new FrmTransLitePayment();
59 - $payment = $frm_payment->get_one_by( $intent_id, 'receipt_id' );
60 58
59 + $payment = $frm_payment->get_one_by( $intent_id, 'receipt_id' );
61 60 if ( ! $payment ) {
62 61 $redirect_helper->handle_error( 'no_payment_record' );
63 62 die();
64 63 }
@@ -63,9 +62,8 @@
63 62 die();
64 63 }
65 64
66 65 $intent = FrmStrpLiteAppHelper::call_stripe_helper_class( 'get_intent', $intent_id );
67 -
68 66 if ( ! is_object( $intent ) ) {
69 67 $redirect_helper->handle_error( 'intent_does_not_exist' );
70 68 die();
71 69 }
@@ -75,11 +73,10 @@
75 73 $redirect_helper->handle_error( 'unable_to_verify' );
76 74 die();
77 75 }
78 76
79 - $status = 'succeeded' === $intent->status ? 'complete' : 'authorized';
80 - $new_payment_values = (array) $payment;
81 - $new_payment_values['status'] = $status;
77 + $status = 'succeeded' === $intent->status ? 'complete' : 'authorized';
78 + $new_payment_values = compact( 'status' );
82 79
83 80 if ( 'complete' === $status ) {
84 81 $charge = reset( $intent->charges->data );
85 82 $new_payment_values['receipt_id'] = $charge->id;
@@ -95,32 +92,13 @@
95 92
96 93 $redirect_helper->set_entry_id( $entry->id );
97 94
98 95 $action = FrmStrpLiteActionsController::get_stripe_link_action( $entry->form_id );
99 -
100 96 if ( ! $action ) {
101 97 $redirect_helper->handle_error( 'no_stripe_link_action' );
102 98 die();
103 99 }
104 100
105 - $currency = FrmTransLiteAppHelper::get_action_setting( 'currency', array( 'payment' => $payment ) );
106 - $currency = FrmCurrencyHelper::get_currency( $currency );
107 - $actual_amount = intval( $intent->amount );
108 - $expected_amount = round( floatval( $payment->amount ), 2 );
109 -
110 - if ( 0 !== $currency['decimals'] ) {
111 - // Convert 10 to 1000 for example for Stripe.
112 - // But avoid for this a 0-decimal currency like JPY.
113 - $expected_amount *= 100;
114 - }
115 -
116 - $expected_amount = intval( round( $expected_amount ) );
117 -
118 - if ( $expected_amount !== $actual_amount ) {
119 - $redirect_helper->handle_error( 'amount_mismatch' );
120 - die();
121 - }
122 -
123 101 if ( 'succeeded' !== $intent->status ) {
124 102 if ( 'processing' === $intent->status ) {
125 103 FrmTransLitePaymentsController::change_payment_status( $payment, 'processing' );
126 104 $redirect_helper->handle_success( $entry, '' );
@@ -158,9 +136,8 @@
158 136 *
159 137 * @param object $intent
160 138 * @param stdClass|WP_Post $action
161 139 * @param stdClass $entry
162 - *
163 140 * @return void
164 141 */
165 142 private static function maybe_update_intent( $intent, $action, $entry ) {
166 143 if ( empty( $action->post_content['description'] ) ) {
@@ -184,9 +161,8 @@
184 161 * @since 6.5, introduced in v3.0 of the Stripe add on.
185 162 *
186 163 * @param string $setup_id
187 164 * @param string $client_secret
188 - *
189 165 * @return void
190 166 */
191 167 private static function handle_recurring_stripe_link_return_url( $setup_id, $client_secret ) {
192 168 $redirect_helper = new FrmStrpLiteLinkRedirectHelper( $setup_id, $client_secret );
@@ -199,9 +175,8 @@
199 175 }
200 176
201 177 // Verify the setup intent.
202 178 $setup_intent = FrmStrpLiteAppHelper::call_stripe_helper_class( 'get_setup_intent', $setup_id );
203 -
204 179 if ( ! is_object( $setup_intent ) ) {
205 180 $redirect_helper->handle_error( 'intent_does_not_exist' );
206 181 die();
207 182 }
@@ -213,9 +188,8 @@
213 188 }
214 189
215 190 // Verify the entry.
216 191 $entry = FrmEntry::getOne( $payment->item_id );
217 -
218 192 if ( ! is_object( $entry ) ) {
219 193 $redirect_helper->handle_error( 'no_entry_found' );
220 194 die();
221 195 }
@@ -223,9 +197,8 @@
223 197 $redirect_helper->set_entry_id( $entry->id );
224 198
225 199 // Verify it's an action with Stripe link enabled.
226 200 $action = FrmStrpLiteActionsController::get_stripe_link_action( $entry->form_id );
227 -
228 201 if ( ! is_object( $action ) ) {
229 202 $redirect_helper->handle_error( 'no_stripe_link_action' );
230 203 die();
231 204 }
@@ -231,9 +204,8 @@
231 204 }
232 205
233 206 $customer_id = $setup_intent->customer;
234 207 $payment_method_id = self::get_link_payment_method( $setup_intent );
235 -
236 208 if ( ! $payment_method_id ) {
237 209 FrmTransLitePaymentsController::change_payment_status( $payment, 'failed' );
238 210 $redirect_helper->handle_error( 'did_not_complete' );
239 211 die();
@@ -263,9 +235,8 @@
263 235 'entry' => $entry,
264 236 );
265 237
266 238 $trial_end = FrmStrpLiteActionsController::get_trial_end_time( $atts );
267 -
268 239 if ( $trial_end ) {
269 240 $new_charge['trial_end'] = $trial_end;
270 241 }
271 242
@@ -284,9 +255,9 @@
284 255 }
285 256
286 257 $customer_has_been_charged = ! empty( $subscription->latest_invoice->charge );
287 258 $atts['charge'] = FrmStrpLiteSubscriptionHelper::prepare_charge_object_for_subscription( $subscription, $amount );
288 - $new_payment_values = (array) $payment;
259 + $new_payment_values = array();
289 260
290 261 if ( $customer_has_been_charged ) {
291 262 $charge = $subscription->latest_invoice->charge;
292 263 $new_payment_values['receipt_id'] = $charge->id;
@@ -302,9 +273,8 @@
302 273
303 274 $new_payment_values['status'] = 'pending' === $charge->status ? 'processing' : 'complete';
304 275
305 276 $new_payment_values['expire_date'] = '0000-00-00';
306 -
307 277 foreach ( $subscription->latest_invoice->lines->data as $line ) {
308 278 $new_payment_values['expire_date'] = gmdate( 'Y-m-d', $line->period->end );
309 279 }
310 280 } elseif ( $trial_end ) {
@@ -323,9 +293,8 @@
323 293 FrmTransLiteActionsController::trigger_payment_status_change( compact( 'status', 'payment' ) );
324 294
325 295 // Update the next billing date.
326 296 $next_bill_date = gmdate( 'Y-m-d' );
327 -
328 297 foreach ( $subscription->latest_invoice->lines->data as $line ) {
329 298 $next_bill_date = gmdate( 'Y-m-d', $line->period->end );
330 299 }
331 300
@@ -347,15 +316,13 @@
347 316 *
348 317 * @since 6.5, introduced in v3.0 of the Stripe add on.
349 318 *
350 319 * @param object $setup_intent
351 - *
352 320 * @return false|string
353 321 */
354 322 private static function get_link_payment_method( $setup_intent ) {
355 323 if ( is_object( $setup_intent->latest_attempt ) && ! empty( $setup_intent->latest_attempt->payment_method_details ) ) {
356 324 $payment_method_details = $setup_intent->latest_attempt->payment_method_details;
357 -
358 325 foreach ( array( 'ideal', 'sofort', 'bancontact' ) as $payment_method_type ) {
359 326 if ( ! empty( $payment_method_details->$payment_method_type ) ) {
360 327 return $payment_method_details->$payment_method_type->generated_sepa_debit;
361 328 }
@@ -384,32 +351,31 @@
384 351 * @type WP_Post $action
385 352 * @type string $amount
386 353 * @type object $customer
387 354 * }
388 - *
389 - * @return bool True on success, false on failure.
355 + * @return void
390 356 */
391 357 public static function create_pending_stripe_link_payment( $atts ) {
392 358 if ( empty( $atts['form'] ) || empty( $atts['entry'] ) || empty( $atts['action'] ) || ! isset( $atts['amount'] ) || empty( $atts['customer'] ) ) {
393 - return false;
359 + return;
394 360 }
395 361
396 362 $form = $atts['form'];
397 - $action = $atts['action'];
398 - $intent_id = self::verify_intent( $form->id, $action );
363 + $intent_id = self::verify_intent( $form->id );
399 364
400 365 if ( ! $intent_id ) {
401 - return false;
366 + return;
402 367 }
403 368
404 - $is_setup_intent = str_starts_with( $intent_id, 'seti_' );
369 + $is_setup_intent = 0 === strpos( $intent_id, 'seti_' );
405 370 $entry = $atts['entry'];
371 + $action = $atts['action'];
406 372 $amount = $atts['amount'];
407 373 $customer = $atts['customer'];
408 374
409 375 if ( ! $is_setup_intent ) {
410 376 // Update the amount and set the customer before confirming the payment.
411 - $updated = FrmStrpLiteAppHelper::call_stripe_helper_class(
377 + FrmStrpLiteAppHelper::call_stripe_helper_class(
412 378 'update_intent',
413 379 $intent_id,
414 380 array(
415 381 'amount' => $amount,
@@ -415,18 +381,14 @@
415 381 'amount' => $amount,
416 382 'customer' => $customer->id,
417 383 )
418 384 );
419 -
420 - if ( ! $updated ) {
421 - return false;
422 - }
423 385 }
424 386
425 387 self::add_temporary_referer_meta( (int) $entry->id );
426 388
427 389 $frm_payment = new FrmTransLitePayment();
428 - $payment_id = $frm_payment->create(
390 + $frm_payment->create(
429 391 array(
430 392 'paysys' => 'stripe',
431 393 'amount' => FrmTransLiteAppHelper::get_formatted_amount_for_currency( $amount, $action ),
432 394 'status' => 'pending',
@@ -436,10 +398,8 @@
436 398 'sub_id' => '',
437 399 'test' => 'test' === FrmStrpLiteAppHelper::active_mode() ? 1 : 0,
438 400 )
439 401 );
440 -
441 - return (bool) $payment_id;
442 402 }
443 403
444 404 /**
445 405 * Verify a payment intent or setup intent client secret is in the POST data and is valid.
@@ -446,15 +406,12 @@
446 406 *
447 407 * @since 6.5, introduced in v3.0 of the Stripe add on.
448 408 *
449 409 * @param int|string $form_id
450 - * @param WP_Post $action
451 - *
452 410 * @return false|string String intent id on success, False if intent is missing or cannot be verified.
453 411 */
454 - private static function verify_intent( $form_id, $action ) {
412 + private static function verify_intent( $form_id ) {
455 413 $client_secrets = FrmAppHelper::get_post_param( 'frmintent' . $form_id, array(), 'sanitize_text_field' );
456 -
457 414 if ( ! $client_secrets ) {
458 415 return false;
459 416 }
460 417
@@ -460,27 +417,15 @@
460 417
461 418 $client_secret = reset( $client_secrets );
462 419 list( $prefix, $intent_id ) = explode( '_', $client_secret );
463 420 $intent_id = $prefix . '_' . $intent_id;
464 - $is_setup_intent = str_starts_with( $intent_id, 'seti_' );
465 - $function_name = $is_setup_intent ? 'get_setup_intent' : 'get_intent';
466 - $intent = FrmStrpLiteAppHelper::call_stripe_helper_class( $function_name, $intent_id );
467 421
468 - if ( ! $intent || $intent->client_secret !== $client_secret || ! self::intent_matches_form_action( $intent, $action ) ) {
469 - return false;
470 - }
422 + $is_setup_intent = 0 === strpos( $intent_id, 'seti_' );
471 423
472 - if ( isset( $intent->charges ) && is_object( $intent->charges ) && ! empty( $intent->charges->data ) ) {
473 - // The intent should not have any charges yet.
474 - // If it does, the intent is invalid.
475 - return false;
476 - }
424 + $function_name = $is_setup_intent ? 'get_setup_intent' : 'get_intent';
425 + $intent = FrmStrpLiteAppHelper::call_stripe_helper_class( $function_name, $intent_id );
477 426
478 - $frm_payment = new FrmTransLitePayment();
479 - $payment = $frm_payment->get_one_by( $intent_id, 'receipt_id' );
480 -
481 - if ( $payment ) {
482 - // A duplicate payment should not exist.
427 + if ( ! $intent || $intent->client_secret !== $client_secret ) {
483 428 return false;
484 429 }
485 430
486 431 return $intent_id;
@@ -486,27 +431,8 @@
486 431 return $intent_id;
487 432 }
488 433
489 434 /**
490 - * Check if an intent matches a form action.
491 - *
492 - * @since 6.29
493 - *
494 - * @param object $intent
495 - * @param WP_Post $action
496 - *
497 - * @return bool
498 - */
499 - private static function intent_matches_form_action( $intent, $action ) {
500 - if ( ! isset( $intent->metadata ) || ! is_object( $intent->metadata ) || empty( $intent->metadata->action ) ) {
501 - // Avoid false positive if the intent is missing metadata.
502 - return true;
503 - }
504 -
505 - return (int) $intent->metadata->action === $action->ID;
506 - }
507 -
508 - /**
509 435 * Set the referer URL as field ID 0 in entry meta.
510 436 * This is required for iDEAL, sofort, and other payment methods that include an additional redirect step.
511 437 * It is used for the redirect in FrmStrpLinkRedirectHelper.
512 438 * It is deleted after the redirect happens.
@@ -511,9 +437,8 @@
511 437 * It is used for the redirect in FrmStrpLinkRedirectHelper.
512 438 * It is deleted after the redirect happens.
513 439 *
514 440 * @param int $entry_id
515 - *
516 441 * @return void
517 442 */
518 443 private static function add_temporary_referer_meta( $entry_id ) {
519 444 $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
@@ -523,9 +448,8 @@
523 448 'payment_intent_client_secret',
524 449 'setup_intent',
525 450 'setup_intent_client_secret',
526 451 );
527 -
528 452 foreach ( $query_args_to_strip_from_referer as $arg ) {
529 453 $referer = remove_query_arg( $arg, $referer );
530 454 }
531 455
@@ -538,9 +462,8 @@
538 462 *
539 463 * @since 6.5, introduced in v3.0 of the Stripe add on.
540 464 *
541 465 * @param stdClass $form
542 - *
543 466 * @return void
544 467 */
545 468 public static function add_form_classes( $form ) {
546 469 if ( false === FrmStrpLiteActionsController::get_stripe_link_action( $form->id ) ) {
@@ -555,9 +478,8 @@
555 478 *
556 479 * @since 6.5, introduced in v3.0 of the Stripe add on.
557 480 *
558 481 * @param mixed $form
559 - *
560 482 * @return mixed
561 483 */
562 484 public static function force_ajax_submit_for_stripe_link( $form ) {
563 485 if ( ! is_object( $form ) ) {