Skip to content

Commit 72578ec

Browse files
authored
Replace unnecessary throws with empty strings when input is invalid (#2374)
* Replace unnecessary throws with empty strings when input is invalid Before, if the key input was invalid an error was thrown. In some cases, the error was not caught and was throwing fatal exceptions. Now, an empty string is returned when a key input is invalid. This follows the same pattern that exists in the validators of: 'woocommerce/includes/abstracts/abstract-wc-settings-api.php' * Update changelog: 'Replace unnecessary throws with empty string when...'
1 parent 13ca628 commit 72578ec

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 6.5.0 - 2022-xx-xx =
4+
* Fix - Replace unnecessary throws with empty string when keys are invalid.
45

56
= 6.4.2 - 2022-06-29 =
67
* Fix - Fix terminal location creation if site title is missing.

includes/class-wc-gateway-stripe.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,31 +992,31 @@ public function process_admin_options() {
992992
public function validate_publishable_key_field( $key, $value ) {
993993
$value = $this->validate_text_field( $key, $value );
994994
if ( ! empty( $value ) && ! preg_match( '/^pk_live_/', $value ) ) {
995-
throw new Exception( __( 'The "Live Publishable Key" should start with "pk_live", enter the correct key.', 'woocommerce-gateway-stripe' ) );
995+
return '';
996996
}
997997
return $value;
998998
}
999999

10001000
public function validate_secret_key_field( $key, $value ) {
10011001
$value = $this->validate_text_field( $key, $value );
10021002
if ( ! empty( $value ) && ! preg_match( '/^[rs]k_live_/', $value ) ) {
1003-
throw new Exception( __( 'The "Live Secret Key" should start with "sk_live" or "rk_live", enter the correct key.', 'woocommerce-gateway-stripe' ) );
1003+
return '';
10041004
}
10051005
return $value;
10061006
}
10071007

10081008
public function validate_test_publishable_key_field( $key, $value ) {
10091009
$value = $this->validate_text_field( $key, $value );
10101010
if ( ! empty( $value ) && ! preg_match( '/^pk_test_/', $value ) ) {
1011-
throw new Exception( __( 'The "Test Publishable Key" should start with "pk_test", enter the correct key.', 'woocommerce-gateway-stripe' ) );
1011+
return '';
10121012
}
10131013
return $value;
10141014
}
10151015

10161016
public function validate_test_secret_key_field( $key, $value ) {
10171017
$value = $this->validate_text_field( $key, $value );
10181018
if ( ! empty( $value ) && ! preg_match( '/^[rs]k_test_/', $value ) ) {
1019-
throw new Exception( __( 'The "Test Secret Key" should start with "sk_test" or "rk_test", enter the correct key.', 'woocommerce-gateway-stripe' ) );
1019+
return '';
10201020
}
10211021
return $value;
10221022
}

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,6 @@ If you get stuck, you can ask for help in the Plugin Forum.
129129
== Changelog ==
130130

131131
= 6.5.0 - 2022-xx-xx =
132+
* Fix - Replace unnecessary throws with empty string when keys are invalid.
132133

133134
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)