medusajs/medusa · warning

Skipping refund of payment ${paymentSession.payment.id}: a l

Error message

Skipping refund of payment ${paymentSession.payment.id}: a later completion attempt already placed order ${orderCartLink.order_id} for cart ${cartId}.

What it means

In the cart completion payment-compensation step, when a payment needs to be refunded/canceled the flow first checks whether the cart already has a linked order. A later or concurrent completion attempt may have already succeeded and placed the order using that payment; refunding it would break the placed order, so the refund is skipped with this warning.

Source

Thrown at packages/core/core-flows/src/cart/steps/compensate-payment-if-needed.ts:86

        entity: "cart_payment_collection",
        fields: ["cart_id"],
        filters: {
          payment_collection_id: paymentSession.payment_collection_id,
        },
      })

      const cartId = cartPaymentCollectionLink?.cart_id
      if (cartId) {
        const {
          data: [orderCartLink],
        } = await query.graph({
          entity: "order_cart",
          fields: ["order_id"],
          filters: { cart_id: cartId },
        })

        if (orderCartLink?.order_id) {
          logger.warn(
            `Skipping refund of payment ${paymentSession.payment.id}: a later completion attempt already placed order ${orderCartLink.order_id} for cart ${cartId}.`
          )
          return
        }
      }

      try {
        const workflowInput = {
          payment_collection_id: paymentSession.payment_collection_id,
          provider_id: paymentSession.provider_id,
          customer_id: paymentSession.payment?.customer?.id,
          data: paymentSession.data,
          amount: paymentSession.raw_amount ?? paymentSession.amount,
          payment_id: paymentSession.payment.id,
          note: "Refunded due to cart completion failure",
        }

        await refundPaymentAndRecreatePaymentSessionWorkflow(container).run({

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Treat this warning as expected under concurrency: verify the order exists via the order_cart link and confirm the payment status is captured for that order
  2. Debounce/guard the checkout submit button and make completion idempotent on cartId
  3. If a wrong payment got captured without an order, cancel/refund it manually via the admin or payment provider
Defensive patterns

Strategy: fallback

Validate before calling

// before completing, check for an existing order on the cart
const { data } = await query.graph({ entity: "order_cart", fields: ["order_id"], filters: { cart_id: cartId } })
if (data.length) { /* order already placed — return it instead of completing again */ }

Prevention

When it happens

Trigger: Two concurrent completeCartWorkflow runs for the same cart (double-click, retry, webhook + user action): the first fails after capturing payment, a compensation triggers, but the second attempt already created an order_cart link.

Common situations: Race conditions on checkout submit; idempotency retries; duplicate webhook-driven completion calls.

Related errors


AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27). Data as JSON: /api/errors/c31a3e835c707fc1. Report an issue: GitHub.