-
Notifications
You must be signed in to change notification settings - Fork 72
Add remediation tool to fix incorrect analytics data from canceled authorizations #11140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
baba383 to
e41ef6a
Compare
Test the buildOption 1. Jetpack Beta
Option 2. Jurassic Ninja - available for logged-in A12s🚀 Launch a JN site with this branch 🚀 ℹ️ Install this Tampermonkey script to get more options. Build info:
Note: the build is updated when a new commit is pushed to this PR. |
|
Size Change: 0 B Total Size: 877 kB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a data remediation migration to fix incorrect transaction fees and refund records that were created for canceled payment authorizations. The bug affected orders between April 2023 and November 2025 where canceled authorizations incorrectly had transaction fees and refund objects created despite no actual payment occurring.
Key Changes
- New migration class that processes affected orders in adaptive batches using Action Scheduler
- Integration with plugin upgrade hooks to automatically schedule remediation when updating from affected versions
- Comprehensive test coverage for the remediation logic and batch processing
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php |
Core migration class implementing batch processing, order remediation, and adaptive batch sizing |
includes/class-wc-payments.php |
Integration of remediation into plugin initialization and update hooks |
tests/unit/migrations/test-class-wc-payments-remediate-canceled-auth-fees.php |
Comprehensive unit tests covering all migration functionality |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
…mprove unit tests
…ynamic button text and status description
… to 'cancelled' and add corresponding unit tests
… remediation process
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
includes/admin/class-wc-payments-admin-notice-canceled-auth-remediation.php
Outdated
Show resolved
Hide resolved
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
…emediation and add new inbox note
…s and correct post type placeholder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @elazzabi I requested your review because you worked on the fix and have some context already. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
tests/unit/migrations/test-class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
tests/unit/migrations/test-class-wc-payments-remediate-canceled-auth-fees.php
Outdated
Show resolved
Hide resolved
…n hook and remove unused method
frosso
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work with the addition of the dry run option!
I ran all the steps for the "Fix canceled authorization analytics", and they worked flawlessly!
I later reset the DB with your instructions, and launched the "Dry run" option (I know it's uncommon to first launch the full action and then the dry run).
I stumbled into a state where I couldn't run the full action, anymore. But the wcpay-fee-remediation log was created:
Is this due to my testing approach? 👀
| /** | ||
| * Version where bug was introduced (5.8.0 = April 2023, commit 2d13751). | ||
| */ | ||
| const BUG_INTRODUCED_VERSION = '5.8.0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed as part of a const? Or can it just be a comment on the class?
| } | ||
|
|
||
| include_once WCPAY_ABSPATH . 'includes/migrations/class-wc-payments-remediate-canceled-auth-fees.php'; | ||
| return as_has_scheduled_action( WC_Payments_Remediate_Canceled_Auth_Fees::ACTION_HOOK ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that here, we only checked if WC_Payments_Remediate_Canceled_Auth_Fees::ACTION_HOOK is scheduled. But on the schedule_canceled_auth_dry_run method, we check both WC_Payments_Remediate_Canceled_Auth_Fees::ACTION_HOOK and WC_Payments_Remediate_Canceled_Auth_Fees::DRY_RUN_ACTION_HOOK.
Could this lead to some inconsistent UI state? I'm unsure if we need to check for the "dry run" action here, as well 🤷
Summary
Fixes #WOOPMNT-5550
Adds a remediation tool to fix incorrect analytics data caused by a bug that existed between April 2023 and November 2025. When payment authorizations were canceled (not captured), the system incorrectly:
_wcpay_transaction_feeand_wcpay_netmetadata)This caused negative values in WooCommerce Analytics for affected stores using manual capture.
Changes
includes/migrations/class-wc-payments-remediate-canceled-auth-fees.phpincludes/notes/class-wc-payments-notes-canceled-auth-remediation.phpincludes/class-wc-payments.phpincludes/class-wc-payments-status.phptests/unit/migrations/test-class-wc-payments-remediate-canceled-auth-fees.phptests/unit/notes/test-class-wc-payments-notes-canceled-auth-remediation.phpHow It Works
_intention_status = canceledcreated after April 2023 that have incorrect fee metadata, WCPay refunds, or "refunded" statuswp_wc_order_statstable and triggers WooCommerce Analytics syncSafety Measures
_intention_status = canceled_wcpay_refund_idmetadata (preserves manual refunds)wc_get_logger()Testing Instructions
Setup - Create test data
wp eval-file create-test-data-canceled-auth.phpVerify the problem exists
Run the remediation
Verify the fix
Test scenarios
Cleanup
npm run changelogto add a changelog filePost merge