UR-4825 Fix - Live Stripe key validated even when Test Mode is enabled - #1393
UR-4825 Fix - Live Stripe key validated even when Test Mode is enabled#1393saurab018 wants to merge 2 commits into
Conversation
|
@tg-autopilot review |
There was a problem hiding this comment.
Pull request overview
This PR fixes a client-side validation bug in the Stripe payment settings save handler so that only the publishable key for the currently active mode (Test vs Live) is validated, preventing saves from being blocked by hidden/inactive fields.
Changes:
- Update Stripe publishable-key prefix validation in
assets/js/admin/settings.jsto validate only the active mode’s key based on the Test Mode toggle. - Regenerate the corresponding minified build in
assets/js/admin/settings.min.js.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| assets/js/admin/settings.js | Adjusts Stripe save-time publishable-key validation to be mode-aware. |
| assets/js/admin/settings.min.js | Minified build reflecting the updated Stripe validation logic. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| var testModeValue = section_data["user_registration_stripe_test_mode"]; | ||
| var isTestMode = | ||
| "undefined" === typeof testModeValue | ||
| ? true | ||
| : !( | ||
| false === testModeValue || | ||
| "false" === testModeValue || | ||
| "0" === testModeValue || | ||
| "" === testModeValue | ||
| ); | ||
| var pubKey = | ||
| ( isTestMode | ||
| ? section_data["user_registration_stripe_test_publishable_key"] | ||
| : section_data["user_registration_stripe_live_publishable_key"] ) || ""; |
There was a problem hiding this comment.
Fair point — that value is always a real boolean from $item.is(":checked"), so the string-form checks were dead code. Simplified to Boolean( section_data["user_registration_stripe_test_mode"] ) , re-minified settings.min.js with the project's own grunt terser:admin task (confirmed all 20 other admin JS files re-minify byte-identical, so this is the correct build output) — pushed in 0f688c9.
All Submissions:
Changes proposed in this Pull Request:
https://themegrill.atlassian.net/browse/UR-4825
Stripe settings could not be saved when Test Mode was enabled if the (hidden) Live Publishable Key field held anything that did not start with
pk_live_. Saving failed with:Root cause: the client-side pre-check in the payment section Save handler (
assets/js/admin/settings.js) validated both the test and the live publishable key on every save, without looking at the Test Mode toggle. Because the Live fields are hidden while Test Mode is on, the request was aborted before the AJAX call and the user had no visible field to correct.The server-side validation in
modules/stripe/class-ur-stripe-module.phpwas already mode-aware — it derives the mode fromuser_registration_stripe_test_modeand only checks that mode's key prefix — so only the JS guard needed fixing.Fix: the JS guard now mirrors the PHP logic: it reads the Test Mode toggle from the collected section data, picks the publishable key of the active mode only, and checks just that prefix (
pk_test_for test,pk_live_for live). Falls back to test mode when the toggle is absent, matching the PHP default. Keys for the inactive mode are no longer validated.Changed files:
assets/js/admin/settings.jsand its minified buildassets/js/admin/settings.min.js.How to test the changes in this Pull Request:
pk_test_...) and test Secret Key into the Live Key fields.pk_live_...(or any non-pk_test_) value in Test Publishable Key and save. Expect "Invalid Stripe test publishable key. It must start with pk_test_."pk_live_value in Live Publishable Key and save. Expect "Invalid Stripe live publishable key. It must start with pk_live_."Types of changes:
Other information:
Changelog entry