src/Services/Transaction/Workflow/EventSubscriber/Fps/Outbound/OutboundTrxSubscriber.php line 61

Open in your IDE?
  1. <?php
  2. namespace App\Services\Transaction\Workflow\EventSubscriber\Fps\Outbound;
  3. use App\Services\Transaction\StatusManagement\ToSignTransactionComponent;
  4. use App\Services\Transaction\Fee\PaymentFeeService;
  5. use App\Services\Transaction\FeeTransactionService;
  6. use App\Services\Transaction\TransactionCancelService;
  7. use App\Entity\Transaction;
  8. use BrokerAction\DTO\TransactionMessage\MessageComponent\Payload;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\Workflow\Event\Event;
  11. class OutboundTrxSubscriber implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var TransactionCancelService
  15.      */
  16.     protected $trxCancelService;
  17.     /**
  18.      * @var FeeTransactionService
  19.      */
  20.     protected $feeTransactionService;
  21.     /**
  22.      * @var PaymentFeeService
  23.      */
  24.     private $paymentFeeService;
  25.     public function __construct(
  26.         TransactionCancelService $trxReadyToClearComponent,
  27.         FeeTransactionService $feeTransactionService,
  28.         ToSignTransactionComponent $toSignTransactionComponent,
  29.         PaymentFeeService $paymentFeeService
  30.     ) {
  31.         $this->trxCancelService $trxReadyToClearComponent;
  32.         $this->feeTransactionService $feeTransactionService;
  33.         $this->toSignTransactionComponent $toSignTransactionComponent;
  34.         $this->paymentFeeService $paymentFeeService;
  35.     }
  36.     public static function getSubscribedEvents()
  37.     {
  38.         return [
  39.             'workflow.starling_payment_outbound.completed.set_reserved' => 'makeOutboundTrx',
  40.             'workflow.starling_payment_outbound.enter.rejected' => 'cancelOutboundMainTrx',
  41.         ];
  42.     }
  43.     public function makeOutboundTrx(Event $event)
  44.     {
  45.         /** @var Transaction $mainTransaction */
  46.         $mainTransaction $event->getSubject()->getEntity();
  47.         $product $mainTransaction->getProduct();
  48.         if ($product->debtorPaysFee() && !$mainTransaction->isDropFees()) {
  49.             $this->paymentFeeService->createOutbound(new Payload(['transaction_id' => $mainTransaction->getId()]));
  50.         }
  51.     }
  52.     public function cancelOutboundMainTrx(Event $event)
  53.     {
  54.         /** @var Transaction $pmtTrx */
  55.         $mainTransaction $event->getSubject()->getEntity();
  56.         $this->feeTransactionService->cancelFeeByMainTrx($mainTransaction);
  57.     }
  58. }