diff --git a/README.md b/README.md index b64e9d8..8b9207b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ CoreShop >= 3.0 ## Installation ```json - "dachcom-digital/payum-postfinance-flex-bundle": "~1.3.0" + "dachcom-digital/payum-postfinance-flex-bundle": "~2.0.0" ``` Add Bundle to `bundles.php`: @@ -29,6 +29,9 @@ Go to CoreShop -> PaymentProvider and add a new Provider. Choose `postfinance_fl ## Changelog +### 2.0.0 +- Dependency `dachcom-digital/payum-postfinance-flex` requirement set to `^2.0` + ### 1.3.0 - [LICENSE] Dual-License with GPL and Dachcom Commercial License (DCL) added @@ -55,6 +58,6 @@ Go to CoreShop -> PaymentProvider and add a new Provider. Choose `postfinance_fl ## License **DACHCOM.DIGITAL AG**, Löwenhofstrasse 15, 9424 Rheineck, Schweiz [dachcom.com](https://www.dachcom.com), dcdi@dachcom.ch -Copyright © 2024 DACHCOM.DIGITAL. All rights reserved. +Copyright © 2025 DACHCOM.DIGITAL. All rights reserved. For licensing details please visit [LICENSE.md](LICENSE.md) \ No newline at end of file diff --git a/composer.json b/composer.json index 54b6851..5cab396 100644 --- a/composer.json +++ b/composer.json @@ -16,11 +16,17 @@ "email": "rkaczmarczyk@dachcom.ch", "homepage": "https://www.dachcom.com", "role": "Developer" + }, + { + "name": "DACHCOM.DIGITAL Stefan Hagspiel", + "email": "shagspiel@dachcom.ch", + "homepage": "https://www.dachcom.com", + "role": "Developer" } ], "require": { "payum/core": "^1.6", - "dachcom-digital/payum-postfinance-flex": "^1.2" + "dachcom-digital/payum-postfinance-flex": "^2.0" }, "require-dev": { "symfony/http-client": "^6.4", diff --git a/src/PayumPostFinanceFlexBundle/Extension/ConvertPaymentExtension.php b/src/PayumPostFinanceFlexBundle/Extension/ConvertPaymentExtension.php index 1b7e2bd..f22ee22 100644 --- a/src/PayumPostFinanceFlexBundle/Extension/ConvertPaymentExtension.php +++ b/src/PayumPostFinanceFlexBundle/Extension/ConvertPaymentExtension.php @@ -18,6 +18,7 @@ use CoreShop\Component\Core\Model\PaymentProviderInterface; use CoreShop\Component\Taxation\Model\TaxItemInterface; use DachcomDigital\Payum\PostFinance\Flex\Request\Api\TransactionExtender; +use DachcomDigital\Payum\PostFinance\Flex\Transaction\Transaction; use Payum\Core\Extension\Context; use Payum\Core\Extension\ExtensionInterface; use Payum\Core\Model\Payment; @@ -54,28 +55,29 @@ public function onPostExecute(Context $context) return; } - /** @var Payment $payment */ - $payment = $request->getFirstModel(); - - $paymentEntity = $this->paymentRepository->createQueryBuilder('p') - ->where('p.number = :orderNumber') - ->setParameter('orderNumber', $payment->getNumber()) - ->getQuery() - ->getSingleResult(); - - if (!$paymentEntity instanceof \Coreshop\Component\Core\Model\Payment) { + $payment = $this->getPayment($request); + if (!$payment instanceof \Coreshop\Component\Core\Model\Payment) { return; } - $order = $paymentEntity->getOrder(); + $order = $this->getOrder($payment); if (!$order instanceof OrderInterface) { return; } - $gatewayLanguage = 'en_EN'; - $transaction = $request->getTransaction(); + $this->addLocaleToTransaction($order, $transaction); + $this->addTaxesToTransaction($order, $transaction); + $this->addPaymentConfigurationToTransaction($payment, $transaction); + + $request->setTransaction($transaction); + } + + private function addLocaleToTransaction(OrderInterface $order, Transaction $transaction): void + { + $gatewayLanguage = 'en_EN'; + if (!empty($order->getLocaleCode())) { $orderLanguage = $order->getLocaleCode(); // post finance always requires a full language ISO Code @@ -87,24 +89,10 @@ public function onPostExecute(Context $context) } $transaction->setLanguage($gatewayLanguage); + } - /** @var PaymentProviderInterface $paymentProvider */ - $paymentProvider = $paymentEntity->getPaymentProvider(); - $gatewayConfig = $paymentProvider->getGatewayConfig()->getConfig(); - - $optionalParameters = []; - if (is_array($gatewayConfig) && array_key_exists('optionalParameters', $gatewayConfig)) { - $optionalParameters = $gatewayConfig['optionalParameters']; - } - - if (array_key_exists('allowedPaymentMethodBrands', $optionalParameters) && !empty($optionalParameters['allowedPaymentMethodBrands'])) { - $transaction->setAllowedPaymentMethodBrands(explode(',', $optionalParameters['allowedPaymentMethodBrands'])); - } - - if (array_key_exists('allowedPaymentMethodConfigurations', $optionalParameters) && !empty($optionalParameters['allowedPaymentMethodConfigurations'])) { - $transaction->setAllowedPaymentMethodConfigurations(explode(',', $optionalParameters['allowedPaymentMethodConfigurations'])); - } - + private function addTaxesToTransaction(OrderInterface $order, Transaction $transaction): void + { $taxes = []; foreach ($order->getTaxes() as $tax) { if (!$tax instanceof TaxItemInterface) { @@ -127,7 +115,53 @@ public function onPostExecute(Context $context) if (count($taxes) > 0) { $transaction->setTotalTaxes($taxes); } + } + + private function addPaymentConfigurationToTransaction(\Coreshop\Component\Core\Model\Payment $payment, Transaction $transaction): void + { + /** @var PaymentProviderInterface $paymentProvider */ + $paymentProvider = $payment->getPaymentProvider(); + $gatewayConfig = $paymentProvider->getGatewayConfig()->getConfig(); + + $optionalParameters = []; + if (is_array($gatewayConfig) && array_key_exists('optionalParameters', $gatewayConfig)) { + $optionalParameters = $gatewayConfig['optionalParameters']; + } - $request->setTransaction($transaction); + if (array_key_exists('allowedPaymentMethodBrands', $optionalParameters) && !empty($optionalParameters['allowedPaymentMethodBrands'])) { + $transaction->getTransactionCreateObject()->setAllowedPaymentMethodBrands(explode(',', $optionalParameters['allowedPaymentMethodBrands'])); + } + + if (array_key_exists('allowedPaymentMethodConfigurations', $optionalParameters) && !empty($optionalParameters['allowedPaymentMethodConfigurations'])) { + $transaction->getTransactionCreateObject()->setAllowedPaymentMethodConfigurations(explode(',', $optionalParameters['allowedPaymentMethodConfigurations'])); + } + } + + private function getOrder(\Coreshop\Component\Core\Model\Payment $payment): ?OrderInterface + { + $order = $payment->getOrder(); + if (!$order instanceof OrderInterface) { + return null; + } + + return $order; + } + + private function getPayment(TransactionExtender $request): ?\Coreshop\Component\Core\Model\Payment + { + /** @var Payment $payment */ + $payment = $request->getFirstModel(); + + $paymentEntity = $this->paymentRepository->createQueryBuilder('p') + ->where('p.number = :orderNumber') + ->setParameter('orderNumber', $payment->getNumber()) + ->getQuery() + ->getSingleResult(); + + if (!$paymentEntity instanceof \Coreshop\Component\Core\Model\Payment) { + return null; + } + + return $paymentEntity; } }