-
Notifications
You must be signed in to change notification settings - Fork 19
Add extra logging for CA taxes added to non-CA merchants #2893
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
Add extra logging for CA taxes added to non-CA merchants #2893
Conversation
samnajian
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.
LGTM,
Left some suggestions.
| $response = $response ? $response : get_transient( $cache_key ); | ||
| if ( $response && 'CA' !== $from_state ) { | ||
| // If $from_state is not California, we need to check for incorrect California tax nexus. | ||
| $this->check_for_incorrect_california_tax_nexus( $response['body'], true ); |
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'd suggest wrapping the calls to this function in try/catch block, so that adding extra logging can't break the main flow of the application.
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.
Thanks for this suggestion. I've added it in 3fe7a48.
| $has_nexus = $response_body->tax->has_nexus; | ||
|
|
||
| if ( 'CA' === $to_state && 'US' === $to_country && true === $has_nexus ) { | ||
| $this->_log( 'Incorrect California tax nexus detected ' . $log_suffix ); |
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.
How about adding the following to the log?
sprintf(
'Incorrect California tax nexus detected %s (from_state: %s, to_state: %s, to_country: %s, has_nexus: %s)',
$log_suffix,
$from_state ?: 'unknown',
$to_state,
$to_country,
$has_nexus ? 'true' : 'false'
)
This adds more information to the log and can help with the debugging.
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.
Good idea! I've added it in 3fe7a48. I re-tested by applying the patch and setting my store address to California to trigger the logging and it worked as expected. Logs and patch below.
[05-Nov-2025 14:25:56 UTC] Incorrect California tax nexus detected in TaxJar API response. (from_state: CA, to_state: CA, to_country: US, has_nexus: true). (WCS Tax)
[05-Nov-2025 14:26:58 UTC] Incorrect California tax nexus detected in cached response. (from_state: CA, to_state: CA, to_country: US, has_nexus: true). (WCS Tax)
diff --git a/classes/class-wc-connect-taxjar-integration.php b/classes/class-wc-connect-taxjar-integration.php
index 7a4879e4..8f0d7929 100644
--- a/classes/class-wc-connect-taxjar-integration.php
+++ b/classes/class-wc-connect-taxjar-integration.php
@@ -1442,7 +1442,7 @@ class WC_Connect_TaxJar_Integration {
$response = get_transient( $zip_state_cache_key );
}
$response = $response ? $response : get_transient( $cache_key );
- if ( $response && 'CA' !== $from_state ) {
+ if ( $response ) {
// If $from_state is not California, we need to check for incorrect California tax nexus.
try {
$this->check_for_incorrect_california_tax_nexus( $response['body'], true, $from_state );
@@ -1460,13 +1460,10 @@ class WC_Connect_TaxJar_Integration {
$response = $this->smartcalcs_request( $json );
$response_code = wp_remote_retrieve_response_code( $response );
$body = json_decode( wp_remote_retrieve_body( $response ) );
- if ( 'CA' !== $from_state ) {
- // If $from_state is not California, we need to check for incorrect California tax nexus.
- try {
- $this->check_for_incorrect_california_tax_nexus( $body, false, $from_state );
- } catch ( Exception $e ) {
- $this->_log( 'Error checking for incorrect California tax nexus: ' . $e->getMessage() );
- }
+ try {
+ $this->check_for_incorrect_california_tax_nexus( $body, false, $from_state );
+ } catch ( Exception $e ) {
+ $this->_log( 'Error checking for incorrect California tax nexus: ' . $e->getMessage() );
}
$is_zip_to_state_mismatch = (
isset( $body->detail )|
@allie500 the fix added here and in this commit will fix the failing tests in this PR as well. |
Description
This change is being added to give us better visibility into the issue reported in WOOSHIP-1686. Many merchants located in US states other than California have reported intermittent issues where California customers are being charged sales tax for orders from their stores.
This PR adds a method that logs when this happens and indicates if the response came directly from TaxJar or if it was a cached response. The method is only called if the store's address state is not California.
Related issue(s)
Fixes WOOSHIP-1713
Testing
To test the logging method, we need to apply a patch file to remove the check for the store address in California so that the logging check method runs and the correct (taxable) responses are returned from TaxJar and the cache.
60 29th Street #343San Francisco, CA 94110Incorrect California tax nexus detected in TaxJar API response. (WCS Tax)Incorrect California tax nexus detected in cached response. (WCS Tax)Post testing clean up:
Example Data
Non-taxable out of state response body from TaxJar API:
Cached response body for taxable order:
TaxJar API response body for taxable order:
Steps to reproduce & screenshots/GIFs
The bug that this PR seeks to log is difficult to reproduce as it is intermittent.
Checklist
changelog.txtentry addedreadme.txtentry added