Ivan Rakitic has agreed to extend his Barcelona contract until 2021, with a buyout clause of 125m euros (£109m).