|
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) |
|
|
|
|
|
|
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()); |
|
|
|
|
|
|
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
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.