The story is that Cohen was repaid, over time, by Trump. Trump, like any other candidate, is permitted UNLIMITED campaign contributions to his own campaign.
The payment could have been made legally, but there are numerous steps including disclosures that didn't happen, so it is very black and white that it was a campaign law violation. That's why Cohen is a crappy lawyer and going to jail.