public function newPaymentAction(Request $request)
    {
        $context = $this->loadContext($request);
        /** @var \Ekyna\Component\Sale\Order\OrderInterface $order */
        $order = $context->getResource();

        $this->isGranted('EDIT', $order);

        $redirectPath = $this->generateResourcePath($order);

        $amount = $this
            ->get('ekyna_order.order.calculator')
            ->calculateOrderRemainingTotal($order)
        ;
        if (0 >= $amount) {
            $this->addFlash('ekyna_order.order.message.already_paid', 'info');
            return $this->redirect($redirectPath);
        }

        $paymentClass = $this->container->getParameter('ekyna_order.order_payment.class');
        /** @var \Ekyna\Component\Sale\Order\OrderPaymentInterface $payment */
        $payment = new $paymentClass;
        $payment
            ->setOrder($order)
            ->setAmount($amount)
        ;

        $action = $this->generateUrl(
            'ekyna_order_order_admin_payment_new',
            ['orderId' => $payment->getOrder()->getId()]
        );
        $form = $this->createPaymentForm($payment, $action, $redirectPath);

        $form->handleRequest($request);
        if ($form->isValid()) {
            $order->addPayment($payment);

            $event = new OrderEvent($order);
            $this->get('event_dispatcher')->dispatch(OrderEvents::CONTENT_CHANGE, $event);
            if (!$event->isPropagationStopped()) {
                return $this->redirect($redirectPath);
            }
        }

        $this->appendBreadcrumb(
            'order-payment-new',
            'ekyna_order.payment.button.new'
        );

        return $this->render('EkynaOrderBundle:Admin/Order/Payment:new.html.twig', [
            'form' => $form->createView(),
            'form_template' => 'EkynaOrderBundle:Admin/Order/Payment:_form.html.twig',
            'order' => $order,
        ]);
    }
public function newPaymentAction(Request $request)
    {
        $context = $this->loadContext($request);
        /** @var \Ekyna\Component\Sale\Order\OrderInterface $order */
        $order = $context->getResource();

        $this->isGranted('EDIT', $order);

        $redirectPath = $this->generateResourcePath($order);

        $amount = $this
            ->get('ekyna_order.order.calculator')
            ->calculateOrderRemainingTotal($order)
        ;
        if (0 >= $amount) {
            $this->addFlash('ekyna_order.order.message.already_paid', 'info');
            return $this->redirect($redirectPath);
        }

        $paymentClass = $this->container->getParameter('ekyna_order.order_payment.class');
        /** @var \Ekyna\Component\Sale\Order\OrderPaymentInterface $payment */
        $payment = new $paymentClass;
        $payment
            ->setOrder($order)
            ->setAmount($amount)
        ;

        $action = $this->generateUrl(
            'ekyna_order_order_admin_payment_new',
            ['orderId' => $payment->getOrder()->getId()]
        );
        $form = $this->createPaymentForm($payment, $action, $redirectPath);

        $form->handleRequest($request);
        if ($form->isValid()) {
            $order->addPayment($payment);

            $event = new OrderEvent($order);
            $this->get('event_dispatcher')->dispatch(OrderEvents::CONTENT_CHANGE, $event);
            if (!$event->isPropagationStopped()) {
                return $this->redirect($redirectPath);
            }
        }

        $this->appendBreadcrumb(
            'order-payment-new',
            'ekyna_order.payment.button.new'
        );

        return $this->render('EkynaOrderBundle:Admin/Order/Payment:new.html.twig', [
            'form' => $form->createView(),
            'form_template' => 'EkynaOrderBundle:Admin/Order/Payment:_form.html.twig',
            'order' => $order,
        ]);
    }
public function newPaymentAction ( Request $ request ) { $ context = $ this -> loadContext ( $ request ) ; /** @var \Ekyna\Component\Sale\Order\OrderInterface $order */ $ order = $ context -> getResource ( ) ; $ this -> isGranted ( 'EDIT' , $ order ) ; $ redirectPath = $ this -> generateResourcePath ( $ order ) ; $ amount = $ this -> get ( 'ekyna_order.order.calculator' ) -> calculateOrderRemainingTotal ( $ order ) ; if ( 0 >= $ amount ) { $ this -> addFlash ( 'ekyna_order.order.message.already_paid' , 'info' ) ; return $ this -> redirect ( $ redirectPath ) ; } $ paymentClass = $ this -> container -> getParameter ( 'ekyna_order.order_payment.class' ) ; /** @var \Ekyna\Component\Sale\Order\OrderPaymentInterface $payment */ $ payment = new $ paymentClass ; $ payment -> setOrder ( $ order ) -> setAmount ( $ amount ) ; $ action = $ this -> generateUrl ( 'ekyna_order_order_admin_payment_new' , [ 'orderId' => $ payment -> getOrder ( ) -> getId ( ) ] ) ; $ form = $ this -> createPaymentForm ( $ payment , $ action , $ redirectPath ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ order -> addPayment ( $ payment ) ; $ event = new OrderEvent ( $ order ) ; $ this -> get ( 'event_dispatcher' ) -> dispatch ( OrderEvents :: CONTENT_CHANGE , $ event ) ; if ( ! $ event -> isPropagationStopped ( ) ) { return $ this -> redirect ( $ redirectPath ) ; } } $ this -> appendBreadcrumb ( 'order-payment-new' , 'ekyna_order.payment.button.new' ) ; return $ this -> render ( 'EkynaOrderBundle:Admin/Order/Payment:new.html.twig' , [ 'form' => $ form -> createView ( ) , 'form_template' => 'EkynaOrderBundle:Admin/Order/Payment:_form.html.twig' , 'order' => $ order , ] ) ; }
New payment action.

@param Request $request
@return \Symfony\Component\HttpFoundation\RedirectResponse
New payment action .