src/Service/App/Merchant/Subscription/Listener/ErrorPaymentListener.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Service\App\Merchant\Subscription\Listener;
  3. use App\Entity\Merchant\PlanProjectNotificationSettingsEntity;
  4. use App\Entity\Merchant\PlanSubscriptionEntity;
  5. use App\Repository\Merchant\Contract\IOrderRepository;
  6. use App\Service\App\Merchant\CustomFeature\Implementation\SubscriptionCustomFeature;
  7. use App\Service\App\Merchant\Payment\Event\ErrorPaymentEvent;
  8. use App\Service\App\Merchant\Subscription\Contract\ISendSubscriptionNotificationService;
  9. use App\Types\PlanProjectNotificationType;
  10. class ErrorPaymentListener extends AbstractSubscriptionListener
  11. {
  12.     /**
  13.      * Constructor
  14.      *
  15.      * @param SubscriptionCustomFeature $subscriptionCustomFeature
  16.      * @param IOrderRepository $orderRepository
  17.      * @param ISendSubscriptionNotificationService $sendSubscriptionNotificationService
  18.      */
  19.     public function __construct(
  20.         SubscriptionCustomFeature $subscriptionCustomFeature,
  21.         IOrderRepository $orderRepository,
  22.         ISendSubscriptionNotificationService $sendSubscriptionNotificationService
  23.     )
  24.     {
  25.         parent::__construct($subscriptionCustomFeature$orderRepository$sendSubscriptionNotificationService);
  26.     }
  27.     /**
  28.      * Listen on confirm payment event
  29.      *
  30.      * @param ErrorPaymentEvent $event
  31.      * @return void
  32.      */
  33.     public function onAction(ErrorPaymentEvent $event): void
  34.     {
  35.         $this->handleEvent($event->getRequest()->getId(), PlanProjectNotificationType::NOTIFICATION_RENEW_FAILED);
  36.     }
  37.     /**
  38.      * Check if notification should be sent
  39.      *
  40.      * @param PlanProjectNotificationSettingsEntity|null $notificationSettings
  41.      * @param PlanSubscriptionEntity $subscription
  42.      * @return bool
  43.      */
  44.     protected function shouldSend(
  45.         ?PlanProjectNotificationSettingsEntity $notificationSettingsPlanSubscriptionEntity $subscription
  46.     ): bool
  47.     {
  48.         if (!$subscription->hasSubscriptionPlan()) {
  49.             return false;
  50.         }
  51.         return $notificationSettings?->isNotificationFail() ?? false;
  52.     }
  53. }