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

ComputopPayPalExpressPrepareHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 5
c 1
b 1
f 1
dl 0
loc 13
rs 10
cc 1
nc 1
nop 5
1
<?php
2
3
namespace SprykerEco\Yves\Computop\Handler\ExpressCheckout;
4
5
use Generated\Shared\Transfer\AddressTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\AddressTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Generated\Shared\Transfer\CustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CustomerTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Spryker\Client\Quote\QuoteClientInterface;
8
use Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface;
9
use SprykerEco\Service\ComputopApi\ComputopApiServiceInterface;
10
use SprykerEco\Yves\Computop\ComputopConfigInterface;
11
use SprykerEco\Yves\Computop\Dependency\Client\ComputopToQuoteClientInterface;
12
use SprykerEco\Yves\Computop\Dependency\External\ComputopToGuzzleHttpClientInterface;
13
14
class ComputopPayPalExpressPrepareHandler implements ComputopPayPalExpressPrepareHandlerInterface
15
{
16
    /**
17
     * @var QuoteClientInterface
18
     */
19
    protected $quoteClient;
20
21
    /**
22
     * @var StepEngineFormDataProviderInterface
23
     */
24
    protected $stepEngineFormDataProvider;
25
26
    /**
27
     * @var ComputopToGuzzleHttpClientInterface
28
     */
29
    protected $computopToGuzzleHttpClient;
30
31
    /**
32
     * @var ComputopApiServiceInterface
33
     */
34
    protected $computopApiService;
35
36
    /**
37
     * @var ComputopConfigInterface
38
     */
39
    protected $computopConfig;
40
41
    /**
42
     * ComputopPayPalExpressPrepareHandler constructor.
43
     */
44
    public function __construct(
45
        ComputopToQuoteClientInterface $quoteClient,
46
        StepEngineFormDataProviderInterface $stepEngineFormDataProvider,
47
        ComputopToGuzzleHttpClientInterface $computopToGuzzleHttpClient,
48
        ComputopApiServiceInterface $computopApiService,
49
        ComputopConfigInterface $computopConfig
50
    )
51
    {
52
        $this->quoteClient = $quoteClient;
0 ignored issues
show
Documentation Bug introduced by
It seems like $quoteClient of type SprykerEco\Yves\Computop...pToQuoteClientInterface is incompatible with the declared type Spryker\Client\Quote\QuoteClientInterface of property $quoteClient.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
53
        $this->stepEngineFormDataProvider = $stepEngineFormDataProvider;
54
        $this->computopToGuzzleHttpClient = $computopToGuzzleHttpClient;
55
        $this->computopApiService = $computopApiService;
56
        $this->computopConfig = $computopConfig;
57
    }
58
59
    public function handle()
60
    {
61
        $quoteTransfer = $this->quoteClient->getQuote();
62
63
//        $handler = $this->getFactory()->createPayPalExpressInitHandler()
64
65
        //Customer kostyl
66
        $customer = new CustomerTransfer();
67
        $customer->setCustomerReference('123');
68
        $customer->setIsGuest(true);
69
        $quoteTransfer->setCustomer($customer);
70
71
        //zip kostyl
72
        $address = new AddressTransfer();
73
        $address->setZipCode(65000);
74
        $quoteTransfer->setShippingAddress($address);
75
76
77
        $quote = $this->stepEngineFormDataProvider->getData($quoteTransfer);
78
        $this->quoteClient->setQuote($quote);
79
80
        $payment = $quote->getPayment()->getComputopPayPalExpress();
81
82
        $response = $this->computopToGuzzleHttpClient->request(
83
            'post',
84
            'https://www.computop-paygate.com/ExternalServices/paypalorders.aspx',
85
            [
86
                'query' => [
87
                    'MerchantID' => $payment->getMerchantId(),
88
                    'Data' => $payment->getData(),
89
                    'Len' => $payment->getLen()
90
                ]
91
            ]
92
        );
93
94
        $responseContents = $response->getBody()->getContents();
95
96
        $respData = [];
97
        parse_str($responseContents, $respData);
98
99
        return $this->computopApiService->decryptResponseHeader($respData, $this->computopConfig->getBlowfishPassword());
100
    }
101
}
102