| @@ -17,8 +17,9 @@ | ||
| 17 | 17 | /** |
| 18 | 18 | * Install required tables. |
| 19 | 19 | * |
| 20 | 20 | * @param mixed $old_db_version |
| 21 | + * | |
| 21 | 22 | * @return void |
| 22 | 23 | */ |
| 23 | 24 | public static function install( $old_db_version = false ) { |
| 24 | 25 | FrmTransLiteAppController::install( $old_db_version ); |
| @@ -43,8 +44,9 @@ | ||
| 43 | 44 | ); |
| 44 | 45 | |
| 45 | 46 | $modes = array( 'test', 'live' ); |
| 46 | 47 | $option_name_keys = array( 'account_id', 'client_password', 'server_password', 'details_submitted' ); |
| 48 | + | |
| 47 | 49 | foreach ( $modes as $mode ) { |
| 48 | 50 | foreach ( $option_name_keys as $key ) { |
| 49 | 51 | $options_to_delete[] = 'frm_strp_connect_' . $key . '_' . $mode; |
| 50 | 52 | } |
| @@ -55,20 +57,16 @@ | ||
| 55 | 57 | } |
| 56 | 58 | } |
| 57 | 59 | |
| 58 | 60 | /** |
| 59 | - * Redirect to Stripe settings when payments are not yet installed | |
| 60 | - * and the payments page is accessed by its URL. | |
| 61 | + * Gets payments settings URL. | |
| 61 | 62 | * |
| 62 | - * @return void | |
| 63 | + * @since 6.30 | |
| 64 | + * | |
| 65 | + * @return string | |
| 63 | 66 | */ |
| 64 | - public static function maybe_redirect_to_stripe_settings() { | |
| 65 | - if ( ! FrmAppHelper::is_admin_page( 'formidable-payments' ) || FrmTransLiteAppHelper::payments_table_exists() ) { | |
| 66 | - return; | |
| 67 | - } | |
| 68 | - | |
| 69 | - wp_safe_redirect( admin_url( 'admin.php?page=formidable-settings&t=stripe_settings' ) ); | |
| 70 | - die(); | |
| 67 | + public static function get_payments_settings_url() { | |
| 68 | + return admin_url( 'admin.php?page=formidable-settings&t=stripe_settings' ); | |
| 71 | 69 | } |
| 72 | 70 | |
| 73 | 71 | /** |
| 74 | 72 | * Add the gateway for compatibility with the Payments submodule. |
| @@ -74,8 +72,9 @@ | ||
| 74 | 72 | * Add the gateway for compatibility with the Payments submodule. |
| 75 | 73 | * This adds the Stripe checkbox option to the list of gateways. |
| 76 | 74 | * |
| 77 | 75 | * @param array $gateways |
| 76 | + * | |
| 78 | 77 | * @return array |
| 79 | 78 | */ |
| 80 | 79 | public static function add_gateway( $gateways ) { |
| 81 | 80 | $gateways['stripe'] = array( |
| @@ -99,12 +98,13 @@ | ||
| 99 | 98 | * @since 6.5.1 |
| 100 | 99 | * |
| 101 | 100 | * @param array $errors Errors data. Is empty array if no errors found. |
| 102 | 101 | * @param array $params Form params. See {@FrmForm::get_params()}. |
| 102 | + * | |
| 103 | 103 | * @return array |
| 104 | 104 | */ |
| 105 | 105 | public static function maybe_add_payment_error( $errors, $params ) { |
| 106 | - if ( ! $params['posted_form_id'] ) { | |
| 106 | + if ( intval( $params['posted_form_id'] ) !== intval( $params['form_id'] ) ) { | |
| 107 | 107 | return self::maybe_add_payment_error_on_redirect( $errors, (int) $params['form_id'] ); |
| 108 | 108 | } |
| 109 | 109 | return $errors; |
| 110 | 110 | } |
| @@ -116,22 +116,25 @@ | ||
| 116 | 116 | * @since 6.5.1 |
| 117 | 117 | * |
| 118 | 118 | * @param array $errors |
| 119 | 119 | * @param int $form_id |
| 120 | + * | |
| 120 | 121 | * @return array |
| 121 | 122 | */ |
| 122 | 123 | private static function maybe_add_payment_error_on_redirect( $errors, $form_id ) { |
| 123 | 124 | $details = FrmStrpLiteUrlParamHelper::get_details_for_form( $form_id ); |
| 125 | + | |
| 124 | 126 | if ( ! is_array( $details ) ) { |
| 125 | 127 | return $errors; |
| 126 | 128 | } |
| 127 | 129 | |
| 128 | - $entry = $details['entry']; | |
| 129 | - $intent = $details['intent']; | |
| 130 | - $payment = $details['payment']; | |
| 130 | + $entry = $details['entry']; | |
| 131 | + $intent = $details['intent']; | |
| 132 | + $payment = $details['payment']; | |
| 133 | + $payment_failed = FrmStrpLiteAuth::payment_failed( $payment, $intent ); | |
| 131 | 134 | |
| 132 | 135 | // Only add the payment error if the intent is incomplete. |
| 133 | - if ( ! in_array( $intent->status, array( 'requires_source', 'requires_payment_method', 'canceled' ), true ) ) { | |
| 136 | + if ( ! $payment_failed ) { | |
| 134 | 137 | return $errors; |
| 135 | 138 | } |
| 136 | 139 | |
| 137 | 140 | $cc_field_id = FrmDb::get_var( |
| @@ -140,19 +143,25 @@ | ||
| 140 | 143 | 'type' => 'credit_card', |
| 141 | 144 | 'form_id' => $entry->form_id, |
| 142 | 145 | ) |
| 143 | 146 | ); |
| 147 | + | |
| 144 | 148 | if ( ! $cc_field_id ) { |
| 145 | 149 | return $errors; |
| 146 | 150 | } |
| 147 | 151 | |
| 148 | - $is_setup_intent = 0 === strpos( $intent->id, 'seti_' ); | |
| 152 | + $is_setup_intent = str_starts_with( $intent->id, 'seti_' ); | |
| 153 | + | |
| 149 | 154 | if ( $is_setup_intent ) { |
| 150 | - $errors[ 'field' . $cc_field_id ] = $intent->last_setup_error->message; | |
| 155 | + $errors[ 'field' . $cc_field_id ] = is_object( $intent->last_setup_error ) ? $intent->last_setup_error->message : ''; | |
| 151 | 156 | } else { |
| 152 | - $errors[ 'field' . $cc_field_id ] = $intent->last_payment_error->message; | |
| 157 | + $errors[ 'field' . $cc_field_id ] = is_object( $intent->last_payment_error ) ? $intent->last_payment_error->message : ''; | |
| 153 | 158 | } |
| 154 | 159 | |
| 160 | + if ( ! $errors[ 'field' . $cc_field_id ] ) { | |
| 161 | + $errors[ 'field' . $cc_field_id ] = 'Payment was not successfully processed.'; | |
| 162 | + } | |
| 163 | + | |
| 155 | 164 | global $frm_vars; |
| 156 | 165 | $frm_vars['frm_trans']['pay_entry'] = $entry; |
| 157 | 166 | |
| 158 | 167 | self::setup_form_after_payment_error( (int) $entry->form_id, (int) $entry->id, $errors ); |
| @@ -169,8 +178,9 @@ | ||
| 169 | 178 | * |
| 170 | 179 | * @param int $form_id |
| 171 | 180 | * @param int $entry_id |
| 172 | 181 | * @param array<string,string> $errors |
| 182 | + * | |
| 173 | 183 | * @return void |
| 174 | 184 | */ |
| 175 | 185 | private static function setup_form_after_payment_error( $form_id, $entry_id, $errors ) { |
| 176 | 186 | $form = FrmForm::getOne( $form_id ); |
| @@ -178,9 +188,10 @@ | ||
| 178 | 188 | |
| 179 | 189 | global $frm_vars; |
| 180 | 190 | $frm_vars['created_entries'][ $form_id ]['errors'] = $errors; |
| 181 | 191 | |
| 182 | - $_POST[ 'frm_page_order_' . $form_id ] = true; // Set to true to get FrmProFieldsHelper::get_page_with_error() run | |
| 192 | + // Set to true to get FrmProFieldsHelper::get_page_with_error() run. | |
| 193 | + $_POST[ 'frm_page_order_' . $form_id ] = true; | |
| 183 | 194 | |
| 184 | 195 | if ( ! $save_draft ) { |
| 185 | 196 | // If draft saving is not on, delete the entry. |
| 186 | 197 | self::$delete_pay_entry = true; |
| @@ -195,11 +206,12 @@ | ||
| 195 | 206 | * Set the entry back to draft status after error. |
| 196 | 207 | * |
| 197 | 208 | * @param string $html |
| 198 | 209 | * @param int $entry_id |
| 210 | + * | |
| 199 | 211 | * @return string |
| 200 | 212 | */ |
| 201 | - function( $html ) use ( $entry_id ) { | |
| 213 | + function ( $html ) use ( $entry_id ) { | |
| 202 | 214 | global $wpdb; |
| 203 | 215 | $wpdb->update( $wpdb->prefix . 'frm_items', array( 'is_draft' => 1 ), array( 'id' => $entry_id ) ); |
| 204 | 216 | return $html; |
| 205 | 217 | } |
| @@ -212,8 +224,9 @@ | ||
| 212 | 224 | * @since 2.08 |
| 213 | 225 | * |
| 214 | 226 | * @param array $values Entry edit values. |
| 215 | 227 | * @param object $field Field object. |
| 228 | + * | |
| 216 | 229 | * @return array |
| 217 | 230 | */ |
| 218 | 231 | public static function maybe_delete_pay_entry( $values, $field ) { |
| 219 | 232 | if ( self::$delete_pay_entry ) { |
| @@ -220,6 +233,18 @@ | ||
| 220 | 233 | self::$delete_pay_entry = false; |
| 221 | 234 | return FrmTransLiteActionsController::fill_entry_from_previous( $values, $field ); |
| 222 | 235 | } |
| 223 | 236 | return $values; |
| 237 | + } | |
| 238 | + | |
| 239 | + /** | |
| 240 | + * Redirect to Stripe settings when payments are not yet installed | |
| 241 | + * and the payments page is accessed by its URL. | |
| 242 | + * | |
| 243 | + * @deprecated 6.33 | |
| 244 | + * | |
| 245 | + * @return void | |
| 246 | + */ | |
| 247 | + public static function maybe_redirect_to_stripe_settings() { | |
| 248 | + _deprecated_function( __METHOD__, '6.33' ); | |
| 224 | 249 | } |
| 225 | 250 | } |