Completed
Push — master ( cddd98...c8ab6f )
by Oleksandr
14s queued 10s
created

PaypalExpressController::addShipmentAction()   A

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
23
    /**
24
     * @param \Symfony\Component\HttpFoundation\Request $request
25
     *
26
     * @return \Symfony\Component\HttpFoundation\JsonResponse
27
     */
28
    public function successAction(Request $request): Response
29
    {
30
        $payload = $this->getFactory()->getUtilEncodingService()->decodeJson($request->getContent(), true);
31
32
        $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

32
        $this->getFactory()->createResponseProcessor()->processSuccessResponse(/** @scrutinizer ignore-type */ $payload);
Loading history...
33
34
        return $this->jsonResponse([
35
            'redirectUrl' => $this->getApplication()->path(CheckoutPageControllerProvider::CHECKOUT_SUMMARY),
36
        ]);
37
    }
38
39
    /**
40
     * @param \Symfony\Component\HttpFoundation\Request $request
41
     *
42
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
43
     */
44
    public function addShipmentAction(Request $request): Response
45
    {
46
        $quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote();
47
48
        $form = $this->getFactory()->getFormFactory()->create(
49
            CheckoutShipmentForm::class,
50
            $this->getFactory()->createBraintreePaypalExpressShipmentFormDataProvider()->getData($quoteTransfer),
51
            $this->getFactory()->createBraintreePaypalExpressShipmentFormDataProvider()->getOptions($quoteTransfer)
52
        );
53
54
        $form->handleRequest($request);
55
56
        if ($form->isValid()) {
57
            $this->getFactory()->createQuoteExpander()->expandQuoteWithShipmentMethod(
58
                $request,
59
                $form->getData()->getShipment()->getShipmentSelection()
60
            );
61
62
            return $this->redirectResponseInternal(CheckoutPageControllerProvider::CHECKOUT_SUMMARY);
63
        }
64
65
        $this->getFactory()->getMessengerClient()->addErrorMessage(static::TRANSLATION_INVALID_SHIPMENT_METHOD);
66
67
        return $this->redirectResponseInternal(CheckoutPageControllerProvider::CHECKOUT_SUMMARY);
68
    }
69
}
70