From fb8533cf5a69177d9d3ff866055dbd6fedd17fc9 Mon Sep 17 00:00:00 2001 From: Edgaras Date: Wed, 22 May 2024 14:19:28 +0300 Subject: [PATCH] Release 1.0.25 --- README.md | 2 +- Services/WalleeTransactionService.php | 73 ++++++++++++++++++++++----- adminmenu/AdminTabProvider.php | 32 +++++++++--- adminmenu/templates/wallee_orders.tpl | 34 ++++++------- docs/en/documentation.html | 2 +- frontend/Handler.php | 73 ++++++++++++++++++--------- info.xml | 9 +++- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 8 +-- vendor/composer/autoload_static.php | 8 +-- vendor/composer/installed.php | 4 +- 11 files changed, 175 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 68c91df..9a722e9 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ account dashboard. ## Documentation -[Documentation](https://plugin-documentation.wallee.com/wallee-payment/jtl-5/1.0.24/docs/en/documentation.html) +[Documentation](https://plugin-documentation.wallee.com/wallee-payment/jtl-5/1.0.25/docs/en/documentation.html) ## License diff --git a/Services/WalleeTransactionService.php b/Services/WalleeTransactionService.php index d659ea8..d87cecc 100644 --- a/Services/WalleeTransactionService.php +++ b/Services/WalleeTransactionService.php @@ -2,6 +2,7 @@ namespace Plugin\jtl_wallee\Services; +use JTL\Alert\Alert; use JTL\Cart\CartItem; use JTL\Catalog\Product\Preise; use JTL\Checkout\Bestellung; @@ -44,12 +45,18 @@ class WalleeTransactionService * @var $spaceViewId */ protected $spaceViewId; + + /** + * @var $plugin + */ + protected $plugin; public function __construct(ApiClient $apiClient, $plugin) { $config = WalleeHelper::getConfigByID($plugin->getId()); $spaceId = $config[WalleeHelper::SPACE_ID]; + $this->plugin = $plugin; $this->apiClient = $apiClient; $this->spaceId = $spaceId; $this->spaceViewId = $config[WalleeHelper::SPACE_VIEW_ID]; @@ -80,8 +87,14 @@ public function createTransaction(Bestellung $order): Transaction $successUrl = Shop::getURL() . '/' . WalleeHelper::PLUGIN_CUSTOM_PAGES['thank-you-page'][$_SESSION['cISOSprache']]; $failedUrl = Shop::getURL() . '/' . WalleeHelper::PLUGIN_CUSTOM_PAGES['fail-page'][$_SESSION['cISOSprache']]; - $transactionPayload->setSuccessUrl($successUrl); - $transactionPayload->setFailedUrl($failedUrl); + $customer = $_SESSION['Kunde']; + $customerEmail = $customer->cMail ?? ''; + $customerId = $customer->kKunde ?? ''; + + $transactionPayload->setSuccessUrl($successUrl) + ->setFailedUrl($failedUrl) + ->setCustomerEmailAddress($customerEmail) + ->setCustomerId($customerId); $orderNr = WalleeHelper::getNextOrderNr(); $transactionPayload->setMerchantReference($orderNr); @@ -169,15 +182,30 @@ public function confirmTransaction(Transaction $transaction): void public function updateTransaction(int $transactionId) { $pendingTransaction = new TransactionPending(); - $pendingTransaction->setId($transactionId); - $transaction = $this->getTransactionFromPortal($transactionId); - if (empty($transaction) || empty($transaction->getVersion())) { - $_SESSION['transactionId'] = null; - $createdTransactionId = $this->createTransaction(); - $_SESSION['transactionId'] = $createdTransactionId; - return; + $failedStates = [ + TransactionState::DECLINE, + TransactionState::FAILED, + TransactionState::VOIDED, + ]; + if (empty($transaction) || empty($transaction->getVersion()) || in_array($transaction->getState(), $failedStates)) { + $_SESSION['transactionId'] = null; + $translations = WalleeHelper::getTranslations($this->plugin->getLocalization(), [ + 'jtl_wallee_transaction_timeout', + ]); + + Shop::Container()->getAlertService()->addAlert( + Alert::TYPE_ERROR, + $translations['jtl_wallee_transaction_timeout'], + 'updateTransaction_transaction_timeout' + ); + + $linkHelper = Shop::Container()->getLinkService(); + \header('Location: ' . $linkHelper->getStaticRoute('bestellvorgang.php') . '?editZahlungsart=1'); + exit; } + + $pendingTransaction->setId($transactionId); $pendingTransaction->setVersion($transaction->getVersion()); $lineItems = $this->getLineItems($_SESSION['Warenkorb']->PositionenArr); @@ -587,11 +615,32 @@ private function createBillingAddress(): AddressCreate $billingAddress->setPostalState($customer->cBundesland); $billingAddress->setOrganizationName($customer->cFirma); $billingAddress->setPhoneNumber($customer->cMobil); - $billingAddress->setSalutation($customer->cTitel); + + $company = $customer->cFirma ?? null; + if ($company) { + $billingAddress->setOrganizationName($company); + } + + $mobile = $customer->cMobil ?? null; + if ($mobile) { + $billingAddress->setMobilePhoneNumber($mobile); + } + + $phone = $customer->cTel ?? $mobile; + if ($phone) { + $billingAddress->setPhoneNumber($phone); + } + + $birthDate = $customer->dGeburtstag_formatted ?? null; + if ($birthDate) { + $birthday = new \DateTime(); + $birthday->setTimestamp(strtotime($birthDate)); + $birthday = $birthday->format('Y-m-d'); + $billingAddress->setDateOfBirth($birthday); + } - $gender = $_SESSION['orderData']?->oKunde?->cAnrede ?? null; + $gender = $_SESSION['orderData']?->oKunde?->cAnrede ?? ''; if ($gender !== null) { - $billingAddress->setGender($gender === 'm' ? Gender::MALE : Gender::FEMALE); $billingAddress->setSalutation($gender === 'm' ? 'Mr' : 'Ms'); } diff --git a/adminmenu/AdminTabProvider.php b/adminmenu/AdminTabProvider.php index 1d7c184..58a0bd9 100644 --- a/adminmenu/AdminTabProvider.php +++ b/adminmenu/AdminTabProvider.php @@ -54,11 +54,28 @@ class AdminTabProvider * @var JTLSmarty */ private $smarty; - + + /** + * @var ApiClient|null + */ + private $apiClient; + + /** + * @var WalleeTransactionService + */ + private $transactionService; + + /** + * @var WalleeRefundService + */ + private $refundService; + + /** * @param PluginInterface $plugin + * @param DbInterface $db + * @param JTLSmarty $smarty */ - public function __construct(PluginInterface $plugin, DbInterface $db, JTLSmarty $smarty) { $this->plugin = $plugin; @@ -145,10 +162,13 @@ public function createOrdersTab(int $menuID): string $orderId = (int)$order->kBestellung; $ordObj = new Bestellung($orderId); $ordObj->fuelleBestellung(true, 0, false); - $ordObj->wallee_transaction_id = $order->transaction_id; - $ordObj->wallee_state = $order->state; - $ordObj->total_amount = (float)$order->fGesamtsumme; - $orders[$orderId] = $ordObj; + $orderDetails = [ + 'orderDetails' => $ordObj, + 'wallee_transaction_id' => $order->transaction_id, + 'wallee_state' => $order->state, + 'total_amount' => (float)$order->fGesamtsumme + ]; + $orders[$orderId] = $orderDetails; } $paymentStatus = WalleeHelper::getPaymentStatusWithTransations($this->plugin->getLocalization()); diff --git a/adminmenu/templates/wallee_orders.tpl b/adminmenu/templates/wallee_orders.tpl index ca07e1a..1e1701d 100644 --- a/adminmenu/templates/wallee_orders.tpl +++ b/adminmenu/templates/wallee_orders.tpl @@ -19,16 +19,16 @@ {foreach $orders as $order} -
{$order->cBestellNr}
+
{$order['orderDetails']->cBestellNr}
{$order->dErstellt} + aria-hidden="true"> {$order['orderDetails']->dErstellt}
- {if isset($order->oKunde->cVorname) || isset($order->oKunde->cNachname) || isset($order->oKunde->cFirma)} - {$order->oKunde->cVorname} {$order->oKunde->cNachname} - {if isset($order->oKunde->cFirma) && $order->oKunde->cFirma|strlen > 0} - ({$order->oKunde->cFirma}) + {if isset($order['orderDetails']->oKunde->cVorname) || isset($order['orderDetails']->oKunde->cNachname) || isset($order['orderDetails']->oKunde->cFirma)} + {$order['orderDetails']->oKunde->cVorname} {$order['orderDetails']->oKunde->cNachname} + {if isset($order['orderDetails']->oKunde->cFirma) && $order['orderDetails']->oKunde->cFirma|strlen > 0} + ({$order['orderDetails']->oKunde->cFirma}) {/if} {else} {__('noAccount')} @@ -36,24 +36,24 @@
- {$order->oKunde->cMail} + {$order['orderDetails']->oKunde->cMail} - {$order->cZahlungsartName} + {$order['orderDetails']->cZahlungsartName} - {$paymentStatus[$order->cStatus]} + {$paymentStatus[$order['orderDetails']->cStatus]} - {$order->WarensummeLocalized[0]} + {$order['orderDetails']->WarensummeLocalized[0]} + 'total_amount':'{$order['total_amount']}', + 'order_id':'{$order['orderDetails']->kBestellung}', + 'order_no':'{$order['orderDetails']->cBestellNr}', + 'transaction_id': '{$order['wallee_transaction_id']}', + 'transaction_state': '{$order['wallee_state']}', + 'action': 'order_details' + })"> diff --git a/docs/en/documentation.html b/docs/en/documentation.html index 9807020..15c1d6d 100644 --- a/docs/en/documentation.html +++ b/docs/en/documentation.html @@ -23,7 +23,7 @@

Documentation

  • - + Source
  • diff --git a/frontend/Handler.php b/frontend/Handler.php index f0720fa..64d3535 100644 --- a/frontend/Handler.php +++ b/frontend/Handler.php @@ -123,29 +123,32 @@ private function handleTransaction(): void } if (!$createdTransactionId || !$arrayOfPossibleMethods) { - if ($createdTransactionId) { - $config = WalleeHelper::getConfigByID($this->plugin->getId()); - $spaceId = $config[WalleeHelper::SPACE_ID]; - $transaction = $this->apiClient->getTransactionService()->read($spaceId, $createdTransactionId); - if ($transaction->getState() === TransactionState::CONFIRMED) { - $_SESSION['transactionId'] = null; - $createdTransactionId = $this->createTransaction(); - $_SESSION['transactionId'] = $createdTransactionId; - } else { - $this->transactionService->updateTransaction($createdTransactionId); - } + if (!$createdTransactionId) { + $this->resetTransaction(); + } else { + $config = WalleeHelper::getConfigByID($this->plugin->getId()); + $spaceId = $config[WalleeHelper::SPACE_ID]; + $transaction = $this->apiClient->getTransactionService()->read($spaceId, $createdTransactionId); + + $failedStates = [ + TransactionState::DECLINE, + TransactionState::FAILED, + TransactionState::VOIDED, + ]; + + if (empty($transaction) || empty($transaction->getVersion()) || in_array($transaction->getState(), $failedStates)) { + $this->resetTransaction(); } else { - $_SESSION['transactionId'] = null; - $createdTransactionId = $this->createTransaction(); - $_SESSION['transactionId'] = $createdTransactionId; - } - - $possiblePaymentMethods = $this->fetchPossiblePaymentMethods((string)$createdTransactionId); - $arrayOfPossibleMethods = []; - foreach ($possiblePaymentMethods as $possiblePaymentMethod) { - $arrayOfPossibleMethods[] = WalleeHelper::PAYMENT_METHOD_PREFIX . '_' . $possiblePaymentMethod->getId(); + $this->transactionService->updateTransaction($createdTransactionId); } - $_SESSION['arrayOfPossibleMethods'] = $arrayOfPossibleMethods; + } + + $possiblePaymentMethods = $this->fetchPossiblePaymentMethods((string)$createdTransactionId); + $arrayOfPossibleMethods = []; + foreach ($possiblePaymentMethods as $possiblePaymentMethod) { + $arrayOfPossibleMethods[] = WalleeHelper::PAYMENT_METHOD_PREFIX . '_' . $possiblePaymentMethod->getId(); + } + $_SESSION['arrayOfPossibleMethods'] = $arrayOfPossibleMethods; } } @@ -213,8 +216,22 @@ public function cancelOrderAfterWawi(array $args): void */ public function confirmTransaction(string $spaceId, int $transactionId): void { - $transaction = $this->apiClient->getTransactionService()->read($spaceId, $transactionId); - $this->transactionService->confirmTransaction($transaction); + $transaction = $this->apiClient->getTransactionService()->read($spaceId, $transactionId); + + $failedStates = [ + TransactionState::DECLINE, + TransactionState::FAILED, + TransactionState::VOIDED, + ]; + + if (empty($transaction) || empty($transaction->getVersion()) || in_array($transaction->getState(), $failedStates)) { + $_SESSION['transactionId'] = null; + $linkHelper = Shop::Container()->getLinkService(); + \header('Location: ' . $linkHelper->getStaticRoute('bestellvorgang.php') . '?editZahlungsart=1'); + exit; + } + + $this->transactionService->confirmTransaction($transaction); } public function getRedirectUrlAfterCreatedTransaction($orderData): string @@ -297,5 +314,15 @@ public function setPaymentMethodLogoSize(): void pq('head')->append($paymentMethodsCss); } } + + /** + * @return void + */ + private function resetTransaction(): void + { + $_SESSION['transactionId'] = null; + $createdTransactionId = $this->createTransaction(); + $_SESSION['transactionId'] = $createdTransactionId; + } } diff --git a/info.xml b/info.xml index 7055a62..ae7d6f7 100644 --- a/info.xml +++ b/info.xml @@ -9,9 +9,16 @@ logo.jpg jtl_wallee 2023-05-29 - 1.0.24 + 1.0.25 + + jtl_wallee_transaction_timeout + Die Transaktion ist abgelaufen + Transaction was expired + La transazione era scaduta + La transaction a expiré + jtl_wallee_cancel Stornieren diff --git a/vendor/autoload.php b/vendor/autoload.php index efe0e38..dac3780 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitbb36d9e72c8b0ce3341be49810f52e97::getLoader(); +return ComposerAutoloaderInitfbf4f5b5940cc1faaf2d04e7841222ff::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index c40bb37..58f77ed 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitbb36d9e72c8b0ce3341be49810f52e97 +class ComposerAutoloaderInitfbf4f5b5940cc1faaf2d04e7841222ff { private static $loader; @@ -24,12 +24,12 @@ public static function getLoader() require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInitbb36d9e72c8b0ce3341be49810f52e97', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInitfbf4f5b5940cc1faaf2d04e7841222ff', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInitbb36d9e72c8b0ce3341be49810f52e97', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInitfbf4f5b5940cc1faaf2d04e7841222ff', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitbb36d9e72c8b0ce3341be49810f52e97::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInitfbf4f5b5940cc1faaf2d04e7841222ff::getInitializer($loader)); $loader->register(true); diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 8e5148f..66700d6 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitbb36d9e72c8b0ce3341be49810f52e97 +class ComposerStaticInitfbf4f5b5940cc1faaf2d04e7841222ff { public static $prefixLengthsPsr4 = array ( 'W' => @@ -32,9 +32,9 @@ class ComposerStaticInitbb36d9e72c8b0ce3341be49810f52e97 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitbb36d9e72c8b0ce3341be49810f52e97::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitbb36d9e72c8b0ce3341be49810f52e97::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitbb36d9e72c8b0ce3341be49810f52e97::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInitfbf4f5b5940cc1faaf2d04e7841222ff::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInitfbf4f5b5940cc1faaf2d04e7841222ff::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInitfbf4f5b5940cc1faaf2d04e7841222ff::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 7c6b39c..2dcd6f4 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '76a2c7461615d5ff759e7c4201252b072a626d98', + 'reference' => 'f2de1d3433707190b20ebfb178e375a7a9ba6542', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '76a2c7461615d5ff759e7c4201252b072a626d98', + 'reference' => 'f2de1d3433707190b20ebfb178e375a7a9ba6542', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(),