| @@ -52,9 +52,9 @@ | ||
| 52 | 52 | * |
| 53 | 53 | * @return void |
| 54 | 54 | */ |
| 55 | 55 | public function handle_error( $error_code, $charge_id = '' ) { |
| 56 | - if ( ! empty( $this->entry_id ) ) { | |
| 56 | + if ( $this->entry_id ) { | |
| 57 | 57 | $referer = FrmStrpLiteAuth::get_referer_url( $this->entry_id ); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | if ( empty( $referer ) ) { |
| @@ -87,10 +87,13 @@ | ||
| 87 | 87 | |
| 88 | 88 | // Let a stripe link success message get handled the same as a 3D secure redirect. |
| 89 | 89 | // When it shows a message, it adds a &frmstrp= param to the URL. |
| 90 | 90 | $redirect = FrmStrpLiteAuth::return_url( compact( 'form', 'entry' ) ); |
| 91 | - $is_message_redirect = false !== strpos( $redirect, 'frmstrp=' ); | |
| 91 | + $is_message_redirect = str_contains( $redirect, 'frmstrp=' ); | |
| 92 | 92 | |
| 93 | + // Call this before all redirects so the referer is always deleted. | |
| 94 | + $referer_url = $this->get_referer_url( $entry->id ); | |
| 95 | + | |
| 93 | 96 | if ( $this->url_is_external( $redirect ) || ! $is_message_redirect ) { |
| 94 | 97 | wp_redirect( $redirect ); |
| 95 | 98 | die(); |
| 96 | 99 | } |
| @@ -95,10 +98,8 @@ | ||
| 95 | 98 | die(); |
| 96 | 99 | } |
| 97 | 100 | |
| 98 | 101 | // $redirect may not include the whole link to the form, breaking the redirect as iDEAL/Sofort have an additional redirect. |
| 99 | - $referer_url = $this->get_referer_url( $entry->id ); | |
| 100 | - | |
| 101 | 102 | if ( is_string( $referer_url ) ) { |
| 102 | 103 | $parts = explode( '?', $redirect, 2 ); |
| 103 | 104 | |
| 104 | 105 | if ( 2 === count( $parts ) ) { |
| @@ -122,9 +123,9 @@ | ||
| 122 | 123 | * |
| 123 | 124 | * @return bool |
| 124 | 125 | */ |
| 125 | 126 | private function url_is_external( $url ) { |
| 126 | - if ( false === strpos( $url, 'http' ) ) { | |
| 127 | + if ( ! str_contains( $url, 'http' ) ) { | |
| 127 | 128 | return false; |
| 128 | 129 | } |
| 129 | 130 | |
| 130 | 131 | $home_url = home_url(); |
| @@ -132,9 +133,10 @@ | ||
| 132 | 133 | |
| 133 | 134 | if ( is_array( $parsed ) ) { |
| 134 | 135 | $home_url = $parsed['scheme'] . '://' . $parsed['host']; |
| 135 | 136 | } |
| 136 | - return 0 !== strpos( $url, $home_url ); | |
| 137 | + | |
| 138 | + return ! str_starts_with( $url, $home_url ); | |
| 137 | 139 | } |
| 138 | 140 | |
| 139 | 141 | /** |
| 140 | 142 | * Try to get the referer URL from the entry meta. |
| @@ -187,9 +189,9 @@ | ||
| 187 | 189 | * |
| 188 | 190 | * @param string $url |
| 189 | 191 | */ |
| 190 | 192 | private function add_intent_info_and_redirect( $url ) { |
| 191 | - if ( 0 === strpos( $this->stripe_id, 'pi_' ) ) { | |
| 193 | + if ( str_starts_with( $this->stripe_id, 'pi_' ) ) { | |
| 192 | 194 | $url = add_query_arg( 'payment_intent', $this->stripe_id, $url ); |
| 193 | 195 | $url = add_query_arg( 'payment_intent_client_secret', $this->client_secret, $url ); |
| 194 | 196 | } else { |
| 195 | 197 | $url = add_query_arg( 'setup_intent', $this->stripe_id, $url ); |