Skip to content

Commit

Permalink
Release 1.0.25
Browse files Browse the repository at this point in the history
  • Loading branch information
edgaraswallee committed May 22, 2024
1 parent 4fbddfb commit fb8533c
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 72 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
73 changes: 61 additions & 12 deletions Services/WalleeTransactionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');
}
Expand Down
32 changes: 26 additions & 6 deletions adminmenu/AdminTabProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
34 changes: 17 additions & 17 deletions adminmenu/templates/wallee_orders.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,41 @@
{foreach $orders as $order}
<tr>
<td class="text-left">
<div>{$order->cBestellNr}</div>
<div>{$order['orderDetails']->cBestellNr}</div>
<small class="text-muted"><i class="far fa-calendar-alt"
aria-hidden="true"></i> {$order->dErstellt}</small>
aria-hidden="true"></i> {$order['orderDetails']->dErstellt}</small>
</td>
<td>
<div>
{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')}
{/if}
</div>
<small class="text-muted">
<i class="fa fa-user" aria-hidden="true"></i>
{$order->oKunde->cMail}
{$order['orderDetails']->oKunde->cMail}
</small>
</td>
<td class="text-left">{$order->cZahlungsartName}</td>
<td class="text-left">{$order['orderDetails']->cZahlungsartName}</td>
<td class="text-left">
{$paymentStatus[$order->cStatus]}
{$paymentStatus[$order['orderDetails']->cStatus]}
</td>
<td class="text-left">
{$order->WarensummeLocalized[0]}
{$order['orderDetails']->WarensummeLocalized[0]}
</td>
<td onclick="showDetails({
'total_amount':'{$order->total_amount}',
'order_id':'{$order->kBestellung}',
'order_no':'{$order->cBestellNr}',
'transaction_id': '{$order->wallee_transaction_id}',
'transaction_state': '{$order->wallee_state}',
'action': 'order_details'
})">
'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'
})">
<a href="#order-datails">
<i class="fa fa-eye"></i>
</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/en/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2>Documentation</h2> </div>
</a>
</li>
<li>
<a href="https://github.com/wallee-payment/jtl-5/releases/tag/1.0.24/">
<a href="https://github.com/wallee-payment/jtl-5/releases/tag/1.0.25/">
Source
</a>
</li>
Expand Down
73 changes: 50 additions & 23 deletions frontend/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

}
9 changes: 8 additions & 1 deletion info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
<Icon>logo.jpg</Icon>
<PluginID>jtl_wallee</PluginID>
<CreateDate>2023-05-29</CreateDate>
<Version>1.0.24</Version>
<Version>1.0.25</Version>
<Install>
<Locales>
<Variable>
<Name>jtl_wallee_transaction_timeout</Name>
<VariableLocalized iso="GER">Die Transaktion ist abgelaufen</VariableLocalized>
<VariableLocalized iso="ENG">Transaction was expired</VariableLocalized>
<VariableLocalized iso="ITA">La transazione era scaduta</VariableLocalized>
<VariableLocalized iso="FRE">La transaction a expiré</VariableLocalized>
</Variable>
<Variable>
<Name>jtl_wallee_cancel</Name>
<VariableLocalized iso="GER">Stornieren</VariableLocalized>
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitbb36d9e72c8b0ce3341be49810f52e97::getLoader();
return ComposerAutoloaderInitfbf4f5b5940cc1faaf2d04e7841222ff::getLoader();
8 changes: 4 additions & 4 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInitbb36d9e72c8b0ce3341be49810f52e97
class ComposerAutoloaderInitfbf4f5b5940cc1faaf2d04e7841222ff
{
private static $loader;

Expand All @@ -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);

Expand Down
Loading

0 comments on commit fb8533c

Please sign in to comment.