Skip to content

Commit

Permalink
payment status is now displayed on order detail for all external paym…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
TomasLudvik committed Dec 12, 2024
1 parent 5966f62 commit 98dab87
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 36 deletions.
32 changes: 18 additions & 14 deletions src/Form/Admin/Order/OrderFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/Model/Order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
*/
protected static function getGoPayStatusesToTranslate(): array
protected static function getStatusesToTranslate(): array
{
return [
PaymentStatus::CREATED => t('Payment created'),
Expand Down
3 changes: 0 additions & 3 deletions src/Model/Payment/Transaction/PaymentTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ public function getPaymentThrowExceptionIfNull(): Payment
* @return string
*/
#[EntityLogIdentify]
/**
* @return string
*/
public function getExternalPaymentIdentifier()
{
return $this->externalPaymentIdentifier;
Expand Down
12 changes: 6 additions & 6 deletions src/Resources/translations/messages.cs.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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ě"

Expand Down Expand Up @@ -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í"
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/translations/messages.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -2023,9 +2023,6 @@ msgstr ""
msgid "GoPay payment method"
msgstr ""

msgid "GoPay payment status"
msgstr ""

msgid "Group"
msgstr ""

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -3025,6 +3022,9 @@ msgstr ""
msgid "Payment refunded"
msgstr ""

msgid "Payment status"
msgstr ""

msgid "Payment successful page content"
msgstr ""

Expand Down

0 comments on commit 98dab87

Please sign in to comment.