Skip to content

Release version 3.2.6 #80

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 3 commits into from
Apr 15, 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.6](https://github.com/unzerdev/magento2/compare/3.2.5..3.2.6)
### Fixed
* Discount amount when taxes are applied

## [3.2.5](https://github.com/unzerdev/magento2/compare/3.2.4..3.2.5)
### Added
* Direct Bank Transfer
Expand Down
46 changes: 43 additions & 3 deletions Helper/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Unzer\PAPI\Helper;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Module\ModuleListInterface;
Expand All @@ -12,6 +13,8 @@
use Magento\Sales\Api\Data\OrderAddressInterface;
use Magento\Sales\Model\Order as OrderModel;
use Magento\Sales\Model\Order\Item;
use Magento\Store\Model\ScopeInterface;
use Magento\Tax\Model\Config as MagentoTaxConfig;
use Unzer\PAPI\Block\System\Config\Form\Field\BirthDateFactory;
use Unzer\PAPI\Model\Config;
use Unzer\PAPI\Model\Source\CreateThreatMetrixId;
Expand Down Expand Up @@ -54,6 +57,11 @@ class Order
*/
private ProductMetadataInterface $_productMetadata;

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @var BasketFactory
*/
Expand All @@ -80,6 +88,7 @@ class Order
* @param Config $moduleConfig
* @param ModuleListInterface $moduleList
* @param ProductMetadataInterface $productMetadata
* @param ScopeConfigInterface $scopeConfig
* @param BasketFactory $basketFactory
* @param BasketItemFactory $basketItemFactory
* @param BirthDateFactory $birthDateFactory
Expand All @@ -89,6 +98,7 @@ public function __construct(
Config $moduleConfig,
ModuleListInterface $moduleList,
ProductMetadataInterface $productMetadata,
ScopeConfigInterface $scopeConfig,
BasketFactory $basketFactory,
BasketItemFactory $basketItemFactory,
BirthDateFactory $birthDateFactory,
Expand All @@ -97,6 +107,7 @@ public function __construct(
$this->_moduleConfig = $moduleConfig;
$this->_moduleList = $moduleList;
$this->_productMetadata = $productMetadata;
$this->scopeConfig = $scopeConfig;
$this->basketFactory = $basketFactory;
$this->basketItemFactory = $basketItemFactory;
$this->birthDateFactory = $birthDateFactory;
Expand All @@ -113,6 +124,7 @@ public function __construct(
public function createBasketForOrder(OrderModel $order): Basket
{
$basket = $this->createBasket($order);
$vatRate = 0;

if ($order->getShippingAmount() > 0) {
$basket->addBasketItem(
Expand All @@ -132,11 +144,15 @@ public function createBasketForOrder(OrderModel $order): Basket
$basket->addBasketItem(
$this->createBasketItem($orderItem)
);

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

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

Expand Down Expand Up @@ -198,12 +214,36 @@ protected function createBasketItem(Item $orderItem): BasketItem
* Create Voucher Item
*
* @param OrderModel $order
* @param float $vatRate
* @return BasketItem
*/
protected function createVoucherItem(OrderModel $order): BasketItem
protected function createVoucherItem(OrderModel $order, float $vatRate): BasketItem
{
$discount = $order->getBaseDiscountAmount();
$storeId = $order->getStoreId();

$taxAfterDiscount = $this->scopeConfig->getValue(
MagentoTaxConfig::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT,
ScopeInterface::SCOPE_STORE,
$storeId
);

$pricesIncludeTax = $this->scopeConfig->getValue(
MagentoTaxConfig::CONFIG_XML_PATH_PRICE_INCLUDES_TAX,
ScopeInterface::SCOPE_STORE,
$storeId
);

if ($taxAfterDiscount && !$pricesIncludeTax) {
$discount *= (1 + $vatRate/100);
}

$basketVoucherItemDiscountAmount = $this->basketItemFactory->create();
$basketVoucherItemDiscountAmount->setAmountDiscountPerUnitGross(abs($order->getBaseDiscountAmount()));
$basketVoucherItemDiscountAmount->setAmountDiscountPerUnitGross(
abs(round($discount, 2, PHP_ROUND_HALF_DOWN)
)
);
$basketVoucherItemDiscountAmount->setVat($vatRate);
$basketVoucherItemDiscountAmount->setAmountPerUnitGross(0);
$basketVoucherItemDiscountAmount->setQuantity(1);
$basketVoucherItemDiscountAmount->setTitle('Discount');
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.5",
"version": "3.2.6",
"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.5">
<module name="Unzer_PAPI" setup_version="3.2.6">
<sequence>
<module name="Magento_Checkout"/>
<module name="Magento_Config" />
Expand Down