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
|
|
|
public const IS_PAYPAL_ENABLED = true; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
26
|
|
|
* |
27
|
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse |
28
|
|
|
*/ |
29
|
|
|
public function successAction(Request $request): Response |
30
|
|
|
{ |
31
|
|
|
if (!self::IS_PAYPAL_ENABLED) { |
32
|
|
|
echo 'The payment method PayPal Express is not an officially approved integration and must not be used without prior agreement with either Braintree and/or Spryker.'; |
33
|
|
|
|
34
|
|
|
return; |
|
|
|
|
35
|
|
|
|
36
|
|
|
} |
37
|
|
|
$payload = $this->getFactory()->getUtilEncodingService()->decodeJson($request->getContent(), true); |
38
|
|
|
|
39
|
|
|
$this->getFactory()->createResponseProcessor()->processSuccessResponse($payload); |
|
|
|
|
40
|
|
|
|
41
|
|
|
return $this->jsonResponse([ |
42
|
|
|
'redirectUrl' => $this->getApplication()->path(CheckoutPageControllerProvider::CHECKOUT_SUMMARY), |
|
|
|
|
43
|
|
|
]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
48
|
|
|
* |
49
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
50
|
|
|
*/ |
51
|
|
|
public function addShipmentAction(Request $request): Response |
52
|
|
|
{ |
53
|
|
|
$quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote(); |
54
|
|
|
|
55
|
|
|
$form = $this->getFactory()->getFormFactory()->create( |
56
|
|
|
CheckoutShipmentForm::class, |
57
|
|
|
$this->getFactory()->createBraintreePaypalExpressShipmentFormDataProvider()->getData($quoteTransfer), |
58
|
|
|
$this->getFactory()->createBraintreePaypalExpressShipmentFormDataProvider()->getOptions($quoteTransfer) |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
$form->handleRequest($request); |
62
|
|
|
|
63
|
|
|
if ($form->isValid()) { |
64
|
|
|
$this->getFactory()->createQuoteExpander()->expandQuoteWithShipmentMethod( |
65
|
|
|
$request, |
66
|
|
|
$form->getData()->getShipment()->getShipmentSelection() |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
return $this->redirectResponseInternal(CheckoutPageControllerProvider::CHECKOUT_SUMMARY); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$this->getFactory()->getMessengerClient()->addErrorMessage(static::TRANSLATION_INVALID_SHIPMENT_METHOD); |
73
|
|
|
|
74
|
|
|
return $this->redirectResponseInternal(CheckoutPageControllerProvider::CHECKOUT_SUMMARY); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|