Online shopping will soon become more expensive, after the U.S. Supreme court ruled Thursday that states can require Internet retailers to collect sales taxes.

Years' worth of legal rulings that barred the states from imposing sales taxes on most of the purchases their residents make from out-of-state retailers.

The decision was a victory for South Dakota, which asked the court to uphold its recently passed law imposing an Internet sales tax. "

Our state is losing millions for education, healthcare, and infrastructure, and our citizens are harmed by an uneven playing field," said Marty Jackley, South Dakota's attorney general.

In 1967, the Supreme Court ruled that states could not force mail-order catalog companies to collect sales taxes unless a buyer lived in a state where the company had a physical presence — a retail store, a headquarters, or a distribution center, for example. The court reasoned then that the volume of mail order business was minor compared to in-store sales and that catalog companies would face too big a burden in having to figure out the correct sales tax, given widely different rates around the country.

South Dakota concluded in 2016 that the explosion in online sales changed the market dramatically. So it passed a law requiring all but the smallest retailers, including Internet companies, to collect taxes on the sales they make in the state, even if they had no physical presence there.

Internet companies opposed to the South Dakota law appealed. They said local tax laws vary widely across the nation and calculating sales taxes for 10,000 local taxing jurisdictions remains a daunting task. Retailer eBay warned that taxing Internet sales would place "crushing burdens on small online businesses, causing many to curtail operations and damaging the national economy."

Some big retailers that sell online already charge sales taxes. WalMart, for example, has stores in all 50 states, so it is required to do so under the physical presence rule.

President Donald Trump gave the issue renewed visibility when he tweeted in early April that Amazon pays "little or no taxes to state & local governments." That wasn't correct: The company has collected taxes since April 1, 2017, on sales to customers in the 45 states that collect them. That leaves out only Alaska, Delaware, Montana, New Hampshire and Oregon. Some local communities have sales taxes in Alaska and Montana, but they are not levied statewide.

South Dakota said the states could pick up a combined $34 billion a year if the court allowed them to tax Internet sales. But the General Accounting Office estimated that the number would be at most about $13 billion.