Mastercard Inc. topped expectations with its second-quarter results Thursday amid a continued recovery in spending trends.