custom/plugins/EasyCreditRatenkauf/src/Subscriber/CheckoutOrderPlacedSubscriber.php line 41

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * (c) NETZKOLLEKTIV GmbH <kontakt@netzkollektiv.com>
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Netzkollektiv\EasyCredit\Subscriber;
  9. use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
  10. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  11. use Shopware\Core\Framework\Context;
  12. use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Netzkollektiv\EasyCredit\EasyCreditRatenkauf;
  15. use Netzkollektiv\EasyCredit\Api\Storage;
  16. class CheckoutOrderPlacedSubscriber implements EventSubscriberInterface
  17. {
  18.     private EntityRepository $orderTransactionRepository;
  19.     private Storage $storage;
  20.     public function __construct(
  21.         EntityRepository $orderTransactionRepository,
  22.         Storage $storage
  23.     ) {
  24.         $this->orderTransactionRepository $orderTransactionRepository;
  25.         $this->storage $storage;
  26.     }
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [
  30.             CheckoutOrderPlacedEvent::class => 'addPaymentStateData',
  31.         ];
  32.     }
  33.     public function addPaymentStateData(CheckoutOrderPlacedEvent $event)
  34.     {
  35.         $order $event->getOrder();
  36.         $context $event->getContext();
  37.         $this->persistPaymentStateData(
  38.             $order->getTransactions()->first(),
  39.             $context
  40.         );
  41.     }
  42.     protected function persistPaymentStateData(
  43.         OrderTransactionEntity $transaction,
  44.         Context $context
  45.     ): void {
  46.         $data = [
  47.             'id' => $transaction->getId(),
  48.             'customFields' => [
  49.                 EasyCreditRatenkauf::ORDER_TRANSACTION_CUSTOM_FIELDS_EASYCREDIT_TRANSACTION_ID => $this->storage->get('transaction_id'),
  50.                 EasyCreditRatenkauf::ORDER_TRANSACTION_CUSTOM_FIELDS_EASYCREDIT_TECHNICAL_TRANSACTION_ID => $this->storage->get('token')
  51.             ],
  52.         ];
  53.         $this->orderTransactionRepository->update([$data], $context);
  54.     }
  55. }