Commit 4a0c966
committed
Refactor - Migrate the TaxJar rate-table seam onto the Address value object.
`create_or_update_tax_rate()` and `allow_street_address_for_matched_rates()`
now derive their `find_rates()` arguments and their `location_code` rows from
one `Address`, through a matched pair of projections the value object owns —
`to_find_rates_args()` and `to_rate_table_locations()`. Deriving them
separately is what let this seam look up values it had never written and
insert a fresh `wp_woocommerce_tax_rates` row for the same address on every
calculation.
Three defects the characterization tests pinned are fixed:
- A state carrying anything outside `[a-z0-9_-]` duplicated a rate row per
calculation. `WC_Tax::prepare_tax_rate()` singles `tax_rate_state` out for
`sanitize_key()` before storing it, and the lookup only stripped spaces —
an approximation that happened to be right for `'N Y'` and wrong for
`'N.Y.'` and for anything non-ASCII. `Address::state_compact()` now mirrors
the core function instead of approximating it, so the lookup asks for the
value core actually stored.
- A city carrying anything `sanitize_text_field()` removes did the same: the
write applied `wc_clean()` and the lookup did not. Sanitisation now happens
once, inside the shared projection.
- `allow_street_address_for_matched_rates()` normalised the city but not the
state, so it could not see rows `create_or_update_tax_rate()` had just
written. Rate rows existed and the `woocommerce_matched_rates` path — price
display, shipping tax, coupons — returned nothing for those addresses,
while itemized cart totals stayed correct.
Two of the plan's three target asymmetries turned out not to be live, and the
tests say so rather than the code pretending to fix them: `find_rates()`
applies the same `wc_normalize_postcode( wc_clean( … ) )` to its argument that
the write applies, so ZIP+4 always round-tripped; and core upper-cases the
city on both ends, so the plugin's asymmetric `strtoupper()` was unobservable.
Behaviour deltas beyond the fixes above:
- A comma-list postcode is now stored as its first segment rather than whole.
The row is keyed by the segment the rate was actually quoted for — the
TaxJar request body has carried only that segment since the request seam
moved onto the value object.
- `get_backend_address()` no longer upper-cases postcode, city and street.
That was this path's own historic behaviour, unmatched by `get_address()`,
and kept only because the city reaches the rate-table city column — which
is now upper-cased at both the write and the lookup. The admin recalculate
and the cart now put identically-cased values on the wire. This changes the
request JSON, so one generation of the `md5( $json )` request cache is
invalidated.
- `tax_rate_country` is trimmed before storage, so a whitespace-padded country
can no longer produce a row nothing matches.
- `create_or_update_tax_rate()` tolerates a missing or non-scalar location
field instead of emitting a notice or storing the literal "Array". It is
public and takes the location it is handed.
`WC_Connect_TaxJar_Integration::normalize_city()` now raises its deprecation
notice. It could not before: the last three in-repo callers were all on this
seam, and the notice would have fired on every checkout. The method itself
stays — it is `protected static`, so an out-of-repo subclass may call it.1 parent ad4ca52 commit 4a0c966
4 files changed
Lines changed: 371 additions & 95 deletions
File tree
- classes
- src/Tax
- tests/php
- Tax
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
691 | 691 | | |
692 | 692 | | |
693 | 693 | | |
694 | | - | |
695 | | - | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
696 | 709 | | |
697 | 710 | | |
698 | 711 | | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
713 | 717 | | |
714 | | - | |
| 718 | + | |
| 719 | + | |
715 | 720 | | |
716 | 721 | | |
717 | 722 | | |
| |||
917 | 922 | | |
918 | 923 | | |
919 | 924 | | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
920 | 932 | | |
921 | 933 | | |
922 | 934 | | |
923 | | - | |
924 | | - | |
925 | | - | |
926 | | - | |
927 | | - | |
928 | | - | |
929 | | - | |
930 | | - | |
931 | | - | |
932 | | - | |
933 | | - | |
934 | | - | |
935 | | - | |
936 | | - | |
937 | | - | |
938 | | - | |
939 | | - | |
940 | | - | |
| 935 | + | |
941 | 936 | | |
942 | 937 | | |
943 | 938 | | |
| |||
1791 | 1786 | | |
1792 | 1787 | | |
1793 | 1788 | | |
1794 | | - | |
1795 | | - | |
1796 | | - | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
1797 | 1794 | | |
1798 | 1795 | | |
1799 | 1796 | | |
| |||
1802 | 1799 | | |
1803 | 1800 | | |
1804 | 1801 | | |
| 1802 | + | |
| 1803 | + | |
1805 | 1804 | | |
1806 | 1805 | | |
1807 | 1806 | | |
| |||
1822 | 1821 | | |
1823 | 1822 | | |
1824 | 1823 | | |
1825 | | - | |
1826 | | - | |
1827 | | - | |
1828 | 1824 | | |
1829 | 1825 | | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
1830 | 1852 | | |
1831 | 1853 | | |
1832 | 1854 | | |
| |||
1850 | 1872 | | |
1851 | 1873 | | |
1852 | 1874 | | |
1853 | | - | |
1854 | | - | |
| 1875 | + | |
| 1876 | + | |
1855 | 1877 | | |
1856 | 1878 | | |
1857 | 1879 | | |
| |||
1863 | 1885 | | |
1864 | 1886 | | |
1865 | 1887 | | |
1866 | | - | |
1867 | | - | |
1868 | | - | |
1869 | | - | |
1870 | | - | |
1871 | | - | |
1872 | | - | |
1873 | | - | |
1874 | | - | |
| 1888 | + | |
1875 | 1889 | | |
1876 | 1890 | | |
1877 | 1891 | | |
| |||
1902 | 1916 | | |
1903 | 1917 | | |
1904 | 1918 | | |
1905 | | - | |
1906 | | - | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
1907 | 1923 | | |
1908 | 1924 | | |
1909 | 1925 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
347 | | - | |
348 | | - | |
349 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
350 | 364 | | |
351 | 365 | | |
352 | 366 | | |
353 | 367 | | |
354 | | - | |
| 368 | + | |
355 | 369 | | |
356 | 370 | | |
357 | 371 | | |
| |||
574 | 588 | | |
575 | 589 | | |
576 | 590 | | |
577 | | - | |
578 | | - | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
579 | 596 | | |
580 | 597 | | |
581 | 598 | | |
| |||
584 | 601 | | |
585 | 602 | | |
586 | 603 | | |
587 | | - | |
588 | | - | |
| 604 | + | |
| 605 | + | |
589 | 606 | | |
590 | 607 | | |
591 | 608 | | |
592 | 609 | | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
593 | 658 | | |
594 | 659 | | |
595 | 660 | | |
| |||
0 commit comments