/**
  * {@inheritdoc}
  */
 public function buildOrderHandoff(CustomerOrder $order)
 {
     $orderUuId = $order->getUuid();
     if (!$orderUuId) {
         throw new \InvalidArgumentException('Order does not exist in entity manager, make sure that it is persisted before handing off');
     }
     $handoff = new OrderHandoff($orderUuId, $this->router->generate($this->handoffUrlRouteName, array('uuid' => $orderUuId), true));
     return $handoff;
 }
 /**
  * Get the refund status
  *
  * @REST\Get("/orders/{uuid}/refundStatus", defaults={"_format"="json"})
  * @REST\View
  */
 public function getRefundStatusAction(CustomerOrder $order)
 {
     if ($order->getUser()->getId() != $this->security->getToken()->getUser()->getId()) {
         throw new AccessDeniedException('Access denied');
     } else {
         if (CustomerOrder::TRANSACTION_TYPE_REFUND != $order->getTransactionType()) {
             throw new InvalidArgumentException('Order was not a refund');
         }
     }
     $refundResponse = $order->getStatusResponse();
     if (!$refundResponse) {
         throw new NotFoundHttpException(sprintf('Payment status for the order "%s" could not be found', $order->getUuid()));
     }
     return $refundResponse;
 }
 /**
  * Action to present the initial payment selection form, or jump to approval if only one payment type
  *
  * @param CustomerOrder $order
  * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  *
  * @Framework\Route("/order/{uuid}/payment-type")
  * @Framework\Template
  */
 public function paymentTypeSelectionAction(CustomerOrder $order)
 {
     $canSkipPaymentSelection = 1 == count($order->getPaymentTypes());
     $instruction = null;
     if ($canSkipPaymentSelection) {
         $instruction = new PaymentInstruction($order->getAmount(), 'GBP', 'paypoint_hosted');
     } else {
         $form = $this->formFactory->create('jms_choose_payment_method', null, array('amount' => $order->getAmount(), 'currency' => 'GBP', 'predefined_data' => array('paypoint_hosted' => array())));
         if ($this->request->isMethod('POST')) {
             $form->submit($this->request);
             if ($form->isValid()) {
                 $instruction = $form->getData();
             }
         }
         if (null === $instruction) {
             return array('form' => $form->createView(), 'order' => $order);
         }
     }
     $this->paymentPluginController->createPaymentInstruction($instruction);
     $order->setPaymentInstruction($instruction);
     $this->em->persist($instruction);
     $this->em->flush();
     return new RedirectResponse($this->router->generate('barbon_paymentportal_payment_approvepayment', array('uuid' => $order->getUuid())));
 }