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); |
|
|
|
|
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
|
|
|
|