Skip to content

Release version 3.2.8 #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

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).

## [3.2.8](https://github.com/unzerdev/magento2/compare/3.2.7..3.2.8)
### Fixed
* Rounding issue in case of total amount mismatch

## [3.2.7](https://github.com/unzerdev/magento2/compare/3.2.6..3.2.7)
### Added
* Client's IP address in every request sent to Unzer API
Expand Down
47 changes: 39 additions & 8 deletions Helper/Order.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Unzer\PAPI\Helper;
Expand Down Expand Up @@ -125,11 +126,12 @@ public function createBasketForOrder(OrderModel $order): Basket
{
$basket = $this->createBasket($order);
$vatRate = 0;
$basketTotal = 0;

if ($order->getShippingAmount() > 0) {
$basket->addBasketItem(
$this->createShippingItem($order)
);
$shippingItem = $this->createShippingItem($order);
$basket->addBasketItem($shippingItem);
$basketTotal += $shippingItem->getAmountPerUnitGross();
}

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

$basket->addBasketItem(
$this->createBasketItem($orderItem)
);
$item = $this->createBasketItem($orderItem);
$basket->addBasketItem($item);

if($orderItem->getTaxPercent() !== null){
if ($orderItem->getTaxPercent() !== null) {
$vatRate = (float)$orderItem->getTaxPercent();
}

$basketTotal += $item->getAmountPerUnitGross() * $item->getQuantity();
}

if (abs($order->getBaseDiscountAmount()) > 0) {
$vaucherItem = $this->createVoucherItem($order, $vatRate);
$basket->addBasketItem($vaucherItem);
$basketTotal -= abs($vaucherItem->getAmountDiscountPerUnitGross());
}

$totalOrder = $order->getBaseGrandTotal();
$difference = round($totalOrder - $basketTotal, 2);

if (abs($difference) > 0) {
$basket->addBasketItem(
$this->createVoucherItem($order, $vatRate)
$this->createRoundingItem($difference)
);
}

Expand Down Expand Up @@ -210,6 +222,25 @@ protected function createBasketItem(Item $orderItem): BasketItem
return $basketItem;
}


private function createRoundingItem(float $amount): BasketItem
{
$item = new BasketItem();
$item->setType(BasketItemTypes::VOUCHER);
$item->setTitle('Rounding Adjustment');
$item->setQuantity(1);
$item->setVat(0.0);

if ($amount < 0) {
$item->setAmountDiscountPerUnitGross(abs($amount));
}
if ($amount > 0) {
$item->setAmountPerUnitGross($amount);
}

return $item;
}

/**
* Create Voucher Item
*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "unzerdev/magento2",
"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).",
"type": "magento2-module",
"version": "3.2.7",
"version": "3.2.8",
"license": "Apache-2.0",
"require": {
"php": "~7.4.0|~8.1.0|~8.2.0|~8.3.0",
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Unzer_PAPI" setup_version="3.2.7">
<module name="Unzer_PAPI" setup_version="3.2.8">
<sequence>
<module name="Magento_Checkout"/>
<module name="Magento_Config" />
Expand Down