PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.5.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.5.2
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
formidable / stripe / helpers / FrmStrpLiteUrlParamHelper.php

FrmStrpLiteUrlParamHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.5.2, at stripe/helpers/FrmStrpLiteUrlParamHelper.php

115 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * Check, verify, and store URL param details.
8 * This is used for 3D Secure and Stripe Link.
9 *
10 * @since 6.5.1
11 */
12 class FrmStrpLiteUrlParamHelper {
13
14 /**
15 * Each set of details includes an entry object, a payment object, and an intent object.
16 *
17 * @var array
18 */
19 private static $details_by_form_id = array();
20
21 /**
22 * Get some associated payment objects based on the URL param data.
23 * This includes the intent, the entry, and the payments table model instance.
24 *
25 * @param string|int $form_id
26 * @return array|false
27 */
28 public static function get_details_for_form( $form_id ) {
29 if ( ! isset( self::$details_by_form_id[ $form_id ] ) ) {
30 self::set_details_for_form( (int) $form_id );
31 }
32 return isset( self::$details_by_form_id[ $form_id ] ) ? self::$details_by_form_id[ $form_id ] : false;
33 }
34
35 /**
36 * Check the URL params for Stripe intent details.
37 * These params are used in 3D secure as well as Stripe Link.
38 *
39 * The params include:
40 * - The ID of the payment intent or setup intent.
41 * - The ID of the entry.
42 * - The client secret which is used to verify the intent.
43 * - The charge ID (if applicable)
44 *
45 * @since 6.5.1
46 *
47 * @param string|int $form_id
48 * @return void
49 */
50 private static function set_details_for_form( $form_id ) {
51 $intent_id = FrmAppHelper::simple_get( 'payment_intent' );
52 $is_setup_intent = false;
53
54 if ( ! $intent_id ) {
55 $intent_id = FrmAppHelper::simple_get( 'setup_intent' );
56 $is_setup_intent = true;
57
58 if ( ! $intent_id ) {
59 return;
60 }
61 }
62
63 $intent_function_name = $is_setup_intent ? 'get_setup_intent' : 'get_intent';
64 $intent = FrmStrpLiteAppHelper::call_stripe_helper_class( $intent_function_name, $intent_id );
65
66 if ( ! $intent || ! self::verify_client_secret( $intent, $is_setup_intent ) ) {
67 return;
68 }
69
70 $charge_id = FrmAppHelper::simple_get( 'charge' );
71 $has_charge = (bool) $charge_id;
72 $frm_payment = new FrmTransLitePayment();
73
74 if ( $has_charge ) {
75 // Stripe link payments use charge id.
76 $payment = $frm_payment->get_one_by( $charge_id, 'receipt_id' );
77 }
78
79 if ( ! isset( $payment ) || ! is_object( $payment ) ) {
80 // 3D secure payments use intent id.
81 $payment = $frm_payment->get_one_by( $intent_id, 'receipt_id' );
82 }
83
84 if ( ! is_object( $payment ) ) {
85 return;
86 }
87
88 $entry = FrmEntry::getOne( $payment->item_id, true );
89 if ( ! is_object( $entry ) || (int) $entry->form_id !== $form_id ) {
90 return;
91 }
92
93 self::$details_by_form_id[ $form_id ] = array(
94 'entry' => $entry,
95 'intent' => $intent,
96 'payment' => $payment,
97 );
98 }
99
100 /**
101 * Check the client secret in the URL, verify it matches the Stripe object and isn't being manipulated.
102 *
103 * @since 6.5.1
104 *
105 * @param object $intent
106 * @param bool $is_setup_intent
107 * @return bool True if the client secret is set and valid.
108 */
109 private static function verify_client_secret( $intent, $is_setup_intent ) {
110 $client_secret_param = $is_setup_intent ? 'setup_intent_client_secret' : 'payment_intent_client_secret';
111 $client_secret = FrmAppHelper::simple_get( $client_secret_param );
112 return $client_secret && $client_secret === $intent->client_secret;
113 }
114 }
115