Skip to content

Commit 497fa75

Browse files
committed
Release 1.0.32
1 parent 9215a09 commit 497fa75

File tree

593 files changed

+4100
-4025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

593 files changed

+4100
-4025
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ account dashboard.
3636

3737
## Documentation
3838

39-
[Documentation](https://plugin-documentation.wallee.com/wallee-payment/jtl-5/1.0.31/docs/en/documentation.html)
39+
[Documentation](https://plugin-documentation.wallee.com/wallee-payment/jtl-5/1.0.32/docs/en/documentation.html)
4040

4141
## License
4242

Services/WalleeTransactionService.php

Lines changed: 80 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,39 @@
44

55
use JTL\Alert\Alert;
66
use JTL\Cart\CartItem;
7-
use JTL\Checkout\Nummern;
8-
use JTL\Catalog\Product\Preise;
97
use JTL\Checkout\Bestellung;
108
use JTL\Checkout\OrderHandler;
119
use JTL\Checkout\Zahlungsart;
12-
use JTL\Helpers\PaymentMethod;
1310
use JTL\Helpers\Tax;
14-
use JTL\Mail\Mailer;
1511
use JTL\Mail\Mail\Mail;
12+
use JTL\Mail\Mailer;
1613
use JTL\Plugin\Payment\Method;
17-
use JTL\Plugin\Plugin;
1814
use JTL\Session\Frontend;
1915
use JTL\Shop;
2016
use Plugin\jtl_wallee\WalleeHelper;
21-
use Plugin\jtl_wallee\Services\WalleeMailService;
17+
use stdClass;
2218
use Wallee\Sdk\ApiClient;
23-
use Wallee\Sdk\Model\{
24-
AddressCreate,
25-
Gender,
26-
LineItemCreate,
27-
LineItemType,
28-
TaxCreate,
29-
Transaction,
30-
TransactionCreate,
31-
TransactionInvoice,
32-
TransactionPending,
33-
TransactionState,
34-
CreationEntityState,
35-
CriteriaOperator,
36-
EntityQuery,
37-
EntityQueryFilter,
38-
EntityQueryFilterType,
39-
RefundState,
40-
TransactionInvoiceState,
41-
WebhookListener,
42-
WebhookListenerCreate,
43-
WebhookUrl,
44-
WebhookUrlCreate,
45-
};
19+
use Wallee\Sdk\Model\{AddressCreate,
20+
CreationEntityState,
21+
CriteriaOperator,
22+
EntityQuery,
23+
EntityQueryFilter,
24+
EntityQueryFilterType,
25+
Gender,
26+
LineItemCreate,
27+
LineItemType,
28+
RefundState,
29+
TaxCreate,
30+
Transaction,
31+
TransactionCreate,
32+
TransactionInvoice,
33+
TransactionInvoiceState,
34+
TransactionPending,
35+
TransactionState,
36+
WebhookListener,
37+
WebhookListenerCreate,
38+
WebhookUrl,
39+
WebhookUrlCreate,};
4640

4741
class WalleeTransactionService
4842
{
@@ -206,7 +200,8 @@ public function confirmTransaction(Transaction $transaction): void
206200
$pendingTransaction->setSuccessUrl($successUrl . '?tID=' . $transactionId);
207201
$pendingTransaction->setFailedUrl($failedUrl . '?tID=' . $transactionId);
208202

209-
203+
204+
210205
$this->apiClient->getTransactionService()
211206
->confirm($this->spaceId, $pendingTransaction);
212207

@@ -503,40 +498,38 @@ public function createLocalWalleeTransaction(string $transactionId, array $order
503498
*/
504499
public function addIncommingPayment(string $transactionId, Bestellung $order, Transaction $transaction): void
505500
{
506-
$localTransaction = $this->getLocalWalleeTransactionById($transactionId);
507-
if ($localTransaction->state !== TransactionState::FULFILL) {
508-
$orderId = (int)$order->kBestellung;
509-
510-
if ($orderId === 0) {
501+
$orderId = (int)$order->kBestellung;
502+
if ($orderId === 0) {
503+
return;
504+
}
505+
$this->updateTransactionStatus($transactionId, TransactionState::FULFILL);
506+
507+
$portalTransaction = $this->getTransactionFromPortal($transactionId);
508+
if ($portalTransaction->getState() === TransactionState::FULFILL) {
509+
// tzahlungseingang - table name of incomming payments
510+
// kBestellung - table field which represents order ID
511+
$incomingPaymentCheck = Shop::Container()->getDB()->selectSingleRow('tzahlungseingang', 'kBestellung', $orderId);
512+
// We check if there's record for incomming payment for current order
513+
if (!empty($incomingPaymentCheck->kZahlungseingang)) {
511514
return;
512515
}
513-
$this->updateTransactionStatus($transactionId, TransactionState::FULFILL);
514-
515-
$portalTransaction = $this->getTransactionFromPortal($transactionId);
516-
if ($portalTransaction->getState() === TransactionState::FULFILL) {
517-
// tzahlungseingang - table name of incomming payments
518-
// kBestellung - table field which represents order ID
519-
$incommingPayment = Shop::Container()->getDB()->selectSingleRow('tzahlungseingang', 'kBestellung', $orderId);
520-
// We check if there's record for incomming payment for current order
521-
if (!empty($incommingPayment->kZahlungseingang)) {
522-
return;
523-
}
524516

525-
$paymentMethodEntity = new Zahlungsart((int)$order->kZahlungsart);
526-
$moduleId = $paymentMethodEntity->cModulId ?? '';
527-
$paymentMethod = new Method($moduleId);
528-
$paymentMethod->setOrderStatusToPaid($order);
529-
$incomingPayment = new \stdClass();
530-
$incomingPayment->fBetrag = $transaction->getAuthorizationAmount();
531-
$incomingPayment->cISO = $transaction->getCurrency();
532-
$incomingPayment->cZahlungsanbieter = $order->cZahlungsartName;
533-
$incomingPayment->cHinweis = $transactionId;
534-
$paymentMethod->addIncomingPayment($order, $incomingPayment);
535-
536-
// At this stage, the transaction goes directly to fulfill, so it's also authorized.
537-
// Even when the sendEmail is invoked here, the email will be or not sent according to several conditions.
538-
$this->sendEmail($orderId, 'fulfill');
539-
}
517+
$paymentMethodEntity = new Zahlungsart((int)$order->kZahlungsart);
518+
$moduleId = $paymentMethodEntity->cModulId ?? '';
519+
$paymentMethod = new Method($moduleId);
520+
$paymentMethod->setOrderStatusToPaid($order);
521+
$incomingPayment = new \stdClass();
522+
$incomingPayment->fBetrag = $transaction->getAuthorizationAmount();
523+
$incomingPayment->cISO = $transaction->getCurrency();
524+
$incomingPayment->cZahlungsanbieter = $order->cZahlungsartName;
525+
$incomingPayment->cHinweis = $transactionId;
526+
$paymentMethod->addIncomingPayment($order, $incomingPayment);
527+
528+
// At this stage, the transaction goes directly to fulfill, so it's also authorized.
529+
// Even when the sendEmail is invoked here, the email will be or not sent according to several conditions.
530+
$this->sendEmail($orderId, 'fulfill');
531+
} else {
532+
Shop::Container()->getLogService()->error('addIncommingPayment payment was not created, because transaction was not in FULFILL status. TransactionId: ' . $transactionId);
540533
}
541534
}
542535

@@ -549,34 +542,26 @@ public function createOrderAfterPayment(int $transactionId): int
549542
$_SESSION['finalize'] = true;
550543

551544
$transaction = $this->getTransactionFromPortal($transactionId);
552-
553545
$orderNr = $transaction->getMetaData()['order_nr'];
554546
$orderHandler = new OrderHandler(Shop::Container()->getDB(), Frontend::getCustomer(), Frontend::getCart());
555547

556548
if ($this->isPreventFromDuplicatedOrders()) {
557549
// We check if order exist with such order nr. If yes, we select it's data, if not - we create it.
558550
// This check prevents only in these cases when webhook is triggered more than once or user refresh the page, or
559551
// got lost internet connection. It's more like catching edge case
560-
$data = Shop::Container()->getDB()->select(
561-
'tbestellung',
562-
'cBestellNr',
563-
$orderNr,
564-
null,
565-
null,
566-
null,
567-
null,
568-
false,
569-
'kBestellung'
570-
);
571-
if ($data !== null && isset($data->kBestellung)) {
572-
$order = new Bestellung((int)$data->kBestellung);
573-
} else {
552+
$data = $this->getOrderIfExists($orderNr);
553+
if ($data === null) {
554+
// Order wasn't created before, so we insert new record
574555
$order = $orderHandler->finalizeOrder($orderNr, false);
556+
} else {
557+
// We select order from database and creating backup with all session data
558+
$order = new Bestellung((int)$data->kBestellung);
575559
}
576560
} else {
577561
// Updates order number for next order. Increase by 1 if is needed
578562
$lastOrderNo = $transaction->getMetaData()['order_no'];
579563
WalleeHelper::createOrderNo(true, $lastOrderNo);
564+
// Always inserting new order
580565
$order = $orderHandler->finalizeOrder($orderNr, false);
581566
}
582567
$this->updateLocalWalleeTransaction((string)$transactionId, TransactionState::AUTHORIZED, (int)$order->kBestellung);
@@ -589,6 +574,24 @@ public function createOrderAfterPayment(int $transactionId): int
589574

590575
return (int)$order->kBestellung;
591576
}
577+
578+
/**
579+
* @param string $orderNr
580+
* @return void
581+
*/
582+
public function getOrderIfExists(string $orderNr): ?stdClass
583+
{
584+
$db = Shop::Container()->getDB();
585+
586+
// Prepare and execute the query directly
587+
$query = "SELECT kBestellung FROM tbestellung WHERE cBestellNr = :orderNr ORDER BY dErstellt DESC LIMIT 1";
588+
$params = ['orderNr' => $orderNr];
589+
590+
$data = $db->executeQueryPrepared($query, $params, 1); // The '1' here signifies to fetch one row only
591+
592+
// Check if data is retrieved, otherwise return null
593+
return $data ?: null;
594+
}
592595

593596
/**
594597
* @param string $transactionId
@@ -848,7 +851,7 @@ private function isPreventFromDuplicatedOrders(): bool
848851
$config = WalleeHelper::getConfigByID($this->plugin->getId());
849852
$preventFromDuplicatedOrders = $config[WalleeHelper::PREVENT_FROM_DUPLICATED_ORDERS] ?? null;
850853

851-
return $preventFromDuplicatedOrders === 'YES';
854+
return strtolower($preventFromDuplicatedOrders) === 'yes';
852855
}
853856

854857
/**

Webhooks/Strategies/WalleeNameOrderUpdateTransactionInvoiceStrategy.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Plugin\jtl_wallee\Webhooks\Strategies;
44

5+
use JTL\Shop;
56
use Plugin\jtl_wallee\Services\WalleeOrderService;
67
use Plugin\jtl_wallee\Services\WalleeTransactionService;
78
use Plugin\jtl_wallee\Webhooks\Strategies\Interfaces\WalleeOrderUpdateStrategyInterface;
@@ -39,8 +40,9 @@ public function updateOrderStatus(string $entityId): void
3940
->getTransaction();
4041

4142
$transactionId = $transaction->getId();
42-
$localTransaction = $this->transactionService->getLocalWalleeTransactionById((string)$transactionId);
43-
$orderId = (int)$localTransaction->order_id;
43+
$orderNr = $transaction->getMetaData()['order_nr'];
44+
$orderData = $this->transactionService->getOrderIfExists($orderNr);
45+
$orderId = (int)$orderData->kBestellung;
4446

4547
switch ($transactionInvoice->getState()) {
4648
case TransactionInvoiceState::DERECOGNIZED:

Webhooks/Strategies/WalleeNameOrderUpdateTransactionStrategy.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44

55
use JTL\Checkout\Bestellung;
66
use JTL\Checkout\Zahlungsart;
7-
use JTL\Customer\Customer;
8-
use JTL\Mail\Mail\Mail;
9-
use JTL\Mail\Mailer;
10-
use JTL\Plugin\Data\PaymentMethod;
117
use JTL\Plugin\Payment\Method;
128
use JTL\Plugin\Plugin;
13-
use JTL\Session\Frontend;
149
use JTL\Shop;
1510
use Plugin\jtl_wallee\Services\WalleeOrderService;
1611
use Plugin\jtl_wallee\Services\WalleeTransactionService;
1712
use Plugin\jtl_wallee\Webhooks\Strategies\Interfaces\WalleeOrderUpdateStrategyInterface;
18-
use Plugin\jtl_wallee\WalleeHelper;
19-
use stdClass;
2013
use Wallee\Sdk\Model\Transaction;
2114
use Wallee\Sdk\Model\TransactionState;
2215

@@ -52,11 +45,12 @@ public function updateOrderStatus(string $entityId): void
5245
{
5346
$transaction = $this->transactionService->getTransactionFromPortal($entityId);
5447
$transactionId = $transaction->getId();
55-
56-
$localTransaction = $this->transactionService->getLocalWalleeTransactionById((string)$transactionId);
57-
$orderId = (int)$localTransaction->order_id;
48+
49+
$orderNr = $transaction->getMetaData()['order_nr'];
50+
$orderData = $this->transactionService->getOrderIfExists($orderNr);
51+
$orderId = (int)$orderData->kBestellung;
5852
$transactionState = $transaction->getState();
59-
53+
6054
switch ($transactionState) {
6155
case TransactionState::FULFILL:
6256
$order = new Bestellung($orderId);

0 commit comments

Comments
 (0)