local/modules/StripePayment/Hook/StripePaymentHook.php line 64

Open in your IDE?
  1. <?php
  2. namespace StripePayment\Hook;
  3. use StripePayment\StripePayment;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. use Thelia\Core\Event\Hook\HookRenderEvent;
  6. use Thelia\Core\Hook\BaseHook;
  7. use Thelia\Core\HttpFoundation\Request;
  8. use Thelia\TaxEngine\TaxEngine;
  9. /**
  10.  * Class StripePaymentHook
  11.  * @package StripePayment\Hook
  12.  * @author Etienne Perriere - OpenStudio <eperriere@openstudio.fr>
  13.  */
  14. class StripePaymentHook extends BaseHook
  15. {
  16.     protected $request;
  17.     protected $taxEngine;
  18.     public function __construct(Request $requestTaxEngine $taxEngine)
  19.     {
  20.         $this->request $request;
  21.         $this->taxEngine $taxEngine;
  22.     }
  23.     public function includeStripe(HookRenderEvent $event)
  24.     {
  25.         if(StripePayment::getConfigValue('stripe_element')){
  26.             $publicKey StripePayment::getConfigValue('publishable_key');
  27.             $clientSecret $this->request->getSession()->get(StripePayment::PAYMENT_INTENT_SECRET_SESSION_KEY);
  28.             $currency strtolower($this->request->getSession()->getCurrency()->getCode());
  29.             $country $this->taxEngine->getDeliveryCountry()->getIsoalpha2();
  30.             $event->add($this->render(
  31.                 'assets/js/stripe-js.html',
  32.                 [
  33.                     'stripe_module_id' => $this->getModule()->getModuleId(),
  34.                     'public_key' => $publicKey,
  35.                     'oneClickPayment' => StripePayment::getConfigValue(StripePayment::ONE_CLICK_PAYMENTfalse),
  36.                     'clientSecret' => $clientSecret,
  37.                     'currency' => $currency,
  38.                     'country' => $country
  39.                 ]
  40.             ));
  41.         }
  42.     }
  43.     public function declareStripeOnClickEvent(HookRenderEvent $event)
  44.     {
  45.         if(StripePayment::getConfigValue('stripe_element')){
  46.             $publicKey StripePayment::getConfigValue('publishable_key');
  47.             $event->add($this->render(
  48.                 'assets/js/order-invoice-after-js-include.html',
  49.                 [
  50.                     'stripe_module_id' => $this->getModule()->getModuleId(),
  51.                     'public_key' => $publicKey
  52.                 ]
  53.             ));
  54.         }
  55.     }
  56.     public function includeStripeJsV3(HookRenderEvent $event)
  57.     {
  58.         $event->add('<script src="https://js.stripe.com/v3/"></script>');
  59.     }
  60.     public function onMainHeadBottom(HookRenderEvent $event)
  61.     {
  62.         $content $this->addCSS('assets/css/styles.css');
  63.         $event->add($content);
  64.     }
  65. }