/** * @return array */ public function registerAction() { $form = new Register($this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager')); $form->get('primary')->setValue($this->getAuthenticationService()->getIdentity()->getId()); $status = null; // Step 3: Returned from PayPal if ($this->params()->fromRoute('payum_token')) { $status = $this->getDogService()->completePayment($this); $details = $status->getFirstModel(); if ($details instanceof DetailsAggregateInterface) { $details = $details->getDetails(); if ($details instanceof \Traversable) { $details = iterator_to_array($details); } } $form->setData($details['dogData']); if ($status->isCaptured()) { $this->getDogService()->registerNewDog($details['dogData']); return $this->redirect()->toRoute('home'); } // Step 2: Confirm dog information and redirect to PayPal } elseif ($dogData = $this->session->offsetGet('dogData')) { $this->session->offsetUnset('dogData'); $request = $this->getRequest(); if ($request->isPost() && $request->getPost('confirm') !== null) { $token = $this->getDogService()->preparePayment($dogData, $this->getAuthenticationService()->getIdentity()); return $this->redirect()->toUrl($token->getTargetUrl()); } $form->setData($dogData); // Step 1: Collect dog information } else { $request = $this->getRequest(); if ($request->isPost()) { if ($request->getPost('cancel') !== null) { return $this->redirect()->toRoute('home'); } $form->setData($request->getPost()); if ($form->isValid()) { $dogData = $form->getData(); $dogData['breedName'] = $this->getDogService()->getBreed($dogData['breed'])->getName(); $this->session->offsetSet('dogData', $dogData); $form = new Confirm(); } } } // Remove payum token from form action url if necessary $form->setAttribute('action', $this->url()->fromRoute('dog/register')); return array('form' => $form, 'status' => $status, 'dogData' => $this->session->offsetGet('dogData')); }