Completed
Pull Request — master (#16)
by Cesar
01:31
created

PaymentsController::payIns()   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"}, defaults={"action" = "pay-ins"})
22
     * @Route("/pay-outs", name="pay-outs", methods={"GET"}, defaults={"action" = "pay-outs"})
23
     * @Route("/bopis", name="bopis", methods={"GET"}, defaults={"action" = "bopis"})
24
     * @Route("/subscriptions", name="subscriptions", methods={"GET"}, defaults={"action" = "subscriptions"})
25
     * @Route("/invoices", name="invoices", methods={"GET"}, defaults={"action" = "invoices"})
26
     *
27
     * @param string $action
28
     *
29
     * @return Response | RedirectResponse
30
     */
31
    public function payments(string $action)
32
    {
33
        return $this->render('paypal/payments/'. $action .'.html.twig');
34
    }
35
36
    /**
37
     * @Route("/{paymentId}/capture", name="capture", methods={"POST"})
38
     * @param string $paymentId
39
     * @return Response | RedirectResponse
40
     */
41
    public function capture(string $paymentId)
42
    {
43
        $capture = $this->paypalService->getPaymentService()->capturePayment($paymentId);
44
        return $this->render('default/dump-input-id.html.twig', [
45
            'raw_result' => false,
46
            'result' => $capture,
47
            'result_id' => 'payment-id'
48
        ]);
49
    }
50
51
    /**
52
     * @Route("/pay-outs", name="pay-outs-create", methods={"POST"})
53
     *
54
     * @return Response | RedirectResponse
55
     */
56
    public function payoutsCreate()
57
    {
58
        $request = Request::createFromGlobals();
59
        $subject = $request->request->get('subject', null);
60
        $note = $request->request->get('note', null);
61
        $email = $request->request->get('email', null);
62
        $itemId = $request->request->get('item-id', null);
63
        $currency = $request->request->get('currency', null);
64
        $amount = $request->request->get('amount', null);
65
        $payout = $this->paypalService
66
            ->getPayoutService()
67
            ->createPayout($subject, $note, $email, $itemId, $amount, $currency);
68
        return $this->render('default/dump-input-id.html.twig', [
69
            'raw_result' => false,
70
            'result' => $payout,
71
            'result_id' => $payout->getBatchHeader()->getPayoutBatchId()
72
        ]);
73
    }
74
75
    /**
76
     * @Route("/pay-outs/{statusId}", name="pay-outs-refresh", methods={"GET"})
77
     *
78
     * @param string $statusId
79
     * @return Response | RedirectResponse
80
     */
81
    public function payoutsRefresh(string $statusId)
82
    {
83
        $payout = $this->paypalService->getPayoutService()->getPayout($statusId);
84
        return $this->render('default/dump-input-id.html.twig', [
85
            'raw_result' => false,
86
            'result' => $payout,
87
            'result_id' => $payout->getBatchHeader()->getPayoutBatchId()
88
        ]);
89
    }
90
91
    /**
92
     * @Route("/invoices", name="invoices-create", methods={"POST"})
93
     *
94
     * @return Response | RedirectResponse
95
     */
96
    public function invoicesCreate()
97
    {
98
        $request = Request::createFromGlobals();
99
        $inputForm = $request->request->all();
100
        $invoice = $this->paypalService->getInvoiceService()->createInvoice($inputForm);
101
        if ($invoice instanceof Invoice) {
102
            $this->paypalService->getInvoiceService()->sendInvoice($invoice);
103
            $invoiceQR = $this->paypalService->getInvoiceService()->getInvoiceQRHTML($invoice);
104
        }
105 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...
106
            return $this->render('default/dump-input-id.html.twig', [
107
                'raw_result' => true,
108
                'result' => $invoiceQR,
109
                'result_id' => $invoice->getId()
110
            ]);
111
        }
112
        return new JsonResponse('Error creating the Invoice, please check the logs');
113
    }
114
115
    /**
116
     * @Route("/invoices/{invoiceId}", name="invoices-refresh", methods={"GET"})
117
     * @param string $invoiceId
118
     * @return Response | RedirectResponse
119
     */
120
    public function invoicesRefresh(string $invoiceId)
121
    {
122
        $invoice = $this->paypalService->getInvoiceService()->getInvoice($invoiceId);
123
        return $this->render('default/dump-input-id.html.twig', [
124
            'raw_result' => false,
125
            'result' => $invoice,
126
            'result_id' => $invoice->getId()
127
        ]);
128
    }
129
}
130