From f7181a871506179db4e103a046297b8bd45b9d32 Mon Sep 17 00:00:00 2001 From: Bushra Asif Date: Wed, 18 Mar 2026 05:16:36 +0000 Subject: [PATCH 1/5] Save transaction data before state change --- src/Service/PaymentService.php | 70 ++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/src/Service/PaymentService.php b/src/Service/PaymentService.php index 936228c..8c8d15d 100644 --- a/src/Service/PaymentService.php +++ b/src/Service/PaymentService.php @@ -180,7 +180,7 @@ public function pay( $paymentMethod = $salesChannelContext->getPaymentMethod(); $terminal = $paymentMethod->getTranslated()['customFields'][self::ALTAPAY_TERMINAL_ID_CUSTOM_FIELD]; - $salesChannelTerminal = $paymentMethod->getTranslated()['customFields'][self::ALTAPAY_SALES_CHANNEL_TERMINAL_ID]; + $salesChannelTerminal = $paymentMethod->getTranslated()['customFields'][self::ALTAPAY_SALES_CHANNEL_TERMINAL_ID] ?? null; if (!empty($salesChannelTerminal)) { $field = 'WexoAltaPay.config.' . $salesChannelTerminal; @@ -278,16 +278,40 @@ public function transactionCallback( ) { $status = "Success"; } + $customFields = $order->getCustomFields() ?? []; + $orderStatus = $customFields[self::ALTAPAY_ORDER_STATUS] ?? null; + + if ($orderStatus === 'processed') { + return; + } + + if ($status === "Open" || $status === "Success") { + $altaPayTransactionId = (string)$result->Body->Transactions->Transaction->TransactionId; + $altaPayPaymentSchemeName = (string)$result->Body->Transactions->Transaction->PaymentSchemeName; + $altaPayPaymentNature = (string)$result->Body->Transactions->Transaction->PaymentNature; + $altaPayPaymentId = (string)$result->Body->Transactions->Transaction->PaymentId; + + $customFields = array_merge( + $customFields, + [ + self::ALTAPAY_TRANSACTION_ID_CUSTOM_FIELD => $altaPayTransactionId, + self::ALTAPAY_TRANSACTION_PAYMENT_SCHEME_NAME_CUSTOM_FIELD => $altaPayPaymentSchemeName, + self::ALTAPAY_TRANSACTION_PAYMENT_NATURE_CUSTOM_FIELD => $altaPayPaymentNature, + self::ALTAPAY_PAYMENT_ID_CUSTOM_FIELD => $altaPayPaymentId, + ] + ); + + $this->orderRepository->update([ + [ + 'id' => $order->getId(), + 'customFields' => $customFields, + ] + ], $salesChannelContext->getContext()); + } switch ($status) { case "Open": break; case "Success": - $customFields = $order->getCustomFields() ?? []; - $orderStatus = $customFields[self::ALTAPAY_ORDER_STATUS] ?? null; - - if ($orderStatus === 'processed') { - break; - } // Delete cart when either customer or AltaPay reaches this page. $cartToken = $order->getCustomFieldsValue(field: WexoAltaPay::ALTAPAY_CART_TOKEN); if (!empty($cartToken)) { @@ -334,10 +358,16 @@ public function transactionCallback( // Update order state to "in progress" $this->updateOrderStateToInProgress($order, $salesChannelContext->getContext()); } - } - $order->changeCustomFields([ - self::ALTAPAY_ORDER_STATUS => 'processed' - ]); + } + $this->orderRepository->update([ + [ + 'id' => $order->getId(), + 'customFields' => array_merge( + $customFields, + [self::ALTAPAY_ORDER_STATUS => 'processed'] + ), + ] + ], $salesChannelContext->getContext()); } catch (\Exception $e) { $this->logger->error("order transaction state error:". $e->getMessage()); } @@ -397,17 +427,6 @@ public function transactionCallback( ?? (string)$result->APIResponse?->Header?->ErrorMessage ); } - $altaPayTransactionId = (string)$result->Body->Transactions->Transaction->TransactionId; - $altaPayPaymentSchemeName= (string)$result->Body->Transactions->Transaction->PaymentSchemeName; - $altaPayPaymentNature= (string)$result->Body->Transactions->Transaction->PaymentNature; - $altaPayPaymentId= (string)$result->Body->Transactions->Transaction->PaymentId; - - $order->changeCustomFields([ - self::ALTAPAY_TRANSACTION_ID_CUSTOM_FIELD => $altaPayTransactionId, - self::ALTAPAY_TRANSACTION_PAYMENT_SCHEME_NAME_CUSTOM_FIELD => $altaPayPaymentSchemeName, - self::ALTAPAY_TRANSACTION_PAYMENT_NATURE_CUSTOM_FIELD => $altaPayPaymentNature, - self::ALTAPAY_PAYMENT_ID_CUSTOM_FIELD => $altaPayPaymentId - ]); $surchargeAmount = (float)$result->Body->Transactions->Transaction->SurchargeAmount; $paymentMethod = $salesChannelContext->getPaymentMethod(); @@ -451,13 +470,6 @@ public function transactionCallback( $this->orderRepository->merge($versionId, $systemContext); } - - $this->orderRepository->update([ - [ - 'id' => $order->getId(), - 'customFields' => $order->getCustomFields() - ] - ], $salesChannelContext->getContext()); } public function getAltaPayClient(string $salesChannelId): Client From c49eb522debe2599405f2ab8d57c2b9ea82958fb Mon Sep 17 00:00:00 2001 From: Bushra Asif Date: Wed, 18 Mar 2026 05:49:36 +0000 Subject: [PATCH 2/5] Update tested version --- README.md | 2 +- wiki.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aded8f5..10e48e5 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Integrates your Shopware web shop to the AltaPay payments gateway. ## Compatibility - Shopware 6.6.x (Tested version 6.6.9.0) -- Shopware 6.7.x (Tested version 6.7.5.1) +- Shopware 6.7.x (Tested version 6.7.8.1) ## Changelog See [Changelog](CHANGELOG.md) for all the release notes. diff --git a/wiki.md b/wiki.md index 85d2f29..3e22c28 100644 --- a/wiki.md +++ b/wiki.md @@ -151,7 +151,7 @@ The new credentials can now be used as the API Username and API Password in the - Shopware 6.6.x - Shopware 6.7.x -The latest tested versions are `6.6.9.0` and `6.7.5.1` +The latest tested versions are `6.6.9.0` and `6.7.8.1` ## Troubleshooting From 2a3a0a2d98728a54215fce6722ff277e3994e023 Mon Sep 17 00:00:00 2001 From: Bushra Asif Date: Wed, 18 Mar 2026 09:15:52 +0000 Subject: [PATCH 3/5] Update version and release notes --- CHANGELOG.md | 4 ++++ composer.json | 2 +- src/WexoAltaPay.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2f7281..e6cbe95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## [2.1.0] +### Fixed +- Fix: Payment not captured when order status is changed to done for digital products. + ## [2.0.9] ### Added - Support for sales channel–specific terminals for payment methods. diff --git a/composer.json b/composer.json index 8ba8815..6181673 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "AltaPay plugin for Shopware 6", "type": "shopware-platform-plugin", "license": "MIT", - "version": "2.0.9", + "version": "2.1.0", "authors": [ { "name": "AltaPay A/S", diff --git a/src/WexoAltaPay.php b/src/WexoAltaPay.php index e7cf9d5..97bef51 100644 --- a/src/WexoAltaPay.php +++ b/src/WexoAltaPay.php @@ -21,7 +21,7 @@ class WexoAltaPay extends Plugin public const ALTAPAY_FIELD_SET_NAME = "wexoAltaPay"; public const ALTAPAY_PAYMENT_METHOD_FIELD_SET_NAME = "wexoAltaPayPaymentMethod"; public const ALTAPAY_CART_TOKEN = "wexoAltaPayCartToken"; - public const ALTAPAY_PLUGIN_VERSION = '2.0.9'; + public const ALTAPAY_PLUGIN_VERSION = '2.1.0'; public const ALTAPAY_PLUGIN_NAME = 'WexoAltaPay'; public function update(UpdateContext $updateContext): void From 3a414184b142eb13e51f7013b41ae8d44c84fad1 Mon Sep 17 00:00:00 2001 From: Bushra Asif Date: Thu, 19 Mar 2026 18:50:21 +0000 Subject: [PATCH 4/5] Check sales channel terminal ID as well in PaymentMethodSubscriber --- src/Resources/config/services.xml | 1 + src/Service/PaymentService.php | 2 +- src/Subscriber/PaymentMethodSubscriber.php | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index ca5f425..f2f28d6 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -53,6 +53,7 @@ + diff --git a/src/Service/PaymentService.php b/src/Service/PaymentService.php index 8c8d15d..f6a1c15 100644 --- a/src/Service/PaymentService.php +++ b/src/Service/PaymentService.php @@ -179,7 +179,7 @@ public function pay( ); $paymentMethod = $salesChannelContext->getPaymentMethod(); - $terminal = $paymentMethod->getTranslated()['customFields'][self::ALTAPAY_TERMINAL_ID_CUSTOM_FIELD]; + $terminal = $paymentMethod->getTranslated()['customFields'][self::ALTAPAY_TERMINAL_ID_CUSTOM_FIELD] ?? null; $salesChannelTerminal = $paymentMethod->getTranslated()['customFields'][self::ALTAPAY_SALES_CHANNEL_TERMINAL_ID] ?? null; if (!empty($salesChannelTerminal)) { diff --git a/src/Subscriber/PaymentMethodSubscriber.php b/src/Subscriber/PaymentMethodSubscriber.php index 7414055..0876232 100644 --- a/src/Subscriber/PaymentMethodSubscriber.php +++ b/src/Subscriber/PaymentMethodSubscriber.php @@ -14,6 +14,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Wexo\AltaPay\Service\PaymentService; use Wexo\AltaPay\WexoAltaPay; +use Shopware\Core\System\SystemConfig\SystemConfigService; class PaymentMethodSubscriber implements EventSubscriberInterface { @@ -22,7 +23,8 @@ class PaymentMethodSubscriber implements EventSubscriberInterface */ public function __construct( protected EntityRepository $paymentMethodRepository, - protected PluginIdProvider $pluginIdProvider + protected PluginIdProvider $pluginIdProvider, + protected SystemConfigService $systemConfigService ) { } @@ -52,7 +54,15 @@ public function associateAltaPayPaymentMethod(EntityWrittenEvent $event): void $payload = []; $payload['id'] = $paymentMethod->getId(); - if ($paymentMethod->getCustomFieldsValue('wexoAltaPayTerminalId')) { + $salesChannelTerminal = $paymentMethod->getCustomFieldsValue('altapaySalesChannelTerminalId'); + $salesChannelTerminalValue = null; + + if (!empty($salesChannelTerminal)) { + $field = 'WexoAltaPay.config.' . $salesChannelTerminal; + $salesChannelTerminalValue = $this->systemConfigService->get($field); + } + + if ($paymentMethod->getCustomFieldsValue('wexoAltaPayTerminalId') || $salesChannelTerminalValue) { $payload['handlerIdentifier'] = PaymentService::class; $payload['pluginId'] = $this->pluginIdProvider->getPluginIdByBaseClass( WexoAltaPay::class, From 9b8acf669a801c8f7a7ecb7c18a0ca56b6e3191f Mon Sep 17 00:00:00 2001 From: Bushra Asif Date: Thu, 19 Mar 2026 19:00:36 +0000 Subject: [PATCH 5/5] Update release notes --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6cbe95..3e94d85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. ## [2.1.0] ### Fixed - Fix: Payment not captured when order status is changed to done for digital products. +- Fix: Payment handler skipped when AltaPay Terminal ID field is empty but Sales Channel dropdown is set. +- Fix: PHP warnings from missing custom field values. ## [2.0.9] ### Added