Plugin Directory


Ignore:
Timestamp:
10/14/2026 04:54:36 PM (2 weeks ago)
Author:
formidableforms
Message:

Update to version 7.0 from GitHub

File:
1 edited

Legend:

Unmodified
Added
Removed
  • formidable/trunk/stripe/controllers/FrmStrpLiteActionsController.php

    r3688662 r3746820  
    1010         */
    1111        private static $customer;
     12
     13        /**
     14         * Default style setting values, keyed the same as FrmStylesHelper::get_settings_for_output().
     15         * Guarantees get_appearance_rules() and its border helpers always have every
     16         * key present, including the no-form-context case where there's no style to read settings from.
     17         *
     18         * @since 7.0
     19         *
     20         * @var array
     21         */
     22        private static $style_setting_defaults = array(
     23                'text_color'          => '',
     24                'font'                => '',
     25                'field_font_size'     => '',
     26                'text_color_disabled' => '',
     27                'required_color'      => '',
     28                'bg_color'            => '',
     29                'field_pad'           => '',
     30                'border_color'        => '',
     31                'field_border_style'  => '',
     32                'field_weight'        => '',
     33                'bg_color_active'     => '',
     34                'label_color'         => '',
     35                'font_size'           => '',
     36                'weight'              => '',
     37                'label_padding'       => '',
     38                'border_color_error'  => '',
     39                'field_shape_type'    => '',
     40                'field_border_width'  => '',
     41                'border_radius'       => '',
     42        );
    1243
    1344        /**
    … …  
    124155                }
    125156
    126                 if ( ! self::stripe_is_configured() ) {
    127                         $response['error'] = __( 'Stripe still needs to be configured.', 'formidable' );
     157                $connection_error = FrmTransLiteAppHelper::get_gateway_connection_error( 'stripe' );
     158
     159                if ( $connection_error ) {
     160                        $response['error'] = $connection_error;
    128161                        return $response;
    129162                }
    130163
    131                 $customer = self::set_customer_with_token( $atts, self::get_customer_id_from_posted_setup_intents( $form->id ) );
     164                $setup_intent = 'recurring' === $action->post_content['type'] ? self::get_posted_setup_intent( $form->id ) : false;
     165                $customer_id  = is_object( $setup_intent ) ? $setup_intent->customer : false;
     166                $customer     = self::set_customer_with_token( $atts, $customer_id );
    132167
    133168                if ( ! is_object( $customer ) ) {
    … …  
    136171                }
    137172
    138                 $one_time_payment_args = compact( 'customer', 'form', 'entry', 'action', 'amount' );
     173                $one_time_payment_args = compact( 'customer', 'form', 'entry', 'action', 'amount', 'setup_intent' );
    139174
    140175                if ( ! FrmStrpLiteLinkController::create_pending_stripe_link_payment( $one_time_payment_args ) ) {
    … …  
    148183
    149184        /**
    150          * Check if either Stripe integration is enabled.
    151          *
    152          * @return bool true if Stripe Connect is set up.
    153          */
    154         private static function stripe_is_configured() {
    155                 return FrmStrpLiteAppHelper::call_stripe_helper_class( 'initialize_api' );
    156         }
    157 
    158         /**
    159185         * Get the customer id from a setup intent that was created for this submission.
    160186         * A Stripe Link subscription builds its subscription from the setup intent's customer,
    … …  
    168194         */
    169195        public static function get_customer_id_from_posted_setup_intents( $form_id ) {
     196                $intent = self::get_posted_setup_intent( $form_id );
     197                return is_object( $intent ) ? $intent->customer : false;
     198        }
     199
     200        /**
     201         * Retrieve and verify the posted setup intent once for customer and payment validation.
     202         *
     203         * @since 7.0
     204         *
     205         * @param int|string $form_id The submitted form id.
     206         *
     207         * @return false|object
     208         */
     209        private static function get_posted_setup_intent( $form_id ) {
    170210                $posted_intents = FrmStrpLiteAuth::get_payment_intents( 'frmintent' . $form_id );
    171211
    … …  
    175215
    176216                $setup_intent_ids = array_filter(
    177                         $posted_intents,
     217                        FrmStrpLiteFormIntentHelper::flatten_client_secrets( $posted_intents ),
    178218                        function ( $intent_id ) {
    179219                                return str_starts_with( $intent_id, 'seti_' );
    … …  
    186226
    187227                $first_setup_intent_id = reset( $setup_intent_ids );
    188                 $first_setup_intent_id = explode( '_secret_', $first_setup_intent_id )[0];
     228                $client_secret         = $first_setup_intent_id;
     229                $first_setup_intent_id = explode( '_secret_', $client_secret )[0];
    189230                $setup_intent          = FrmStrpLiteAppHelper::call_stripe_helper_class( 'get_setup_intent', $first_setup_intent_id );
    190231
    191                 if ( ! is_object( $setup_intent ) || empty( $setup_intent->customer ) ) {
     232                if ( ! is_object( $setup_intent ) || $setup_intent->client_secret !== $client_secret || empty( $setup_intent->customer ) ) {
    192233                        return false;
    193234                }
    194235
    195                 return $setup_intent->customer;
     236                return $setup_intent;
    196237        }
    197238
    … …  
    554595                $stripe_vars    = array(
    555596                        'publishable_key' => $publishable,
     597                        'https_error'     => __( 'Stripe payments require HTTPS. Please use a secure URL or contact the site administrator.', 'formidable' ),
    556598                        'form_id'         => $form_id,
    557599                        'nonce'           => wp_create_nonce( 'frm_strp_ajax' ),
    … …  
    578620        private static function get_style_settings_for_form( $form_id ) {
    579621                if ( ! $form_id ) {
    580                         return array();
     622                        return self::$style_setting_defaults;
    581623                }
    582624
    … …  
    584626
    585627                if ( ! $style ) {
    586                         return array();
     628                        return self::$style_setting_defaults;
    587629                }
    588630
    … …  
    596638                }
    597639
    598                 return $settings;
     640                return wp_parse_args( $settings, self::$style_setting_defaults );
    599641        }
    600642
    … …  
    632674                        ),
    633675                        '.Label'              => array(
     676                                'fontFamily'   => $settings['font'],
    634677                                'color'        => $settings['label_color'],
    635678                                'fontSize'     => $settings['font_size'],
    … …  
    643686                );
    644687
     688                if ( '' === (string) $settings['font'] ) {
     689                        // Leave the font out so Stripe uses its default stack instead of an empty value.
     690                        unset( $rules['.Input']['fontFamily'], $rules['.Label']['fontFamily'] );
     691                }
     692
    645693                /*
    646694                 * Filters the appearance rules for Stripe elements.
    … …  
    728776                return FrmTransLiteActionsController::remove_cc_errors( $errors, $field );
    729777        }
     778
     779        /**
     780         * Resolve the payment action that created a payment row.
     781         *
     782         * Use the action recorded on the payment, even if the form settings changed after submission.
     783         *
     784         * @since 7.0
     785         *
     786         * @param object $payment A row from the payments table.
     787         *
     788         * @return false|WP_Post
     789         */
     790        public static function get_action_for_payment( $payment ) {
     791                if ( empty( $payment->action_id ) ) {
     792                        return false;
     793                }
     794
     795                $action = FrmFormAction::get_single_action_type( (int) $payment->action_id, 'payment' );
     796
     797                return is_object( $action ) ? $action : false;
     798        }
    730799}
Note: See TracChangeset for help on using the changeset viewer.