Skip to content

Commit e08228a

Browse files
committed
UR-4825 Fix - Live Stripe key validated even when Test Mode is enabled
1 parent 902e10e commit e08228a

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

assets/js/admin/settings.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,21 +1742,28 @@
17421742
});
17431743

17441744
if ( setting_id === "stripe" ) {
1745-
var testPubKey = section_data["user_registration_stripe_test_publishable_key"] || "";
1746-
var livePubKey = section_data["user_registration_stripe_live_publishable_key"] || "";
1747-
1748-
if ( testPubKey && testPubKey.indexOf( "pk_test_" ) !== 0 ) {
1749-
$this.find( ".ur-spinner" ).remove();
1750-
show_failure_message(
1751-
user_registration_settings_params.i18n.invalid_stripe_test_publishable_key
1752-
);
1753-
return;
1754-
}
1755-
1756-
if ( livePubKey && livePubKey.indexOf( "pk_live_" ) !== 0 ) {
1745+
// Only the keys of the mode currently in use are validated; the other mode's fields are hidden and unused.
1746+
var testModeValue = section_data["user_registration_stripe_test_mode"];
1747+
var isTestMode =
1748+
"undefined" === typeof testModeValue
1749+
? true
1750+
: !(
1751+
false === testModeValue ||
1752+
"false" === testModeValue ||
1753+
"0" === testModeValue ||
1754+
"" === testModeValue
1755+
);
1756+
var pubKey =
1757+
( isTestMode
1758+
? section_data["user_registration_stripe_test_publishable_key"]
1759+
: section_data["user_registration_stripe_live_publishable_key"] ) || "";
1760+
1761+
if ( pubKey && pubKey.indexOf( isTestMode ? "pk_test_" : "pk_live_" ) !== 0 ) {
17571762
$this.find( ".ur-spinner" ).remove();
17581763
show_failure_message(
1759-
user_registration_settings_params.i18n.invalid_stripe_live_publishable_key
1764+
isTestMode
1765+
? user_registration_settings_params.i18n.invalid_stripe_test_publishable_key
1766+
: user_registration_settings_params.i18n.invalid_stripe_live_publishable_key
17601767
);
17611768
return;
17621769
}

0 commit comments

Comments
 (0)