From 089555e77f90b4942200ed218ea17d54235bab31 Mon Sep 17 00:00:00 2001 From: andrewrowanwallee Date: Mon, 24 Nov 2025 11:56:40 +0100 Subject: [PATCH] Release 7.1.6 --- CHANGELOG.md | 6 ++ CHANGELOG_de-DE.md | 6 ++ README.md | 8 +-- composer.json | 2 +- docs/de/documentation.html | 2 +- docs/en/documentation.html | 2 +- docs/fr/documentation.html | 2 +- docs/it/documentation.html | 2 +- .../Service/TransactionService.php | 18 +++++- .../VRPaymentPaymentHandler.php | 62 +++++++++++++------ src/Core/Util/Analytics/Analytics.php | 2 +- src/Core/Util/Payload/TransactionPayload.php | 18 ++++-- 12 files changed, 94 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d5c1d8..44c689c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 7.1.6 +- Improved rounding handling to force 2 decimal places +- Removed references to unused classes +- Fixed some type errors +- Further improved 0 amount transaction; state transitions + # 7.1.5 - Improved analytics - Improved error handling for refunding amount 0 and too many items diff --git a/CHANGELOG_de-DE.md b/CHANGELOG_de-DE.md index d863183..23efd00 100644 --- a/CHANGELOG_de-DE.md +++ b/CHANGELOG_de-DE.md @@ -1,3 +1,9 @@ +# 7.1.6 +- Verbesserte Rundungsbehandlung für zwei Dezimalstellen +- Entfernte Verweise auf ungenutzte Klassen +- Behebung einiger Typfehler +- Weitere Verbesserung von Transaktionen mit dem Betrag 0 und Zustandsübergängen + # 7.1.5 - Verbesserte Analysefunktionen - Verbesserte Fehlerbehandlung bei Rückerstattungen von 0 Beträgen und zu vielen Artikeln diff --git a/README.md b/README.md index d2ddb8d..1b92d08 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,10 @@ Please note that this plugin is for versions 6.5, 6.6 or 6.7. For the 6.4 plugin ## Documentation -- For English documentation click [here](https://docs.plugin-documentation.vr-payment.de/vr-payment/shopware-6/7.1.5/docs/en/documentation.html) -- Für die deutsche Dokumentation klicken Sie [hier](https://docs.plugin-documentation.vr-payment.de/vr-payment/shopware-6/7.1.5/docs/de/documentation.html) -- Pour la documentation Française, cliquez [ici](https://docs.plugin-documentation.vr-payment.de/vr-payment/shopware-6/7.1.5/docs/fr/documentation.html) -- Per la documentazione in tedesco, clicca [qui](https://docs.plugin-documentation.vr-payment.de/vr-payment/shopware-6/7.1.5/docs/it/documentation.html) +- For English documentation click [here](https://docs.plugin-documentation.vr-payment.de/vr-payment/shopware-6/7.1.6/docs/en/documentation.html) +- Für die deutsche Dokumentation klicken Sie [hier](https://docs.plugin-documentation.vr-payment.de/vr-payment/shopware-6/7.1.6/docs/de/documentation.html) +- Pour la documentation Française, cliquez [ici](https://docs.plugin-documentation.vr-payment.de/vr-payment/shopware-6/7.1.6/docs/fr/documentation.html) +- Per la documentazione in tedesco, clicca [qui](https://docs.plugin-documentation.vr-payment.de/vr-payment/shopware-6/7.1.6/docs/it/documentation.html) ## Installation diff --git a/composer.json b/composer.json index af53dec..d681543 100644 --- a/composer.json +++ b/composer.json @@ -59,5 +59,5 @@ "vrpayment/sdk": "^4.0.0" }, "type": "shopware-platform-plugin", - "version": "7.1.5" + "version": "7.1.6" } diff --git a/docs/de/documentation.html b/docs/de/documentation.html index f04dd0e..649be25 100644 --- a/docs/de/documentation.html +++ b/docs/de/documentation.html @@ -23,7 +23,7 @@
  • - + Source
  • diff --git a/docs/en/documentation.html b/docs/en/documentation.html index 5e4b115..64724b0 100644 --- a/docs/en/documentation.html +++ b/docs/en/documentation.html @@ -23,7 +23,7 @@
  • - + Source
  • diff --git a/docs/fr/documentation.html b/docs/fr/documentation.html index eddd876..d3f40d6 100644 --- a/docs/fr/documentation.html +++ b/docs/fr/documentation.html @@ -23,7 +23,7 @@
  • - + Source
  • diff --git a/docs/it/documentation.html b/docs/it/documentation.html index a218506..d4fb81b 100644 --- a/docs/it/documentation.html +++ b/docs/it/documentation.html @@ -23,7 +23,7 @@
  • - + Source
  • diff --git a/src/Core/Api/Transaction/Service/TransactionService.php b/src/Core/Api/Transaction/Service/TransactionService.php index 9fccd66..e67ca20 100644 --- a/src/Core/Api/Transaction/Service/TransactionService.php +++ b/src/Core/Api/Transaction/Service/TransactionService.php @@ -387,7 +387,7 @@ class TransactionService * * @return \Shopware\Core\Checkout\Order\OrderEntity */ - protected function getOrderEntity(string $orderId, Context $context): OrderEntity + public function getOrderEntity(string $orderId, Context $context): OrderEntity { try { $criteria = (new Criteria([$orderId]))->addAssociations(['deliveries']); @@ -721,18 +721,20 @@ class TransactionService { $lineItem = new LineItemCreate(); + $roundedPrice = $this->round($productData->getPrice()->getUnitPrice()); + if ($productData instanceof LineItem) { $lineItem->setName($productData->getLabel()); $lineItem->setUniqueId($productData->getId()); $lineItem->setSku($productData->getReferencedId() ?? $productData->getId()); $lineItem->setQuantity($productData->getQuantity()); - $lineItem->setAmountIncludingTax($productData->getPrice()->getUnitPrice()); + $lineItem->setAmountIncludingTax($roundedPrice); } elseif ($productData instanceof OrderLineItemEntity) { $lineItem->setName($productData->getLabel()); $lineItem->setUniqueId($productData->getId()); $lineItem->setSku($productData->getProductId() ?? $productData->getIdentifier() ?? $productData->getId()); $lineItem->setQuantity($productData->getQuantity()); - $lineItem->setAmountIncludingTax($productData->getUnitPrice()); + $lineItem->setAmountIncludingTax($roundedPrice); } else { throw new \InvalidArgumentException('Unsupported line item type: ' . get_class($productData)); } @@ -806,4 +808,14 @@ class TransactionService } return false; } + + /** + * @param $amount + * @param int $precision + * + * @return float + */ + private function round($value, $precision = 2): float { + return \round($value, $precision); + } } diff --git a/src/Core/Checkout/PaymentHandler/VRPaymentPaymentHandler.php b/src/Core/Checkout/PaymentHandler/VRPaymentPaymentHandler.php index 1de2c2f..517e495 100644 --- a/src/Core/Checkout/PaymentHandler/VRPaymentPaymentHandler.php +++ b/src/Core/Checkout/PaymentHandler/VRPaymentPaymentHandler.php @@ -125,7 +125,9 @@ class VRPaymentPaymentHandler extends AbstractPaymentHandler $orderTransactionId = $transaction->getOrderTransactionId(); $orderTransaction = $this->orderTransactionRepository->search( (new Criteria([$orderTransactionId])) - ->addAssociation('order'), $context + ->addAssociation('order') + ->addAssociation('stateMachineState'), + $context )->getEntities()->first(); $contextSource = $context->getSource(); @@ -133,20 +135,9 @@ class VRPaymentPaymentHandler extends AbstractPaymentHandler $salesChannelContextId = $contextSource->getSalesChannelId(); } - $orderCustomer = $orderTransaction->getOrder()?->getOrderCustomer(); - - if ($orderCustomer) { - $customerId = $orderCustomer->getCustomerId(); - } else { - $customerId = null; - } + $contextToken = $this->getContextToken($request); + $parameters = new SalesChannelContextServiceParameters($salesChannelContextId, $contextToken, originalContext: $context); - $parameters = new SalesChannelContextServiceParameters( - $salesChannelContextId, - $request->getSession()->get("sw-context-token", Random::getAlphanumericString(32)), - originalContext: $context, - customerId: $customerId - ); $salesChannelContext = $this->salesChannelContextService->get($parameters); $redirectUrl = $transaction->getReturnUrl(); @@ -162,7 +153,10 @@ class VRPaymentPaymentHandler extends AbstractPaymentHandler $request->getSession()->remove('transactionId'); $errorMessage = 'An error occurred during the communication with external payment gateway : ' . $e->getMessage(); $this->logger->critical($errorMessage); - throw PaymentException::customerCanceled($orderTransactionId, $errorMessage); + if ($orderTransaction->getState()?->getTechnicalName() === OrderTransactionStates::STATE_CANCELLED) { + throw PaymentException::asyncFinalizeInterrupted($orderTransaction->getOrder()->getId(), $errorMessage); + } + throw PaymentException::customerCanceled($transaction->getOrderTransactionId(), $errorMessage); } } @@ -186,7 +180,9 @@ class VRPaymentPaymentHandler extends AbstractPaymentHandler $orderTransactionId = $transaction->getOrderTransactionId(); $orderTransaction = $this->orderTransactionRepository->search( (new Criteria([$orderTransactionId])) - ->addAssociation('order'), $context + ->addAssociation('order') + ->addAssociation('stateMachineState'), + $context )->getEntities()->first(); if ($orderTransaction->getOrder()->getAmountTotal() > 0) { @@ -215,7 +211,11 @@ class VRPaymentPaymentHandler extends AbstractPaymentHandler $token = $request->getSession()->get('sw-context-token'); if ($token) { - $salesChannelId = $transactionEntity->getSalesChannelId(); + $orderEntity = $this->pluginTransactionService->getOrderEntity( + $orderTransaction->getOrder()->getId(), + $context + ); + $salesChannelId = $orderEntity->getSalesChannelId(); $parameters = new SalesChannelContextServiceParameters($salesChannelId, $token, originalContext: $context); $salesChannelContext = $this->salesChannelContextService->get($parameters); @@ -432,7 +432,9 @@ class VRPaymentPaymentHandler extends AbstractPaymentHandler { $lineItemCreate = new \VRPayment\Sdk\Model\LineItemCreate(); - $lineItemCreate->setAmountIncludingTax($lineItem->getAmountIncludingTax()); + $roundedPrice = $this->round($lineItem->getAmountIncludingTax()); + + $lineItemCreate->setAmountIncludingTax($roundedPrice); $attributes = $lineItem->getAttributes(); $attributesCreate = []; @@ -469,4 +471,28 @@ class VRPaymentPaymentHandler extends AbstractPaymentHandler return $lineItemCreate; } + + /** + * @param $amount + * @param int $precision + * + * @return float + */ + private function round($value, $precision = 2): float { + return \round($value, $precision); + } + + private function getContextToken(Request $request): string + { + $headerContextToken = $request->headers->get('sw-context-token'); + if ($headerContextToken) { + return $headerContextToken; + } + + $sessionContextToken = $request->getSession()->get("sw-context-token"); + if (!$sessionContextToken) { + return $sessionContextToken; + } + return Random::getAlphanumericString(32); + } } diff --git a/src/Core/Util/Analytics/Analytics.php b/src/Core/Util/Analytics/Analytics.php index 5f84b9a..95c0e0b 100644 --- a/src/Core/Util/Analytics/Analytics.php +++ b/src/Core/Util/Analytics/Analytics.php @@ -26,7 +26,7 @@ class Analytics { self::SHOP_SYSTEM => 'shopware', self::SHOP_SYSTEM_VERSION => '6', self::SHOP_SYSTEM_AND_VERSION => 'shopware-6', - self::PLUGIN_SYSTEM_VERSION => '7.1.5', + self::PLUGIN_SYSTEM_VERSION => '7.1.6', ]; } diff --git a/src/Core/Util/Payload/TransactionPayload.php b/src/Core/Util/Payload/TransactionPayload.php index 29dc8f1..f8041fc 100644 --- a/src/Core/Util/Payload/TransactionPayload.php +++ b/src/Core/Util/Payload/TransactionPayload.php @@ -397,7 +397,9 @@ class TransactionPayload extends AbstractPayload $discountTitle = sprintf('DISCOUNT: %s', $discountName); } - $lineItem->setAmountIncludingTax($amount) + $roundedAmount = self::round($amount); + + $lineItem->setAmountIncludingTax($roundedAmount) ->setName($discountTitle) ->setQuantity(1) ->setShippingRequired(false) @@ -520,12 +522,14 @@ class TransactionPayload extends AbstractPayload $amount = self::round($amount + $shopLineItem->getPrice()->getCalculatedTaxes()->getAmount()); } + $roundedAmount = self::round($amount); + $lineItem = (new LineItemCreate()) ->setName($this->fixLength($shopLineItem->getLabel(), 150)) ->setUniqueId($uniqueId) ->setSku($sku) ->setQuantity($shopLineItem->getQuantity() ?? 1) - ->setAmountIncludingTax($amount); + ->setAmountIncludingTax($roundedAmount); if (!empty($shopLineItem->getType()) && $shopLineItem->getType() == CustomProductsLineItemTypes::LINE_ITEM_TYPE_CUSTOMIZED_PRODUCTS) { @@ -644,9 +648,10 @@ class TransactionPayload extends AbstractPayload $amount = self::round($amount + $this->order->getShippingCosts()->getCalculatedTaxes()->getAmount()); } + $roundedAmount = self::round($amount); $lineItem = (new LineItemCreate()) - ->setAmountIncludingTax($amount) + ->setAmountIncludingTax($roundedAmount) ->setName($this->fixLength($shippingName . ' ' . $this->translator->trans('vrpayment.payload.shipping.lineItem'), 150)) ->setQuantity($this->order->getShippingCosts()->getQuantity() ?? 1) ->setSku($this->fixLength($shippingName . '-Shipping', 200)) @@ -694,9 +699,11 @@ class TransactionPayload extends AbstractPayload ->setRate($taxRate) ->setTitle('Tax rate: '.$taxRate); + $roundedAmount = self::round($amount); + $name = $taxRate . '%-' . $shippingName; $lineItem = (new LineItemCreate()) - ->setAmountIncludingTax($amount) + ->setAmountIncludingTax($roundedAmount) ->setName($this->fixLength($name . ' ' . $this->translator->trans('vrpayment.payload.shipping.lineItem'), 150)) ->setQuantity($this->order->getShippingCosts()->getQuantity() ?? 1) ->setSku($this->fixLength($name . '-Shipping', 200)) @@ -768,7 +775,8 @@ class TransactionPayload extends AbstractPayload ->setSku('Adjustment-Line-Item') ->setQuantity(1); /** @noinspection PhpParamsInspection */ - $lineItem->setAmountIncludingTax($adjustmentPrice) + $roundedAdjustmentPrice = self::round($adjustmentPrice); + $lineItem->setAmountIncludingTax($roundedAdjustmentPrice) ->setType(($adjustmentPrice > 0) ? LineItemType::FEE : LineItemType::DISCOUNT); if (!$lineItem->valid()) {