Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<service id="Wexo\AltaPay\Subscriber\PaymentMethodSubscriber">
<argument type="service" id="payment_method.repository" />
<argument type="service" id="Shopware\Core\Framework\Plugin\Util\PluginIdProvider" />
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService" />
<tag name="kernel.event_subscriber" />
</service>

Expand Down
72 changes: 42 additions & 30 deletions src/Service/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/Subscriber/PaymentMethodSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -22,7 +23,8 @@ class PaymentMethodSubscriber implements EventSubscriberInterface
*/
public function __construct(
protected EntityRepository $paymentMethodRepository,
protected PluginIdProvider $pluginIdProvider
protected PluginIdProvider $pluginIdProvider,
protected SystemConfigService $systemConfigService
) {
}

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/WexoAltaPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wiki.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading