Skip to content

Release/3.2.6 #79

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 4 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
76 changes: 48 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,53 @@
[![PHP 8.1](https://img.shields.io/badge/php-8.1-blue.svg)](http://www.php.net)
[![PHP 8.2](https://img.shields.io/badge/php-8.2-blue.svg)](http://www.php.net)

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

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

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

Currently supported payment methods are:
* Cards (Credit Card / Debit Card)
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.

## Features

* Seamless integration into the Shop-system
* Merchant-friendly order management with up-to-date payment details, real-time billing and refunds made easy.
* Payment processing via the Unzer Payment API
* 3D-Secure authentication
* PCI-DSS Level 1 certified

## Content security policy (CSP)

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

## Supported payment methods

Unzer payment plugin includes the following payment methods:
* Alipay
* Apple Pay
* Bancontact
* Credit Card
* Unzer Direct Bank Transfer
* EPS
* Giropay
* Google Pay
* iDEAL
* PayPal
* Sofort
* Unzer (SEPA) Direct Debit
* Unzer (SEPA) Direct Debit secured B2C
* Unzer Bank Transfer
* Unzer Invoice
* Unzer Invoice secured B2B
* Unzer Invoice secured B2C
* Unzer Prepayment
* Bancontact
* Przelewy
* Alipay
* Wechat
* Prepayment
* SEPA Direct Debit
* SOFORT
* TWINT
* Unzer Direct Debit
* Unzer direct Debit (secured)
* Unzer Invoice B2C / B2B (secured)
* Unzer Installment (secured)
* WeChat Pay

Regarding plugin compatibility, please take a look at the release notes for more information.

## Installation

Please see our documentation for [how to install the plugin](https://docs.unzer.com/plugins/magento-2/magento2-install-plugin/).

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

## User Guide
Please find information on installation, configuration and usage within the [manual](https://docs.unzer.com/plugins/magento-2).

Please find information on installation, configuration, usage etc on our [documentation pages](https://docs.unzer.com/plugins/magento-2).

## Support

For any issues or questions please get in touch with our support.

#### Web pages
* https://unzer.com/
* https://docs.unzer.com/
**Email**: [email protected]

#### Email
[email protected]
**Phone**: +49 (0)6221/6471-100

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

#### Twitter
[@UnzerTech](https://twitter.com/UnzerTech)
**Webpage**: https://unzer.com/
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