local/modules/PayPal/Hook/FrontHookManager.php line 94

  1. <?php
  2. /*************************************************************************************/
  3. /*                                                                                   */
  4. /*      Thelia                                                                         */
  5. /*                                                                                   */
  6. /*      Copyright (c) OpenStudio                                                     */
  7. /*      email : info@thelia.net                                                      */
  8. /*      web : http://www.thelia.net                                                  */
  9. /*                                                                                   */
  10. /*      This program is free software; you can redistribute it and/or modify         */
  11. /*      it under the terms of the GNU General Public License as published by         */
  12. /*      the Free Software Foundation; either version 3 of the License                */
  13. /*                                                                                   */
  14. /*      This program is distributed in the hope that it will be useful,              */
  15. /*      but WITHOUT ANY WARRANTY; without even the implied warranty of               */
  16. /*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                */
  17. /*      GNU General Public License for more details.                                 */
  18. /*                                                                                   */
  19. /*      You should have received a copy of the GNU General Public License            */
  20. /*        along with this program. If not, see <http://www.gnu.org/licenses/>.         */
  21. /*                                                                                   */
  22. /*************************************************************************************/
  23. namespace PayPal\Hook;
  24. use PayPal\Model\PaypalCartQuery;
  25. use PayPal\PayPal;
  26. use PayPal\Service\Base\PayPalBaseService;
  27. use Symfony\Component\DependencyInjection\ContainerInterface;
  28. use Symfony\Component\HttpFoundation\RequestStack;
  29. use Thelia\Core\Event\Hook\HookRenderEvent;
  30. use Thelia\Core\Hook\BaseHook;
  31. use Thelia\Core\HttpFoundation\Session\Session;
  32. /**
  33.  * Class FrontHookManager
  34.  * @package PayPal\Hook
  35.  */
  36. class FrontHookManager extends BaseHook
  37. {
  38.     /** @var RequestStack */
  39.     protected $requestStack;
  40.     /** @var ContainerInterface */
  41.     protected $container;
  42.     /**
  43.      * FrontHookManager constructor.
  44.      * @param RequestStack $requestStack
  45.      * @param ContainerInterface $container
  46.      */
  47.     public function __construct(RequestStack $requestStackContainerInterface $container)
  48.     {
  49.         $this->requestStack $requestStack;
  50.         $this->container $container;
  51.     }
  52.     /**
  53.      * @param HookRenderEvent $event
  54.      */
  55.     public function onLoginMainBottom(HookRenderEvent $event)
  56.     {
  57.         $templateData $event->getArguments();
  58.         $templateData['paypal_appid'] = PayPalBaseService::getLogin();
  59.         $templateData['paypal_authend'] = PayPalBaseService::getMode();
  60.         $event->add(
  61.             $this->render(
  62.                 'paypal/login-bottom.html',
  63.                 $templateData
  64.             )
  65.         );
  66.     }
  67.     /**
  68.      * @param HookRenderEvent $event
  69.      */
  70.     public function onOrderInvoicePaymentExtra(HookRenderEvent $event)
  71.     {
  72.         $templateData $event->getArguments();
  73.         $templateData['method_paypal_with_in_context'] = PayPal::getConfigValue('method_paypal_with_in_context');
  74.         $event->add(
  75.             $this->render(
  76.                 'paypal/order-invoice-payment-extra.html',
  77.                 $templateData
  78.             )
  79.         );
  80.     }
  81.     /**
  82.      * @param HookRenderEvent $event
  83.      */
  84.     public function onOrderInvoiceBottom(HookRenderEvent $event)
  85.     {
  86.         $templateData $event->getArguments();
  87.         $templateData['paypal_mode'] = PayPalBaseService::getMode();
  88.         $templateData['paypal_merchantid'] = PayPalBaseService::getMerchantId();
  89.         $event->add(
  90.             $this->render(
  91.                 'paypal/order-invoice-bottom.html',
  92.                 $templateData
  93.             )
  94.         );
  95.     }
  96.     public function onOrderInvoiceJavascriptInitialization(HookRenderEvent $event)
  97.     {
  98.         $render $this->render(
  99.             'paypal/order-invoice-js.html',
  100.             [
  101.                 'module_id' => PayPal::getModuleId(),
  102.             ]
  103.         );
  104.         $event->add($render);
  105.     }
  106.     /**
  107.      * @param HookRenderEvent $event
  108.      */
  109.     public function onOrderPlacedAdditionalPaymentInfo(HookRenderEvent $event)
  110.     {
  111.         $templateData $event->getArguments();
  112.         $event->add(
  113.             $this->render(
  114.                 'paypal/order-placed-additional-payment-info.html',
  115.                 $templateData
  116.             )
  117.         );
  118.     }
  119.     /**
  120.      * @param HookRenderEvent $event
  121.      */
  122.     public function onCartBottom(HookRenderEvent $event)
  123.     {
  124.         $payPal = new PayPal();
  125.         $payPal->setContainer($this->container);
  126.         if (PayPal::getConfigValue('method_express_checkout') == && $payPal->isValidPayment()) {
  127.             $templateData $event->getArguments();
  128.             $templateData['paypal_mode'] = PayPalBaseService::getMode();
  129.             $templateData['paypal_merchantid'] = PayPalBaseService::getMerchantId();
  130.             $event->add(
  131.                 $this->render(
  132.                     'paypal/cart-bottom.html',
  133.                     $templateData
  134.                 )
  135.             );
  136.         }
  137.     }
  138.     /**
  139.      * @param HookRenderEvent $event
  140.      */
  141.     public function onOrderDeliveryFormBottom(HookRenderEvent $event)
  142.     {
  143.         if ($this->isValidExpressCheckout()) {
  144.             $templateData $event->getArguments();
  145.             $event->add(
  146.                 $this->render(
  147.                     'paypal/order-delivery-bottom.html',
  148.                     $templateData
  149.                 )
  150.             );
  151.         }
  152.     }
  153.     /**
  154.      * @param HookRenderEvent $event
  155.      */
  156.     public function onOrderAfterJavascriptInclude(HookRenderEvent $event)
  157.     {
  158.         if ($this->isValidExpressCheckout()) {
  159.             $templateData $event->getArguments();
  160.             $event->add(
  161.                 $this->render(
  162.                     'paypal/order-delivery-bottom-js.html',
  163.                     $templateData
  164.                 )
  165.             );
  166.         }
  167.     }
  168.     protected function isValidExpressCheckout()
  169.     {
  170.         $isValid false;
  171.         /** @var Session $session */
  172.         $session $this->requestStack->getCurrentRequest()->getSession();
  173.         $cart $session->getSessionCart($this->dispatcher);
  174.         $payPal = new PayPal();
  175.         $payPal->setContainer($this->container);
  176.         if (PayPal::getConfigValue('method_express_checkout') == && $payPal->isValidPayment()) {
  177.             if (null !== $payPalCart PaypalCartQuery::create()->findOneById($cart->getId())) {
  178.                 if ($payPalCart->getExpressPaymentId() && $payPalCart->getExpressPayerId() && $payPalCart->getExpressToken()) {
  179.                     $isValid true;
  180.                 }
  181.             }
  182.         }
  183.         return $isValid;
  184.     }
  185. }