| @@ -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 | } |
| @@ -95,9 +93,8 @@ | ||
| 95 | 93 | |
| 96 | 94 | $redirect_helper->set_entry_id( $entry->id ); |
| 97 | 95 | |
| 98 | 96 | $action = FrmStrpLiteActionsController::get_stripe_link_action( $entry->form_id ); |
| 99 | - | |
| 100 | 97 | if ( ! $action ) { |
| 101 | 98 | $redirect_helper->handle_error( 'no_stripe_link_action' ); |
| 102 | 99 | die(); |
| 103 | 100 | } |
| @@ -140,9 +137,8 @@ | ||
| 140 | 137 | * |
| 141 | 138 | * @param object $intent |
| 142 | 139 | * @param stdClass|WP_Post $action |
| 143 | 140 | * @param stdClass $entry |
| 144 | - * | |
| 145 | 141 | * @return void |
| 146 | 142 | */ |
| 147 | 143 | private static function maybe_update_intent( $intent, $action, $entry ) { |
| 148 | 144 | if ( empty( $action->post_content['description'] ) ) { |
| @@ -166,9 +162,8 @@ | ||
| 166 | 162 | * @since 6.5, introduced in v3.0 of the Stripe add on. |
| 167 | 163 | * |
| 168 | 164 | * @param string $setup_id |
| 169 | 165 | * @param string $client_secret |
| 170 | - * | |
| 171 | 166 | * @return void |
| 172 | 167 | */ |
| 173 | 168 | private static function handle_recurring_stripe_link_return_url( $setup_id, $client_secret ) { |
| 174 | 169 | $redirect_helper = new FrmStrpLiteLinkRedirectHelper( $setup_id, $client_secret ); |
| @@ -181,9 +176,8 @@ | ||
| 181 | 176 | } |
| 182 | 177 | |
| 183 | 178 | // Verify the setup intent. |
| 184 | 179 | $setup_intent = FrmStrpLiteAppHelper::call_stripe_helper_class( 'get_setup_intent', $setup_id ); |
| 185 | - | |
| 186 | 180 | if ( ! is_object( $setup_intent ) ) { |
| 187 | 181 | $redirect_helper->handle_error( 'intent_does_not_exist' ); |
| 188 | 182 | die(); |
| 189 | 183 | } |
| @@ -195,9 +189,8 @@ | ||
| 195 | 189 | } |
| 196 | 190 | |
| 197 | 191 | // Verify the entry. |
| 198 | 192 | $entry = FrmEntry::getOne( $payment->item_id ); |
| 199 | - | |
| 200 | 193 | if ( ! is_object( $entry ) ) { |
| 201 | 194 | $redirect_helper->handle_error( 'no_entry_found' ); |
| 202 | 195 | die(); |
| 203 | 196 | } |
| @@ -205,9 +198,8 @@ | ||
| 205 | 198 | $redirect_helper->set_entry_id( $entry->id ); |
| 206 | 199 | |
| 207 | 200 | // Verify it's an action with Stripe link enabled. |
| 208 | 201 | $action = FrmStrpLiteActionsController::get_stripe_link_action( $entry->form_id ); |
| 209 | - | |
| 210 | 202 | if ( ! is_object( $action ) ) { |
| 211 | 203 | $redirect_helper->handle_error( 'no_stripe_link_action' ); |
| 212 | 204 | die(); |
| 213 | 205 | } |
| @@ -213,9 +205,8 @@ | ||
| 213 | 205 | } |
| 214 | 206 | |
| 215 | 207 | $customer_id = $setup_intent->customer; |
| 216 | 208 | $payment_method_id = self::get_link_payment_method( $setup_intent ); |
| 217 | - | |
| 218 | 209 | if ( ! $payment_method_id ) { |
| 219 | 210 | FrmTransLitePaymentsController::change_payment_status( $payment, 'failed' ); |
| 220 | 211 | $redirect_helper->handle_error( 'did_not_complete' ); |
| 221 | 212 | die(); |
| @@ -245,9 +236,8 @@ | ||
| 245 | 236 | 'entry' => $entry, |
| 246 | 237 | ); |
| 247 | 238 | |
| 248 | 239 | $trial_end = FrmStrpLiteActionsController::get_trial_end_time( $atts ); |
| 249 | - | |
| 250 | 240 | if ( $trial_end ) { |
| 251 | 241 | $new_charge['trial_end'] = $trial_end; |
| 252 | 242 | } |
| 253 | 243 | |
| @@ -284,9 +274,8 @@ | ||
| 284 | 274 | |
| 285 | 275 | $new_payment_values['status'] = 'pending' === $charge->status ? 'processing' : 'complete'; |
| 286 | 276 | |
| 287 | 277 | $new_payment_values['expire_date'] = '0000-00-00'; |
| 288 | - | |
| 289 | 278 | foreach ( $subscription->latest_invoice->lines->data as $line ) { |
| 290 | 279 | $new_payment_values['expire_date'] = gmdate( 'Y-m-d', $line->period->end ); |
| 291 | 280 | } |
| 292 | 281 | } elseif ( $trial_end ) { |
| @@ -305,9 +294,8 @@ | ||
| 305 | 294 | FrmTransLiteActionsController::trigger_payment_status_change( compact( 'status', 'payment' ) ); |
| 306 | 295 | |
| 307 | 296 | // Update the next billing date. |
| 308 | 297 | $next_bill_date = gmdate( 'Y-m-d' ); |
| 309 | - | |
| 310 | 298 | foreach ( $subscription->latest_invoice->lines->data as $line ) { |
| 311 | 299 | $next_bill_date = gmdate( 'Y-m-d', $line->period->end ); |
| 312 | 300 | } |
| 313 | 301 | |
| @@ -329,15 +317,13 @@ | ||
| 329 | 317 | * |
| 330 | 318 | * @since 6.5, introduced in v3.0 of the Stripe add on. |
| 331 | 319 | * |
| 332 | 320 | * @param object $setup_intent |
| 333 | - * | |
| 334 | 321 | * @return false|string |
| 335 | 322 | */ |
| 336 | 323 | private static function get_link_payment_method( $setup_intent ) { |
| 337 | 324 | if ( is_object( $setup_intent->latest_attempt ) && ! empty( $setup_intent->latest_attempt->payment_method_details ) ) { |
| 338 | 325 | $payment_method_details = $setup_intent->latest_attempt->payment_method_details; |
| 339 | - | |
| 340 | 326 | foreach ( array( 'ideal', 'sofort', 'bancontact' ) as $payment_method_type ) { |
| 341 | 327 | if ( ! empty( $payment_method_details->$payment_method_type ) ) { |
| 342 | 328 | return $payment_method_details->$payment_method_type->generated_sepa_debit; |
| 343 | 329 | } |
| @@ -366,9 +352,8 @@ | ||
| 366 | 352 | * @type WP_Post $action |
| 367 | 353 | * @type string $amount |
| 368 | 354 | * @type object $customer |
| 369 | 355 | * } |
| 370 | - * | |
| 371 | 356 | * @return void |
| 372 | 357 | */ |
| 373 | 358 | public static function create_pending_stripe_link_payment( $atts ) { |
| 374 | 359 | if ( empty( $atts['form'] ) || empty( $atts['entry'] ) || empty( $atts['action'] ) || ! isset( $atts['amount'] ) || empty( $atts['customer'] ) ) { |
| @@ -381,9 +366,9 @@ | ||
| 381 | 366 | if ( ! $intent_id ) { |
| 382 | 367 | return; |
| 383 | 368 | } |
| 384 | 369 | |
| 385 | - $is_setup_intent = str_starts_with( $intent_id, 'seti_' ); | |
| 370 | + $is_setup_intent = 0 === strpos( $intent_id, 'seti_' ); | |
| 386 | 371 | $entry = $atts['entry']; |
| 387 | 372 | $action = $atts['action']; |
| 388 | 373 | $amount = $atts['amount']; |
| 389 | 374 | $customer = $atts['customer']; |
| @@ -422,14 +407,12 @@ | ||
| 422 | 407 | * |
| 423 | 408 | * @since 6.5, introduced in v3.0 of the Stripe add on. |
| 424 | 409 | * |
| 425 | 410 | * @param int|string $form_id |
| 426 | - * | |
| 427 | 411 | * @return false|string String intent id on success, False if intent is missing or cannot be verified. |
| 428 | 412 | */ |
| 429 | 413 | private static function verify_intent( $form_id ) { |
| 430 | 414 | $client_secrets = FrmAppHelper::get_post_param( 'frmintent' . $form_id, array(), 'sanitize_text_field' ); |
| 431 | - | |
| 432 | 415 | if ( ! $client_secrets ) { |
| 433 | 416 | return false; |
| 434 | 417 | } |
| 435 | 418 | |
| @@ -435,12 +418,14 @@ | ||
| 435 | 418 | |
| 436 | 419 | $client_secret = reset( $client_secrets ); |
| 437 | 420 | list( $prefix, $intent_id ) = explode( '_', $client_secret ); |
| 438 | 421 | $intent_id = $prefix . '_' . $intent_id; |
| 439 | - $is_setup_intent = str_starts_with( $intent_id, 'seti_' ); | |
| 440 | - $function_name = $is_setup_intent ? 'get_setup_intent' : 'get_intent'; | |
| 441 | - $intent = FrmStrpLiteAppHelper::call_stripe_helper_class( $function_name, $intent_id ); | |
| 442 | 422 | |
| 423 | + $is_setup_intent = 0 === strpos( $intent_id, 'seti_' ); | |
| 424 | + | |
| 425 | + $function_name = $is_setup_intent ? 'get_setup_intent' : 'get_intent'; | |
| 426 | + $intent = FrmStrpLiteAppHelper::call_stripe_helper_class( $function_name, $intent_id ); | |
| 427 | + | |
| 443 | 428 | if ( ! $intent || $intent->client_secret !== $client_secret ) { |
| 444 | 429 | return false; |
| 445 | 430 | } |
| 446 | 431 | |
| @@ -453,9 +438,8 @@ | ||
| 453 | 438 | * It is used for the redirect in FrmStrpLinkRedirectHelper. |
| 454 | 439 | * It is deleted after the redirect happens. |
| 455 | 440 | * |
| 456 | 441 | * @param int $entry_id |
| 457 | - * | |
| 458 | 442 | * @return void |
| 459 | 443 | */ |
| 460 | 444 | private static function add_temporary_referer_meta( $entry_id ) { |
| 461 | 445 | $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); |
| @@ -465,9 +449,8 @@ | ||
| 465 | 449 | 'payment_intent_client_secret', |
| 466 | 450 | 'setup_intent', |
| 467 | 451 | 'setup_intent_client_secret', |
| 468 | 452 | ); |
| 469 | - | |
| 470 | 453 | foreach ( $query_args_to_strip_from_referer as $arg ) { |
| 471 | 454 | $referer = remove_query_arg( $arg, $referer ); |
| 472 | 455 | } |
| 473 | 456 | |
| @@ -480,9 +463,8 @@ | ||
| 480 | 463 | * |
| 481 | 464 | * @since 6.5, introduced in v3.0 of the Stripe add on. |
| 482 | 465 | * |
| 483 | 466 | * @param stdClass $form |
| 484 | - * | |
| 485 | 467 | * @return void |
| 486 | 468 | */ |
| 487 | 469 | public static function add_form_classes( $form ) { |
| 488 | 470 | if ( false === FrmStrpLiteActionsController::get_stripe_link_action( $form->id ) ) { |
| @@ -497,9 +479,8 @@ | ||
| 497 | 479 | * |
| 498 | 480 | * @since 6.5, introduced in v3.0 of the Stripe add on. |
| 499 | 481 | * |
| 500 | 482 | * @param mixed $form |
| 501 | - * | |
| 502 | 483 | * @return mixed |
| 503 | 484 | */ |
| 504 | 485 | public static function force_ajax_submit_for_stripe_link( $form ) { |
| 505 | 486 | if ( ! is_object( $form ) ) { |