Browse Source

fix(payments-plugin): Mollie - ignore completed state to prevent unneccesary error throwing (#2569)

Martijn 2 years ago
parent
commit
ed80c6848e
1 changed files with 6 additions and 1 deletions
  1. 6 1
      packages/payments-plugin/src/mollie/mollie.service.ts

+ 6 - 1
packages/payments-plugin/src/mollie/mollie.service.ts

@@ -184,7 +184,7 @@ export class MollieService {
             orderInput.method = molliePaymentMethodCode as MollieClientMethod;
         }
         const mollieOrder = await mollieClient.orders.create(orderInput);
-        Logger.info(`Created Mollie order ${mollieOrder.id} for order ${order.code}`);
+        Logger.info(`Created Mollie order ${mollieOrder.id} for order ${order.code}`, loggerCtx);
         const url = mollieOrder.getCheckoutUrl();
         if (!url) {
             throw Error('Unable to getCheckoutUrl() from Mollie order');
@@ -255,6 +255,11 @@ export class MollieService {
         if (order.state === 'PaymentAuthorized' && mollieOrder.status === OrderStatus.completed) {
             return this.settleExistingPayment(ctx, order, mollieOrder.id);
         }
+        if (autoCapture && mollieOrder.status === OrderStatus.completed) {
+            // When autocapture is enabled, we should not handle the completed status from Mollie,
+            // because the order will be transitioned to PaymentSettled during auto capture
+            return;
+        }
         // Any other combination of Mollie status and Vendure status indicates something is wrong.
         throw Error(
             `Unhandled incoming Mollie status '${mollieOrder.status}' for order ${order.code} with status '${order.state}'`,