I found this question about John Wick that stated that Marcus took the contract, but out of friendship he decided to help Wick. But couldn't he refuse the contract and help Wick anyway? Why take it, help Wick, and then have Viggo come after you for not killing him?
If he refused the contract, then Viggo would have just hired other people to kill John. Marcus, wanting to protect John, chose to take the contract, thus giving Viggo some reassuring and stalling John's assassination.
Helping John was going to get him killed anyways out of revenge from Viggo, so taking the contract or not won't change that fact. He only took it to buy John some time, allowing him to focus on his mission and reducing the chances of him getting killed by another professional hit-man (who would've been hired by Viggo if Marcus had rejected the contract).
Conversation between Viggo and Marcus when they first discussed the contract:
Viggo: It's a timely matter, it has to be handled quickly.
Marcus: Consider it done.
Viggo: Thank you, Marcus. I know I can trust you. Thanks for the drink.
Another point that needs mentioning is the fact that Viggo knew about Marcus helping John from Ms. Perkins who saw them together earlier. Marcus might have planned to secretly help John and let him kill Viggo's son, then tell Viggo later that he had failed. Viggo, knowing John's skills and what type of hitman he is, would understand and spare Marcus' life (for failing not betraying him).