Completed
Pull Request — master (#15)
by Cesar
01:41
created

PaymentsController::payOuts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Controller\Paypal;
4
5
use PayPal\Api\Invoice;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\Routing\Annotation\Route;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\HttpFoundation\RedirectResponse;
11
12
/**
13
 * Class PaymentsController
14
 * @package App\Controller\Paypal
15
 *
16
 * @Route("/paypal/payments", name="paypal-payments-")
17
 */
18
class PaymentsController extends AbstractController
19
{
20
    /**
21
     * @Route("/pay-ins", name="pay-ins", methods={"GET"})
22
     *
23
     * @return Response | RedirectResponse
24
     */
25
    public function payIns()
26
    {
27
        return $this->render('paypal/payments/pay-ins.html.twig');
28
    }
29
30
    /**
31
     * @Route("/{paymentId}/capture", name="capture", methods={"POST"})
32
     * @param string $paymentId
33
     * @return Response | RedirectResponse
34
     */
35 View Code Duplication
    public function capture(string $paymentId)
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...
36
    {
37
        $capture = $this->paypalService->getPaymentService()->capturePayment($paymentId);
38
        return $this->render('default/dump-input-id.html.twig', [
39
            'raw_result' => false,
40
            'result' => $capture,
41
            'result_id' => 'payment-id'
42
        ]);
43
    }
44
45
    /**
46
     * @Route("/pay-outs", name="pay-outs", methods={"GET"})
47
     *
48
     * @return Response | RedirectResponse
49
     */
50
    public function payOuts()
51
    {
52
        return $this->render('paypal/payments/pay-outs.html.twig');
53
    }
54
55
    /**
56
     * @Route("/pay-outs", name="pay-outs-create", methods={"POST"})
57
     *
58
     * @return Response | RedirectResponse
59
     */
60
    public function payoutsCreate()
61
    {
62
        $request = Request::createFromGlobals();
63
        $subject = $request->request->get('subject', null);
64
        $note = $request->request->get('note', null);
65
        $email = $request->request->get('email', null);
66
        $itemId = $request->request->get('item-id', null);
67
        $currency = $request->request->get('currency', null);
68
        $amount = $request->request->get('amount', null);
69
        $payout = $this->paypalService
70
            ->getPayoutService()
71
            ->createPayout($subject, $note, $email, $itemId, $amount, $currency);
72
        return $this->render('default/dump-input-id.html.twig', [
73
            'raw_result' => false,
74
            'result' => $payout,
75
            'result_id' => $payout->getBatchHeader()->getPayoutBatchId()
76
        ]);
77
    }
78
79
    /**
80
     * @Route("/pay-outs/{statusId}", name="pay-outs-refresh", methods={"GET"})
81
     *
82
     * @param string $statusId
83
     * @return Response | RedirectResponse
84
     */
85
    public function payoutsRefresh(string $statusId)
86
    {
87
        $payout = $this->paypalService->getPayoutService()->getPayout($statusId);
88
        return $this->render('default/dump-input-id.html.twig', [
89
            'raw_result' => false,
90
            'result' => $payout,
91
            'result_id' => $payout->getBatchHeader()->getPayoutBatchId()
92
        ]);
93
    }
94
95
    /**
96
     * @Route("/invoices", name="invoices", methods={"GET"})
97
     *
98
     * @return Response | RedirectResponse
99
     */
100
    public function invoices()
101
    {
102
        return $this->render('paypal/payments/invoices.html.twig');
103
    }
104
105
    /**
106
     * @Route("/invoices", name="invoices-create", methods={"POST"})
107
     *
108
     * @return Response | RedirectResponse
109
     */
110
    public function invoicesCreate()
111
    {
112
        $request = Request::createFromGlobals();
113
        $inputForm = $request->request->all();
114
        $invoice = $this->paypalService->getInvoiceService()->createInvoice($inputForm);
115
        if ($invoice instanceof Invoice) {
116
            $this->paypalService->getInvoiceService()->sendInvoice($invoice);
117
            $invoiceQR = $this->paypalService->getInvoiceService()->getInvoiceQRHTML($invoice);
118
        }
119 View Code Duplication
        if (isset($invoiceQR)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
120
            return $this->render('default/dump-input-id.html.twig', [
121
                'raw_result' => true,
122
                'result' => $invoiceQR,
123
                'result_id' => $invoice->getId()
124
            ]);
125
        }
126
        return new JsonResponse('Error creating the Invoice, please check the logs');
127
    }
128
129
    /**
130
     * @Route("/invoices/{invoiceId}", name="invoices-refresh", methods={"GET"})
131
     * @param string $invoiceId
132
     * @return Response | RedirectResponse
133
     */
134 View Code Duplication
    public function invoicesRefresh(string $invoiceId)
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...
135
    {
136
        $invoice = $this->paypalService->getInvoiceService()->getInvoice($invoiceId);
137
        return $this->render('default/dump-input-id.html.twig', [
138
            'raw_result' => false,
139
            'result' => $invoice,
140
            'result_id' => $invoice->getId()
141
        ]);
142
    }
143
144
    /**
145
     * @Route("/subscriptions", name="subscriptions", methods={"GET"})
146
     *
147
     * @return Response | RedirectResponse
148
     */
149
    public function subscriptions()
150
    {
151
        return $this->render('paypal/payments/subscriptions.html.twig');
152
    }
153
}
154