"When you do" is a new templating introduced in Amonkhet which is mostly used when the thing that follows targets, or the thing you can do doesn't use the stack (like exert).
For an example of why the targeting matters, Willbreaker and Throwing Knife were both in Origins. The creature with the knife attacks, and its ability targets a creature. Willbreaker then gains control of that creature. Then Throwing Knife asks if you want to sacrifice it, which of course you don't and you keep the knife and the stolen creature.
It also creates scenarios where you can know if a payment will be made before you have to react. "you may pay 2. If you do..." requires players to respond before they know if the 2 will be paid or not. "you may pay 2. When you do..." means players will get to respond after the 2 is paid but before the rest of the effect happens.
edit: And in your examples, the "When" is a card that targets and the "If" doesn't