src/EventListener/Payment/CommonProcess.php line 28

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XCart\EventListener\Payment;
  7. use Psr\Log\LoggerAwareInterface;
  8. use Psr\Log\LoggerAwareTrait;
  9. use XCart\Event\Payment\PaymentActionEvent;
  10. use XCart\Payment\RequestProcessor;
  11. use XLite\Core\Mailer;
  12. use XLite\Core\OrderHistory;
  13. use XLite\Core\Translation;
  14. final class CommonProcess implements LoggerAwareInterface
  15. {
  16.     use LoggerAwareTrait;
  17.     public function __construct(
  18.         private Translation $translation,
  19.         private OrderHistory $orderHistory
  20.     ) {
  21.     }
  22.     public function onPaymentActionPreProcess(PaymentActionEvent $event): void
  23.     {
  24.         $this->logger->debug(
  25.             $event->getProcessorServiceName() . ' payment gateway : return',
  26.             [
  27.                 'action'    => $event->getAction(),
  28.                 'data'      => $event->getData(),
  29.                 'meta_data' => $event->getMetaData(),
  30.             ]
  31.         );
  32.     }
  33.     public function onPaymentActionPostProcess(PaymentActionEvent $event): void
  34.     {
  35.         $transaction $event->getTransaction();
  36.         if ($event->getOutputCode() === RequestProcessor::OUTPUT_CODE_FAILED && !$transaction->getDataCell('cart_items')) {
  37.             // Failed transaction: Register info about cart items
  38.             $event->addOutputTransactionData(
  39.                 'cart_items',
  40.                 serialize($transaction->getCartItems()),
  41.                 'Cart items'
  42.             );
  43.         }
  44.         $description $this->translation->translate($transaction->getHistoryEventDescription(), $transaction->getHistoryEventDescriptionData());
  45.         $this->orderHistory->registerTransaction(
  46.             $transaction->getOrder()->getOrderId(),
  47.             $description,
  48.             $transaction->getEventData()
  49.         );
  50.         if ($event->getOutputCode() === RequestProcessor::OUTPUT_CODE_FAILED) {
  51.             // Send notification 'Failed transaction' to the Orders department
  52.             Mailer::sendFailedTransactionAdmin($transaction);
  53.         }
  54.     }
  55. }