FILE – This April 23, 2018, file photo shows the Supreme Court in Washington. The Supreme Court says states can force online shoppers to pay sales tax. The 5-4 ruling Thursday is a win for states, who said they were losing out on billions of dollars annually under two decades-old Supreme Court decisions that impacted online sales tax collection. The high court ruled Thursday to overturn those decisions. (AP Photo/Jessica Gresko, File)

The 5-4 ruling Thursday is a win for states, who said they were losing out on billions of dollars annually under two decades-old Supreme Court decisions that impacted online sales tax collection.

The high court ruled Thursday to overturn those decisions. They had resulted in some companies not collecting sales tax on every online purchase. The cases the court overturned said that if a business was shipping a product to a state where it didn’t have a physical presence such as a warehouse or office, the business didn’t have to collect the state’s sales tax. Customers were generally supposed to pay the tax to the state themselves if they don’t get charged it, but the vast majority didn’t.

Justice Anthony Kennedy wrote that the previous decisions were flawed.

“Each year the physical presence rule becomes further removed from economic reality and results in significant revenue losses to the States. These critiques underscore that the physical presence rule, both as first formulated and as applied today, is an incorrect interpretation of the Commerce Clause,” he wrote.

In addition to being a win for states, the ruling is also a win for large retailers, who argued the physical presence rule was unfair. Retailers including Apple, Macy’s, Target and Walmart, which have brick-and-mortar stores nationwide, generally collect sales tax from their customers who buy online. That’s because they typically have a physical store in whatever state the purchase is being shipped to. Amazon.com, with its network of warehouses, also collects sales tax in every state that charges it, though third party sellers who use the site to sell goods don’t have to.

But sellers that only have a physical presence in a single state or a few states could avoid charging customers sales tax when they’re shipping to addresses outside those states. Online sellers that don’t charge sales tax on goods shipped to every state range from jewelry website Blue Nile to pet products site Chewy.com to clothing retailer L.L. Bean. Sellers who use eBay and Etsy, which provide platforms for smaller sellers, also aren’t required to collect sales tax nationwide.

The case the court ruled in has to do with a law passed by South Dakota in 2016. South Dakota’s governor has said his state loses out on an estimated $50 million a year in sales tax that doesn’t get collected by out-of-state sellers. Lawmakers in the state, which has no income tax, passed a law designed to directly challenge the Supreme Court’s 1992 decision. The law required out-of-state sellers who do more than $100,000 of business in the state or more than 200 transactions annually with state residents to collect sales tax and turn it over to the state.

South Dakota wanted out-of-state retailers to begin collecting the tax and sued several of them: Overstock.com, electronics retailer Newegg and home goods company Wayfair. The state conceded in court, however, that it could only win by persuading the Supreme Court to do away with its physical presence rule.

The Trump administration had urged the justices to side with South Dakota.