{"record":{"id":"c31a3e835c707fc1","repo":"medusajs/medusa","slug":"skipping-refund-of-payment-paymentsession-paymen","errorCode":null,"errorMessage":"Skipping refund of payment ${paymentSession.payment.id}: a later completion attempt already placed order ${orderCartLink.order_id} for cart ${cartId}.","messagePattern":"Skipping refund of payment (.+?): a later completion attempt already placed order (.+?) for cart (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/core/core-flows/src/cart/steps/compensate-payment-if-needed.ts","lineNumber":86,"sourceCode":"        entity: \"cart_payment_collection\",\n        fields: [\"cart_id\"],\n        filters: {\n          payment_collection_id: paymentSession.payment_collection_id,\n        },\n      })\n\n      const cartId = cartPaymentCollectionLink?.cart_id\n      if (cartId) {\n        const {\n          data: [orderCartLink],\n        } = await query.graph({\n          entity: \"order_cart\",\n          fields: [\"order_id\"],\n          filters: { cart_id: cartId },\n        })\n\n        if (orderCartLink?.order_id) {\n          logger.warn(\n            `Skipping refund of payment ${paymentSession.payment.id}: a later completion attempt already placed order ${orderCartLink.order_id} for cart ${cartId}.`\n          )\n          return\n        }\n      }\n\n      try {\n        const workflowInput = {\n          payment_collection_id: paymentSession.payment_collection_id,\n          provider_id: paymentSession.provider_id,\n          customer_id: paymentSession.payment?.customer?.id,\n          data: paymentSession.data,\n          amount: paymentSession.raw_amount ?? paymentSession.amount,\n          payment_id: paymentSession.payment.id,\n          note: \"Refunded due to cart completion failure\",\n        }\n\n        await refundPaymentAndRecreatePaymentSessionWorkflow(container).run({","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/core/core-flows/src/cart/steps/compensate-payment-if-needed.ts#L68-L104","documentation":"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.","triggerScenarios":"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.","commonSituations":"Race conditions on checkout submit; idempotency retries; duplicate webhook-driven completion calls.","solutions":["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","Debounce/guard the checkout submit button and make completion idempotent on cartId","If a wrong payment got captured without an order, cancel/refund it manually via the admin or payment provider"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// before completing, check for an existing order on the cart\nconst { data } = await query.graph({ entity: \"order_cart\", fields: [\"order_id\"], filters: { cart_id: cartId } })\nif (data.length) { /* order already placed — return it instead of completing again */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make cart completion idempotent: check for an existing order_cart link before calling completeCartWorkflow","Disable the submit button while completion is in flight to prevent double submits","Key retries by cartId and return the existing order on repeat calls"],"tags":["cart","payment","race-condition","compensation","core-flows"],"backgroundTag":"concurrent-duplicate-request","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}