Completed
Push — feature/eco-3656/eco-3658-enab... ( 4f4220...78bea4 )
by
unknown
04:14
created

ExpressCheckoutController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A placeOrderPayPalExpressAction() 0 10 1
A mockRequest() 0 37 1
A preparePayPalExpressAction() 0 6 1
1
<?php
2
3
namespace SprykerEco\Yves\Computop\Controller;
4
5
use Spryker\Yves\Kernel\Controller\AbstractController;
6
use SprykerEco\Shared\Computop\Config\ComputopApiConfig;
7
use SprykerEco\Yves\Computop\ComputopFactory;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
11
/**
12
 * @method \SprykerEco\Yves\Computop\ComputopFactory getFactory()
13
 * @method \SprykerEco\Client\Computop\ComputopClientInterface getClient()
14
 */
15
class ExpressCheckoutController extends AbstractController
16
{
17
    /** @see CheckoutPageRouteProviderPlugin::ROUTE_NAME_CHECKOUT_PLACE_ORDER */
18
    protected const ROUTE_NAME_CHECKOUT_PLACE_ORDER = 'checkout-place-order';
19
20
    /**
21
     * @param Request $request
22
     *
23
     * @return JsonResponse
24
     */
25
    public function preparePayPalExpressAction(): JsonResponse
26
    {
27
        $handler = $this->getFactory()->createPayPalExpressPrepareHandler();
28
        $decryptedArray = $handler->handle();
29
30
        return new JsonResponse(['id' => $decryptedArray['token']]);
31
    }
32
33
34
    /**
35
     * @param Request $request
36
     * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
37
     */
38
    public function placeOrderPayPalExpressAction(Request $request)
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

38
    public function placeOrderPayPalExpressAction(/** @scrutinizer ignore-unused */ Request $request)

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...
39
    {
40
        $request1 = $this->mockRequest();
41
42
        $quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote();
43
        $handler = (new ComputopFactory())->createPayPalExpressInitHandler();
44
45
        $quoteTransfer = $handler->handle($quoteTransfer, $request1->query->all());
0 ignored issues
show
Unused Code introduced by
The assignment to $quoteTransfer is dead and can be removed.
Loading history...
46
47
        return $this->redirectResponseInternal(static::ROUTE_NAME_CHECKOUT_PLACE_ORDER);
48
    }
49
50
51
52
53
54
55
56
57
58
59
60
    private function mockRequest(): Request
61
    {
62
        $request = new Request();
63
64
        $data = [
65
            ComputopApiConfig::MERCHANT_ID_SHORT => 'spryker_test',
66
            ComputopApiConfig::PAY_ID => 123,
67
            ComputopApiConfig::MAC => '299BEB7656F5B1ED2FDE6D50C8F2CA38196F8658F853CE6471730726CB8FD0F9',
68
            ComputopApiConfig::TRANS_ID => 12355,
69
            ComputopApiConfig::CODE => 0,
70
71
            ComputopApiConfig::STATUS => 'AUTHORIZE_REQUEST',
72
            ComputopApiConfig::FIRST_NAME => 'Kos',
73
            ComputopApiConfig::LAST_NAME => 'Spryker',
74
            ComputopApiConfig::EMAIL => '[email protected]',
75
76
77
//            ComputopApiConfig::ADDRESS_STREET => 'test street',
78
            ComputopApiConfig::ADDRESS_COUNTRY_CODE => 'UA',
79
            ComputopApiConfig::ADDRESS_CITY => 'Odessa1',
80
            ComputopApiConfig::ADDR_ZIP => 65001,
81
82
83
            ComputopApiConfig::BILLING_NAME => 'KosBilling',
84
            ComputopApiConfig::BILLING_ADDRESS_STREET => 'test billing street',
85
            ComputopApiConfig::BILLING_ADDRESS_COUNTRY_CODE => 'US',
86
            ComputopApiConfig::BILLING_ADDRESS_CITY => 'Odessa2',
87
            ComputopApiConfig::BILLING_ADDRESS_ZIP => 65002,
88
        ];
89
90
        $encrData = (new ComputopFactory())->getComputopApiService()
91
            ->getEncryptedArray($data, (new ComputopFactory())->getConfig()->getBlowfishPassword());
92
93
        $request->query->set('Data', $encrData['Data']);
94
        $request->query->set('Len', $encrData['Len']);
95
96
        return $request;
97
    }
98
}
99