src/EventHandler/Payment/Stripe/StripePayEvent.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\EventHandler\Payment\Stripe;
  3. use App\Entity\ShopOrder;
  4. use App\EventListener\Payment\Stripe\StripeEvent;
  5. use App\Repository\ShopOrderRepository;
  6. use App\Service\Payment\Stripe\StripePaymentService;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Stripe\Checkout\Session;
  9. use Stripe\Event;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class StripePayEvent implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var EntityManagerInterface
  15.      */
  16.     private $entityManager;
  17.     /**
  18.      * @var StripePaymentService
  19.      */
  20.     private $stripePaymentService;
  21.     /**
  22.      * @var ShopOrderRepository
  23.      */
  24.     private $shopOrderRepository;
  25.     public function __construct(
  26.         EntityManagerInterface $entityManager,
  27.         StripePaymentService $stripePaymentService,
  28.         ShopOrderRepository $shopOrderRepository
  29.     )
  30.     {
  31.         $this->entityManager $entityManager;
  32.         $this->stripePaymentService $stripePaymentService;
  33.         $this->shopOrderRepository $shopOrderRepository;
  34.     }
  35.     public static function getSubscribedEvents(): array
  36.     {
  37.         return [
  38.             Event::CHECKOUT_SESSION_COMPLETED => 'onCheckoutSessionCompleted'
  39.         ];
  40.     }
  41.     public function onCheckoutSessionCompleted(StripeEvent $stripeEvent)
  42.     {
  43.         /** @var Session $session */
  44.         $session $stripeEvent->getResource();
  45.         $paymentData $this->stripePaymentService->getPaymentDataFromStripeSession($session);
  46.         $this->shopOrderRepository->find($paymentData['orderId'])->setPaymentStatus(ShopOrder::PAYMENT_STATUTES['payed']);
  47.         $this->entityManager->flush();
  48.     }
  49. }