Skip to content

Commit d229451

Browse files
Merge pull request #83 from unzerdev/fix/magento-91
Release version 3.2.8
2 parents 6d70a38 + 703d452 commit d229451

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
55

6+
## [3.2.8](https://github.com/unzerdev/magento2/compare/3.2.7..3.2.8)
7+
### Fixed
8+
* Rounding issue in case of total amount mismatch
9+
610
## [3.2.7](https://github.com/unzerdev/magento2/compare/3.2.6..3.2.7)
711
### Added
812
* Client's IP address in every request sent to Unzer API

Helper/Order.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Unzer\PAPI\Helper;
@@ -125,11 +126,12 @@ public function createBasketForOrder(OrderModel $order): Basket
125126
{
126127
$basket = $this->createBasket($order);
127128
$vatRate = 0;
129+
$basketTotal = 0;
128130

129131
if ($order->getShippingAmount() > 0) {
130-
$basket->addBasketItem(
131-
$this->createShippingItem($order)
132-
);
132+
$shippingItem = $this->createShippingItem($order);
133+
$basket->addBasketItem($shippingItem);
134+
$basketTotal += $shippingItem->getAmountPerUnitGross();
133135
}
134136

135137
foreach ($order->getAllVisibleItems() as $orderItem) {
@@ -141,18 +143,28 @@ public function createBasketForOrder(OrderModel $order): Basket
141143
continue;
142144
}
143145

144-
$basket->addBasketItem(
145-
$this->createBasketItem($orderItem)
146-
);
146+
$item = $this->createBasketItem($orderItem);
147+
$basket->addBasketItem($item);
147148

148-
if($orderItem->getTaxPercent() !== null){
149+
if ($orderItem->getTaxPercent() !== null) {
149150
$vatRate = (float)$orderItem->getTaxPercent();
150151
}
152+
153+
$basketTotal += $item->getAmountPerUnitGross() * $item->getQuantity();
151154
}
152155

153156
if (abs($order->getBaseDiscountAmount()) > 0) {
157+
$vaucherItem = $this->createVoucherItem($order, $vatRate);
158+
$basket->addBasketItem($vaucherItem);
159+
$basketTotal -= abs($vaucherItem->getAmountDiscountPerUnitGross());
160+
}
161+
162+
$totalOrder = $order->getBaseGrandTotal();
163+
$difference = round($totalOrder - $basketTotal, 2);
164+
165+
if (abs($difference) > 0) {
154166
$basket->addBasketItem(
155-
$this->createVoucherItem($order, $vatRate)
167+
$this->createRoundingItem($difference)
156168
);
157169
}
158170

@@ -210,6 +222,25 @@ protected function createBasketItem(Item $orderItem): BasketItem
210222
return $basketItem;
211223
}
212224

225+
226+
private function createRoundingItem(float $amount): BasketItem
227+
{
228+
$item = new BasketItem();
229+
$item->setType(BasketItemTypes::VOUCHER);
230+
$item->setTitle('Rounding Adjustment');
231+
$item->setQuantity(1);
232+
$item->setVat(0.0);
233+
234+
if ($amount < 0) {
235+
$item->setAmountDiscountPerUnitGross(abs($amount));
236+
}
237+
if ($amount > 0) {
238+
$item->setAmountPerUnitGross($amount);
239+
}
240+
241+
return $item;
242+
}
243+
213244
/**
214245
* Create Voucher Item
215246
*

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "unzerdev/magento2",
33
"description": "This extension for Magento 2 provides a direct integration of the Unzer payment types to your Magento 2 shop via the Unzer Payment API (PAPI).",
44
"type": "magento2-module",
5-
"version": "3.2.7",
5+
"version": "3.2.8",
66
"license": "Apache-2.0",
77
"require": {
88
"php": "~7.4.0|~8.1.0|~8.2.0|~8.3.0",

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
4-
<module name="Unzer_PAPI" setup_version="3.2.7">
4+
<module name="Unzer_PAPI" setup_version="3.2.8">
55
<sequence>
66
<module name="Magento_Checkout"/>
77
<module name="Magento_Config" />

0 commit comments

Comments
 (0)