Skip to content

Warn when the Stripe connection belongs to a different site URL - #3737

Open
Crabcyborg wants to merge 9 commits into
masterfrom
feat/stripe-site-url-mismatch
Open

Crabcyborg wants to merge 9 commits into
masterfrom
feat/stripe-site-url-mismatch

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Saves the site URL when Stripe is connected and compares it to the current site URL on the Stripe settings page. When they don't match, an error under that mode's connection status suggests disconnecting and reconnecting. This usually happens when a database is copied from one site to another, so the copy is still using the original site's Stripe connection.

This lives in Lite, so it works with or without the Stripe add-on. The add-on uses Lite's settings view for the connection status.

Details

  • The URL is stored per mode as frm_strp_connect_site_url_{mode}, using the same normalized URL the connect server already gets (no protocol, port, or WPML language suffix). Switching between http and https does not trigger the warning.
  • A difference of only a trailing slash is ignored, since WPML can add one. A server side fix for the slash is planned separately, so the plugin keeps this logic minimal.
  • Connections made before this change have no saved URL. Database migration 108 saves the current URL for them when the site updates, so the settings page only reads the option. This is best-effort for those older connections: a database copied before the update records the copy's own URL and will not warn.
  • The saved URL is removed on disconnect and on uninstall.
  • The URL normalization in build_headers_for_post() moved into its own method. The Authorization header it sends is unchanged.

Testing

  1. Connect Stripe in test mode and open Global Settings > Payments > Stripe. No warning shows.
  2. Change frm_strp_connect_site_url_test to another domain, for example wp option update frm_strp_connect_site_url_test old-site.com. Reload the settings. An error shows under TEST naming both URLs, and LIVE is unaffected.
  3. Set the option to the current URL with a trailing slash added. No warning shows.
  4. Delete the option and reload. No warning shows and the option stays empty. Then set frm_db_version back to 107 (keep the plugin version prefix) and load any admin page. The migration saves the current URL to the option.
  5. Disconnect. The option is removed.

PHPUnit: tests/phpunit/stripe/test_FrmStrpLiteConnectHelper.php and test_FrmMigrate::test_migrate_to_108.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • The Stripe settings page alerts you when a connected account’s site URL differs from the current site URL, shows both addresses, and advises you to disconnect and reconnect.
  • Bug Fixes
    • Existing connected accounts without a saved site URL are updated with the current URL. Trailing slashes are ignored when comparing URLs, preventing false mismatch alerts. Saved URLs are cleared when you disconnect or uninstall.

Save the site URL when Stripe is connected and compare it to the
current site URL on the Stripe settings page. When they differ, show
an error suggesting the user disconnect and reconnect, since this
usually means the database was copied from another site. A trailing
slash difference is ignored. Connections made before this change save
the current URL the first time the settings load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 28 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 96aaecb and 101a0a4.

Files selected for processing: 7

  • classes/helpers/FrmAppHelper.php
  • classes/models/FrmMigrate.php
  • stripe/controllers/FrmStrpLiteAppController.php
  • stripe/helpers/FrmStrpLiteConnectHelper.php
  • stripe/views/settings/connect.php
  • tests/phpunit/database/test_FrmMigrate.php
  • tests/phpunit/stripe/test_FrmStrpLiteConnectHelper.php

No actionable comments were generated in the recent review.

Walkthrough

The Stripe connection helper saves a site URL for each connected mode and checks it against the current URL. Migration 108 backfills missing URLs for connected accounts. The settings page displays both URLs and reconnect instructions when they differ. Disconnect and uninstall cleanup remove the saved URL.

Changes: Site URL tracking and mismatch alert

Layer / File(s) Summary
Save and compare connection URLs
stripe/helpers/FrmStrpLiteConnectHelper.php, stripe/controllers/FrmStrpLiteAppController.php, tests/phpunit/stripe/test_FrmStrpLiteConnectHelper.php
The helper saves a normalized site URL during OAuth setup, checks saved and current URLs for mismatches, and removes saved URLs during disconnect and uninstall cleanup. Tests cover URL comparisons, persistence, and cleanup.
Backfill existing connection URLs
classes/helpers/FrmAppHelper.php, classes/models/FrmMigrate.php, tests/phpunit/database/test_FrmMigrate.php
Database version 108 runs a migration that saves a missing site URL for connected modes. The migration test checks connected and unconnected modes.
Show URL mismatch in settings
stripe/helpers/FrmStrpLiteConnectHelper.php, stripe/views/settings/connect.php
The settings renderer supplies the mismatch and current URLs. The view displays them with reconnect instructions when they differ.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Merge Risk: Minimal · previous review 96aae

This adds a warning on the Stripe settings page when the saved connection URL differs from the current site URL. It is display-only and easy to roll back. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Warn when the Stripe connection belongs to a different site URL" matches the main change. The PR adds a per-mode saved site URL, compares it with the current URL on the Stripe settings page…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Warn when the Stripe connection belongs to a different site URL" matches the main change. The PR adds a per-mode saved site URL, compares it with the current URL on the Stripe settings page, and shows a warning on mismatch. The title is specific and describes the primary behavior without file lists or vague terms.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e28b50c and 96aaecb.

Files selected for processing: 5

  • classes/models/FrmMigrate.php
  • stripe/controllers/FrmStrpLiteAppController.php
  • stripe/helpers/FrmStrpLiteConnectHelper.php
  • stripe/views/settings/connect.php
  • tests/phpunit/database/test_FrmMigrate.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@deepsource-io

deepsource-io Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in e690e5a...101a0a4 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Dec 1, 2026 7:04p.m. Review ↗
JavaScript Dec 1, 2026 7:04p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 25, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. The warning works as described, and I found nothing blocking. Two non-blocking notes are inline.

Live check (PR branch loaded in the preview env, head 4cd13f020092e5e2352672a09de8922893025231): I seeded test mode with an account ID and a saved URL of old-site.example.com, and live mode as a pre-upgrade connection with no saved URL.

  • Test mode shows the red warning naming both URLs. This holds in both the "Finish Stripe Setup" and "Connected" states:

mismatch, finish setup state
mismatch, connected state
(The round icon at the right edge of the second image is the Formidable floating widget, not part of this PR.)

  • The live-mode connection with no saved URL shows no warning. Its option was filled with 127.0.0.1 on that first view, as the code intends.
  • Both URLs are esc_html-escaped, and the markup renders as intended.

Read-only, not exercised live: the Disconnect AJAX path (it calls the real connect server). reset_stripe_connect_integration() and the uninstall key list both delete site_url, and I confirmed that from the source. account_id is written in one place only (check_server_for_oauth_account_id), and that is where the URL gets saved. connect.php is included only from render_settings(), so the new view variables are always set. php -l is clean on all three changed files.

CI: PHPUnit, PHPCS, PHPStan and the other test jobs are marked skipped on this head, so none of them ran. I did not run them locally either. Psalm, typos, CodeRabbit and DeepSource pass.

Tests run: none. This PR adds no tests, and the live check above was manual.

$connected_url = get_option( self::get_site_url_option_name( $mode ) );

if ( ! $connected_url || ! is_string( $connected_url ) ) {
// Connections made before the site URL was tracked have nothing saved yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: sites that were already connected before this release can't be caught reliably. A connection with no saved URL gets the current URL written the first time an admin opens the Stripe settings tab. If the database was copied before that first view, and the copy's admin opens the settings first, the copy records its own URL as the original and never warns.

Moving the backfill into the plugin's upgrade routine would close most of that gap, because it would run on every site at update time instead of on a rarely visited tab. It would also stop get_mismatched_site_url(), which reads like a getter, from writing to the database during a page render.

If you keep the first-view backfill, say in the docblock that it is best-effort for pre-existing connections.

*
* @return false|string The site URL the account was connected on, or false when it matches. A trailing slash (WPML can add one) is ignored.
*/
public static function get_mismatched_site_url( $mode ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: this adds no PHPUnit coverage. The logic is plain option handling, so it is cheap to test. tests/phpunit/stripe/ has no test for FrmStrpLiteConnectHelper yet. Worth covering in get_mismatched_site_url():

  • no account ID returns false;
  • no saved URL returns false and saves the current URL (the backfill);
  • a matching URL returns false, including when one side has a trailing slash;
  • a different URL returns the saved one;
  • reset_stripe_connect_integration() deletes the site_url option;
  • FrmStrpLiteAppController::uninstall() deletes frm_strp_connect_site_url_test and _live.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 25, 2026
Move the backfill for connections made before the site URL was
tracked out of get_mismatched_site_url() and into a new db migration
(108), so every site records its own URL when it updates instead of
the first time an admin opens the Stripe settings. The getter no
longer writes to the database during a page render.

Add PHPUnit coverage for get_mismatched_site_url(), the backfill,
the trailing slash handling, and the site_url cleanup on disconnect
and uninstall.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@franky-the-going-merry franky-the-going-merry Bot added franky-working Franky is actively reviewing this and removed franky-working Franky is actively reviewing this labels Nov 25, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. Re-review at 6a37eea (my Approve was at 4cd13f0). The new commit closes both earlier notes: a migrate_to_108 upgrade routine backfills the site URL for existing connections, and the PR now adds tests. One non-blocking note is inline.

Live check (PR loaded in the preview env, head 6a37eea0f): I seeded test mode with an account ID and no saved URL, live mode with an account ID and saved URL old-site.example.com, and set frm_db_version to 7.1.1-107. Then I ran the real FrmAppController::install() upgrade.

  • frm_db_version moved to 7.1.1-108. Test mode got site_url = '127.0.0.1' (backfilled). Live mode kept old-site.example.com (not overwritten).
  • Global Settings > Stripe: test mode shows no warning, live mode shows the mismatch warning naming both URLs:

live mode mismatch warning
(The round icon at the right edge is the Formidable floating widget, not part of this PR.)

Tests run: test_FrmStrpLiteConnectHelper.php at 6a37eea0f in the wordpress-develop harness (PHP 8.4) → OK (7 tests, 16 assertions); test_FrmMigrate.php --filter test_migrate_to_108 → OK (1 test, 2 assertions). CI's PHPUnit job is skipped on this head, so these did not run anywhere else. Mutations that each make a test fail: dropping the site_url delete in reset_stripe_connect_integration(), dropping the untrailingslashit() comparison, dropping 108 from the $migrations list, dropping site_url from the uninstall key list.

Not exercised: the Disconnect AJAX path (it calls the real connect server; the delete is covered by the unit test), a real Stripe OAuth connect, multisite upgrade. PHPCS was not run. php -l is clean on the changed files.


if ( is_object( $data ) && ! empty( $data->account_id ) ) {
update_option( self::get_account_id_option_name( $mode ), $data->account_id, false );
self::save_connected_site_url( $mode );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: this line is the only place a new connection gets its saved URL, and no test covers it. Deleting it leaves all 7 new tests green, so a regression here would silently turn off the warning for every new connection. check_server_for_oauth_account_id() calls post_to_connect_server(), so a test needs that stubbed, for example with a pre_http_request filter returning an oauth_account_status response with an account_id, then asserting frm_strp_connect_site_url_test equals get_site_url_for_connect_server().

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 25, 2026
Stub the connect server's oauth_account_status response and check that
check_server_for_oauth_account_id() saves the current site URL along
with the account ID.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 25, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. Re-review at f47ec2b (my last Approve was at 6a37eea). The only new commit adds test_check_server_for_oauth_account_id_saves_site_url, which closes my earlier note that the save_connected_site_url call in check_server_for_oauth_account_id had no test. Source is unchanged since 6a37eea, so the live check from that round still holds.

The new test mocks the connect server's oauth_account_status reply through pre_http_request, then asserts the account ID and the current site URL are both saved for the mode.

Tests run: test_FrmStrpLiteConnectHelper.php at f47ec2bfa in the wordpress-develop harness (PHP 8.4) → OK (8 tests, 19 assertions). Mutation: commenting out the save_connected_site_url( $mode ) call in check_server_for_oauth_account_id makes the new test fail (the only failure). test_migrate_to_108 → OK (1 test, 2 assertions). CI's PHPUnit job is skipped on this head, so these ran nowhere else.

Not exercised: the Disconnect AJAX path and a real Stripe OAuth connect (both call the real connect server). PHPCS was not run.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant