PaymentOrderManualConfirmController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 36
rs 10
c 2
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A manualConfirmation() 0 31 4
1
<?php
2
/*
3
 * Copyright (C) 2020  Jan Böhmer
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as published
7
 * by the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace App\Controller\Admin;
20
21
use App\Entity\PaymentOrder;
22
use App\Form\PaymentOrderManualConfirmationType;
23
use App\Services\EmailConfirmation\ManualConfirmationHelper;
24
use Doctrine\ORM\EntityManagerInterface;
25
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
26
use Symfony\Component\HttpFoundation\Request;
27
use Symfony\Component\Routing\Annotation\Route;
28
29
/**
30
 * @Route("/admin/payment_order")
31
 */
32
class PaymentOrderManualConfirmController extends AbstractController
33
{
34
    /**
35
     * @Route("/{id}/confirm", name="payment_order_manual_confirm")
36
     */
37
    public function manualConfirmation(PaymentOrder $paymentOrder, Request $request,
38
        ManualConfirmationHelper $manualConfirmationHelper, EntityManagerInterface $entityManager,
39
        array $notifications_risky)
40
    {
41
        $this->denyAccessUnlessGranted('ROLE_MANUAL_CONFIRMATION');
42
43
        //We can only confirm PaymentOrders that are not confirmed yet
44
        if ($paymentOrder->isConfirmed()) {
45
            $this->addFlash('error', 'payment_order.manual_confirm.already_confirmed');
46
47
            return $this->redirectToRoute('admin_dashboard');
48
        }
49
50
        $form = $this->createForm(PaymentOrderManualConfirmationType::class);
51
        $form->handleRequest($request);
52
53
        if ($form->isSubmitted() && $form->isValid()) {
54
            $manualConfirmationHelper->confirmManually($paymentOrder, $form->get('reason')->getData());
55
            //Save changes
56
            $entityManager->flush();
57
58
            //Show a success flash notification
59
            $this->addFlash('success', 'payment_order.manual_confirm.success');
60
61
            return $this->redirectToRoute('admin_dashboard');
62
        }
63
64
        return $this->render('admin/payment_order/manual_confirm.html.twig', [
65
            'entity' => $paymentOrder,
66
            'notifications_risky' => array_filter($notifications_risky),
67
            'form' => $form->createView(),
68
        ]);
69
    }
70
}
71