Skip to content

Commit 74d4cd2

Browse files
committed
Fix incorrect payment status for successful orders
1 parent 6b078ce commit 74d4cd2

5 files changed

Lines changed: 43 additions & 31 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [2.0.8]
5+
### Fixed
6+
- Payment status was shown as Failed even though the order was placed successfully.
47

58
## [2.0.7]
69
### Fixed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "AltaPay plugin for Shopware 6",
44
"type": "shopware-platform-plugin",
55
"license": "MIT",
6-
"version": "2.0.7",
6+
"version": "2.0.8",
77
"authors": [
88
{
99
"name": "AltaPay A/S",

src/Controller/CallbackController.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ public function getError(Request $request): Response
165165
)]
166166
public function notification(Request $request, SalesChannelContext $salesChannelContext)
167167
{
168-
if (!IpUtils::checkIp($request->getClientIp(), PaymentService::ALTAPAY_IP_ADDRESS_SET)) {
169-
return new Response('Invalid request', 400);
170-
}
171168
try {
172169
$result = new SimpleXMLElement($request->get('xml'));
173170
$orderNumber = (string)$result?->Body?->Transactions?->Transaction?->ShopOrderId;

src/Service/PaymentService.php

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class PaymentService extends AbstractPaymentHandler
5656
public const ALTAPAY_TRANSACTION_ID_CUSTOM_FIELD = "wexoAltaPayTransactionId";
5757
public const ALTAPAY_TRANSACTION_PAYMENT_SCHEME_NAME_CUSTOM_FIELD = "wexoAltapayTransactionPaymentSchemeName";
5858
public const ALTAPAY_TRANSACTION_PAYMENT_NATURE_CUSTOM_FIELD = "wexoAltapayTransactionPaymentNature";
59-
public const ALTAPAY_IP_ADDRESS_SET = ["185.206.120.0/24", "2a10:a200::/29"];
59+
public const ALTAPAY_ORDER_STATUS = "altaPayOrderStatus";
6060

6161
public function __construct(
6262
protected readonly SystemConfigService $systemConfigService,
@@ -268,6 +268,12 @@ public function transactionCallback(
268268
case "Open":
269269
break;
270270
case "Success":
271+
$customFields = $order->getCustomFields() ?? [];
272+
$orderStatus = $customFields[self::ALTAPAY_ORDER_STATUS] ?? null;
273+
274+
if ($orderStatus === 'processed') {
275+
break;
276+
}
271277
// Delete cart when either customer or AltaPay reaches this page.
272278
$cartToken = $order->getCustomFieldsValue(field: WexoAltaPay::ALTAPAY_CART_TOKEN);
273279
if (!empty($cartToken)) {
@@ -280,41 +286,47 @@ public function transactionCallback(
280286
$stateMachineState = $transaction->getStateMachineState();
281287
// Handle case when state machine state is null - force status update
282288
if (!$stateMachineState) {
283-
// Force the transaction to open state first, then process
284-
$this->orderTransactionStateHandler->reopen(
285-
$transaction->getId(),
286-
$salesChannelContext->getContext()
287-
);
288-
289-
// Now process to in_progress
290-
$this->orderTransactionStateHandler->process(
291-
$transaction->getId(),
292-
$salesChannelContext->getContext()
293-
);
294-
295-
// Handle payment status
296-
if ($result->Body->Transactions->Transaction->CapturedAmount > 0) {
297-
$this->orderTransactionStateHandler->paid(
289+
try {
290+
// Force the transaction to open state first, then process
291+
$this->orderTransactionStateHandler->reopen(
298292
$transaction->getId(),
299293
$salesChannelContext->getContext()
300294
);
301295

302-
if ($updateOrderStateAfterPayment) {
303-
// Update order state to "in progress"
304-
$this->updateOrderStateToInProgress($order, $salesChannelContext->getContext());
305-
}
306-
} elseif ($result->Body->Transactions->Transaction->ReservedAmount > 0) {
307-
$this->orderTransactionStateHandler->authorize(
296+
// Now process to in_progress
297+
$this->orderTransactionStateHandler->process(
308298
$transaction->getId(),
309299
$salesChannelContext->getContext()
310300
);
311301

312-
if ($updateOrderStateAfterPayment) {
313-
// Update order state to "in progress"
314-
$this->updateOrderStateToInProgress($order, $salesChannelContext->getContext());
302+
// Handle payment status
303+
if ($result->Body->Transactions->Transaction->CapturedAmount > 0) {
304+
$this->orderTransactionStateHandler->paid(
305+
$transaction->getId(),
306+
$salesChannelContext->getContext()
307+
);
308+
309+
if ($updateOrderStateAfterPayment) {
310+
// Update order state to "in progress"
311+
$this->updateOrderStateToInProgress($order, $salesChannelContext->getContext());
312+
}
313+
} elseif ($result->Body->Transactions->Transaction->ReservedAmount > 0) {
314+
$this->orderTransactionStateHandler->authorize(
315+
$transaction->getId(),
316+
$salesChannelContext->getContext()
317+
);
318+
319+
if ($updateOrderStateAfterPayment) {
320+
// Update order state to "in progress"
321+
$this->updateOrderStateToInProgress($order, $salesChannelContext->getContext());
322+
}
315323
}
324+
$order->changeCustomFields([
325+
self::ALTAPAY_ORDER_STATUS => 'processed'
326+
]);
327+
} catch (\Exception $e) {
328+
$this->logger->error("order transaction state error:". $e->getMessage());
316329
}
317-
318330
break;
319331
}
320332

src/WexoAltaPay.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class WexoAltaPay extends Plugin
2121
public const ALTAPAY_FIELD_SET_NAME = "wexoAltaPay";
2222
public const ALTAPAY_PAYMENT_METHOD_FIELD_SET_NAME = "wexoAltaPayPaymentMethod";
2323
public const ALTAPAY_CART_TOKEN = "wexoAltaPayCartToken";
24-
public const ALTAPAY_PLUGIN_VERSION = '2.0.7';
24+
public const ALTAPAY_PLUGIN_VERSION = '2.0.8';
2525
public const ALTAPAY_PLUGIN_NAME = 'WexoAltaPay';
2626

2727
public function update(UpdateContext $updateContext): void

0 commit comments

Comments
 (0)