src/Services/Transaction/Workflow/EventSubscriber/Internal/OutboundTrxSubscriber.php line 83

Open in your IDE?
  1. <?php
  2. namespace App\Services\Transaction\Workflow\EventSubscriber\Internal;
  3. use App\Services\Transaction\StatusManagement\ToSignTransactionComponent;
  4. use App\Services\Transaction\Fee\Builder\FeeBuilder;
  5. use App\Services\Transaction\Fee\PaymentFeeService;
  6. use App\Services\Transaction\FeeTransactionService;
  7. use App\Services\Transaction\TransactionCancelService;
  8. use App\Services\Transaction\TransactionReturnService;
  9. use App\Services\Transaction\TransactionService;
  10. use App\Entity\Transaction;
  11. use App\Repository\TransactionRepository;
  12. use BrokerAction\DTO\TransactionMessage\MessageComponent\Payload;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Symfony\Component\Workflow\Event\Event;
  15. /**
  16.  * Class OutboundTrxSubscriber.
  17.  */
  18. class OutboundTrxSubscriber implements EventSubscriberInterface
  19. {
  20.     /**
  21.      * @var FeeTransactionService
  22.      */
  23.     private $feeTransactionService;
  24.     /**
  25.      * @var TransactionReturnService
  26.      */
  27.     private $trxReturnService;
  28.     /**
  29.      * @var PaymentFeeService
  30.      */
  31.     private $paymentFeeService;
  32.     public function __construct(
  33.         FeeTransactionService $feeTransactionService,
  34.         TransactionRepository $transactionRepository,
  35.         TransactionService $transactionService,
  36.         FeeBuilder $feeBuilder,
  37.         TransactionReturnService $trxReturnService,
  38.         ToSignTransactionComponent $toSignTransactionComponent,
  39.         TransactionCancelService $trxCancelService,
  40.         PaymentFeeService $paymentFeeService
  41.     ) {
  42.         $this->feeTransactionService $feeTransactionService;
  43.         $this->transactionRepository $transactionRepository;
  44.         $this->transactionService $transactionService;
  45.         $this->feeBuilder $feeBuilder;
  46.         $this->trxReturnService $trxReturnService;
  47.         $this->toSignTransactionComponent $toSignTransactionComponent;
  48.         $this->trxCancelService $trxCancelService;
  49.         $this->paymentFeeService $paymentFeeService;
  50.     }
  51.     public static function getSubscribedEvents()
  52.     {
  53.         return [
  54.             'workflow.internal_transaction_creating.completed.reject' => 'cancelOutboundMainTrx',
  55.             'workflow.internal_transaction_creating.completed.set_reserved' => 'makeOutboundTrx',
  56.         ];
  57.     }
  58.     public function cancelOutboundMainTrx(Event $event)
  59.     {
  60.         /** @var Transaction $pmtTrx */
  61.         $pmtTrx $event->getSubject()->getEntity();
  62.         $isRejectedByBank $event->getTransition()->getFroms()[0] == 'review';
  63.         if (
  64.             !$isRejectedByBank
  65.             && ($pmtTrx->hasTypePayment() || $pmtTrx->hasTypePaymentReturn())
  66.             && $pmtTrx->getOutbound() && $pmtTrx->isMoneyReleased()
  67.         ) {
  68.             $this->trxReturnService->processSepaSentButRejectedTrx($pmtTrx);
  69.         }
  70.         $this->feeTransactionService->cancelFeeByMainTrx($pmtTrx);
  71.     }
  72.     public function makeOutboundTrx(Event $event)
  73.     {
  74.         /** @var Transaction $mainTransaction */
  75.         $mainTransaction $event->getSubject()->getEntity();
  76.         $product $mainTransaction->getProduct();
  77.         if ($product->debtorPaysFee() && !$mainTransaction->isDropFees()) {
  78.             $this->paymentFeeService->createOutbound(new Payload(['transaction_id' => $mainTransaction->getId()]));
  79.         }
  80.     }
  81. }