- Timestamp:
- 10/14/2026 04:54:36 PM (2 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
formidable/trunk/stripe/controllers/FrmStrpLiteActionsController.php
r3688662 r3746820 10 10 */ 11 11 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 ); 12 43 13 44 /** … … 124 155 } 125 156 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; 128 161 return $response; 129 162 } 130 163 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 ); 132 167 133 168 if ( ! is_object( $customer ) ) { … … 136 171 } 137 172 138 $one_time_payment_args = compact( 'customer', 'form', 'entry', 'action', 'amount' );173 $one_time_payment_args = compact( 'customer', 'form', 'entry', 'action', 'amount', 'setup_intent' ); 139 174 140 175 if ( ! FrmStrpLiteLinkController::create_pending_stripe_link_payment( $one_time_payment_args ) ) { … … 148 183 149 184 /** 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 /**159 185 * Get the customer id from a setup intent that was created for this submission. 160 186 * A Stripe Link subscription builds its subscription from the setup intent's customer, … … 168 194 */ 169 195 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 ) { 170 210 $posted_intents = FrmStrpLiteAuth::get_payment_intents( 'frmintent' . $form_id ); 171 211 … … 175 215 176 216 $setup_intent_ids = array_filter( 177 $posted_intents,217 FrmStrpLiteFormIntentHelper::flatten_client_secrets( $posted_intents ), 178 218 function ( $intent_id ) { 179 219 return str_starts_with( $intent_id, 'seti_' ); … … 186 226 187 227 $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]; 189 230 $setup_intent = FrmStrpLiteAppHelper::call_stripe_helper_class( 'get_setup_intent', $first_setup_intent_id ); 190 231 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 ) ) { 192 233 return false; 193 234 } 194 235 195 return $setup_intent ->customer;236 return $setup_intent; 196 237 } 197 238 … … 554 595 $stripe_vars = array( 555 596 'publishable_key' => $publishable, 597 'https_error' => __( 'Stripe payments require HTTPS. Please use a secure URL or contact the site administrator.', 'formidable' ), 556 598 'form_id' => $form_id, 557 599 'nonce' => wp_create_nonce( 'frm_strp_ajax' ), … … 578 620 private static function get_style_settings_for_form( $form_id ) { 579 621 if ( ! $form_id ) { 580 return array();622 return self::$style_setting_defaults; 581 623 } 582 624 … … 584 626 585 627 if ( ! $style ) { 586 return array();628 return self::$style_setting_defaults; 587 629 } 588 630 … … 596 638 } 597 639 598 return $settings;640 return wp_parse_args( $settings, self::$style_setting_defaults ); 599 641 } 600 642 … … 632 674 ), 633 675 '.Label' => array( 676 'fontFamily' => $settings['font'], 634 677 'color' => $settings['label_color'], 635 678 'fontSize' => $settings['font_size'], … … 643 686 ); 644 687 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 645 693 /* 646 694 * Filters the appearance rules for Stripe elements. … … 728 776 return FrmTransLiteActionsController::remove_cc_errors( $errors, $field ); 729 777 } 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 } 730 799 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)