src/AtechNet/CoreBundle/Helper/Furbify/OrderHelper.php line 58

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Helper\Furbify;
  3. use App\AtechNet\CoreBundle\Entity\Attribute;
  4. use App\AtechNet\CoreBundle\Entity\Basket;
  5. use App\AtechNet\CoreBundle\Entity\BasketItem;
  6. use App\AtechNet\CoreBundle\Entity\Coupon;
  7. use App\AtechNet\CoreBundle\Entity\Customer;
  8. use App\AtechNet\CoreBundle\Entity\CustomerAddress;
  9. use App\AtechNet\CoreBundle\Entity\CustomerBillingoData;
  10. use App\AtechNet\CoreBundle\Entity\Document;
  11. use App\AtechNet\CoreBundle\Entity\DocumentGroup;
  12. use App\AtechNet\CoreBundle\Entity\Domain;
  13. use App\AtechNet\CoreBundle\Entity\DomainPaymentType;
  14. use App\AtechNet\CoreBundle\Entity\DomainShippingType;
  15. use App\AtechNet\CoreBundle\Entity\Order;
  16. use App\AtechNet\CoreBundle\Entity\OrderItem;
  17. use App\AtechNet\CoreBundle\Entity\PickupPoint;
  18. use App\AtechNet\CoreBundle\Entity\Product;
  19. use App\AtechNet\CoreBundle\Entity\ProductType;
  20. use App\AtechNet\CoreBundle\Entity\UnasTranslator;
  21. use App\AtechNet\CoreBundle\Entity\User;
  22. use App\AtechNet\CoreBundle\Enum\PaymentType;
  23. use App\AtechNet\CoreBundle\Helper\Billingo;
  24. use App\AtechNet\CoreBundle\Helper\Instacash;
  25. use App\AtechNet\CoreBundle\Helper\Milpay;
  26. use App\AtechNet\CoreBundle\Repository\OrderRepository;
  27. use GoPay\Definition\Response\PaymentStatus;
  28. use GuzzleHttp\Exception\GuzzleException;
  29. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  30. use Symfony\Component\HttpFoundation\Request;
  31. use Symfony\Contracts\Translation\TranslatorInterface;
  32. class OrderHelper
  33. {
  34.     private $request;
  35.     private $entityManager;
  36.     private $translator;
  37.     private $dbTranslator;
  38.     private $container;
  39.     private $environment;
  40.     public static string $apiToken = '423235h54gf42154132g541tf45rer4832r24364yrd231rf4tgtf432r3246h324rf36y4fde3r432';
  41.     /**
  42.      * OrderHelper constructor.
  43.      *
  44.      * @param $request
  45.      * @param $entityManager
  46.      * @param $translator
  47.      * @param $dbTranslator
  48.      * @param $router
  49.      * @param $mailer
  50.      * @param $mailerReplyTo
  51.      * @param $cloudFlareConfig
  52.      */
  53.     public function __construct($request, $entityManager, $translator, $dbTranslator, $router, $mailer, $mailerReplyTo, $cloudFlareConfig, $environment)
  54.     {
  55.         $this->request = $request;
  56.         $this->entityManager = $entityManager;
  57.         $this->translator = $translator;
  58.         $this->dbTranslator = $dbTranslator;
  59.         $this->router = $router;
  60.         $this->mailer = $mailer;
  61.         $this->mailerReplyTo = $mailerReplyTo;
  62.         $this->cloudFlareConfig = $cloudFlareConfig;
  63.         $this->environment = $environment;
  64.     }
  65.     /**
  66.      * @param Order $order
  67.      * @param ProductHelper $productHelper
  68.      * @param $contactInfos
  69.      * @param array $whitelistCouponCodes
  70.      * @param bool $bccSalesManager
  71.      * @param bool $confirmOrder
  72.      *
  73.      * @return array
  74.      */
  75.     public function sendOrderEmail(Order $order, ProductHelper $productHelper, $contactInfos, array $whitelistCouponCodes = [], bool $bccSalesManager = false, $confirmOrder = false): array
  76.     {
  77.         if ($unasDomainSetting = $order->getUnasOrderDomainSetting()) {
  78.             $this->translator->setLocale($unasDomainSetting->getValue());
  79.             $unasData['isUnas'] = true;
  80.             $unasData['unasDomain'] = "https://www.furbify.{$unasDomainSetting->getValue()}/";
  81.             $unasData['externalOrderId'] = $order->getExternalOrderCode();
  82.         }
  83.         else {
  84.             $unasData['isUnas'] = false;
  85.         }
  86.         $orderData = $this->getDataFromEmail($order, $productHelper, $contactInfos, $whitelistCouponCodes);
  87.         $emailData = array_merge($orderData['emailData'], $unasData);
  88.         $response = $orderData['response'];
  89.         // Order Confirmed Email
  90.         $emailData['confirmOrder'] = $confirmOrder;
  91.         $domain = $order->getDomain();
  92.         $emailData['domainId'] = $order->getDomain()->getId();
  93.         $emailData['createdDate'] = $order->getCreated();
  94.         if ($confirmOrder) {
  95.             $subject = 'Furbify - ' . $this->translator->trans('Order confirmed') . ' ' . $order->getId();
  96.         }
  97.         else {
  98.             $subject = 'Furbify - ' . $this->translator->trans('Order') . ' ' . $order->getId();
  99.         }
  100.         $emailTo = !is_null($order->getCustomer()->getSalesManager())
  101.         && $order->getCustomer()->getSalesManager()->getId() == User::USER_ID_IMRICH_ZUBER
  102.         && !is_null($order->getCustomer()->getFinanceEmail())
  103.         && $order->getCustomer()->getFinanceEmail() != ''
  104.             ? $order->getCustomer()->getFinanceEmail()
  105.             : $order->getBillingEmail();
  106.         switch ($order->getDomain()->getId()) {
  107.             case Domain::DOMAIN_ID_RT_SK:
  108.                 $emailData['furbifyManualLink'] = 'https://www.furbify.sk/furbify-manual';
  109.                 break;
  110.             case Domain::DOMAIN_ID_RT_HU:
  111.                 $emailData['furbifyManualLink'] = 'https://www.furbify.hu/furbify-kisokos';
  112.                 break;
  113.             case Domain::DOMAIN_ID_RT_CZ:
  114.                 $emailData['furbifyManualLink'] = 'https://www.furbify.cz/furbify-manual';
  115.                 break;
  116.         }
  117.         $email = (new TemplatedEmail())
  118.             ->subject($subject)
  119.             ->to($emailTo)
  120.             ->replyTo($this->mailerReplyTo)
  121.             ->bcc('webshop@furbify.eu')
  122.             ->htmlTemplate('AtechNetCoreBundle/Email/order.html.twig')
  123.             ->context($emailData);
  124.         //for testing the email
  125.         //you need to enable this part in CheckoutController return $this->render('AtechNetCoreBundle/Email/order.html.twig', $emailSendingResult);
  126.         /*return $emailData;*/
  127.         if (
  128.             $bccSalesManager
  129.             && in_array($domain->getId(), [
  130.                 Domain::DOMAIN_ID_RT_SK,
  131.                 Domain::DOMAIN_ID_RT_HU,
  132.                 Domain::DOMAIN_ID_RT_CZ,
  133.                 Domain::DOMAIN_ID_RT_EU,
  134.                 Domain::DOMAIN_ID_WS_SK,
  135.                 Domain::DOMAIN_ID_WS_HU,
  136.                 Domain::DOMAIN_ID_WS_CZ,
  137.                 Domain::DOMAIN_ID_WS_EU,
  138.             ]) && !is_null($order->getCustomer()->getSalesManager())) {
  139.             if (!in_array($domain->getId(), [Domain::DOMAIN_ID_RT_EU, Domain::DOMAIN_ID_WS_EU])) {
  140.                 if (
  141.                     $order->getCustomer()->getSalesManager()->getId() != User::USER_ID_BEATA_SEDLAROVA
  142.                     && ((
  143.                             $order->getCustomer()->isB2B()
  144.                             && in_array($order->getDomain()->getId(), [Domain::DOMAIN_ID_RT_SK, Domain::DOMAIN_ID_RT_CZ])
  145.                         )
  146.                         || $order->getDomain()->getId() == Domain::DOMAIN_ID_WS_CZ
  147.                     )
  148.                 ) {
  149.                     $email->addBcc('bea.sedlarova@furbify.eu');
  150.                 }
  151.                 else {
  152.                     $email->addBcc($order->getCustomer()->getSalesManager()->getEmail());
  153.                 }
  154.             }
  155.             else {
  156.                 if ($domain->getId() == Domain::DOMAIN_ID_RT_EU) {
  157.                     $email->addBcc('webshop@furbify.eu');
  158.                 }
  159.                 else {
  160.                     $email->addBcc('export@furbify.eu');
  161.                 }
  162.             }
  163.         }
  164.         if ($domain->getId() == Domain::DOMAIN_ID_RT_SK) {
  165.             $email->attachFromPath('https://www.furbify.sk/storage/files/furbify-vop-2026-sk.pdf');
  166.             $email->attachFromPath('https://www.furbify.sk/storage/files/furbify-reklamacny-poriadok-2026-sk.pdf');
  167.         }
  168.         if ($domain->getId() == Domain::DOMAIN_ID_RT_CZ) {
  169.             $email->attachFromPath('https://www.furbify.cz/storage/files/furbify-vop-2026-cz.pdf');
  170.             $email->attachFromPath('https://www.furbify.cz/storage/files/furbify-reklamacny-poriadok-2026-cz.pdf');
  171.         }
  172.         if ($domain->getId() == Domain::DOMAIN_ID_RT_HU) {
  173.             $email->attachFromPath('https://www.furbify.hu/storage/files/furbify-vop-2026-hu.pdf');
  174.             $email->attachFromPath('https://www.furbify.hu/storage/files/garancialis_es_jotallasi_feltetelek_furbify.pdf');
  175.         }
  176.         $this->mailer->send($email);
  177.         $response['total'] = $emailData['total'];
  178.         $response['currency'] = $emailData['currency'];
  179.         return $response;
  180.     }
  181.     /**
  182.      * @param string $status
  183.      * @param order $order
  184.      * @param ProductHelper $productHelper
  185.      * @param $contactInfos
  186.      * @param array $whitelistCouponCodes
  187.      */
  188.     public function sendPaymentStatusEmail(string $status, Order $order, ProductHelper $productHelper, $contactInfos, array $whitelistCouponCodes = [])
  189.     {
  190.         $orderData = $this->getDataFromEmail($order, $productHelper, $contactInfos, $whitelistCouponCodes);
  191.         $emailData = $orderData['emailData'];
  192.         $response = $orderData['response'];
  193.         if ($status == 'success') {
  194.             $emailData['successfulPayment'] = true;
  195.             $subject = $this->translator->trans('Successful card payment');
  196.         }
  197.         else {
  198.             $emailData['successfulPayment'] = false;
  199.             $subject = $this->translator->trans('Unsuccessful card payment');
  200.         }
  201.         $emailData['domainId'] = $order->getDomain()->getId();
  202.         $orderRepository = $this->entityManager->getRepository(Order::class);
  203.         $emailData['publicOrderLink'] = $order->getDomain()->getUrl() .
  204.             $this->router->generate(
  205.                 'customer_order_show',
  206.                 [
  207.                     'orderId' => $order->getId(),
  208.                     'token'   => $orderRepository->generatePublicLinkToken([
  209.                         'orderId' => $order->getId(),
  210.                     ]),
  211.                 ]
  212.             );
  213.         $email = (new TemplatedEmail())
  214.             ->subject($subject)
  215.             ->to($order->getBillingEmail())
  216.             ->replyTo($this->mailerReplyTo)
  217.             ->htmlTemplate('AtechNetCoreBundle/Email/payment.html.twig')
  218.             ->context($emailData);
  219.         $this->mailer->send($email);
  220.         $response['total'] = $emailData['total'];
  221.         $response['currency'] = $emailData['currency'];
  222.         return $response;
  223.     }
  224.     /**
  225.      * @param Order $order
  226.      * @param ProductHelper $productHelper
  227.      * @param $contactInfos
  228.      * @param array $whitelistCouponCodes
  229.      *
  230.      * @return array
  231.      */
  232.     public function sendOrderShippingConfirmationEmail(Order $order, ProductHelper $productHelper, $contactInfos, array $whitelistCouponCodes = [], ?Billingo $billingoHelper = null)
  233.     {
  234.         $orderData = $this->getDataFromEmail($order, $productHelper, $contactInfos, $whitelistCouponCodes, true);
  235.         $emailData = $orderData['emailData'];
  236.         $response = $orderData['response'];
  237.         $emailAddress = !is_null($order->getCustomer()->getFinanceEmail()) && $order->getCustomer()->getFinanceEmail() != '' ? $order->getCustomer()->getFinanceEmail() : $order->getBillingEmail();
  238.         $subject = 'Furbify - ' . $this->translator->trans('Order') . ' ' . $order->getId() . ' - ' . $this->translator->trans('Package sent') . ' & ' . $this->translator->trans('Invoice in the attachment mail header');
  239.         $email = (new TemplatedEmail())
  240.             ->subject($subject)
  241.             ->to($emailAddress)
  242.             ->replyTo($this->mailerReplyTo)
  243.             ->htmlTemplate('AtechNetCoreBundle/Email/orderShippingConfirmation.html.twig')
  244.             ->attachFromPath($this->getOutinvoiceForAttachment($order, $billingoHelper))
  245.             ->context($emailData);
  246.         $trustindexEmail = $this->getTrustindexEmail($order);
  247.         if ($trustindexEmail) {
  248.             $email->addBcc($trustindexEmail);
  249.         }
  250.         $this->mailer->send($email);
  251.         $response['total'] = $emailData['total'];
  252.         $response['currency'] = $emailData['currency'];
  253.         return $response;
  254.     }
  255.     /**
  256.      * @param Order $order
  257.      * @param ProductHelper $productHelper
  258.      * @param $contactInfos
  259.      * @param array $whitelistCouponCodes
  260.      *
  261.      * @return array
  262.      */
  263.     public function sendOrderPickupConfirmationEmail(Order $order, ProductHelper $productHelper, $contactInfos, array $whitelistCouponCodes = [], ?Billingo $billingoHelper = null)
  264.     {
  265.         $orderData = $this->getDataFromEmail($order, $productHelper, $contactInfos, $whitelistCouponCodes, true);
  266.         $emailData = $orderData['emailData'];
  267.         $response = $orderData['response'];
  268.         $emailAddress = !is_null($order->getCustomer()->getFinanceEmail()) && $order->getCustomer()->getFinanceEmail() != '' ? $order->getCustomer()->getFinanceEmail() : $order->getBillingEmail();
  269.         $email = (new TemplatedEmail())
  270.             ->subject('Furbify - ' . $this->translator->trans('Order') . ' ' . $order->getId() . ' ' . $this->translator->trans('prepared'))
  271.             ->to($emailAddress)
  272.             ->replyTo($this->mailerReplyTo)
  273.             ->htmlTemplate('AtechNetCoreBundle/Email/orderPickupConfirmation.html.twig')
  274.             ->attachFromPath($this->getOutinvoiceForAttachment($order, $billingoHelper))
  275.             ->context($emailData);
  276.         $trustindexEmail = $this->getTrustindexEmail($order);
  277.         if ($trustindexEmail) {
  278.             $email->addBcc($trustindexEmail);
  279.         }
  280.         $this->mailer->send($email);
  281.         $response['total'] = $emailData['total'];
  282.         $response['currency'] = $emailData['currency'];
  283.         return $response;
  284.     }
  285.     /**
  286.      * @param Order $order
  287.      *
  288.      * @return string|null
  289.      */
  290.     private function getTrustindexEmail(Order $order): string|null
  291.     {
  292.         return match ($order->getDomain()->getId()) {
  293.             Domain::DOMAIN_ID_RT_SK => 'invite-d0d9ea14612g351d@trustindex.io',
  294.             Domain::DOMAIN_ID_RT_HU => 'invite-b304b414586g16b5@trustindex.io',
  295.             Domain::DOMAIN_ID_RT_EU => 'invite-014e1316997g1716@trustindex.io',
  296.             default => null,
  297.         };
  298.     }
  299.     /**
  300.      * @param Order $order
  301.      * @param Billingo|null $billingoHelper
  302.      *
  303.      * @throws GuzzleException
  304.      */
  305.     private function getOutinvoiceForAttachment(Order $order, ?Billingo $billingoHelper)
  306.     {
  307.         if ($order->getDomain()->getLanguage()->getCode() == 'hu' && $order->getBillingoDocuments()->count() > 0) {
  308.             /**
  309.              * @var CustomerBillingoData $billingoInvoice
  310.              */
  311.             $billingoInvoice = $order->getBillingoDocuments()->filter(function (CustomerBillingoData $cbd) {
  312.                 return $cbd->getType() == Billingo::TYPE_INVOICE;
  313.             })->last();
  314.             $pdfString = $billingoHelper->downloadDocument($billingoInvoice->getInvoiceV3Id());
  315.             $documentCode = $billingoInvoice->getInvoiceCode();
  316.             $pdfString = "data:application/pdf;base64,$pdfString";
  317.             $pdfPath = sprintf(
  318.                 '%s/%s_%d.pdf',
  319.                 sys_get_temp_dir(),
  320.                 strtolower(
  321.                     str_replace(
  322.                         ' ',
  323.                         '_',
  324.                         iconv(
  325.                             'utf-8',
  326.                             'us-ascii//TRANSLIT',
  327.                             'faktúra'
  328.                         )
  329.                     )
  330.                 ),
  331.                 $documentCode
  332.             );
  333.             $f = fopen($pdfPath, 'wb');
  334.             fwrite($f, $pdfString, strlen($pdfString));
  335.             fclose($f);
  336.             return $pdfPath;
  337.         }
  338.         else {
  339.             $invoice = false;
  340.             foreach ([DocumentGroup::TYPE_INVOICE_OUT, DocumentGroup::TYPE_INVOICE_PRE, DocumentGroup::TYPE_BILL_OF_DELIVERY] as $documentGroupId) {
  341.                 foreach ($order->getDocuments() as $document) {
  342.                     if ($document->getGroup()->getType() == $documentGroupId) {
  343.                         $invoice = $document;
  344.                         break 2;
  345.                     }
  346.                 }
  347.             }
  348.             $documentCode = $invoice->getCode();
  349.             $invoice->setSentDate(new \DateTime());
  350.             $invoice->setEmailSent($order->getBillingEmail());
  351.             $this->entityManager->flush();
  352.             $pdf = $this->entityManager->getRepository(Document::class)->createPdf($invoice, 0);
  353.             $pdfPath = sprintf(
  354.                 '%s/%s_%d.pdf',
  355.                 sys_get_temp_dir(),
  356.                 strtolower(
  357.                     str_replace(
  358.                         ' ',
  359.                         '_',
  360.                         iconv(
  361.                             'utf-8',
  362.                             'us-ascii//TRANSLIT',
  363.                             'faktúra'
  364.                         )
  365.                     )
  366.                 ),
  367.                 $documentCode
  368.             );
  369.             $pdf->output($pdfPath, 'F');
  370.             return $pdfPath;
  371.         }
  372.     }
  373.     /**
  374.      * @param Order $order
  375.      * @param ProductHelper $productHelper
  376.      * @param $contactInfos
  377.      * @param $whitelistCouponCodes
  378.      *
  379.      * @return array[]
  380.      */
  381.     public function getDataFromEmail(Order $order, ProductHelper $productHelper, $contactInfos, $whitelistCouponCodes, $hideInvoicePublicLink = false): array
  382.     {
  383.         $needTranslation = !is_null($order->getUnasOrderDomainSetting());
  384.         $translationLocal = $order->getUnasOrderDomainSetting()?->getValue();
  385.         $unasTranslatorEntity = $this->entityManager->getRepository(UnasTranslator::class);
  386.         $emailData = [];
  387.         $emailData['containsNB'] = false;
  388.         $response['marketingProducts'] = $response['marketingProductsGA4'] = '';
  389.         $domain = $order->getDomain();
  390.         $emailData['currency'] = $domain->getCurrency();
  391.         $emailData['precision'] = $domain->getPricePrecision();
  392.         if (mb_strtolower(trim($domain->getCurrency())) == 'ft') {
  393.             $emailData['currencyCode'] = 'HUF';
  394.         }
  395.         else if (mb_strtolower(trim($domain->getCurrency())) == 'kč') {
  396.             $emailData['currencyCode'] = 'CZK';
  397.         }
  398.         else {
  399.             $emailData['currencyCode'] = 'EUR';
  400.         }
  401.         $emailData['orderId'] = $order->getId();
  402.         $emailData['bankTransfer'] = $order->getPaymentType() == 3;
  403.         $emailData['dateAdded'] = $order->getCreated()->format($this->translator->trans('datetime.format'));
  404.         $emailData['customerEmail'] = $order->getBillingEmail();
  405.         $emailData['telephone'] = $order->getBillingPhone();
  406.         $emailData['greetingName'] = !is_null($order->getBillingBusinessName()) && $order->getBillingBusinessName() != '' && !is_null($order->getBillingBusinessId()) && $order->getBillingBusinessId() != '' ? $order->getBillingBusinessName() : $order->getBillingFirstName();
  407.         $format = '{businessname}' . "\n" . ($order->getBillingBusinessId() != null ? '{businessId}' . "\n" : '') . ($order->getBillingTaxId() != null ? '{taxId}' . "\n" : '') . '{firstname} {lastname}' . "\n" . '{street}' . "\n" . '{postalcode} {city}' . "\n" . '{country}';
  408.         $find = [
  409.             '{businessname}',
  410.             '{businessId}',
  411.             '{taxId}',
  412.             '{firstname}',
  413.             '{lastname}',
  414.             '{street}',
  415.             '{city}',
  416.             '{postalcode}',
  417.             '{country}',
  418.         ];
  419.         $replace = [
  420.             'businessname' => (!is_null($order->getBillingBusinessName()) && $order->getBillingBusinessName() != '') ? $order->getBillingBusinessName() : '',
  421.             'businessId'   => "<b>{$this->translator->trans('Business ID')}:</b> {$order->getBillingBusinessId()}",
  422.             'taxId'        => "<b>{$this->translator->trans('Tax ID')}:</b> {$order->getBillingTaxId()}",
  423.             'firstname'    => $order->getBillingFirstName(),
  424.             'lastname'     => $order->getBillingLastName(),
  425.             'street'       => $order->getBillingStreet(),
  426.             'city'         => $order->getBillingCity(),
  427.             'postalcode'   => $order->getBillingZip(),
  428.             'country'      => isset(CustomerAddress::getCountries()[$order->getBillingCountry()]) ? CustomerAddress::getCountries()[$order->getBillingCountry()] : $order->getBillingCountry(),
  429.         ];
  430.         $emailData['billingAddress'] = str_replace(
  431.             ["\r\n", "\r", "\n"],
  432.             '<br />',
  433.             preg_replace(
  434.                 ["/\s\s+/", "/\r\r+/", "/\n\n+/"],
  435.                 '<br />',
  436.                 trim(str_replace($find, $replace, $format))
  437.             )
  438.         );
  439.         $emailData['billingFirstName'] = $order->getBillingFirstName();
  440.         $emailData['billingLastName'] = $order->getBillingLastName();
  441.         $emailData['billingStreet'] = $order->getBillingStreet();
  442.         $emailData['billingCity'] = $order->getBillingCity();
  443.         $emailData['billingCountry'] = $order->getBillingCountry();
  444.         if ($order->useBillingAddressAsShippingAddress()) {
  445.             $emailData['shippingAddress'] = $emailData['billingAddress'];
  446.             $emailData['shippingFirstName'] = $order->getBillingFirstName();
  447.             $emailData['shippingLastName'] = $order->getBillingLastName();
  448.             $emailData['shippingStreet'] = $order->getBillingStreet();
  449.             $emailData['shippingCity'] = $order->getBillingCity();
  450.             $emailData['shippingPostalCode'] = $order->getBillingZip();
  451.             $emailData['shippingCountry'] = $order->getBillingCountry();
  452.         }
  453.         else {
  454.             $replace = [
  455.                 'businessname' => (!is_null($order->getShippingBusinessName()) && $order->getShippingBusinessName() != '') ? $order->getShippingBusinessName() : '',
  456.                 'firstname'    => $order->getShippingFirstName(),
  457.                 'lastname'     => $order->getShippingLastName(),
  458.                 'street'       => $order->getShippingStreet(),
  459.                 'city'         => $order->getShippingCity(),
  460.                 'postalcode'   => $order->getShippingZip(),
  461.                 'country'      => isset(CustomerAddress::getCountries()[$order->getShippingCountry()]) ? CustomerAddress::getCountries()[$order->getShippingCountry()] : $order->getShippingCountry(),
  462.             ];
  463.             $emailData['shippingAddress'] = str_replace(
  464.                 ["\r\n", "\r", "\n"],
  465.                 '<br />',
  466.                 preg_replace(
  467.                     ["/\s\s+/", "/\r\r+/", "/\n\n+/"],
  468.                     '<br />',
  469.                     trim(str_replace($find, $replace, $format))
  470.                 )
  471.             );
  472.             $emailData['shippingFirstName'] = $order->getShippingFirstName();
  473.             $emailData['shippingLastName'] = $order->getShippingLastName();
  474.             $emailData['shippingStreet'] = $order->getShippingStreet();
  475.             $emailData['shippingCity'] = $order->getShippingCity();
  476.             $emailData['shippingPostalCode'] = $order->getShippingZip();
  477.             $emailData['shippingCountry'] = $order->getShippingCountry();
  478.         }
  479.         $emailData['isShippedToPickupPoint'] = $order->getPickupPointSetting() || (!is_null($order->getPacketaBranchIdSetting()) && is_numeric($order->getPacketaBranchIdSetting()->getValue()));
  480.         $emailData['pickupPointAddress'] = '';
  481.         $pickupPoint = false;
  482.         if ($emailData['isShippedToPickupPoint']) {
  483.             if ($order->getPickupPointSetting()) {
  484.                 $pickupPointId = $order->getPickupPointSetting()->getValue();
  485.                 $pickupPoint = $this->entityManager->getRepository(PickupPoint::class)->findOneById($pickupPointId);
  486.                 $emailData['pickupPointAddress'] = $pickupPoint->getStreet() . ', ' . $pickupPoint->getCity() . ', ' . $pickupPoint->getZip() . ', ' . CustomerAddress::getCountries()[$pickupPoint->getCountry()];
  487.             }
  488.             if (!is_null($order->getPacketaBranchIdSetting()) && is_numeric($order->getPacketaBranchIdSetting()->getValue())) {
  489.                 $emailData['pickupPointAddress'] = $order->getPacketaBranchNameSetting()->getValue();
  490.             }
  491.             /**
  492.              * @var PickupPoint $pickupPoint
  493.              */
  494.             if ($emailData['pickupPointAddress'] != '') {
  495.                 $emailData['shippingFirstName'] = '';
  496.                 $emailData['shippingLastName'] = '';
  497.                 $emailData['shippingStreet'] = '';
  498.                 $emailData['shippingCity'] = '';
  499.                 $emailData['shippingPostalCode'] = '';
  500.                 $emailData['shippingCountry'] = '';
  501.             }
  502.             if ($pickupPoint) {
  503.                 $emailData['shippingStreet'] = $pickupPoint->getStreet();
  504.                 $emailData['shippingCity'] = $pickupPoint->getCity();
  505.                 $emailData['shippingPostalCode'] = $pickupPoint->getZip();
  506.                 $emailData['shippingCountry'] = $pickupPoint->getCountry();
  507.             }
  508.         }
  509.         $emailData['total'] = 0;
  510.         $emailData['subTotal'] = 0;
  511.         $emailData['items'] = [];
  512.         $emailData['countItems'] = 0;
  513.         $placeholder = $this->getImage('placeholder.png', '')->resize(Image::PRODUCT_CART_THUMB_WIDTH, Image::PRODUCT_CART_THUMB_HEIGHT);
  514.         $couponRepo = $this->entityManager->getRepository(Coupon::class);
  515.         if ($order->getCouponCode()) {
  516.             $coupon = $couponRepo->findOneByCode($order->getCouponCode());
  517.             if ($coupon) {
  518.                 $emailData['discount'] = $coupon->getDiscount();
  519.             }
  520.         }
  521.         /**
  522.          * @var int $index
  523.          * @var OrderItem $item
  524.          */
  525.         foreach ($order->getOrderItems() as $index => $item) {
  526.             if ($item->getProduct()->getType()->getId() === ProductType::PRODUCT_TYPE_ID_NOTEBOOK) {
  527.                 $emailData['containsNB'] = true;
  528.             }
  529.             if ($item->getItemFullPrice() == 0.00 && in_array($item->getProduct()->getType()->getId(), ProductType::getConfigurableProductTypes())) {
  530.                 continue;
  531.             }
  532.             if ($item->getParent() == null) {
  533.                 $itemProduct = $item->getProduct();
  534.                 $product = $productHelper->getStructuredDataForProduct($itemProduct, 'cart');
  535.                 if ($product) {
  536.                     $options = [];
  537.                     foreach ($item->getItemAttributes() as $attribute) {
  538.                         $option = $attribute->getAttributeOption();
  539.                         $optionMeta = $option->getDomainMeta($domain);
  540.                         if ($optionMeta) {
  541.                             $optionValue = $option->getLongTitle($this->dbTranslator);
  542.                             if (!$optionValue) {
  543.                                 $optionValue = $option->getTitle($this->dbTranslator);
  544.                             }
  545.                             $optionTitle = $option->getAttribute()->getTitle();
  546.                             if ($needTranslation) {
  547.                                 $optionTitle = $unasTranslatorEntity->findOneBy(['translationKey' => $optionTitle])
  548.                                     ?->getTranslationByCountryCode($translationLocal) ?? $optionTitle;
  549.                                 if ($option->getAttribute()->getId() != Attribute::ATTRIBUTE_ID_NOTEBOOK_SKIN) {
  550.                                     $optionValue = $unasTranslatorEntity->findOneBy(['translationKey' => $optionValue])
  551.                                         ?->getTranslationByCountryCode($translationLocal) ?? $optionValue;
  552.                                 }
  553.                             }
  554.                             $options[] = [
  555.                                 'id'    => $attribute->getId(),
  556.                                 'title' => $optionTitle,
  557.                                 'value' => $optionValue,
  558.                             ];
  559.                         }
  560.                     }
  561.                     $configText = !is_null($item->getCustomConfiguration()) && $item->getCustomConfiguration() != '' ? $item->getCustomConfiguration() : $product['shortDescription'];
  562.                     if ($needTranslation) {
  563.                         $translated = '';
  564.                         foreach (explode("|", $configText) as $line) {
  565.                             $translation = $unasTranslatorEntity->findOneBy(['translationKey' => trim($line)]);
  566.                             if ($translation && !preg_match('/bronze|silver|gold|new/', strtolower($line))) {
  567.                                 $translated .= $translation->getTranslationByCountryCode($translationLocal) . ' | ';
  568.                             }
  569.                             else {
  570.                                 $translated .= trim($line) . ' | ';
  571.                             }
  572.                         }
  573.                         if ($translated != '') {
  574.                             $configText = trim($translated, ' | ');
  575.                         }
  576.                     }
  577.                     $image = $markupImage = $placeholder;
  578.                     if (is_object($product['images'])) {
  579.                         $image = $this->getImage($product['images'], 'product/' . $product['code'])->resize(Image::PRODUCT_CART_THUMB_WIDTH, Image::PRODUCT_CART_THUMB_HEIGHT);
  580.                         $markupImage = $this->getImage($product['images'], 'product/' . $product['code'])->resize(Image::PRODUCT_VIEW_POPUP_WIDTH, Image::PRODUCT_VIEW_POPUP_HEIGHT);
  581.                     }
  582.                     $emailData['items'][] = [
  583.                         'id'               => $item->getId(),
  584.                         'productId'        => $product['id'],
  585.                         'model'            => $product['code'],
  586.                         'name'             => ($product['vendor'] !== '' ? $product['vendor'] . ' ' : '') . $product['title'],
  587.                         'description'      => $configText,
  588.                         'quantity'         => $item->getQuantity(),
  589.                         'price'            => $item->getItemFullPrice(),
  590.                         'originalPrice'    => array_key_exists('discount', $emailData) && $emailData['discount'] ? $item->getItemFullPrice() / (1-( $emailData['discount']/100)) : null,
  591.                         'image'            => $image,
  592.                         'markupImage'      => $markupImage,
  593.                         'options'          => $options,
  594.                         'url'              => $this->url()->link('product', [
  595.                             'product_id' => $item->getId(),
  596.                             'isBazaar'   => $product['isBazaar'] ?? 0
  597.                         ]),
  598.                         'outOfStockStatus' => $item->getProduct()->getOutOfStockStatus(),
  599.                     ];
  600.                     $response['marketingProducts'] = ($response['marketingProducts'] !== '' ? ',' : '') . '{"id": "' . $product['code'] . '","name": "' . ($product['vendor'] !== '' ? $product['vendor'] . ' ' : '') . $product['title'] . '","brand": "' . $product['vendor'] . '","category": "' . $product['productType'] . '","quantity": ' . $item->getQuantity() . ',"price": \'' . $item->getItemFullPrice() . '\'}';
  601.                     $response['marketingProductsGA4'] .= ($response['marketingProductsGA4'] !== '' ? ',' : '') . '{ item_id: \'' . $product['code'] . '\', item_name: \'' . ($product['vendor'] !== '' ? $product['vendor'] . ' ' : '') . $product['title'] . '\', item_brand: \'' . $product['vendor'] . '\', item_category: \'' . $product['productType'] . '\', quantity: ' . $item->getQuantity() . ', price: \'' . $item->getItemFullPrice() . '\', index: ' . $index . '}';
  602.                 }
  603.             }
  604.         }
  605.         $emailData['paymentTitle'] = $emailData['shippingTitle'] = $emailData['paymentTitle'] = $emailData['coupon'] = '';
  606.         $emailData['paymentCost'] = $emailData['shippingCost'] = $emailData['discount'] = 0;
  607.         $emailData['paymentType'] = $order->getPaymentType();
  608.         $emailData['isShippedByCarrier'] = in_array($order->getShippingType(), [DomainShippingType::ShippingType_Carrier_Id, DomainShippingType::ShippingType_Post_Id, DomainShippingType::ShippingType_PICKUP_POINT_Id]);
  609.         $translationKey = 'shipping.method.type.' . $order->getShippingType() . ($order->getDomain()->getId() == 4 ? '.achu' : '');
  610.         if (($emailData['shippingTitle'] = $this->translator->trans($translationKey)) == $translationKey) {
  611.             $translationKey = str_replace('.achu', '', $translationKey);
  612.             $emailData['shippingTitle'] = $this->translator->trans($translationKey);
  613.         }
  614.         $emailData['shippingCost'] = $order->getShippingPrice();
  615.         if ($order->getDomain()->getId() == Domain::DOMAIN_ID_WS_HU && $order->getPaymentType() == PaymentType::BankTransfer->value) {
  616.             $translationKey = 'payment.method.type.' . $order->getPaymentType() . '.wshu';
  617.         }
  618.         else {
  619.             $translationKey = 'payment.method.type.' . $order->getPaymentType();
  620.         }
  621.         $emailData['paymentTitle'] = $this->translator->trans($translationKey);
  622.         $emailData['paymentCost'] = $order->getPaymentPrice();
  623.         if (!empty($order->getCouponCode()) && !in_array($order->getCouponCode(), $whitelistCouponCodes)) {
  624.             $emailData['coupon'] = $order->getCouponCode();
  625.             $couponSetting = $order->getCouponCodeSetting();
  626.             if ($couponSetting) {
  627.                 $coupon = $this->entityManager->getRepository(Coupon::class)->findOneById($couponSetting->getValue());
  628.                 if ($coupon) {
  629.                     $emailData['discount'] = $coupon->getDiscount();
  630.                     $emailData['discountType'] = $coupon->getDiscountType();
  631.                     $emailData['freeShippingCoupon'] = $coupon->hasFreeShipping();
  632.                 }
  633.             }
  634.         }
  635.         $emailData['isPaidByCard'] = in_array($order->getPaymentType(), [PaymentType::DebitCard->value, PaymentType::DebitCard3Percent->value]);
  636.         $emailData['subTotal'] = $order->getSubTotal();
  637.         $emailData['total'] = $order->getFullPrice();
  638.         $domain = $order->getDomain();
  639.         $domainLanguageCode = $domain->getLanguage()->getCode();
  640.         if ($domainLanguageCode == 'en') {
  641.             $emailData['domainLanguageCode'] = 'eu';
  642.         }
  643.         else {
  644.             $emailData['domainLanguageCode'] = $domainLanguageCode;
  645.         }
  646.         $emailData['logo_country_suffix'] = '';
  647.         if (in_array($domainLanguageCode, ['sk', 'hu'])) {
  648.             $emailData['logo_country_suffix'] = '-' . $domainLanguageCode;
  649.         }
  650.         $emailData['deliveryData'] = [
  651.             'packageNumber' => '',
  652.             'trackingUrl'   => '',
  653.         ];
  654.         if ($emailData['isShippedByCarrier']) {
  655.             $post = json_decode($this->request->getContent(), true);
  656.             if (!is_null($post)) {
  657.                 $post = array_column($post, null, 'id');
  658.                 $tracking = $post[$order->getId()]['tracking'][0] ?? null;
  659.                 if ($tracking) {
  660.                     $emailData['deliveryData']['packageNumber'] = $tracking['number'];
  661.                     $emailData['deliveryData']['trackingUrl'] = $tracking['url'];
  662.                 }
  663.             }
  664.         }
  665.         $expectedDeliveryBaseDate = !is_null($order->getShipDate()) ? clone $order->getShipDate() : clone $order->getCreated();
  666.         $emailData['expectedArrivalUntil'] = str_replace('+', '-', $expectedDeliveryBaseDate->add(new \DateInterval('P1D'))->format('c'));
  667.         // Public Order Link
  668.         $orderRepository = $this->entityManager->getRepository(Order::class);
  669.         $emailData['publicOrderLink'] = !$hideInvoicePublicLink ? $order->getDomain()->getUrl() .
  670.             $this->router->generate('customer_order_show', [
  671.                 'orderId' => $order->getId(),
  672.                 'token'   => $orderRepository->generatePublicLinkToken([
  673.                     'orderId' => $order->getId(),
  674.                 ]),
  675.             ]) : '';
  676.         $emailData['customerTypeId'] = $this->request->getSession()->get('customerTypeId');
  677.         $emailData['company_name'] = $contactInfos['company.' . $domainLanguageCode . '.name'];
  678.         $emailData['bank_account'] = $contactInfos['company.' . $domainLanguageCode . '.bankAccount'];
  679.         $emailData['phone_number'] = $contactInfos['phone.webshop.' . $domainLanguageCode . '.' . $order->getDomain()->getType()];
  680.         $emailData['iban'] = $contactInfos['company.' . $domainLanguageCode . '.iban'];
  681.         switch ($domain->getId()) {
  682.             case Domain::DOMAIN_ID_RT_SK:
  683.             case Domain::DOMAIN_ID_WS_SK:
  684.             case Domain::DOMAIN_ID_RT_CZ:
  685.             case Domain::DOMAIN_ID_WS_CZ:
  686.             case Domain::DOMAIN_ID_RT_EU:
  687.             case Domain::DOMAIN_ID_WS_EU:
  688.                 $emailData['facebook_link'] = 'https://www.facebook.com/furbify.atechnet/';
  689.                 $emailData['instagram_link'] = 'https://www.instagram.com/furbify.sk';
  690.                 break;
  691.             case Domain::DOMAIN_ID_RT_HU:
  692.             case Domain::DOMAIN_ID_WS_HU:
  693.                 $emailData['facebook_link'] = 'https://www.facebook.com/furbify.hu/';
  694.                 $emailData['instagram_link'] = 'https://www.instagram.com/furbify.hu';
  695.                 break;
  696.             default:
  697.                 $emailData['facebook_link'] = '';
  698.                 $emailData['instagram_link'] = '';
  699.         }
  700.         return [
  701.             'emailData' => $emailData,
  702.             'response'  => $response,
  703.         ];
  704.     }
  705.     /**
  706.      * @return string[]
  707.      */
  708.     protected function getBaseGlsTrackingUrls(): array
  709.     {
  710.         return [
  711.             'sk' => 'https://gls-group.eu/SK/sk/parcel-tracking.html?match=',
  712.             'hu' => 'https://gls-group.eu/HU/hu/csomagkovetes.html?match=',
  713.             'cz' => 'https://gls-group.eu/CZ/cs/sledovani-zasilek?match=',
  714.             'en' => 'https://gls-group.eu/EU/en/parcel-tracking.html?match=',
  715.         ];
  716.     }
  717.     /**
  718.      * @param string $postalCode
  719.      * @param string $country
  720.      * @param Request $request
  721.      *
  722.      * @return string
  723.      */
  724.     public static function findDistrict(string $postalCode, string $country, Request $request): string
  725.     {
  726.         if (!empty($postalCode) && !empty($country) && in_array(strtolower($country), ['sk', 'hu', 'cz'])) {
  727.             $ch = curl_init();
  728.             curl_setopt($ch, CURLOPT_URL, 'https://www.atechcomp.eu/centralis/web/api/customer/find/district');
  729.             curl_setopt($ch, CURLOPT_PORT, 443);
  730.             curl_setopt($ch, CURLOPT_HEADER, false);
  731.             curl_setopt($ch, CURLINFO_HEADER_OUT, false);
  732.             curl_setopt($ch, CURLOPT_USERAGENT, $request->server->get('HTTP_USER_AGENT'));
  733.             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  734.             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  735.             curl_setopt($ch, CURLOPT_FORBID_REUSE, false);
  736.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  737.             curl_setopt($ch, CURLOPT_POST, true);
  738.             curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
  739.                 'tkn'    => self::$apiToken,
  740.                 'pstlCd' => $postalCode,
  741.                 'cntr'   => $country,
  742.             ]));
  743.             $response = curl_exec($ch);
  744.             curl_close($ch);
  745.             $response = json_decode($response, true);
  746.             if (!empty($response['result'])) {
  747.                 if ($response['result'] !== false) {
  748.                     return $response['result'];
  749.                 }
  750.             }
  751.             return '';
  752.         }
  753.         return '';
  754.     }
  755.     /**
  756.      * @return SeoUrlHelper
  757.      */
  758.     public function url(): SeoUrlHelper
  759.     {
  760.         return new SeoUrlHelper($this->entityManager, $this->request, $this->environment);
  761.     }
  762.     /**
  763.      * @param object|string $photo
  764.      * @param string $directory
  765.      *
  766.      * @return Image
  767.      */
  768.     protected function getImage($photo, string $directory = 'product'): Image
  769.     {
  770.         return new Image($this->cloudFlareConfig, $photo, $directory);
  771.     }
  772.     /**
  773.      * @param int $domainId
  774.      * @param null|Customer $customer
  775.      * @param null|Basket $cart
  776.      * @param null|Instacash $instacash
  777.      * @param Milpay|null $milpay
  778.      * @param bool $isCompany
  779.      * @param OrderRepository|null $orderRepository
  780.      *
  781.      * @return array
  782.      */
  783.     public function getPaymentMethodData(int $domainId, ?Customer $customer = null, ?Basket $cart = null, ?Instacash $instacash = null, ?Milpay $milpay = null, bool $isCompany = false, ?OrderRepository $orderRepository = null): array
  784.     {
  785.         $paymentMethodList = [];
  786.         // Get all integrated payment methods
  787.         $paymentMethods = $this->entityManager->createQueryBuilder()
  788.             ->select('dpt')
  789.             ->from('AtechNetCoreBundle:DomainPaymentType', 'dpt')
  790.             ->andWhere('dpt.domain = :domainId')
  791.             ->setParameter(':domainId', $domainId)
  792.             ->andWhere('dpt.integrated = :integrated')
  793.             ->setParameter(':integrated', 1)
  794.             ->orderBy('dpt.sortOrder', 'ASC')
  795.             ->getQuery()->getResult();
  796.         // Custom customer payment methods
  797.         $customCustomerPaymentMethods = null;
  798.         if ($customer) {
  799.             $customCustomerPaymentMethods = $customer->getPaymentTypes();
  800.         }
  801.         $translator = $this->translator;
  802.         $payOnDelivery = true;
  803.         $noDeliveryPaymentDescription = '';
  804.         if ($cart) {
  805.             $priceLimits = DomainPaymentType::CASH_ON_DELIVERY_LIMITS;
  806.             $price = 0;
  807.             /**
  808.              * @var $cartItem BasketItem
  809.              */
  810.             foreach ($cart->getBasketItems() as $cartItem) {
  811.                 $productMeta = array_filter($cartItem->getProduct()->getMetas(), function ($meta) use ($domainId) {
  812.                     return $meta->getDomain()->getId() === $domainId;
  813.                 });
  814.                 $price += $productMeta[array_key_first($productMeta)]->isDiscounted()
  815.                     ? $productMeta[array_key_first($productMeta)]->getDomainVatDiscount() * $cartItem->getQuantity()
  816.                     : $productMeta[array_key_first($productMeta)]->getDomainVatPrice() * $cartItem->getQuantity();
  817.                 $domainCurrency = $productMeta[array_key_first($productMeta)]->getDomain()->getCurrency();
  818.                 if ($price > $priceLimits[$domainCurrency]) {
  819.                     $payOnDelivery = false;
  820.                     $noDeliveryPaymentDescription = $translator->trans('noOnDeliveryPayment.description') . ' ' . $priceLimits[$domainCurrency] . $domainCurrency;
  821.                     break;
  822.                 }
  823.             }
  824.         }
  825.         $showCetelemCalculator = false;
  826.         $cetelemDescLink = '';
  827.         $cetelemDesc = '';
  828.         $pastPayAvailable = false;
  829.         /**
  830.          * @var DomainPaymentType $paymentMethod
  831.          */
  832.         foreach ($paymentMethods as $paymentMethod) {
  833.             $bnplWarning = null;
  834.             if ($this->entityManager->getRepository(Product::class)->isBasketIncludesOnlyGiftCart($cart)) {
  835.                 if (
  836.                     in_array($paymentMethod->getType(), [
  837.                         PaymentType::Cetelem->value,
  838.                         PaymentType::PastPay->value,
  839.                         PaymentType::Quatro->value,
  840.                         PaymentType::Klarna->value,
  841.                         PaymentType::Instacash->value,
  842.                         PaymentType::PayPal->value,
  843.                         PaymentType::Milpay->value,
  844.                     ])) {
  845.                     continue;
  846.                 }
  847.             }
  848.             if (($customer?->isB2B() || $isCompany) && in_array($paymentMethod->getType(), [PaymentType::Klarna->value, PaymentType::Instacash->value, PaymentType::Milpay->value])) {
  849.                 continue;
  850.             }
  851.             if (!is_null($customCustomerPaymentMethods) && $customCustomerPaymentMethods->count() > 0) {
  852.                 foreach ($customCustomerPaymentMethods as $customCustomerPaymentMethod) {
  853.                     if ($paymentMethod->getType() == $customCustomerPaymentMethod->getPaymentType()->getType() && !$customCustomerPaymentMethod->isActive()) {
  854.                         continue 2;
  855.                     }
  856.                 }
  857.             }
  858.             else if (!$paymentMethod->isActiveOnWeb()) {
  859.                 continue;
  860.             }
  861.             if ($domainId == Domain::DOMAIN_ID_WS_HU && $paymentMethod->getType() == PaymentType::BankTransfer->value) {
  862.                 $translationKey = 'payment.method.type.' . $paymentMethod->getType() . '.wshu';
  863.             }
  864.             else {
  865.                 $translationKey = 'payment.method.type.' . $paymentMethod->getType();
  866.             }
  867.             $defaultCountry = $this->request->getSession()->get('defaultCountry');
  868.             $cartTotalPrice = $cart ? $cart->getTotalPrice() : false;
  869.             if ($paymentMethod->getType() == PaymentType::Cetelem->value) {
  870.                 if ($cartTotalPrice && constant(MultiStore::class . '::MINIMAL_LOAN_CETELEM_' . $defaultCountry) > $cartTotalPrice) {
  871.                     continue;
  872.                 }
  873.                 if ($defaultCountry != 'SK') {
  874.                     if ($defaultCountry == 'HU') {
  875.                         $showCetelemCalculator = true;
  876.                         $cetelemDescLink = $this->url($this->request)->link('page', [
  877.                             'static_id' => 19,
  878.                         ]);
  879.                         $cetelemDesc = $translator->trans('CetelemDesc');
  880.                     }
  881.                     else {
  882.                         continue;
  883.                     }
  884.                 }
  885.             }
  886.             if ($cart && $paymentMethod->getType() == PaymentType::Quatro->value && MultiStore::MINIMAL_LOAN_QUATRO > $cart->getTotalPrice()) {
  887.                 continue;
  888.             }
  889.             if ($cartTotalPrice && $paymentMethod->getType() == PaymentType::Instacash->value) {
  890.                 $availableOffer = $instacash->getAvailableOffers();
  891.                 if ($cartTotalPrice && $cartTotalPrice < $availableOffer['minAmount'] || $cartTotalPrice > $availableOffer['maxAmount']) {
  892.                     continue;
  893.                 }
  894.             }
  895.             if ($paymentMethod->getType() == PaymentType::Klarna->value) {
  896.                 if ($cart && $orderRepository->haveNotFinishedBnpOrdersFromThisCustomer($cart, PaymentType::Klarna)) {
  897.                     $bnplWarning = $translator->trans('bnplWarning.notFinishedOrders.klarna');
  898.                 }
  899.             }
  900.             if (!is_null($milpay) && $cartTotalPrice && $paymentMethod->getType() == PaymentType::Milpay->value) {
  901.                 $availableOffer = $milpay->getAvailableOffers();
  902.                 if ($cartTotalPrice < $availableOffer['minAmount'] || $cartTotalPrice > $availableOffer['maxAmount']) {
  903.                     continue;
  904.                 }
  905.                 if ($cart && $orderRepository->haveNotFinishedBnpOrdersFromThisCustomer($cart, PaymentType::Milpay)) {
  906.                     $bnplWarning = $translator->trans('bnplWarning.notFinishedOrders.miplay');
  907.                 }
  908.             }
  909.             else if (is_null($milpay) && $paymentMethod->getType() == PaymentType::Milpay->value) {
  910.                 continue;
  911.             }
  912.             if (($title = $translator->trans($translationKey)) == $translationKey) {
  913.                 $title = false;
  914.             }
  915.             if (($plusInfo = $translator->trans($translationKey . '.plusInfo')) == $translationKey . '.plusInfo') {
  916.                 $plusInfo = false;
  917.             }
  918.             if (($description = $translator->trans($translationKey . '.description')) == $translationKey . '.description') {
  919.                 $description = false;
  920.             }
  921.             if (($icon = $translator->trans($translationKey . '.icon')) == $translationKey . '.icon') {
  922.                 $icon = false;
  923.             }
  924.             $inactive = false;
  925.             if (!$payOnDelivery && in_array($paymentMethod->getType(), [PaymentType::CashOnDelivery->value, PaymentType::CashOnDelivery3Percent->value]) && !in_array($domainId, [Domain::DOMAIN_ID_WS_HU, Domain::DOMAIN_ID_WS_SK, Domain::DOMAIN_ID_WS_CZ, Domain::DOMAIN_ID_WS_EU])) {
  926.                 $description = $noDeliveryPaymentDescription;
  927.                 $inactive = true;
  928.             }
  929.             if ($title) {
  930.                 $paymentMethodList[$paymentMethod->getId()] = [
  931.                     'id'          => $paymentMethod->getId(),
  932.                     'type'        => $paymentMethod->getType(),
  933.                     'title'       => $title,
  934.                     'plusInfo'    => $plusInfo,
  935.                     'description' => $description,
  936.                     'price'       => $paymentMethod->getPrice(),
  937.                     'icon'        => $icon,
  938.                     'logo'        => (PaymentType::tryFrom($paymentMethod->getType()))?->getLogoFileName(),
  939.                 ];
  940.                 if ($bnplWarning) {
  941.                     $paymentMethodList[$paymentMethod->getId()]['bnplWarning'] = $bnplWarning;
  942.                     $paymentMethodList[$paymentMethod->getId()]['inactive'] = true;
  943.                 }
  944.                 if ($paymentMethod->getType() == PaymentType::PastPay->value) {
  945.                     $pastPayAvailable = true;
  946.                 }
  947.                 if ($inactive) {
  948.                     $paymentMethodList[$paymentMethod->getId()]['inactive'] = true;
  949.                 }
  950.             }
  951.         }
  952.         return [
  953.             'paymentList'           => $paymentMethodList,
  954.             'showCetelemCalculator' => $showCetelemCalculator,
  955.             'cetelemDescLink'       => $cetelemDescLink,
  956.             'cetelemDesc'           => $cetelemDesc,
  957.             'pastPayAvailable'      => $pastPayAvailable,
  958.         ];
  959.     }
  960. }