diff --git a/README.md b/README.md index 90fb836..baec01c 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.29/docs/en/documentation.html) +[Documentation](https://plugin-documentation.wallee.com/wallee-payment/jtl-5/1.0.30/docs/en/documentation.html) ## License diff --git a/Webhooks/Strategies/WalleeNameOrderUpdateRefundStrategy.php b/Webhooks/Strategies/WalleeNameOrderUpdateRefundStrategy.php index e40ec89..bf07712 100644 --- a/Webhooks/Strategies/WalleeNameOrderUpdateRefundStrategy.php +++ b/Webhooks/Strategies/WalleeNameOrderUpdateRefundStrategy.php @@ -7,6 +7,9 @@ use Plugin\jtl_wallee\Services\WalleeTransactionService; use Plugin\jtl_wallee\Webhooks\Strategies\Interfaces\WalleeOrderUpdateStrategyInterface; use Wallee\Sdk\Model\TransactionState; +use JTL\Catalog\Product\Artikel; +use JTL\Checkout\StockUpdater; +use JTL\Helpers\Product; class WalleeNameOrderUpdateRefundStrategy implements WalleeOrderUpdateStrategyInterface { @@ -25,11 +28,23 @@ class WalleeNameOrderUpdateRefundStrategy implements WalleeOrderUpdateStrategyIn */ private $orderService; + /** + * The StockUpdater's JTL service. + * + * @var JTL\Checkout\StockUpdater + */ + protected $stockUpdater; + public function __construct(WalleeRefundService $refundService, WalleeTransactionService $transactionService) { $this->refundService = $refundService; $this->transactionService = $transactionService; $this->orderService = new WalleeOrderService(); + + if (!function_exists('getStockUpdater')) { + require_once \PFAD_ROOT . \PFAD_INCLUDES . 'bestellabschluss_inc.php'; + } + $this->stockUpdater = getStockUpdater(); } /** @@ -54,6 +69,31 @@ public function updateOrderStatus(string $entityId): void $transaction = $refund->getTransaction(); $amountToBeRefunded = round(floatval($transaction->getCompletedAmount()) - $transaction->getRefundedAmount(), 2); + // Restores the stock of the refunded product. + $reductions = $refund->getReductions(); + $quantity = 0; + if (count($reductions) > 0) { + foreach ($reductions as $reduction) { + $quantity = $reduction->getQuantityReduction(); + $line_item_id = $reduction->getLineItemUniqueId(); + if ($quantity > 0) { + foreach ($refund->getReducedLineItems() as $line_item) { + if ($line_item_id == $line_item->getUniqueId()) { + $product_name = $line_item->getName(); + $product = Product::getProductByAttribute('cName', $product_name); + if ($product instanceof Artikel) { + $productID = $product->getID(); + // Amount is negative because we're filling up the stock. + $this->stockUpdater->updateProductStockLevel($productID, -1, $quantity); + } + } + } + } + + $quantity = 0; + } + } + if ($amountToBeRefunded > 0) { $this->orderService->updateOrderStatus($orderId, \BESTELLUNG_STATUS_BEZAHLT, \BESTELLUNG_STATUS_TEILVERSANDT); $this->transactionService->updateTransactionStatus($transaction->getId(), 'PARTIALLY REFUNDED'); diff --git a/docs/en/documentation.html b/docs/en/documentation.html index a4ff46b..ccd819e 100644 --- a/docs/en/documentation.html +++ b/docs/en/documentation.html @@ -23,7 +23,7 @@

Documentation

  • - + Source
  • diff --git a/frontend/wallee_iframe.php b/frontend/wallee_iframe.php index 35b66db..b9d41d3 100644 --- a/frontend/wallee_iframe.php +++ b/frontend/wallee_iframe.php @@ -1,5 +1,6 @@ logo.jpg jtl_wallee 2023-05-29 - 1.0.29 + 1.0.30 diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index b63cbaf..df5ade1 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' => '23881441945da62c99ed76e8ccae1abaa8c573cc', + 'reference' => '444a0d4db972eeb5f986817906a3c2d5411820ed', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '23881441945da62c99ed76e8ccae1abaa8c573cc', + 'reference' => '444a0d4db972eeb5f986817906a3c2d5411820ed', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(),