src/Integration/Simplypay/Subscribers/SimplypayInitBookingPaymentEventSubscriber.php line 47

Open in your IDE?
  1. <?php
  2. namespace Harmonizely\Integration\Simplypay\Subscribers;
  3. use Harmonizely\CalendarEvents;
  4. use Harmonizely\Model\EventInterface;
  5. use Harmonizely\Model\EventPayment;
  6. use Harmonizely\Model\EventTypeInterface;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\EventDispatcher\GenericEvent;
  9. use Harmonizely\Integration\Simplypay\Contract\SimplypayGetIntegrationConfigInterface;
  10. class SimplypayInitBookingPaymentEventSubscriber implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @var SimplypayGetIntegrationConfigInterface
  14.      */
  15.     private SimplypayGetIntegrationConfigInterface $getIntegrationConfig;
  16.     /**
  17.      * @param SimplypayGetIntegrationConfigInterface $getIntegrationConfig
  18.      */
  19.     public function __construct(SimplypayGetIntegrationConfigInterface $getIntegrationConfig)
  20.     {
  21.         $this->getIntegrationConfig $getIntegrationConfig;
  22.     }
  23.     /**
  24.      * Subscribe to events
  25.      *
  26.      * @return string[]
  27.      */
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             CalendarEvents::EVENT_PRE_CREATE => 'onEventPreCreate',
  32.         ];
  33.     }
  34.     /**
  35.      * Before create event
  36.      *
  37.      * @param GenericEvent $event
  38.      */
  39.     public function onEventPreCreate(GenericEvent $event): void
  40.     {
  41.         $bookedEvent $event->getSubject();
  42.         if (false === $bookedEvent instanceof EventInterface) {
  43.             return;
  44.         }
  45.         $eventType $bookedEvent->getEventType();
  46.         $payment $eventType->getPayment();
  47.         if (null === $payment || EventTypeInterface::ACCEPT_PAYMENTS_SIMPLYPAY !== $eventType->getAcceptPayments()) {
  48.             return;
  49.         }
  50.         $config $this->getIntegrationConfig->perform($eventType->getUser());
  51.         if (!$config) {
  52.             return;
  53.         }
  54.         $amount $payment->getAmount();
  55.         if (!$config->isPriceIncludesTax()) {
  56.             if ($eventType->getTaxDTO()) {
  57.                 $amount *= + ($eventType->getTaxDTO()->getRatio() / 100);
  58.             }
  59.         }
  60.         $bookedEvent->setPayment(new EventPayment(
  61.             EventTypeInterface::ACCEPT_PAYMENTS_SIMPLYPAY,
  62.             round($amount2),
  63.             $payment->getCurrency(),
  64.             $bookedEvent->getPaymentSystem(),
  65.             EventPayment::STATUS_PENDING,
  66.             null,
  67.             $config && $config->isOverwritePersonal()
  68.         ));
  69.     }
  70. }