/**
  * Activate a customer account using a key that was sent in a confirmation email.
  *
  * @param \Magento\Customer\Api\Data\CustomerInterface $customer
  * @param string $confirmationKey
  * @return \Magento\Customer\Api\Data\CustomerInterface
  * @throws \Magento\Framework\Exception\State\InvalidTransitionException
  * @throws \Magento\Framework\Exception\State\InputMismatchException
  */
 private function activateCustomer($customer, $confirmationKey)
 {
     // check if customer is inactive
     if (!$customer->getConfirmation()) {
         throw new InvalidTransitionException(__('Account already active'));
     }
     if ($customer->getConfirmation() !== $confirmationKey) {
         throw new InputMismatchException(__('Invalid confirmation token'));
     }
     $customer->setConfirmation(null);
     $this->customerRepository->save($customer);
     $this->sendNewAccountEmail($customer, 'confirmed', '', $this->storeManager->getStore()->getId());
     return $customer;
 }