fix(woocommerce): resolve checkout attempts from order status, not payment_complete - #65
Merged
Merged
Conversation
…yment_complete (#60) The card-testing and velocity filters exclude attempts that became a real order. That was decided solely by `woocommerce_payment_complete`, which Cash on Delivery, Direct Bank Transfer and Cheque never fire — they move the order to processing or on-hold and return. On a store using only those gateways no attempt row was ever closed, so `status <> 'success'` excluded nothing and every genuine order kept counting toward card testing and the 5/hour velocity limit. The #52 fix did not apply there at all. Now resolved from `woocommerce_order_status_changed`, which every gateway reaches. processing / completed / on-hold / refunded close the attempt as a sale; failed, cancelled and pending keep counting, because those are the card-testing signal. `on-hold` is deliberately in the accepted set: it is where BACS and Cheque leave a legitimate order awaiting funds, and nobody tests stolen cards by promising a bank transfer. An unrecognised status degrades to "still an attempt" rather than silently closing it. Two adjacent defects in the same path, both of which also left rows open: - `track_payment()` and `track_failure()` keyed their UPDATE on the CURRENT request's IP. Payment resolution usually arrives on an asynchronous gateway callback where that IP is the gateway's or absent, so the UPDATE matched nothing. Both now key on order_id alone, which already identifies the row. - `get_recent_attempts()`'s exclusion is now NULL-safe. In MySQL `NULL <> 'success'` is NULL rather than TRUE, so a status-less row was silently dropped from the result instead of counting. The new test caught a real bug in the first version of this fix: `ltrim($status, 'wc-')` takes a character LIST, not a prefix, so it ate the leading "c" of both "completed" and "cancelled" and answered wrongly for each. Replaced with an explicit prefix strip. 80/80 tests (5 new), no new phpcs errors, phpstan unchanged.
Merged
cport1
added a commit
that referenced
this pull request
Jul 30, 2026
Version bump plus changelog/readme for the four WooCommerce and reporting fixes merged as #65 and #66 (issues #60, #61, #62, #63). The 2.3.2 changelog carried a stated limitation — that the card-testing fix did not apply to Cash on Delivery, Bank Transfer or Cheque stores. That limitation is now resolved, so the entry says so rather than leaving the caveat standing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #60.
woocommerce_payment_completeis not universal — COD, BACS and Cheque never fire it, so on a store using only those gateways no attempt row was ever closed and the #52 card-testing fix did not apply at all. Every genuine order kept counting toward card testing and the 5/hour velocity limit.Resolution now comes from
woocommerce_order_status_changed, which every gateway reaches:on-holdis in the accepted set on purpose: it is where BACS and Cheque leave a legitimate order awaiting funds, and nobody tests stolen cards by promising a bank transfer.Two adjacent defects fixed in the same path, both of which independently left rows open:
track_payment()/track_failure()keyed their UPDATE on the current request's IP. Payment resolution arrives on an async gateway callback where that is the gateway's address or empty, so the UPDATE matched nothing. Now keyed onorder_idalone.get_recent_attempts()is NULL-safe now —NULL <> 'success'is NULL in MySQL, so a status-less row was silently dropped rather than counted.The test earned its place immediately: the first version used
ltrim($status, 'wc-'), which takes a character list rather than a prefix, so it ate the leadingcof bothcompletedandcancelled. The suite failed oncompletedand I replaced it with an explicit prefix strip.80/80 tests (5 new), no new phpcs errors, phpstan unchanged (the one error is the pre-existing
class-webdecoy-updater.phpissue).