src/Services/Transaction/Workflow/EventSubscriber/Sepa/PaymentReturn/RejectTransactionSubscriber.php line 48

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