custom/plugins/EasyCreditRatenkauf/src/Subscriber/OrderStatus.php line 62

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /*
  3.  * (c) NETZKOLLEKTIV GmbH <kontakt@netzkollektiv.com>
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Netzkollektiv\EasyCredit\Subscriber;
  8. use Shopware\Core\Checkout\Order\Event\OrderStateMachineStateChangeEvent;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Netzkollektiv\EasyCredit\Setting\Service\SettingsServiceInterface;
  11. use Netzkollektiv\EasyCredit\Service\TransactionService;
  12. use Netzkollektiv\EasyCredit\Compatibility\Capabilities;
  13. use Teambank\EasyCreditApiV3\Model\CaptureRequest;
  14. use Teambank\EasyCreditApiV3\Model\RefundRequest;
  15. use Teambank\EasyCreditApiV3\Model\TransactionResponse;
  16. class OrderStatus implements EventSubscriberInterface
  17. {
  18.     private SettingsServiceInterface $settings;
  19.     private TransactionService $transactionService;
  20.     private Capabilities $caps;
  21.     public function __construct(
  22.         SettingsServiceInterface $settingsService,
  23.         TransactionService $transactionService,
  24.         Capabilities $caps
  25.     ) {
  26.         $this->settings $settingsService;
  27.         $this->transactionService $transactionService;
  28.         $this->caps $caps;
  29.     }
  30.     public static function getSubscribedEvents(): array
  31.     {
  32.         return [
  33.             'state_enter.order_delivery.state.shipped' => 'onOrderShipped',
  34.             'state_enter.order_delivery.state.returned' => 'onOrderReturned',
  35.         ];
  36.     }
  37.     public function onOrderShipped(OrderStateMachineStateChangeEvent $event): void
  38.     {
  39.         if ($this->caps->hasFlowBuilder()) {
  40.             return;
  41.         }
  42.         $markShipped $this->settings
  43.             ->getSettings($event->getSalesChannelId(), false)
  44.             ->getMarkShipped();
  45.         if (!$markShipped) {
  46.             return;
  47.         }
  48.         $this->transactionService->captureTransaction($event);
  49.     }
  50.     public function onOrderReturned(OrderStateMachineStateChangeEvent $event): void
  51.     {
  52.         if ($this->caps->hasFlowBuilder()) {
  53.             return;
  54.         }
  55.         $markRefunded $this->settings
  56.             ->getSettings($event->getSalesChannelId(), false)
  57.             ->getMarkRefunded();
  58.             
  59.         if (!$markRefunded) {
  60.             return;
  61.         }
  62.         
  63.         $this->transactionService->refundTransaction($event);
  64.     }
  65. }