1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Yves\Computop\Controller; |
9
|
|
|
|
10
|
|
|
use Spryker\Yves\Kernel\Controller\AbstractController; |
11
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
12
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @method \SprykerEco\Yves\Computop\ComputopFactory getFactory() |
17
|
|
|
* @method \SprykerEco\Client\Computop\ComputopClientInterface getClient() |
18
|
|
|
*/ |
19
|
|
|
class ExpressCheckoutController extends AbstractController |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @uses CheckoutPageRouteProviderPlugin::ROUTE_NAME_CHECKOUT_PLACE_ORDER |
23
|
|
|
*/ |
24
|
|
|
protected const ROUTE_NAME_CHECKOUT_PLACE_ORDER = 'checkout-place-order'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @uses CheckoutPageRouteProviderPlugin::ROUTE_NAME_CHECKOUT_SUCCESS |
28
|
|
|
*/ |
29
|
|
|
protected const ROUTE_NAME_CHECKOUT_SUCCESS = 'checkout-success'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse |
33
|
|
|
*/ |
34
|
|
|
public function preparePayPalExpressAction(): JsonResponse |
35
|
|
|
{ |
36
|
|
|
$quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote(); |
37
|
|
|
$payPalExpressPrepareHandler = $this->getFactory()->createComputopPayPalExpressPrepareHandler(); |
38
|
|
|
$computopApiPayPalExpressPrepareResponseTransfer = $payPalExpressPrepareHandler->handle($quoteTransfer); |
|
|
|
|
39
|
|
|
|
40
|
|
|
// return new JsonResponse([ |
41
|
|
|
// 'orderId' => $computopApiPayPalExpressPrepareResponseTransfer->getOrderId(), |
42
|
|
|
// 'merchantId' => $computopApiPayPalExpressPrepareResponseTransfer->getMid(), |
43
|
|
|
// 'payId' => $computopApiPayPalExpressPrepareResponseTransfer->getPayID() |
44
|
|
|
// ]); |
45
|
|
|
|
46
|
|
|
return new JsonResponse([ |
47
|
|
|
'orderId' => '1MB40413MG869772K', |
48
|
|
|
'merchantId' => 'spryker_test', |
49
|
|
|
'payId' => 'f3a0268fd98e4989938903c9c0e8760e', |
50
|
|
|
'clientId' => 'test', |
51
|
|
|
'currency' => 'EUR' |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
57
|
|
|
* |
58
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
59
|
|
|
*/ |
60
|
|
|
public function placeOrderPayPalExpressAction(Request $request): RedirectResponse |
61
|
|
|
{ |
62
|
|
|
$quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote(); |
63
|
|
|
$payPalExpressInitHandler = $this->getFactory()->createComputopPayPalExpressInitHandler(); |
64
|
|
|
$payPalExpressInitHandler->handle($quoteTransfer, $request->query->all()); |
65
|
|
|
|
66
|
|
|
return $this->redirectResponseInternal(static::ROUTE_NAME_CHECKOUT_PLACE_ORDER); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
71
|
|
|
* |
72
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
73
|
|
|
*/ |
74
|
|
|
public function completeOrderPayPalExpressAction(Request $request): RedirectResponse |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
$quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote(); |
77
|
|
|
$payPalExpressCompleteHandler = $this->getFactory()->createComputopPayPalExpressCompleteHandler(); |
78
|
|
|
|
79
|
|
|
$payPalExpressCompleteHandler->handle($quoteTransfer); |
80
|
|
|
|
81
|
|
|
return $this->redirectResponseInternal(static::ROUTE_NAME_CHECKOUT_SUCCESS); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|