From 98dab870d4cddc8cc790b6fe4539a984bb7ab130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Ludvik?= Date: Thu, 12 Dec 2024 10:17:28 +0100 Subject: [PATCH] payment status is now displayed on order detail for all external payments --- src/Form/Admin/Order/OrderFormType.php | 32 +++++++++++-------- src/Model/Order/Order.php | 25 +++++++++++++++ .../Transaction/ExternalPaymentStatus.php} | 18 +++++------ .../Transaction/PaymentTransaction.php | 3 -- src/Resources/translations/messages.cs.po | 12 +++---- src/Resources/translations/messages.en.po | 8 ++--- 6 files changed, 62 insertions(+), 36 deletions(-) rename src/Model/{GoPay/GoPayOrderStatus.php => Payment/Transaction/ExternalPaymentStatus.php} (60%) diff --git a/src/Form/Admin/Order/OrderFormType.php b/src/Form/Admin/Order/OrderFormType.php index 2bc4ad0137..e3243919e8 100644 --- a/src/Form/Admin/Order/OrderFormType.php +++ b/src/Form/Admin/Order/OrderFormType.php @@ -17,10 +17,10 @@ use Shopsys\FrameworkBundle\Form\OrderItemsType; use Shopsys\FrameworkBundle\Form\ValidationGroup; use Shopsys\FrameworkBundle\Model\Country\CountryFacade; -use Shopsys\FrameworkBundle\Model\GoPay\GoPayOrderStatus; use Shopsys\FrameworkBundle\Model\Order\Order; use Shopsys\FrameworkBundle\Model\Order\OrderData; use Shopsys\FrameworkBundle\Model\Order\Status\OrderStatusFacade; +use Shopsys\FrameworkBundle\Model\Payment\Transaction\ExternalPaymentStatus; use Shopsys\FrameworkBundle\Twig\DateTimeFormatterExtension; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; @@ -200,20 +200,24 @@ private function createBasicInformationGroup(FormBuilderInterface $builder, Orde 'data' => $order->getPayment()->getName(), ]); - if ($order->getPayment()->isGoPay() === true) { - $goPayPaymentTransactions = $order->getGoPayTransactions(); - - if (count($goPayPaymentTransactions) > 0) { - $translatedGoPayStatus = GoPayOrderStatus::getTranslatedGoPayStatus(end($goPayPaymentTransactions)->getExternalPaymentStatus()); - } else { - $translatedGoPayStatus = t('Order has not been sent to GoPay'); + if ($order->hasExternalPayment()) { + $paymentTransactions = $order->getTransactionsOfCurrentPayment(); + /** @var \Shopsys\FrameworkBundle\Model\Payment\Transaction\PaymentTransaction|bool $paymentTransaction */ + $paymentTransaction = end($paymentTransactions)->getExternalPaymentStatus(); + + if ($paymentTransaction !== false) { + if ($paymentTransaction->getExternalPaymentStatus() !== null) { + $translatedPaymentStatus = ExternalPaymentStatus::getTranslatedStatus($paymentTransaction->getExternalPaymentStatus()); + } else { + $translatedPaymentStatus = t('Order has not been sent to payment gateway'); + } + + $builderBasicInformationGroup + ->add('paymentStatus', DisplayOnlyType::class, [ + 'label' => t('Payment status'), + 'data' => $translatedPaymentStatus, + ]); } - - $builderBasicInformationGroup - ->add('gopayStatus', DisplayOnlyType::class, [ - 'label' => t('GoPay payment status'), - 'data' => $translatedGoPayStatus, - ]); } $builderBasicInformationGroup diff --git a/src/Model/Order/Order.php b/src/Model/Order/Order.php index 915c22b0fa..2365c915fc 100644 --- a/src/Model/Order/Order.php +++ b/src/Model/Order/Order.php @@ -18,6 +18,7 @@ use Shopsys\FrameworkBundle\Model\Order\Item\OrderItemTypeEnum; use Shopsys\FrameworkBundle\Model\Order\Mail\OrderMail; use Shopsys\FrameworkBundle\Model\Order\Status\OrderStatusTypeEnum; +use Shopsys\FrameworkBundle\Model\Payment\PaymentTypeEnum; use Shopsys\FrameworkBundle\Model\Payment\Transaction\PaymentTransaction; use Shopsys\FrameworkBundle\Model\Pricing\Price; use Shopsys\FrameworkBundle\Model\Product\Exception\ProductNotFoundException; @@ -432,6 +433,30 @@ public function getGoPayTransactions(): array return $paymentTransactions; } + /** + * @return \Shopsys\FrameworkBundle\Model\Payment\Transaction\PaymentTransaction[] + */ + public function getTransactionsOfCurrentPayment(): array + { + $paymentTransactions = []; + + foreach ($this->getPaymentTransactions() as $paymentTransaction) { + if ($paymentTransaction->getPayment() === $this->payment) { + $paymentTransactions[] = $paymentTransaction; + } + } + + return $paymentTransactions; + } + + /** + * @return bool + */ + public function hasExternalPayment(): bool + { + return $this->getPayment()->getType() !== PaymentTypeEnum::TYPE_BASIC; + } + /** * @return bool */ diff --git a/src/Model/GoPay/GoPayOrderStatus.php b/src/Model/Payment/Transaction/ExternalPaymentStatus.php similarity index 60% rename from src/Model/GoPay/GoPayOrderStatus.php rename to src/Model/Payment/Transaction/ExternalPaymentStatus.php index 80cc5e9d59..d705ebb622 100644 --- a/src/Model/GoPay/GoPayOrderStatus.php +++ b/src/Model/Payment/Transaction/ExternalPaymentStatus.php @@ -2,31 +2,31 @@ declare(strict_types=1); -namespace Shopsys\FrameworkBundle\Model\GoPay; +namespace Shopsys\FrameworkBundle\Model\Payment\Transaction; use GoPay\Definition\Response\PaymentStatus; -class GoPayOrderStatus +class ExternalPaymentStatus { /** - * @param string $goPayStatus + * @param string $externalStatus * @return string */ - public static function getTranslatedGoPayStatus(string $goPayStatus): string + public static function getTranslatedStatus(string $externalStatus): string { - $goPayStatusToTranslate = self::getGoPayStatusesToTranslate(); + $statusesToTranslate = self::getStatusesToTranslate(); - if (array_key_exists($goPayStatus, $goPayStatusToTranslate)) { - return $goPayStatusToTranslate[$goPayStatus]; + if (array_key_exists(mb_strtoupper($externalStatus), $statusesToTranslate)) { + return $statusesToTranslate[$externalStatus]; } - return $goPayStatus; + return $externalStatus; } /** * @return array */ - protected static function getGoPayStatusesToTranslate(): array + protected static function getStatusesToTranslate(): array { return [ PaymentStatus::CREATED => t('Payment created'), diff --git a/src/Model/Payment/Transaction/PaymentTransaction.php b/src/Model/Payment/Transaction/PaymentTransaction.php index c9d682f7cc..c4d1b88756 100644 --- a/src/Model/Payment/Transaction/PaymentTransaction.php +++ b/src/Model/Payment/Transaction/PaymentTransaction.php @@ -137,9 +137,6 @@ public function getPaymentThrowExceptionIfNull(): Payment * @return string */ #[EntityLogIdentify] - /** - * @return string - */ public function getExternalPaymentIdentifier() { return $this->externalPaymentIdentifier; diff --git a/src/Resources/translations/messages.cs.po b/src/Resources/translations/messages.cs.po index 881a737c4f..04fadda83f 100644 --- a/src/Resources/translations/messages.cs.po +++ b/src/Resources/translations/messages.cs.po @@ -2023,9 +2023,6 @@ msgstr "GoPay API vrátilo chybu - jděte do administrace GoPay, najděte transa msgid "GoPay payment method" msgstr "Platební metoda GoPay" -msgid "GoPay payment status" -msgstr "Stav platby GoPay" - msgid "Group" msgstr "Skupina" @@ -2812,8 +2809,8 @@ msgstr "Detail objednávky" msgid "Order detail URL address" msgstr "URL adresa detailu objednávky" -msgid "Order has not been sent to GoPay" -msgstr "Objednávka nebyla odeslána do GoPay" +msgid "Order has not been sent to payment gateway" +msgstr "Objednávka ještě nebyla odeslána do platební brány" msgid "Order in CZK round to whole crowns" msgstr "Objednávku v CZK zaokrouhlit na celé koruny" @@ -3025,6 +3022,9 @@ msgstr "Platba částečně refundována" msgid "Payment refunded" msgstr "Refundovaná platba" +msgid "Payment status" +msgstr "Stav platby" + msgid "Payment successful page content" msgstr "Obsah stránky po dokončené platbě" @@ -3680,7 +3680,7 @@ msgid "Set prices manually" msgstr "Manuálně nastavené ceny" msgid "Setting for domain \"%domainName%\" was saved." -msgstr "" +msgstr "Nastavení pro doménu \"%domainName%\" bylo uloženo." msgid "Settings" msgstr "Nastavení" diff --git a/src/Resources/translations/messages.en.po b/src/Resources/translations/messages.en.po index 6eba6ae509..98be2c4ae4 100644 --- a/src/Resources/translations/messages.en.po +++ b/src/Resources/translations/messages.en.po @@ -2023,9 +2023,6 @@ msgstr "" msgid "GoPay payment method" msgstr "" -msgid "GoPay payment status" -msgstr "" - msgid "Group" msgstr "" @@ -2812,7 +2809,7 @@ msgstr "" msgid "Order detail URL address" msgstr "" -msgid "Order has not been sent to GoPay" +msgid "Order has not been sent to payment gateway" msgstr "" msgid "Order in CZK round to whole crowns" @@ -3025,6 +3022,9 @@ msgstr "" msgid "Payment refunded" msgstr "" +msgid "Payment status" +msgstr "" + msgid "Payment successful page content" msgstr ""