Passed
Pull Request — feature/eco-3656/dev-paypal-ex... (#40)
by
unknown
09:58 queued 04:12
created

ExpressCheckoutController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 3
eloc 18
c 1
b 1
f 1
dl 0
loc 55
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A placeOrderPayPalExpressAction() 0 7 1
A preparePayPalExpressAction() 0 10 1
A completeOrderPayPalExpressAction() 0 8 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Yves\Computop\Controller;
9
10
use Spryker\Yves\Kernel\Controller\AbstractController;
11
use Symfony\Component\HttpFoundation\JsonResponse;
12
use Symfony\Component\HttpFoundation\RedirectResponse;
13
use Symfony\Component\HttpFoundation\Request;
14
15
/**
16
 * @method \SprykerEco\Yves\Computop\ComputopFactory getFactory()
17
 * @method \SprykerEco\Client\Computop\ComputopClientInterface getClient()
18
 */
19
class ExpressCheckoutController extends AbstractController
20
{
21
    /**
22
     * @uses CheckoutPageRouteProviderPlugin::ROUTE_NAME_CHECKOUT_PLACE_ORDER
23
     */
24
    protected const ROUTE_NAME_CHECKOUT_PLACE_ORDER = 'checkout-place-order';
25
26
    /**
27
     * @uses CheckoutPageRouteProviderPlugin::ROUTE_NAME_CHECKOUT_SUCCESS
28
     */
29
    protected const ROUTE_NAME_CHECKOUT_SUCCESS = 'checkout-success';
30
31
    /**
32
     * @return \Symfony\Component\HttpFoundation\JsonResponse
33
     */
34
    public function preparePayPalExpressAction(): JsonResponse
35
    {
36
        $quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote();
37
        $payPalExpressPrepareHandler = $this->getFactory()->createComputopPayPalExpressPrepareHandler();
38
        $computopApiPayPalExpressPrepareResponseTransfer = $payPalExpressPrepareHandler->handle($quoteTransfer);
39
40
        return new JsonResponse([
41
            'orderId' => $computopApiPayPalExpressPrepareResponseTransfer->getOrderId(),
42
            'merchantId' => $computopApiPayPalExpressPrepareResponseTransfer->getMid(),
43
            'payId' => $computopApiPayPalExpressPrepareResponseTransfer->getPayID(),
44
        ]);
45
    }
46
47
    /**
48
     * @param \Symfony\Component\HttpFoundation\Request $request
49
     *
50
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
51
     */
52
    public function placeOrderPayPalExpressAction(Request $request): RedirectResponse
53
    {
54
        $quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote();
55
        $payPalExpressInitHandler = $this->getFactory()->createComputopPayPalExpressInitHandler();
56
        $payPalExpressInitHandler->handle($quoteTransfer, $request->query->all());
57
58
        return $this->redirectResponseInternal(static::ROUTE_NAME_CHECKOUT_PLACE_ORDER);
59
    }
60
61
    /**
62
     * @param \Symfony\Component\HttpFoundation\Request $request
63
     *
64
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
65
     */
66
    public function completeOrderPayPalExpressAction(Request $request): RedirectResponse
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

66
    public function completeOrderPayPalExpressAction(/** @scrutinizer ignore-unused */ Request $request): RedirectResponse

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
    {
68
        $quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote();
69
        $payPalExpressCompleteHandler = $this->getFactory()->createComputopPayPalExpressCompleteHandler();
70
71
        $payPalExpressCompleteHandler->handle($quoteTransfer);
72
73
        return $this->redirectResponseInternal(static::ROUTE_NAME_CHECKOUT_SUCCESS);
74
    }
75
}
76