Skip to content

Commit f09d92b

Browse files
Merge pull request #79 from unzerdev/release/3.2.6
Release/3.2.6
2 parents d61f90a + 95604f3 commit f09d92b

File tree

5 files changed

+97
-33
lines changed

5 files changed

+97
-33
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.6](https://github.com/unzerdev/magento2/compare/3.2.5..3.2.6)
7+
### Fixed
8+
* Discount amount when taxes are applied
9+
610
## [3.2.5](https://github.com/unzerdev/magento2/compare/3.2.4..3.2.5)
711
### Added
812
* Direct Bank Transfer

Helper/Order.php

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Unzer\PAPI\Helper;
55

6+
use Magento\Framework\App\Config\ScopeConfigInterface;
67
use Magento\Framework\App\ProductMetadataInterface;
78
use Magento\Framework\Exception\LocalizedException;
89
use Magento\Framework\Module\ModuleListInterface;
@@ -12,6 +13,8 @@
1213
use Magento\Sales\Api\Data\OrderAddressInterface;
1314
use Magento\Sales\Model\Order as OrderModel;
1415
use Magento\Sales\Model\Order\Item;
16+
use Magento\Store\Model\ScopeInterface;
17+
use Magento\Tax\Model\Config as MagentoTaxConfig;
1518
use Unzer\PAPI\Block\System\Config\Form\Field\BirthDateFactory;
1619
use Unzer\PAPI\Model\Config;
1720
use Unzer\PAPI\Model\Source\CreateThreatMetrixId;
@@ -54,6 +57,11 @@ class Order
5457
*/
5558
private ProductMetadataInterface $_productMetadata;
5659

60+
/**
61+
* @var ScopeConfigInterface
62+
*/
63+
private $scopeConfig;
64+
5765
/**
5866
* @var BasketFactory
5967
*/
@@ -80,6 +88,7 @@ class Order
8088
* @param Config $moduleConfig
8189
* @param ModuleListInterface $moduleList
8290
* @param ProductMetadataInterface $productMetadata
91+
* @param ScopeConfigInterface $scopeConfig
8392
* @param BasketFactory $basketFactory
8493
* @param BasketItemFactory $basketItemFactory
8594
* @param BirthDateFactory $birthDateFactory
@@ -89,6 +98,7 @@ public function __construct(
8998
Config $moduleConfig,
9099
ModuleListInterface $moduleList,
91100
ProductMetadataInterface $productMetadata,
101+
ScopeConfigInterface $scopeConfig,
92102
BasketFactory $basketFactory,
93103
BasketItemFactory $basketItemFactory,
94104
BirthDateFactory $birthDateFactory,
@@ -97,6 +107,7 @@ public function __construct(
97107
$this->_moduleConfig = $moduleConfig;
98108
$this->_moduleList = $moduleList;
99109
$this->_productMetadata = $productMetadata;
110+
$this->scopeConfig = $scopeConfig;
100111
$this->basketFactory = $basketFactory;
101112
$this->basketItemFactory = $basketItemFactory;
102113
$this->birthDateFactory = $birthDateFactory;
@@ -113,6 +124,7 @@ public function __construct(
113124
public function createBasketForOrder(OrderModel $order): Basket
114125
{
115126
$basket = $this->createBasket($order);
127+
$vatRate = 0;
116128

117129
if ($order->getShippingAmount() > 0) {
118130
$basket->addBasketItem(
@@ -132,11 +144,15 @@ public function createBasketForOrder(OrderModel $order): Basket
132144
$basket->addBasketItem(
133145
$this->createBasketItem($orderItem)
134146
);
147+
148+
if($orderItem->getTaxPercent() !== null){
149+
$vatRate = (float)$orderItem->getTaxPercent();
150+
}
135151
}
136152

137153
if (abs($order->getBaseDiscountAmount()) > 0) {
138154
$basket->addBasketItem(
139-
$this->createVoucherItem($order)
155+
$this->createVoucherItem($order, $vatRate)
140156
);
141157
}
142158

@@ -198,12 +214,36 @@ protected function createBasketItem(Item $orderItem): BasketItem
198214
* Create Voucher Item
199215
*
200216
* @param OrderModel $order
217+
* @param float $vatRate
201218
* @return BasketItem
202219
*/
203-
protected function createVoucherItem(OrderModel $order): BasketItem
220+
protected function createVoucherItem(OrderModel $order, float $vatRate): BasketItem
204221
{
222+
$discount = $order->getBaseDiscountAmount();
223+
$storeId = $order->getStoreId();
224+
225+
$taxAfterDiscount = $this->scopeConfig->getValue(
226+
MagentoTaxConfig::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT,
227+
ScopeInterface::SCOPE_STORE,
228+
$storeId
229+
);
230+
231+
$pricesIncludeTax = $this->scopeConfig->getValue(
232+
MagentoTaxConfig::CONFIG_XML_PATH_PRICE_INCLUDES_TAX,
233+
ScopeInterface::SCOPE_STORE,
234+
$storeId
235+
);
236+
237+
if ($taxAfterDiscount && !$pricesIncludeTax) {
238+
$discount *= (1 + $vatRate/100);
239+
}
240+
205241
$basketVoucherItemDiscountAmount = $this->basketItemFactory->create();
206-
$basketVoucherItemDiscountAmount->setAmountDiscountPerUnitGross(abs($order->getBaseDiscountAmount()));
242+
$basketVoucherItemDiscountAmount->setAmountDiscountPerUnitGross(
243+
abs(round($discount, 2, PHP_ROUND_HALF_DOWN)
244+
)
245+
);
246+
$basketVoucherItemDiscountAmount->setVat($vatRate);
207247
$basketVoucherItemDiscountAmount->setAmountPerUnitGross(0);
208248
$basketVoucherItemDiscountAmount->setQuantity(1);
209249
$basketVoucherItemDiscountAmount->setTitle('Discount');

README.md

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,53 @@
33
[![PHP 8.1](https://img.shields.io/badge/php-8.1-blue.svg)](http://www.php.net)
44
[![PHP 8.2](https://img.shields.io/badge/php-8.2-blue.svg)](http://www.php.net)
55

6-
![Logo](unzer_logo.svg)
6+
# Unzer Payment plugin for Magento 2
77

8-
# Payment extension for Magento2 and Unzer Payment API (PAPI)
8+
Use Unzer Payment plugin for Magento 2 to provide an easy-to-install payment gateway integration for all your online payments.
99

10-
This extension for Magento2 provides a direct integration of the Unzer payment methods to your Magento2 shop.
10+
## Description
1111

12-
Currently supported payment methods are:
13-
* Cards (Credit Card / Debit Card)
12+
Accept payments with cards, bank transfers, wallets, and other global and local payment methods. Unzer Payment plugin helps you with quick and easy integration, full support, and flexible solutions that grow with your business. We are your payment partner for every situation.
13+
14+
## Features
15+
16+
* Seamless integration into the Shop-system
17+
* Merchant-friendly order management with up-to-date payment details, real-time billing and refunds made easy.
18+
* Payment processing via the Unzer Payment API
19+
* 3D-Secure authentication
20+
* PCI-DSS Level 1 certified
21+
22+
## Content security policy (CSP)
23+
24+
If you are using a Content Security Policy (CSP) you must include different Unzer URL's to your policy, which are required by the UI components to work. For more information, please go to [Unzer Documentation CSP Information](https://docs.unzer.com/online-payments/ui-component-v2/#content-security-policy-csp).
25+
26+
## Supported payment methods
27+
28+
Unzer payment plugin includes the following payment methods:
29+
* Alipay
30+
* Apple Pay
31+
* Bancontact
32+
* Credit Card
33+
* Unzer Direct Bank Transfer
1434
* EPS
15-
* Giropay
35+
* Google Pay
1636
* iDEAL
1737
* PayPal
18-
* Sofort
19-
* Unzer (SEPA) Direct Debit
20-
* Unzer (SEPA) Direct Debit secured B2C
21-
* Unzer Bank Transfer
22-
* Unzer Invoice
23-
* Unzer Invoice secured B2B
24-
* Unzer Invoice secured B2C
25-
* Unzer Prepayment
26-
* Bancontact
27-
* Przelewy
28-
* Alipay
29-
* Wechat
38+
* Prepayment
39+
* SEPA Direct Debit
40+
* SOFORT
41+
* TWINT
42+
* Unzer Direct Debit
43+
* Unzer direct Debit (secured)
44+
* Unzer Invoice B2C / B2B (secured)
45+
* Unzer Installment (secured)
46+
* WeChat Pay
47+
48+
Regarding plugin compatibility, please take a look at the release notes for more information.
49+
50+
## Installation
51+
52+
Please see our documentation for [how to install the plugin](https://docs.unzer.com/plugins/magento-2/magento2-install-plugin/).
3053

3154
## SYSTEM REQUIREMENTS
3255
This extension requires PHP 7.4, PHP 8.1 or PHP 8.2.
@@ -50,20 +73,17 @@ See the License for the specific language governing permissions and
5073
limitations under the License.
5174

5275
## User Guide
53-
Please find information on installation, configuration and usage within the [manual](https://docs.unzer.com/plugins/magento-2).
76+
77+
Please find information on installation, configuration, usage etc on our [documentation pages](https://docs.unzer.com/plugins/magento-2).
5478

5579
## Support
80+
5681
For any issues or questions please get in touch with our support.
5782

58-
#### Web pages
59-
* https://unzer.com/
60-
* https://docs.unzer.com/
83+
6184

62-
#### Email
63-
85+
**Phone**: +49 (0)6221/6471-100
6486

65-
#### Phone
66-
+49 (0)6221/6471-100
87+
**Twitter**: [@UnzerTech](https://twitter.com/UnzerTech)
6788

68-
#### Twitter
69-
[@UnzerTech](https://twitter.com/UnzerTech)
89+
**Webpage**: https://unzer.com/

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.5",
5+
"version": "3.2.6",
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.5">
4+
<module name="Unzer_PAPI" setup_version="3.2.6">
55
<sequence>
66
<module name="Magento_Checkout"/>
77
<module name="Magento_Config" />

0 commit comments

Comments
 (0)