src/Services/Transaction/Workflow/EventSubscriber/Internal/PaymentReturn/OutboundTrxSubscriber.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\Services\Transaction\Workflow\EventSubscriber\Internal\PaymentReturn;
  3. use App\Services\Transaction\StatusManagement\ToSignTransactionComponent;
  4. use App\Services\Transaction\FeeTransactionService;
  5. use App\Services\Transaction\TransactionCancelService;
  6. use App\Services\Transaction\TransactionReturnService;
  7. use App\Entity\Transaction;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\Workflow\Event\Event;
  10. class OutboundTrxSubscriber implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @var FeeTransactionService
  14.      */
  15.     protected $feeTransactionService;
  16.     /**
  17.      * @var TransactionReturnService
  18.      */
  19.     protected $trxReturnService;
  20.     public function __construct(
  21.         FeeTransactionService $feeTransactionService,
  22.         TransactionReturnService $trxReturnService,
  23.         TransactionCancelService $trxCancelService,
  24.         ToSignTransactionComponent $toSignTransactionComponent
  25.     ) {
  26.         $this->feeTransactionService $feeTransactionService;
  27.         $this->trxReturnService $trxReturnService;
  28.         $this->trxCancelService $trxCancelService;
  29.         $this->toSignTransactionComponent $toSignTransactionComponent;
  30.     }
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             'workflow.internal_payment_return_outbound.completed.reject' => 'cancelOutboundMainTrx',
  35.         ];
  36.     }
  37.     public function cancelOutboundMainTrx(Event $event)
  38.     {
  39.         /** @var Transaction $pmtTrx */
  40.         $pmtTrx $event->getSubject()->getEntity();
  41.         $isRejectedByBank $event->getTransition()->getFroms()[0] == 'review';
  42.         if (
  43.             !$isRejectedByBank
  44.             && ($pmtTrx->hasTypePayment() || $pmtTrx->hasTypePaymentReturn())
  45.             && $pmtTrx->getOutbound() && $pmtTrx->isMoneyReleased()
  46.         ) {
  47.             $this->trxReturnService->processSepaSentButRejectedTrx($pmtTrx);
  48.         }
  49.         $this->feeTransactionService->cancelFeeByMainTrx($pmtTrx);
  50.     }
  51. }