diff --git a/CHANGELOG.md b/CHANGELOG.md index e2f7281..3e94d85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # 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. +- 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 - Support for sales channel–specific terminals for payment methods. 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/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/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 936228c..f6a1c15 100644 --- a/src/Service/PaymentService.php +++ b/src/Service/PaymentService.php @@ -179,8 +179,8 @@ 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]; + $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)) { $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 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, 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 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