PaypalExpressController::addShipmentAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
nc 2
nop 1
dl 0
loc 24
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Yves\Braintree\Controller;
9
10
use Spryker\Yves\Kernel\Controller\AbstractController;
11
use SprykerEco\Yves\Braintree\Form\CheckoutShipmentForm;
12
use SprykerShop\Yves\CheckoutPage\Plugin\Provider\CheckoutPageControllerProvider;
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\HttpFoundation\Response;
15
16
/**
17
 * @method \SprykerEco\Yves\Braintree\BraintreeFactory getFactory()
18
 */
19
class PaypalExpressController extends AbstractController
20
{
21
    public const TRANSLATION_INVALID_SHIPMENT_METHOD = 'checkout.pre.check.shipment.failed';
22
    public const IS_PAYPAL_ENABLED = true;
23
24
    /**
25
     * @param \Symfony\Component\HttpFoundation\Request $request
26
     *
27
     * @return \Symfony\Component\HttpFoundation\JsonResponse
28
     */
29
    public function successAction(Request $request): Response
30
    {
31
        if (!self::IS_PAYPAL_ENABLED) {
32
            echo 'The payment method PayPal Express is not an officially approved integration and must not be used without prior agreement with either Braintree and/or Spryker.';
33
34
            return;
0 ignored issues
show
Bug Best Practice introduced by
The expression return returns the type null which is incompatible with the type-hinted return Symfony\Component\HttpFoundation\Response.
Loading history...
35
36
        }
37
        $payload = $this->getFactory()->getUtilEncodingService()->decodeJson($request->getContent(), true);
38
39
        $this->getFactory()->createResponseProcessor()->processSuccessResponse($payload);
0 ignored issues
show
Bug introduced by
It seems like $payload can also be of type null; however, parameter $payload of SprykerEco\Yves\Braintre...rocessSuccessResponse() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

39
        $this->getFactory()->createResponseProcessor()->processSuccessResponse(/** @scrutinizer ignore-type */ $payload);
Loading history...
40
41
        return $this->jsonResponse([
42
            'redirectUrl' => $this->getApplication()->path(CheckoutPageControllerProvider::CHECKOUT_SUMMARY),
0 ignored issues
show
Bug introduced by
The method path() does not exist on Spryker\Service\Container\ContainerInterface. It seems like you code against a sub-type of Spryker\Service\Container\ContainerInterface such as Silex\Tests\Application\UrlGeneratorApplication. ( Ignorable by Annotation )

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

42
            'redirectUrl' => $this->getApplication()->/** @scrutinizer ignore-call */ path(CheckoutPageControllerProvider::CHECKOUT_SUMMARY),
Loading history...
Bug introduced by
The method path() does not exist on Spryker\Yves\Kernel\Application. ( Ignorable by Annotation )

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

42
            'redirectUrl' => $this->getApplication()->/** @scrutinizer ignore-call */ path(CheckoutPageControllerProvider::CHECKOUT_SUMMARY),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
        ]);
44
    }
45
46
    /**
47
     * @param \Symfony\Component\HttpFoundation\Request $request
48
     *
49
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
50
     */
51
    public function addShipmentAction(Request $request): Response
52
    {
53
        $quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote();
54
55
        $form = $this->getFactory()->getFormFactory()->create(
56
            CheckoutShipmentForm::class,
57
            $this->getFactory()->createBraintreePaypalExpressShipmentFormDataProvider()->getData($quoteTransfer),
58
            $this->getFactory()->createBraintreePaypalExpressShipmentFormDataProvider()->getOptions($quoteTransfer)
59
        );
60
61
        $form->handleRequest($request);
62
63
        if ($form->isValid()) {
64
            $this->getFactory()->createQuoteExpander()->expandQuoteWithShipmentMethod(
65
                $request,
66
                $form->getData()->getShipment()->getShipmentSelection()
67
            );
68
69
            return $this->redirectResponseInternal(CheckoutPageControllerProvider::CHECKOUT_SUMMARY);
70
        }
71
72
        $this->getFactory()->getMessengerClient()->addErrorMessage(static::TRANSLATION_INVALID_SHIPMENT_METHOD);
73
74
        return $this->redirectResponseInternal(CheckoutPageControllerProvider::CHECKOUT_SUMMARY);
75
    }
76
}
77