src/Services/Transaction/Workflow/EventSubscriber/Sepa/Outbound/OutboundTrxSubscriber.php line 76

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