/** * 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()))); }