Visa, Mastercard reach legal pact with merchants