Completed
Pull Request — master (#11)
by Cesar
01:33
created

PaymentsController::dropUI()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Controller\Braintree;
4
5
use Braintree\Exception\NotFound;
6
use Braintree\Transaction;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\Routing\Annotation\Route;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * Class PaymentsController
13
 *
14
 * @package App\Controller\Braintree
15
 *
16
 * @Route("/braintree/payments", name="braintree-payments-")
17
 */
18
class PaymentsController extends AbstractController
19
{
20
    /**
21
     * @Route("/dropui", name="dropui", methods={"GET"})
22
     *
23
     * @return Response
24
     */
25 View Code Duplication
    public function dropUI()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        $clientToken = $this->braintreeService->getPaymentService()->getClientToken();
28
        return $this->render('braintree/payments/dropui.html.twig', [
29
            'clientToken' => $clientToken,
30
            'name' => 'Drop UI'
31
        ]);
32
    }
33
34
    /**
35
     * @Route("/hosted-fields", name="hosted-fields", methods={"GET"})
36
     *
37
     * @return Response
38
     */
39 View Code Duplication
    public function hostedFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        $clientToken = $this->braintreeService->getPaymentService()->getClientToken();
42
        return $this->render('braintree/payments/hosted-fields.html.twig', [
43
            'clientToken' => $clientToken,
44
            'name' => 'Hosted Fields'
45
        ]);
46
    }
47
48
    /**
49
     * @Route("/apm", name="apm", methods={"GET"})
50
     *
51
     * @return Response
52
     */
53 View Code Duplication
    public function apm()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $clientToken = $this->braintreeService->getPaymentService()->getClientToken();
56
        return $this->render('braintree/payments/apm.html.twig', [
57
            'clientToken' => $clientToken,
58
            'name' => 'APM',
59
            'paypalClientId' => $this->getParameter('PAYPAL_SDK_CLIENT_ID'),
60
        ]);
61
    }
62
63
    /**
64
     * @Route("/3ds", name="three-ds", methods={"GET"})
65
     *
66
     * @return Response
67
     */
68 View Code Duplication
    public function threeDS()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $clientToken = $this->braintreeService->getPaymentService()->getClientToken();
71
        return $this->render('braintree/payments/3ds.html.twig', [
72
            'clientToken' => $clientToken,
73
            'name' => 'DropIn 3DS',
74
        ]);
75
    }
76
77
    /**
78
     * @Route("/vault", name="vault", methods={"GET"})
79
     *
80
     * @return Response
81
     */
82 View Code Duplication
    public function vault()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
    {
84
        $clientToken = $this->braintreeService->getPaymentService()->getClientToken();
85
        return $this->render('braintree/payments/vault.html.twig', [
86
            'clientToken' => $clientToken,
87
            'name' => 'DropIn Vaulting',
88
        ]);
89
    }
90
91
    /**
92
     * @Route("/payload", name="payload", methods={"POST"})
93
     *
94
     * @return Response
95
     */
96
    public function paymentsPayload()
97
    {
98
        $request = Request::createFromGlobals();
99
        $payload = $request->request->all();
100
        return $this->render('default/dump.html.twig', [
101
            'result' => (object) $payload,
102
            'raw_result' => false,
103
        ]);
104
    }
105
106
    /**
107
     * @Route("/transaction", name="create", methods={"POST"})
108
     *
109
     * @return Response
110
     */
111
    public function createTransaction()
112
    {
113
        $request = Request::createFromGlobals();
114
        $paymentNonce = $request->request->get('payment_nonce');
115
        $amount = $request->request->get('amount');
116
        $deviceData = $request->request->get('device_data');
117
        $sale = $this->braintreeService->getPaymentService()->createSale($amount, $paymentNonce, $deviceData);
118
        /** @var Transaction $transaction */
119
        $transaction = $sale->transaction;
120
        return $this->render('default/dump-input-id.html.twig', [
121
            'result' => $sale,
122
            'raw_result' => false,
123
            'result_id' => $transaction->id
124
        ]);
125
    }
126
127
    /**
128
     * @Route("/transaction/{transactionId}/capture", name="capture", methods={"POST"})
129
     *
130
     * @param string $transactionId
131
     *
132
     * @return Response
133
     */
134
    public function captureTransaction(string $transactionId)
135
    {
136
        $request = Request::createFromGlobals();
137
        $amount = $request->request->get('amount');
138
        $capture = $this->braintreeService->getPaymentService()->captureSale($transactionId, $amount);
139
        return $this->render('default/dump.html.twig', [
140
            'result' => (object) $capture,
141
            'raw_result' => false,
142
        ]);
143
    }
144
145
    /**
146
     * @Route("/{transactionId}", name="get", methods={"GET"})
147
     *
148
     * @param string $transactionId
149
     * @return Response
150
     * @throws NotFound
151
     */
152
    public function getTransaction(string $transactionId)
153
    {
154
        $transaction = $this->braintreeService->getPaymentService()->getTransaction($transactionId);
155
        return $this->render('default/dump.html.twig', [
156
            'result' => (object) $transaction,
157
            'raw_result' => false,
158
        ]);
159
    }
160
}
161