You can buy your tickets on the official website of the Piazza del Duomo in Pisa.  At the time of writing, you can only purchase tickets up to 20 days in advance.  If there are no time slots available for your chosen date or time, you can also try third-party resellers like GetYourGuide or Viator.