/**
  * @test
  * @return void
  */
 public function redirectPaymentEnabledReturnsTrueIfPaymentRedirectEnabled()
 {
     $event = new Event();
     $event->setEnablePayment(true);
     $mockRegistration = $this->getMock('DERHANSEN\\SfEventMgt\\Domain\\Model\\Registration', ['getEvent', 'getPaymentMethod'], [], '', false);
     $mockRegistration->expects($this->once())->method('getEvent')->will($this->returnValue($event));
     $mockRegistration->expects($this->once())->method('getPaymentMethod');
     // Payment mock object with redirect enabled
     $mockInvoice = $this->getMock('DERHANSEN\\SfEventMgt\\Payment\\Invoice', ['isRedirectEnabled'], [], '', false);
     $mockInvoice->expects($this->once())->method('isRedirectEnabled')->will($this->returnValue(true));
     $mockPaymentService = $this->getMock('DERHANSEN\\SfEventMgt\\Domain\\Service\\PaymentService', ['getPaymentInstance'], [], '', false);
     $mockPaymentService->expects($this->once())->method('getPaymentInstance')->will($this->returnValue($mockInvoice));
     $this->inject($this->subject, 'paymentService', $mockPaymentService);
     $this->assertTrue($this->subject->redirectPaymentEnabled($mockRegistration));
 }
 /**
  * Confirms the registration if possible and sends e-mails to admin and user
  *
  * @param int $reguid UID of registration
  * @param string $hmac HMAC for parameters
  *
  * @return void
  */
 public function confirmRegistrationAction($reguid, $hmac)
 {
     /* @var $registration Registration */
     list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkConfirmRegistration($reguid, $hmac);
     if ($failed === false) {
         $registration->setConfirmed(true);
         $this->registrationRepository->update($registration);
         $messageType = MessageType::REGISTRATION_CONFIRMED;
         if ($registration->getWaitlist()) {
             $messageType = MessageType::REGISTRATION_WAITLIST_CONFIRMED;
         }
         // Send notifications to user and admin
         $this->notificationService->sendUserMessage($registration->getEvent(), $registration, $this->settings, $messageType);
         $this->notificationService->sendAdminMessage($registration->getEvent(), $registration, $this->settings, $messageType);
         // Confirm registrations depending on main registration if necessary
         if ($registration->getAmountOfRegistrations() > 1) {
             $this->registrationService->confirmDependingRegistrations($registration);
         }
     }
     // Redirect to payment provider if payment/redirect is enabled
     $paymentPid = (int) $this->settings['paymentPid'];
     if (!$failed && $paymentPid > 0 && $this->registrationService->redirectPaymentEnabled($registration)) {
         $this->uriBuilder->reset()->setTargetPageUid($paymentPid)->setUseCacheHash(false);
         $uri = $this->uriBuilder->uriFor('redirect', ['registration' => $registration, 'hmac' => $this->hashService->generateHmac('redirectAction-' . $registration->getUid())], 'Payment', 'sfeventmgt', 'Pipayment');
         $this->redirectToUri($uri);
     }
     $this->view->assign('messageKey', $messageKey);
     $this->view->assign('titleKey', $titleKey);
 }