From 3260fa657b0308145abbb81c64447e49e675f412 Mon Sep 17 00:00:00 2001 From: Martijn Date: Fri, 29 Nov 2024 13:40:27 +0100 Subject: [PATCH] fix(payments-plugin): False positive error logging fix --- .../src/mollie/mollie.service.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/payments-plugin/src/mollie/mollie.service.ts b/packages/payments-plugin/src/mollie/mollie.service.ts index 0e2dbea9ab..b9d62dabb5 100644 --- a/packages/payments-plugin/src/mollie/mollie.service.ts +++ b/packages/payments-plugin/src/mollie/mollie.service.ts @@ -279,15 +279,21 @@ export class MollieService { `Unable to find order ${mollieOrder.orderNumber}, unable to process Mollie order ${mollieOrder.id}`, ); } - if (mollieOrder.status === OrderStatus.expired) { - // Expired is fine, a customer can retry the payment later + const mollieStatesThatRequireAction: OrderStatus[] = [ + OrderStatus.completed, + OrderStatus.authorized, + OrderStatus.paid, + ]; + if (!mollieStatesThatRequireAction.includes(mollieOrder.status)) { + // No need to handle this mollie webhook status + Logger.info( + `Ignoring Mollie status '${mollieOrder.status}' from incoming webhook for '${order.code}'`, + loggerCtx, + ); return; } if (order.orderPlacedAt) { - // Verify if the Vendure order isn't already paid for, and log if so - const paymentWithSameTransactionId = order.payments.find( - p => p.transactionId === mollieOrder.id && p.state === 'Settled', - ); + const paymentWithSameTransactionId = order.payments.find(p => p.transactionId === mollieOrder.id); if (!paymentWithSameTransactionId) { // The order is paid for again, with another transaction ID. This means the customer paid twice Logger.error( @@ -297,14 +303,14 @@ export class MollieService { return; } } - const statesThatRequireAction: OrderState[] = [ + const vendureStatesThatRequireAction: OrderState[] = [ 'AddingItems', 'ArrangingPayment', 'ArrangingAdditionalPayment', 'PaymentAuthorized', 'Draft', ]; - if (!statesThatRequireAction.includes(order.state)) { + if (!vendureStatesThatRequireAction.includes(order.state)) { // If order is not in one of these states, we don't need to handle the Mollie webhook Logger.info( `Order ${order.code} is already '${order.state}', no need for handling Mollie status '${mollieOrder.status}'`,