From 7b00860e6d08aae7e13d98d550aee6b396a4b029 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Mon, 12 Aug 2024 10:39:44 +0200 Subject: [PATCH] update deps, added totalTaxes to transaction line item --- README.md | 13 +++++++++- composer.json | 3 +-- .../Extension/ConvertPaymentExtension.php | 25 +++++++++++++++++++ .../Resources/config/services.yaml | 1 + 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 78ca64b..de52ee0 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ CoreShop >= 3.0 ## Installation ```json - "dachcom-digital/payum-postfinance-flex-bundle": "~1.1.0" + "dachcom-digital/payum-postfinance-flex-bundle": "~1.2.0" ``` Add Bundle to `bundles.php`: @@ -24,10 +24,21 @@ Go to CoreShop -> PaymentProvider and add a new Provider. Choose `postfinance_fl ## Changelog +### 1.2.0 +- Dependency `dachcom-digital/payum-postfinance-flex` requirement set to `^1.2` +- Unnecessary dependency `postfinancecheckout/sdk` removed +- `totalTaxes` added to line item + - rate `title` gets translated by key: `coreshop.payum.postfinance.line_item.tax_title_[TAX_RATE]` + - where `[TAX_RATE]` represents the tax rate (`.` gets replaced by `_`) + - Example: If your taxrate represents `8.1`, the generated title would be `coreshop.payum.postfinance.line_item.tax_title_8_1` + ### 1.1.0 - add integration type config - add `allowedPaymentMethodConfigurations` option +### 1.0.1 +- add `setAllowedPaymentMethodBrands` option + ## Copyright and License Copyright: [DACHCOM.DIGITAL](https://www.dachcom-digital.ch) For licensing details please visit [LICENSE.md](LICENSE.md) \ No newline at end of file diff --git a/composer.json b/composer.json index 10755bb..225870b 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,7 @@ "type": "pimcore-bundle", "require": { "payum/core": "^1.6", - "dachcom-digital/payum-postfinance-flex": "^1.0", - "postfinancecheckout/sdk": "^3.1" + "dachcom-digital/payum-postfinance-flex": "^1.2" }, "keywords": [ "payment", diff --git a/src/PayumPostFinanceFlexBundle/Extension/ConvertPaymentExtension.php b/src/PayumPostFinanceFlexBundle/Extension/ConvertPaymentExtension.php index 958e2a0..eae0467 100644 --- a/src/PayumPostFinanceFlexBundle/Extension/ConvertPaymentExtension.php +++ b/src/PayumPostFinanceFlexBundle/Extension/ConvertPaymentExtension.php @@ -5,14 +5,17 @@ use CoreShop\Bundle\PaymentBundle\Doctrine\ORM\PaymentRepository; use CoreShop\Component\Core\Model\OrderInterface; use CoreShop\Component\Core\Model\PaymentProviderInterface; +use CoreShop\Component\Taxation\Model\TaxItemInterface; use DachcomDigital\Payum\PostFinance\Flex\Request\Api\TransactionExtender; use Payum\Core\Extension\Context; use Payum\Core\Extension\ExtensionInterface; use Payum\Core\Model\Payment; +use Symfony\Contracts\Translation\TranslatorInterface; class ConvertPaymentExtension implements ExtensionInterface { public function __construct( + protected TranslatorInterface $translator, protected PaymentRepository $paymentRepository ) { @@ -94,6 +97,28 @@ public function onPostExecute(Context $context) $transaction->setAllowedPaymentMethodConfigurations(explode(',', $optionalParameters['allowedPaymentMethodConfigurations'])); } + $taxes = []; + foreach ($order->getTaxes() as $tax) { + + if (!$tax instanceof TaxItemInterface) { + continue; + } + + $taxes[] = [ + 'rate' => $tax->getRate(), + 'title' => $this->translator->trans( + sprintf('coreshop.payum.postfinance.line_item.tax_title_%s', str_replace('.', '_', $tax->getRate())), + [], + 'admin', + $order->getLocaleCode() + ) + ]; + } + + if (count($taxes) > 0) { + $transaction->setTotalTaxes($taxes); + } + $request->setTransaction($transaction); } } diff --git a/src/PayumPostFinanceFlexBundle/Resources/config/services.yaml b/src/PayumPostFinanceFlexBundle/Resources/config/services.yaml index 10f705e..5c867a0 100644 --- a/src/PayumPostFinanceFlexBundle/Resources/config/services.yaml +++ b/src/PayumPostFinanceFlexBundle/Resources/config/services.yaml @@ -24,6 +24,7 @@ services: autowire: true public: true arguments: + - '@translator' - '@coreshop.repository.payment' tags: - { name: payum.extension, alias: postfinance_flex_coreshop_convert_payment, factory: postfinance_flex, prepend: false }