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

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

        if (null === $payment = $order->findPaymentById($request->attributes->get('paymentId'))) {
            throw new NotFoundHttpException('Payment not found.');
        }
        if ($payment->getState() !== PaymentStates::STATE_NEW) {
            throw new NotFoundHttpException('Payment is not new.');
        }

        $redirectPath = $this->generateResourcePath($order);
        $action = $this->generateUrl('ekyna_order_order_admin_payment_remove', [
            'orderId' => $order->getId(),
            'paymentId' => $payment->getId(),
        ]);
        $form = $this->createRemovePaymentForm($action, $redirectPath);

        $form->handleRequest($request);
        if ($form->isValid()) {
            $order->removePayment($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-remove',
            'ekyna_order.payment.button.remove'
        );

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

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

        if (null === $payment = $order->findPaymentById($request->attributes->get('paymentId'))) {
            throw new NotFoundHttpException('Payment not found.');
        }
        if ($payment->getState() !== PaymentStates::STATE_NEW) {
            throw new NotFoundHttpException('Payment is not new.');
        }

        $redirectPath = $this->generateResourcePath($order);
        $action = $this->generateUrl('ekyna_order_order_admin_payment_remove', [
            'orderId' => $order->getId(),
            'paymentId' => $payment->getId(),
        ]);
        $form = $this->createRemovePaymentForm($action, $redirectPath);

        $form->handleRequest($request);
        if ($form->isValid()) {
            $order->removePayment($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-remove',
            'ekyna_order.payment.button.remove'
        );

        return $this->render('EkynaOrderBundle:Admin/Order/Payment:remove.html.twig', [
            'form' => $form->createView(),
            'order' => $order,
        ]);
    }
public function removePaymentAction ( Request $ request ) { $ context = $ this -> loadContext ( $ request ) ; /** @var \Ekyna\Component\Sale\Order\OrderInterface $order */ $ order = $ context -> getResource ( ) ; $ this -> isGranted ( 'EDIT' , $ order ) ; if ( null === $ payment = $ order -> findPaymentById ( $ request -> attributes -> get ( 'paymentId' ) ) ) { throw new NotFoundHttpException ( 'Payment not found.' ) ; } if ( $ payment -> getState ( ) !== PaymentStates :: STATE_NEW ) { throw new NotFoundHttpException ( 'Payment is not new.' ) ; } $ redirectPath = $ this -> generateResourcePath ( $ order ) ; $ action = $ this -> generateUrl ( 'ekyna_order_order_admin_payment_remove' , [ 'orderId' => $ order -> getId ( ) , 'paymentId' => $ payment -> getId ( ) , ] ) ; $ form = $ this -> createRemovePaymentForm ( $ action , $ redirectPath ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ order -> removePayment ( $ 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-remove' , 'ekyna_order.payment.button.remove' ) ; return $ this -> render ( 'EkynaOrderBundle:Admin/Order/Payment:remove.html.twig' , [ 'form' => $ form -> createView ( ) , 'order' => $ order , ] ) ; }
Remove payment action.

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